Skip to content

Commit

Permalink
Merge pull request #241 from RackerWilliams/fixed_template
Browse files Browse the repository at this point in the history
Fixed values not working in template parameters...
  • Loading branch information
wdschei authored Jul 25, 2016
2 parents ce548e2 + 17ae417 commit 39b80ff
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/src/main/resources/xsl/builder.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,12 @@
</xsl:choose>
</xsl:variable>
<xsl:variable name="templatePath" select="starts-with(@path,'{')" as="xsd:boolean"/>
<xsl:variable name="templatePathFixedValue" as="xsd:string?"
select="if ($templatePath) then check:paramForTemplatePath(.)/@fixed else ()"/>
<step>
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="$templatePath and check:isXSDURL(.)">
<xsl:when test="$templatePath and not($templatePathFixedValue) and check:isXSDURL(.)">
<xsl:text>URLXSD</xsl:text>
</xsl:when>
<xsl:otherwise>
Expand All @@ -478,6 +480,9 @@
<xsl:attribute name="id" select="generate-id()"/>
<xsl:attribute name="match">
<xsl:choose>
<xsl:when test="$templatePathFixedValue">
<xsl:value-of select="check:toRegExEscaped($templatePathFixedValue)"/>
</xsl:when>
<xsl:when test="$templatePath">
<xsl:call-template name="check:getTemplateMatch"/>
</xsl:when>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,39 @@ class ValidatorWADLSuite extends BaseValidatorSuite {
assertResultFailed(validator_INT.validate(request("GET","/a/7/d"),response,chain), 404)
}

//
// validator_FIXED allows a GET on /a/FOO/c. That is, the 2nd URI
// component may be the value FOO, but foo is described as a FIXED
// string. The validator is used in the following tests.
//
val validator_FIXED = Validator(
<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<grammars/>
<resources base="https://test.api.openstack.com">
<resource path="a/{foo}/c">
<param name="foo" style="template" type="xsd:string" fixed="FOO"/>
<method href="#getMethod" />
</resource>
</resources>
<method id="getMethod" name="GET">
<response status="200 203"/>
</method>
</application>
, assertConfig)

test ("GET on /a/FOO/c should pass with validator_FOO") {
validator_FIXED.validate(request("GET","/a/FOO/c"), response, chain)
}

test ("GET on /a/foo/c should fail on validator_FOO") {
assertResultFailed(validator_FIXED.validate(request("GET","/a/foo/c"), response, chain), 404)
}

test ("GET on /a/bar/c should fail on validator_FOO") {
assertResultFailed(validator_FIXED.validate(request("GET","/a/bar/c"), response, chain), 404)
}

//
// validator_RT allows:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,56 @@ class WADLCheckerSpec extends BaseCheckerSpec with LogAssertions {
assert (checker, URL("element2"), MethodFail)
}

scenario("The WADL contains a / path deeper in the URI structure (with sub elements one of which is a fixed template param)") {
Given("a WADL that contains a / path deeper in the URI structure")
val inWADL =
<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<grammars/>
<resources base="https://test.api.openstack.com">
<resource path="/">
<method name="GET">
<response status="200"/>
</method>
<resource path="{elm}">
<param name="elm" style="template" type="xsd:string" fixed="element"/>
<resource path="/">
<method name="GET">
<response status="200"/>
</method>
<resource path="element2">
<method name="POST">
<response status="200"/>
</method>
</resource>
</resource>
</resource>
</resource>
</resources>
</application>
val checker = builder.build (inWADL, stdConfig)
Then("The checker should contain an URL node and element2")
assert (checker, "count(/chk:checker/chk:step[@type='URL']) = 2")
And ("The checker should contain two GET methods")
assert (checker, "count(/chk:checker/chk:step[@type='METHOD' and @match='GET']) = 2")
And ("The checker should contain a POST methods")
assert (checker, "count(/chk:checker/chk:step[@type='METHOD' and @match='POST']) = 1")
And ("The checker should NOT contian URL steps with a match == '/'")
assert (checker, "count(/chk:checker/chk:step[@type='URL' and @match='/']) = 0")
And ("The URL path should exist from Start to the element")
assert (checker, Start, URL("element"), Method("GET"))
And ("The URL path should exist from Start to the element2")
assert (checker, Start, URL("element"), URL("element2"), Method("POST"))
And ("The URL path should exist from START directly to GET method")
assert (checker, Start, Method("GET"))
And ("The Start state and each URL state should contain a path to MethodFail and URLFail")
assert (checker, Start, URLFail)
assert (checker, Start, MethodFail)
assert (checker, URL("element"), URLFail)
assert (checker, URL("element"), MethodFail)
assert (checker, URL("element2"), URLFail)
assert (checker, URL("element2"), MethodFail)
}

scenario("The WADL contains a / path deeper in the URI structure (with sub elements and multiple nested '/')") {
Given("a WADL that contains a / path deeper in the URI structure")
Expand Down

0 comments on commit 39b80ff

Please sign in to comment.