BAEL-12 xmlBody into a variable

This commit is contained in:
Tomasz Lelek 2017-02-14 10:05:16 +01:00
parent a985a9fb5a
commit 24d0acbbd6
1 changed files with 3 additions and 2 deletions

View File

@ -58,16 +58,17 @@ public class HttpClientAdvancedConfiguration {
@Test @Test
public void givenClientThatSendDataInBody_whenSendXmlInBody_shouldReturn200() throws IOException { public void givenClientThatSendDataInBody_whenSendXmlInBody_shouldReturn200() throws IOException {
//given //given
String xmlBody = "<xml><id>1</id></xml>";
serviceMock.stubFor(post(urlEqualTo("/person")) serviceMock.stubFor(post(urlEqualTo("/person"))
.withHeader("Content-Type", equalTo("application/xml")) .withHeader("Content-Type", equalTo("application/xml"))
.withRequestBody(equalTo("<xml><id>1</id></xml>")) .withRequestBody(equalTo(xmlBody))
.willReturn(aResponse() .willReturn(aResponse()
.withStatus(200))); .withStatus(200)));
HttpClient httpClient = HttpClients.createDefault(); HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://localhost:8089/person"); HttpPost httpPost = new HttpPost("http://localhost:8089/person");
httpPost.setHeader("Content-Type", "application/xml"); httpPost.setHeader("Content-Type", "application/xml");
StringEntity xmlEntity = new StringEntity("<xml><id>1</id></xml>"); StringEntity xmlEntity = new StringEntity(xmlBody);
httpPost.setEntity(xmlEntity); httpPost.setEntity(xmlEntity);
//when //when