Skip to content

Commit 3c01725

Browse files
committed
[test] Further integration tests
1 parent dd4cc5e commit 3c01725

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

http-client-saxon/src/test/java/org/expath/httpclient/saxon/SendRequestFunctionIT.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,54 @@ public void simpleRequestGet() throws IOException, SaxonApiException, ParserConf
9999
assertSimpleRequest(endpoint, inputXmlFilename, expectedResultFilename);
100100
}
101101

102+
@Test
103+
public void simpleRequestPut() throws IOException, SaxonApiException, ParserConfigurationException {
104+
final String endpoint = "/simpleRequestPut";
105+
106+
// Stub the HTTP Server endpoint for this test
107+
wireMockRule.stubFor(
108+
put(endpoint)
109+
.withHeader("Content-Type", equalTo("application/xml; charset=UTF-8"))
110+
.withRequestBody(equalToXml("<data>hello</data>"))
111+
.willReturn(created()
112+
.withHeader("Content-Type", "application/xml")
113+
.withBody("<response>SUCCESS</response>"))
114+
);
115+
116+
// the EXPath HTTP Client request to test
117+
final String inputXmlFilename = "simple-request-put.input.xml";
118+
119+
// the expected result
120+
final String expectedResultFilename = "simple-request-put.expected.xml";
121+
122+
// perform the request and assert the result
123+
assertSimpleRequest(endpoint, inputXmlFilename, expectedResultFilename);
124+
}
125+
126+
@Test
127+
public void simpleRequestPost() throws IOException, SaxonApiException, ParserConfigurationException {
128+
final String endpoint = "/simpleRequestPost";
129+
130+
// Stub the HTTP Server endpoint for this test
131+
wireMockRule.stubFor(
132+
post(endpoint)
133+
.withHeader("Content-Type", equalTo("application/json"))
134+
.withRequestBody(equalToJson("{ \"key1\": \"value1\", \"key2\": \"value2\" }"))
135+
.willReturn(aResponse().withStatus(202)
136+
.withHeader("Content-Type", "application/xml")
137+
.withBody("<response>SUCCESS</response>"))
138+
);
139+
140+
// the EXPath HTTP Client request to test
141+
final String inputXmlFilename = "simple-request-post.input.xml";
142+
143+
// the expected result
144+
final String expectedResultFilename = "simple-request-post.expected.xml";
145+
146+
// perform the request and assert the result
147+
assertSimpleRequest(endpoint, inputXmlFilename, expectedResultFilename);
148+
}
149+
102150
private void assertSimpleRequest(final String endpoint, final String inputXmlFilename, final String expectedResultFilename) throws IOException, SaxonApiException, ParserConfigurationException {
103151
final String request;
104152
try (final InputStream isRequest = getClass().getResourceAsStream(inputXmlFilename)) {
@@ -112,13 +160,13 @@ private void assertSimpleRequest(final String endpoint, final String inputXmlFil
112160

113161
assertNotNull(result);
114162

115-
// START TEMP
163+
// NOTE(AR) - START DEBUG RESPONSE
116164
// final StringWriter stringWriter = new StringWriter();
117165
// Serializer serializer = PROCESSOR.newSerializer(stringWriter);
118166
// XdmNode source = PROCESSOR.newDocumentBuilder().wrap(result);
119167
// serializer.serializeNode(source);
120168
// System.out.println(stringWriter);
121-
// END TEMP
169+
// NOTE(AR) - END DEBUG RESPONSE
122170

123171
try (final InputStream is = getClass().getResourceAsStream(expectedResultFilename)) {
124172
final Source expected = Input.fromStream(is).build();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<result xmlns:http="http://expath.org/ns/http-client">
3+
<http:response message="Accepted" spent-millis="151" status="202">
4+
<http:header name="content-type" value="application/xml"/>
5+
<http:header name="matched-stub-id" value="453be29a-0054-4c16-8bb6-2f5607c0f369"/>
6+
<http:header name="transfer-encoding" value="chunked"/>
7+
<http:header name="server" value="Jetty(9.2.28.v20190418)"/>
8+
<http:body media-type="application/xml; charset=utf-8"/>
9+
</http:response>
10+
<response>SUCCESS</response>
11+
</result>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<http:request xmlns:http="http://expath.org/ns/http-client" href="${ENDPOINT_URL}" method="POST" default-charset="utf-8">
2+
<http:header name="Accept" value="*/*;charset=utf-8"/>
3+
<http:header name="Accept-Encoding" value="utf-8"/>
4+
<http:header name="Authorization" value="Bearer ${UUID}"/>
5+
<http:header name="Content-Type" value="application/json"/>
6+
<http:body media-type="text/plain">{ "key1": "value1", "key2": "value2" }</http:body>
7+
</http:request>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<result xmlns:http="http://expath.org/ns/http-client">
3+
<http:response message="Created" spent-millis="297" status="201">
4+
<http:header name="content-type" value="application/xml"/>
5+
<http:header name="matched-stub-id" value="fbef452b-a3f9-4bd5-8c93-219394b6e67c"/>
6+
<http:header name="vary" value="Accept-Encoding, User-Agent"/>
7+
<http:header name="transfer-encoding" value="chunked"/>
8+
<http:header name="server" value="Jetty(9.2.28.v20190418)"/>
9+
<http:body media-type="application/xml"/>
10+
</http:response>
11+
<response>SUCCESS</response>
12+
</result>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<http:request xmlns:http="http://expath.org/ns/http-client" href="${ENDPOINT_URL}" method="PUT">
2+
<http:body media-type="application/xml">
3+
<data>hello</data>
4+
</http:body>
5+
</http:request>

0 commit comments

Comments
 (0)