Skip to content

Commit

Permalink
disable deprecated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sterchi Daniel committed Jul 5, 2024
1 parent 3b5d3f5 commit 276fb14
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@
//@ExtendWith({CitrusSpringExtension.class})
//@SpringBootTest(classes = {CitrusSpringConfig.class, GeneratedApiIT.Config.class})
//@TestPropertySource(
// properties = {"applicationServiceClient.basic.username=Max Mustermann",
// "applicationServiceClient.basic.password=Top secret"}
// properties = {"applicationServiceClient.basic.username=Max Mustermann",
// "applicationServiceClient.basic.password=Top secret"}
//)
class GeneratedApiIT {

// TODO TAT-1291 migrate tests

// @Autowired
// @Autowired
// private ApplicationContext applicationContext;
//
// @Autowired
Expand Down Expand Up @@ -567,55 +567,55 @@ class GeneratedApiIT {
// return receiveMessage;
// }
//
// public static class Config {
//
// @Bean(name = {"applicationServiceClient", "multipartTestEndpoint",
// "soapSampleStoreEndpoint", "petStoreEndpoint"})
// public HttpClient applicationServiceClient() {
// HttpClient clientMock = mock();
// EndpointConfiguration endpointConfigurationMock = mock();
// when(clientMock.getEndpointConfiguration()).thenReturn(new HttpEndpointConfiguration());
// when(endpointConfigurationMock.getTimeout()).thenReturn(5000L);
// return clientMock;
// }
//
// @Bean
// public ApiActionBuilderCustomizerService customizer() {
// return new ApiActionBuilderCustomizerService() {
// @Override
// public <T extends SendMessageActionBuilder<?, ?, ?>> T build(
// GeneratedApi generatedApi, TestAction action, TestContext context, T builder) {
// builder.getMessageBuilderSupport()
// .header("x-citrus-api-version", generatedApi.getApiVersion());
// return builder;
// }
// };
// }
//
// @Bean({"oas3", "testSchema"})
// public SimpleJsonSchema testSchema() {
// JsonSchema schemaMock = mock();
// SimpleJsonSchema jsonSchemaMock = mock();
//
// when(jsonSchemaMock.getSchema()).thenReturn(schemaMock);
//
// Set<ValidationMessage> okReport = new HashSet<>();
// when(schemaMock.validate(any())).thenReturn(okReport);
// return jsonSchemaMock;
// }
//
// @Bean
// public SimpleJsonSchema failingTestSchema() {
// JsonSchema schemaMock = mock();
// SimpleJsonSchema jsonSchemaMock = mock();
//
// when(jsonSchemaMock.getSchema()).thenReturn(schemaMock);
//
// Set<ValidationMessage> nokReport = new HashSet<>();
// nokReport.add(new ValidationMessage.Builder().customMessage(
// "This is a simulated validation error message").build());
// when(schemaMock.validate(any())).thenReturn(nokReport);
// return jsonSchemaMock;
// }
// }
public static class Config {

@Bean(name = {"applicationServiceClient", "multipartTestEndpoint",
"soapSampleStoreEndpoint", "petStoreEndpoint"})
public HttpClient applicationServiceClient() {
HttpClient clientMock = mock();
EndpointConfiguration endpointConfigurationMock = mock();
when(clientMock.getEndpointConfiguration()).thenReturn(new HttpEndpointConfiguration());
when(endpointConfigurationMock.getTimeout()).thenReturn(5000L);
return clientMock;
}

@Bean
public ApiActionBuilderCustomizerService customizer() {
return new ApiActionBuilderCustomizerService() {
@Override
public <T extends SendMessageActionBuilder<?, ?, ?>> T build(
GeneratedApi generatedApi, TestAction action, TestContext context, T builder) {
builder.getMessageBuilderSupport()
.header("x-citrus-api-version", generatedApi.getApiVersion());
return builder;
}
};
}

@Bean({"oas3", "testSchema"})
public SimpleJsonSchema testSchema() {
JsonSchema schemaMock = mock();
SimpleJsonSchema jsonSchemaMock = mock();

when(jsonSchemaMock.getSchema()).thenReturn(schemaMock);

Set<ValidationMessage> okReport = new HashSet<>();
when(schemaMock.validate(any())).thenReturn(okReport);
return jsonSchemaMock;
}

@Bean
public SimpleJsonSchema failingTestSchema() {
JsonSchema schemaMock = mock();
SimpleJsonSchema jsonSchemaMock = mock();

when(jsonSchemaMock.getSchema()).thenReturn(schemaMock);

Set<ValidationMessage> nokReport = new HashSet<>();
nokReport.add(new ValidationMessage.Builder().customMessage(
"This is a simulated validation error message").build());
when(schemaMock.validate(any())).thenReturn(nokReport);
return jsonSchemaMock;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
import org.citrusframework.annotations.CitrusResource;
import org.citrusframework.annotations.CitrusTest;
import org.citrusframework.config.CitrusSpringConfig;
import org.citrusframework.context.TestContext;
import org.citrusframework.http.client.HttpClient;
import org.citrusframework.http.client.HttpClientBuilder;
import org.citrusframework.http.server.HttpServer;
import org.citrusframework.http.server.HttpServerBuilder;
import org.citrusframework.junit.jupiter.spring.CitrusSpringSupport;
import org.citrusframework.message.Message;
import org.citrusframework.openapi.generator.rest.petstore.spring.PetStoreBeanConfiguration;
import org.citrusframework.spi.BindToRegistry;
import org.citrusframework.util.SocketUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ContextConfiguration;

import java.io.File;

import static org.assertj.core.api.Assertions.assertThat;
import static org.citrusframework.http.actions.HttpActionBuilder.http;
import static org.citrusframework.message.MessageType.JSON;
import static org.citrusframework.openapi.generator.rest.petstore.request.PetApi.openapiPetstore;
Expand All @@ -25,38 +31,14 @@


@CitrusSpringSupport
@ContextConfiguration(classes = {PetStoreBeanConfiguration.class, CitrusSpringConfig.class})
@ContextConfiguration(classes = {PetStoreBeanConfiguration.class, CitrusSpringConfig.class, GetPetByIdIT.Config.class})
class GetPetByIdIT {

private final int port = SocketUtils.findAvailableTcpPort(8080);

// private final MessageQueue inboundQueue = new DefaultMessageQueue("inboundQueue");
// private final EndpointAdapter endpointAdapter = new DirectEndpointAdapter(direct()
// .synchronous()
// .timeout(5000L)
// .queue(inboundQueue)
// .build());

@BindToRegistry
private final HttpClient httpClient = new HttpClientBuilder()
.requestUrl("http://localhost:%d".formatted(port))
.build();

// TODO TAT-1291 the GetPetByIdIT class gets instantiated twice, but the second time
// the httpServer, respectively the "endpoint", is not initialized correctly...
// why is the Test Class instantiated twice (once per testmethod?) anyway?!
@BindToRegistry
private final HttpServer httpServer = new HttpServerBuilder()
.port(port)
// .endpointAdapter(endpointAdapter)
.timeout(5000L)
.autoStart(true)
.defaultStatus(NO_CONTENT)
.build();

@BeforeEach
public void beforeTest() {
}
@Autowired
private HttpClient httpClient;

@Autowired
private HttpServer httpServer;

@Test
@CitrusTest
Expand Down Expand Up @@ -95,8 +77,6 @@ void testJsonFileBody(@CitrusResource TestCaseRunner runner) {
openapiPetstore(httpClient)
.getPetById()
.send(request -> request
// TODO
// .withBodyFile("org/citrusframework/openapi/generator/GeneratedApiTest/payloads/getPetByIdControlMessage1.json")
.withPetId(2002L)
.withCorrelationIds("5599")
.withVerbose(true)
Expand All @@ -105,16 +85,17 @@ void testJsonFileBody(@CitrusResource TestCaseRunner runner) {

respondPet(runner);

var expectedResponse = new File("src/test/resources/org/citrusframework/openapi/generator/GeneratedApiTest/payloads/getPetByIdControlMessage1.json");
runner.$(
openapiPetstore(httpClient)
.getPetById()
.receive()
.message()
.validate(
pathExpression()
.jsonPath("$.name", "Snoopy")
.jsonPath("$.id", 2002)
)
.validate((Message message, TestContext context) -> {
assertThat(expectedResponse).exists().content().satisfies(expectedContent -> {
assertThat(message.getPayload(String.class)).isEqualToIgnoringWhitespace(expectedContent);
});
})
);
}

Expand Down Expand Up @@ -147,78 +128,27 @@ private void respondPet(TestCaseRunner runner) {
.contentType("application/json").type(JSON));
}

/* @Test
@CitrusTest
void testValidationFailureByResource(@CitrusResource TestCaseRunner runner) {
// Given
getPetByIdRequest.setPetId("1234");
// Then
getPetByIdRequest.setResponseStatus(HttpStatus.OK.value());
getPetByIdRequest.setResponseReasonPhrase(HttpStatus.OK.getReasonPhrase());
// Assert body by resource
getPetByIdRequest.setResource(
"org/citrusframework/openapi/generator/GeneratedApiTest/payloads/getPetByIdControlMessage2.json");
// When
runner.$(assertException()
.exception(org.citrusframework.exceptions.CitrusRuntimeException.class)
.message("Values not equal for entry: '$['name']', expected 'Garfield' but was 'Snoopy'")
.when(
getPetByIdRequest
)
);
}
@Test
@CitrusTest
void validateByVariable(@CitrusResource TestContext testContext,
@CitrusResource TestCaseRunner runner) {
// Given
getPetByIdRequest.setPetId("1234");
// Then
getPetByIdRequest.setResponseStatus(HttpStatus.OK.value());
getPetByIdRequest.setResponseReasonPhrase(HttpStatus.OK.getReasonPhrase());
// Assert load data into variables
getPetByIdRequest.setResponseVariable(Map.of("$", "RESPONSE", "$.id", "ID"));
// When
runner.$(getPetByIdRequest);
// Then
assertThat(testContext)
.satisfies(
c -> assertThat(c.getVariable("RESPONSE"))
.isNotNull(),
c -> assertThat(c.getVariable("ID"))
.isNotNull()
.isEqualTo("12")
);
@TestConfiguration
public static class Config {

private final int port = SocketUtils.findAvailableTcpPort(8080);

@Bean
public HttpClient httpClient() {
return new HttpClientBuilder()
.requestUrl("http://localhost:%d".formatted(port))
.build();
}

@Bean
public HttpServer httpServer() {
return new HttpServerBuilder()
.port(port)
// .endpointAdapter(endpointAdapter)
.timeout(5000L)
.autoStart(true)
.defaultStatus(NO_CONTENT)
.build();
}
}
@Test
@CitrusTest
void validateReceivedResponse(@CitrusResource TestContext testContext) {
// Given
getPetByIdRequest.setPetId("1234");
// When
getPetByIdRequest.sendRequest(testContext);
// Then
Message receiveResponse = getPetByIdRequest.receiveResponse(testContext);
assertThat(receiveResponse)
.isNotNull()
.extracting(Message::getPayload)
.asString()
.isEqualToIgnoringWhitespace(defaultResponse);
assertThat(receiveResponse.getHeaders())
.containsEntry("citrus_http_status_code", 200)
.containsEntry("citrus_http_reason_phrase", "OK");
}*/
}
Loading

0 comments on commit 276fb14

Please sign in to comment.