Skip to content

Commit 24d0acb

Browse files
author
Tomasz Lelek
committed
BAEL-12 xmlBody into a variable
1 parent a985a9f commit 24d0acb

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

httpclient/src/test/java/org/baeldung/httpclient/advancedconfig/HttpClientAdvancedConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ public void givenClientWithCustomUserAgentHeader_whenExecuteRequest_shouldReturn
5858
@Test
5959
public void givenClientThatSendDataInBody_whenSendXmlInBody_shouldReturn200() throws IOException {
6060
//given
61+
String xmlBody = "<xml><id>1</id></xml>";
6162
serviceMock.stubFor(post(urlEqualTo("/person"))
6263
.withHeader("Content-Type", equalTo("application/xml"))
63-
.withRequestBody(equalTo("<xml><id>1</id></xml>"))
64+
.withRequestBody(equalTo(xmlBody))
6465
.willReturn(aResponse()
6566
.withStatus(200)));
6667

6768
HttpClient httpClient = HttpClients.createDefault();
6869
HttpPost httpPost = new HttpPost("http://localhost:8089/person");
6970
httpPost.setHeader("Content-Type", "application/xml");
70-
StringEntity xmlEntity = new StringEntity("<xml><id>1</id></xml>");
71+
StringEntity xmlEntity = new StringEntity(xmlBody);
7172
httpPost.setEntity(xmlEntity);
7273

7374
//when

0 commit comments

Comments
 (0)