Skip to content

Commit 0bf3b6a

Browse files
add multi schema elements saxon tests with byte code generation disabled
1 parent a5436c9 commit 0bf3b6a

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

core/src/test/scala/com/rackspace/com/papi/components/checker/MultiSchemaElementsBaseSuite.scala

+19-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.rackspace.com.papi.components.checker
1818
import com.rackspace.com.papi.components.checker.Converters._
1919
import com.rackspace.com.papi.components.checker.servlet.RequestAttributes._
2020
import org.w3c.dom.Document
21+
import scala.xml.XML
2122

2223
abstract class MultiSchemaElementsBaseSuite extends BaseValidatorSuite {
2324
val wadl_SimpleSame =
@@ -208,11 +209,14 @@ abstract class MultiSchemaElementsBaseSuite extends BaseValidatorSuite {
208209
}
209210
}
210211

211-
def createConfigWithSaxonEE(enabled: Boolean): Config = {
212+
def createConfigWithSaxonEE(enabled: Boolean, disableByteCodeGen: Boolean = false): Config = {
212213
val config = new Config
213214

214215
if (enabled) {
215216
config.xsdEngine = "SaxonEE"
217+
if (disableByteCodeGen) {
218+
config.disableSaxonByteCodeGen = disableByteCodeGen
219+
}
216220
}
217221
config.removeDups = true // -d Wadl2Checker default is different from Config default.
218222
config.checkWellFormed = true // -w
@@ -327,4 +331,18 @@ abstract class MultiSchemaElementsBaseSuite extends BaseValidatorSuite {
327331
}
328332
}
329333
}
334+
335+
def assertions_Repeat(validator: Validator, generateByteCode: Boolean, useSaxon: Boolean) {
336+
for (i <- 1 to 50) {
337+
test("POST repeated requests with valid XML One should succeed, count : " + i) {
338+
val node = XML.loadString(s"""<e xmlns="http://www.rackspace.com/repose/wadl/element/one/test">
339+
<id>$i</id>
340+
</e>""")
341+
val req = request("POST", "/test", "application/xml", node)
342+
validator.validate(req, response, chain)
343+
val dom = req.getAttribute(PARSED_XML).asInstanceOf[Document]
344+
assert((dom \ "id").text == i.toString)
345+
}
346+
}
347+
}
330348
}

core/src/test/scala/com/rackspace/com/papi/components/checker/MultiSchemaElementsSuiteSaxonEE.scala

+8
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ class MultiSchemaElementsSuiteSaxonEE extends MultiSchemaElementsBaseSuite {
2828
val validator_SimpleDiff = Validator((localWADLURI, wadl_SimpleDiff), config)
2929
val validator_ElementSame = Validator((localWADLURI, wadl_ElementSame), config)
3030
val validator_ElementDiff = Validator((localWADLURI, wadl_ElementDiff), config)
31+
val validator_ElementRepeat = Validator((localWADLURI, wadl_ElementSame), config)
32+
33+
assert(validator_SimpleSame.config.disableSaxonByteCodeGen == false)
34+
assert(validator_SimpleDiff.config.disableSaxonByteCodeGen == false)
35+
assert(validator_ElementSame.config.disableSaxonByteCodeGen == false)
36+
assert(validator_ElementDiff.config.disableSaxonByteCodeGen == false)
37+
assert(validator_ElementRepeat.config.disableSaxonByteCodeGen == false)
3138

3239
assertions_Simple(validator_SimpleSame, true, useSaxon)
3340
assertions_Simple(validator_SimpleDiff, false, useSaxon)
3441
assertions_Element(validator_ElementSame, true, useSaxon)
3542
assertions_Element(validator_ElementDiff, false, useSaxon)
43+
assertions_Repeat(validator_ElementRepeat, true, useSaxon) // TODO: update to large enough wadl schema in order to crash saxon when byte code generation is triggered.
3644
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/** *
2+
* Copyright 2024 Rackspace US, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.rackspace.com.papi.components.checker
17+
18+
import com.rackspace.cloud.api.wadl.Converters._
19+
import org.junit.runner.RunWith
20+
import org.scalatestplus.junit.JUnitRunner
21+
22+
@RunWith(classOf[JUnitRunner])
23+
class MultiSchemaElementsSuiteSaxonEEDisabledByteCodeGen extends MultiSchemaElementsBaseSuite {
24+
val useSaxon = true
25+
val disableByteCodeGen = true
26+
val config = createConfigWithSaxonEE(useSaxon, disableByteCodeGen)
27+
28+
val validator_SimpleSame = Validator((localWADLURI, wadl_SimpleSame), config)
29+
val validator_SimpleDiff = Validator((localWADLURI, wadl_SimpleDiff), config)
30+
val validator_ElementSame = Validator((localWADLURI, wadl_ElementSame), config)
31+
val validator_ElementDiff = Validator((localWADLURI, wadl_ElementDiff), config)
32+
val validator_ElementRepeat = Validator((localWADLURI, wadl_ElementSame), config)
33+
34+
assert(validator_SimpleSame.config.disableSaxonByteCodeGen == true)
35+
assert(validator_SimpleDiff.config.disableSaxonByteCodeGen == true)
36+
assert(validator_ElementSame.config.disableSaxonByteCodeGen == true)
37+
assert(validator_ElementDiff.config.disableSaxonByteCodeGen == true)
38+
assert(validator_ElementRepeat.config.disableSaxonByteCodeGen == true)
39+
40+
assertions_Simple(validator_SimpleSame, true, useSaxon)
41+
assertions_Simple(validator_SimpleDiff, false, useSaxon)
42+
assertions_Element(validator_ElementSame, true, useSaxon)
43+
assertions_Element(validator_ElementDiff, false, useSaxon)
44+
assertions_Repeat(validator_ElementRepeat, false, useSaxon)
45+
}

0 commit comments

Comments
 (0)