@@ -4,11 +4,11 @@ import models.NodeImplicits.NodeEnhancer
4
4
import models .TestBase
5
5
import play .api .Application
6
6
import play .api .inject .guice .GuiceApplicationBuilder
7
- import play .api .libs .json .{Json , OFormat }
7
+ import play .api .libs .json .{ Json , OFormat }
8
8
import play .api .test .FakeRequest
9
9
import play .api .test .Helpers ._
10
10
import smithy4s .http .CaseInsensitive
11
- import testDefinitions .test .{XmlControllerDefGen , XmlTestInputBody , XmlTestOutput }
11
+ import testDefinitions .test .{ XmlControllerDefGen , XmlTestInputBody , XmlTestOutput }
12
12
13
13
import scala .concurrent .ExecutionContext .Implicits .global
14
14
@@ -33,6 +33,53 @@ class XmlControllerTest extends TestBase {
33
33
res.body.body.requiredTestStringConcat mustBe " ThisGetsConcat"
34
34
}
35
35
36
+ " route to xml with charset in header endpoint with smithy client" in {
37
+ val res = genericClient
38
+ .xmlTestWithInputAndOutput(
39
+ " Concat" ,
40
+ XmlTestInputBody (" 05.02.2024" , " ThisGets" , Some (10 )),
41
+ Some (" application/xml; charset=utf-8" )
42
+ )
43
+ .awaitRight
44
+
45
+ res.body.body.requiredIntSquared mustBe Some (100 )
46
+ res.body.body.requiredTestStringConcat mustBe " ThisGetsConcat"
47
+ res.headers.get(CaseInsensitive (" content-type" )) mustBe Some (List (" application/xml; charset=utf-8" ))
48
+ }
49
+
50
+ " route to xml with charset in header with external client" in {
51
+ val concatVal1 = " ConcatThis"
52
+ val concatVal2 = " Test2"
53
+ val squareTest = 3
54
+ val xml =
55
+ <XmlTestInputBody serverzeit =" 05.02.2024" >
56
+ <requiredTest >{concatVal1}</requiredTest >
57
+ <requiredInt >{squareTest}</requiredInt >
58
+ </XmlTestInputBody >
59
+ val request = route(
60
+ app,
61
+ FakeRequest (" POST" , s " /xml/ $concatVal2" )
62
+ .withHeaders((" content-type" , " application/xml; charset=utf-8" ))
63
+ .withXmlBody(
64
+ xml
65
+ )
66
+ ).get
67
+ status(request) mustBe 200
68
+
69
+ val result = scala.xml.XML .loadString(contentAsString(request))
70
+ val resContentType = contentType(request)
71
+ val resCharset = charset(request)
72
+
73
+
74
+ result.normalize mustBe <XmlTestOutput serverzeit =" 05.02.2024" >
75
+ <requiredTestStringConcat >
76
+ {concatVal1 + concatVal2}</requiredTestStringConcat >
77
+ <requiredIntSquared >
78
+ {squareTest * squareTest}</requiredIntSquared >
79
+ </XmlTestOutput >.normalize
80
+ resContentType.map(_ + " ; charset=" + resCharset.getOrElse(" " )) mustBe Some (" application/xml; charset=utf-8" )
81
+ }
82
+
36
83
" route to xml test endpoint with external client" in {
37
84
val concatVal1 = " ConcatThis"
38
85
val concatVal2 = " Test2"
@@ -115,13 +162,13 @@ class XmlControllerTest extends TestBase {
115
162
}
116
163
117
164
" route to test endpoint with external client and json protocol" in {
118
- implicit val formatI : OFormat [XmlTestInputBody ] = Json .format[XmlTestInputBody ]
119
- implicit val formatO : OFormat [XmlTestOutput ] = Json .format[XmlTestOutput ]
120
- val concatVal2 = " Test2"
121
- val concatVal1 = " ConcatThis"
122
- val squareTest = Some (15 )
123
- val date = " 05.02.2024"
124
- val request = route(
165
+ implicit val formatI : OFormat [XmlTestInputBody ] = Json .format[XmlTestInputBody ]
166
+ implicit val formatO : OFormat [XmlTestOutput ] = Json .format[XmlTestOutput ]
167
+ val concatVal2 = " Test2"
168
+ val concatVal1 = " ConcatThis"
169
+ val squareTest = Some (15 )
170
+ val date = " 05.02.2024"
171
+ val request = route(
125
172
app,
126
173
FakeRequest (" POST" , s " /xml/ $concatVal2" )
127
174
.withHeaders((" content-type" , " application/json" ))
@@ -130,7 +177,7 @@ class XmlControllerTest extends TestBase {
130
177
)
131
178
).get
132
179
status(request) mustBe 200
133
- val result = contentAsJson(request).as[XmlTestOutput ]
180
+ val result = contentAsJson(request).as[XmlTestOutput ]
134
181
result.requiredTestStringConcat mustBe concatVal1 + concatVal2
135
182
result.requiredIntSquared mustBe squareTest.map(s => s * s)
136
183
result.serverzeit mustBe date
0 commit comments