Skip to content

Commit 63fa80a

Browse files
author
Jorge L. Williams
committed
Tests to confirm that the case of a header name does not matter.
1 parent 4e6e72d commit 63fa80a

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

RELEASE.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Releases #
22
## In Progress Work ##
33
1. Fixed a bug where adding extra whitespace in the ```rax:roles``` attribute caused errors.
4+
1. Clean up : Added simple tests to confirm case of a header param name is irrelevant.
45

56
## Release 2.6.0 (2018-02-12) ##
67
1. Added support for ```rax:representation```, this works like ```wadl:representation``` in that it can make assertions about XML, JSON representations. With ```rax:representation```, the representation may be embedded in another representation (JSON in XML), or in a header.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/***
2+
* Copyright 2016 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.wadl
17+
18+
import com.rackspace.com.papi.components.checker.{LogAssertions, Config}
19+
import org.apache.logging.log4j.Level
20+
import org.junit.runner.RunWith
21+
import org.scalatest.junit.JUnitRunner
22+
23+
24+
@RunWith(classOf[JUnitRunner])
25+
class WADLCheckerHeaderNameSpec extends BaseCheckerSpec {
26+
27+
register ("xsd", "http://www.w3.org/2001/XMLSchema")
28+
register ("chk","http://www.rackspace.com/repose/wadl/checker")
29+
30+
val tstConfig = {
31+
val c = new Config
32+
c.checkHeaders = true
33+
c.removeDups = true
34+
c
35+
}
36+
37+
feature ("The WADLCheckerBuilder can correctly transforma a WADL into checker format") {
38+
39+
info ("As a developer")
40+
info ("I want to be able to transform a WADL which references multiple headers")
41+
info ("without worring about the case of the header name")
42+
43+
scenario ("The WADL contains header single with different cases (remove dups is enabled)") {
44+
Given("A WADL that contains multiple header checks with the same name written in different cases")
45+
val inWADL =
46+
<application xmlns="http://wadl.dev.java.net/2009/02"
47+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
48+
<resources>
49+
<resource path="/path/to/resource">
50+
<param name="X-FOO" fixed="FOO" style="header" repeating="false" required="true"/>
51+
<param name="X-BAR" fixed="BAR" style="header" repeating="false" required="true"/>
52+
<param name="X-BaR" fixed="CAR" style="header" repeating="false" required="true"/>
53+
<param name="X-Bar" fixed="SCAR" style="header" repeating="false" required="true"/>
54+
<param name="x-bar" fixed="bar" style="header" repeating="false" required="true"/>
55+
<param name="X-FoO" fixed="FoO" style="header" repeating="false" required="true"/>
56+
<method name="GET"/>
57+
</resource>
58+
</resources>
59+
</application>
60+
When ("the WADL is translated")
61+
val checker = builder.build(inWADL, tstConfig)
62+
Then ("Headers with the same name should be treated equally")
63+
assert (checker, "count(/chk:checker/chk:step[@type='HEADER_SINGLE' and @name='X-FOO']) = 1")
64+
assert (checker, "/chk:checker/chk:step[@type='HEADER_SINGLE' and @name='X-FOO']/@match ='FOO|FoO'")
65+
assert (checker, "count(/chk:checker/chk:step[@type='HEADER_SINGLE' and @name='X-BAR']) = 1")
66+
assert (checker, "/chk:checker/chk:step[@type='HEADER_SINGLE' and @name='X-BAR']/@match ='BAR|CAR|SCAR|bar'")
67+
}
68+
69+
70+
scenario ("The WADL contains header any with different cases (remove dups is enabled)") {
71+
Given("A WADL that contains multiple header checks with the same name written in different cases")
72+
val inWADL =
73+
<application xmlns="http://wadl.dev.java.net/2009/02"
74+
xmlns:rax="http://docs.rackspace.com/api"
75+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
76+
<resources>
77+
<resource path="/path/to/resource">
78+
<param name="X-FOO" fixed="FOO" style="header" repeating="true" required="true" rax:anyMatch="true"/>
79+
<param name="X-BAR" fixed="BAR" style="header" repeating="true" required="true" rax:anyMatch="true"/>
80+
<param name="X-BaR" fixed="CAR" style="header" repeating="true" required="true" rax:anyMatch="true"/>
81+
<param name="X-Bar" fixed="SCAR" style="header" repeating="true" required="true" rax:anyMatch="true"/>
82+
<param name="x-bar" fixed="bar" style="header" repeating="true" required="true" rax:anyMatch="true"/>
83+
<param name="X-FoO" fixed="FoO" style="header" repeating="true" required="true" rax:anyMatch="true"/>
84+
<method name="GET"/>
85+
</resource>
86+
</resources>
87+
</application>
88+
When ("the WADL is translated")
89+
val checker = builder.build(inWADL, tstConfig)
90+
Then ("Headers with the same name should be treated equally")
91+
assert (checker, "count(/chk:checker/chk:step[@type='HEADER_ANY' and @name='X-FOO']) = 1")
92+
assert (checker, "/chk:checker/chk:step[@type='HEADER_ANY' and @name='X-FOO']/@match ='FOO|FoO'")
93+
assert (checker, "count(/chk:checker/chk:step[@type='HEADER_ANY' and @name='X-BAR']) = 1")
94+
assert (checker, "/chk:checker/chk:step[@type='HEADER_ANY' and @name='X-BAR']/@match ='BAR|CAR|SCAR|bar'")
95+
}
96+
97+
98+
scenario ("The WADL contains header all with different cases (remove dups is enabled)") {
99+
Given("A WADL that contains multiple header checks with the same name written in different cases")
100+
val inWADL =
101+
<application xmlns="http://wadl.dev.java.net/2009/02"
102+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
103+
<resources>
104+
<resource path="/path/to/resource">
105+
<param name="X-FOO" fixed="FOO" style="header" repeating="true" required="true"/>
106+
<param name="X-BAR" fixed="BAR" style="header" repeating="true" required="true"/>
107+
<param name="X-BaR" fixed="CAR" style="header" repeating="true" required="true"/>
108+
<param name="X-Bar" fixed="SCAR" style="header" repeating="true" required="true"/>
109+
<param name="x-bar" fixed="bar" style="header" repeating="true" required="true"/>
110+
<param name="X-FoO" fixed="FoO" style="header" repeating="true" required="true"/>
111+
<method name="GET"/>
112+
</resource>
113+
</resources>
114+
</application>
115+
When ("the WADL is translated")
116+
val checker = builder.build(inWADL, tstConfig)
117+
Then ("Headers with the same name should be treated equally")
118+
assert (checker, "count(/chk:checker/chk:step[@type='HEADER_ALL' and @name='X-FOO']) = 1")
119+
assert (checker, "/chk:checker/chk:step[@type='HEADER_ALL' and @name='X-FOO']/@matchRegEx ='FOO|FoO'")
120+
assert (checker, "count(/chk:checker/chk:step[@type='HEADER_ALL' and @name='X-BAR']) = 1")
121+
assert (checker, "/chk:checker/chk:step[@type='HEADER_ALL' and @name='X-BAR']/@matchRegEx ='BAR|CAR|SCAR|bar'")
122+
}
123+
124+
}
125+
126+
}

0 commit comments

Comments
 (0)