Skip to content

Commit

Permalink
chore: cleanup send helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Nov 30, 2023
1 parent c204d66 commit 54520f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public HttpServerActionBuilder.HttpServerSendActionBuilder send() {
*/
public HttpMessageBuilderSupport sendOkJson(String json) {
return server(scenarioEndpoint)
.send()
.response(HttpStatus.OK)
.respond(HttpStatus.OK)
.message()
.contentType(MediaType.APPLICATION_JSON_VALUE)
.body(json);
Expand All @@ -60,17 +59,10 @@ public HttpMessageBuilderSupport sendOkJson(String json) {
* @return
*/
public HttpMessageBuilderSupport sendOkJson(Object jsonObject) {
HttpMessageBuilderSupport httpMessageBuilderSupport = server(scenarioEndpoint).send()
.response(HttpStatus.OK)
.message()
.contentType(MediaType.APPLICATION_JSON_VALUE);

try {
httpMessageBuilderSupport.body(OBJECT_MAPPER.writeValueAsString(jsonObject));
return sendOkJson(OBJECT_MAPPER.writeValueAsString(jsonObject));
} catch (JsonProcessingException e) {
throw new CitrusRuntimeException(e);
}

return httpMessageBuilderSupport;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package org.citrusframework.simulator.http;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.citrusframework.http.actions.HttpServerResponseActionBuilder.HttpMessageBuilderSupport;
import org.citrusframework.http.message.HttpMessage;
import org.citrusframework.simulator.scenario.ScenarioEndpoint;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;

@ExtendWith(MockitoExtension.class)
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

class HttpScenarioActionBuilderTest {

private static final TestJsonObject JSON_OBJECT_REPRESENTATION = new TestJsonObject("value");
Expand All @@ -24,23 +20,20 @@ class HttpScenarioActionBuilderTest {
"property" : "value"
}""";

@Mock
private ScenarioEndpoint scenarioEndpointMock;

private HttpScenarioActionBuilder fixture;

private static void verifyOkJsonResponse(HttpMessageBuilderSupport httpMessageBuilderSupport) {
HttpMessage httpMessage = (HttpMessage) ReflectionTestUtils.getField(httpMessageBuilderSupport, "httpMessage");
assertNotNull(httpMessage);

assertEquals(HttpStatus.OK, httpMessage.getStatusCode());
assertEquals(MediaType.APPLICATION_JSON_VALUE, httpMessage.getContentType());
assertEquals(JSON_STRING_REPRESENTATION, httpMessage.getPayload(String.class).replace("\r\n", "\n"));
assertThat(httpMessageBuilderSupport).extracting("httpMessage")
.isInstanceOfSatisfying(HttpMessage.class, httpMessage -> {
assertEquals(HttpStatus.OK, httpMessage.getStatusCode());
assertEquals(MediaType.APPLICATION_JSON_VALUE, httpMessage.getContentType());
assertEquals(JSON_STRING_REPRESENTATION, httpMessage.getPayload(String.class).replace("\r\n", "\n"));
});
}

@BeforeEach
void beforeEachSetup() {
fixture = new HttpScenarioActionBuilder(scenarioEndpointMock);
fixture = new HttpScenarioActionBuilder(mock(ScenarioEndpoint.class));
}

@Test
Expand Down

0 comments on commit 54520f6

Please sign in to comment.