diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiTestDataGenerator.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiTestDataGenerator.java index 0f5457757f..87f0bc79c1 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiTestDataGenerator.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiTestDataGenerator.java @@ -313,7 +313,6 @@ public static String createValidationExpression( } /** - * TODO BUG this method does not respect optional/required properties * Create validation expression using functions according to schema type and format. * * @param schema diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/integration/OpenApiClientIT.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/integration/OpenApiClientIT.java index f9831727b6..d111475007 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/integration/OpenApiClientIT.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/integration/OpenApiClientIT.java @@ -77,9 +77,6 @@ public void getPetById() { .get("/pet/1001") .queryParam("verbose", "true") .message() - // TODO BUG? - cannot check correlationId - // see: org/citrusframework/validation/DefaultMessageHeaderValidator.java:68 - // see: org.citrusframework.message.MessageHeaderUtils.isSpringInternalHeader .header("correlationIds", "1234abcd") .accept("@contains('application/json')@") ); @@ -109,10 +106,6 @@ public void getPetById_requiredParamsShouldBeGeneratedIfNotProvided() { .receive() .get("@matches('/pet/\\d+')@") .message() - // TODO BUG? - cannot check correlationId - // see: org/citrusframework/validation/DefaultMessageHeaderValidator.java:68 - // see: org.citrusframework.message.MessageHeaderUtils.isSpringInternalHeader - // .header("correlationId", "@matches('\\w+')@") ); variable("petId", "1001"); diff --git a/test-api-generator/citrus-test-api-generator-core/src/main/java/org/citrusframework/openapi/generator/JavaCitrusCodegen.java b/test-api-generator/citrus-test-api-generator-core/src/main/java/org/citrusframework/openapi/generator/JavaCitrusCodegen.java index a1c0de6e4c..a20840b5c7 100644 --- a/test-api-generator/citrus-test-api-generator-core/src/main/java/org/citrusframework/openapi/generator/JavaCitrusCodegen.java +++ b/test-api-generator/citrus-test-api-generator-core/src/main/java/org/citrusframework/openapi/generator/JavaCitrusCodegen.java @@ -267,62 +267,6 @@ public void preprocessOpenAPI(OpenAPI openAPI) { } } - public void setApiPrefix(String apiPrefix) { - this.apiPrefix = apiPrefix; - } - - public String getHttpClient() { - return httpClient; - } - - public void setHttpClient(String httpClient) { - this.httpClient = httpClient; - } - - public String getHttpPathPrefix() { - return httpPathPrefix; - } - - public void setHttpPathPrefix(String httpPathPrefix) { - this.httpPathPrefix = httpPathPrefix; - } - - public String getOpenapiSchema() { - return openapiSchema; - } - - public void setOpenapiSchema(String openapiSchema) { - this.openapiSchema = openapiSchema; - } - - public String getResourceFolder() { - return resourceFolder; - } - - public void setResourceFolder(String resourceFolder) { - this.resourceFolder = resourceFolder; - } - - public String getGeneratedSchemaFolder() { - return generatedSchemaFolder; - } - - public void setGeneratedSchemaFolder(String generatedSchemaFolder) { - this.generatedSchemaFolder = generatedSchemaFolder; - } - - public String getTargetXmlnsNamespace() { - return targetXmlnsNamespace; - } - - public void setTargetXmlnsNamespace(String targetXmlnsNamespace) { - this.targetXmlnsNamespace = targetXmlnsNamespace; - } - - public String getApiPrefix() { - return apiPrefix; - } - private void addRestSupportingFiles(final String citrusFolder, String schemaFolder) { supportingFiles.add(new SupportingFile("schema.mustache", schemaFolder, apiPrefix.toLowerCase() + "-api.xsd")); diff --git a/test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/gen/OpenapiPetstore.java b/test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/gen/OpenapiPetstore.java deleted file mode 100644 index e40075b73a..0000000000 --- a/test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/gen/OpenapiPetstore.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.citrusframework.openapi.generator.gen; - -import org.citrusframework.endpoint.Endpoint; -import org.citrusframework.http.client.HttpClient; -import org.citrusframework.openapi.OpenApiSpecification; -import org.citrusframework.openapi.actions.OpenApiClientActionBuilder; -import org.citrusframework.openapi.actions.OpenApiClientActionBuilder.OpenApiOperationBuilder; -import org.citrusframework.openapi.actions.OpenApiClientRequestActionBuilder; -import org.citrusframework.openapi.actions.OpenApiClientResponseActionBuilder; - -import java.util.function.UnaryOperator; - -import static org.citrusframework.spi.Resources.create; - -// TODO TAT-1291 is in api.mustache File - delete this class -public class OpenapiPetstore { - private static final OpenApiSpecification petstoreSpec = OpenApiSpecification.from( - create("src/test/resources/apis/petstore.yaml") - ); - - public static OpenapiPetstore openapiPetstore(HttpClient httpClient) { - return new OpenapiPetstore(httpClient); - } - - private final HttpClient httpClient; - - private OpenapiPetstore(HttpClient httpClient) { - this.httpClient = httpClient; - } - - public PetstoreAction getPetById() { - return petstoreAction(new GetPetByIdRequest()); - } - - private PetstoreAction petstoreAction(B requestBuilder) { - return new PetstoreAction<>(httpClient, petstoreSpec, requestBuilder); - } - - public static class GetPetByIdRequest extends OperationRequestBuilder { - @Override - public String getOperationId() { - return "getPetById"; - } - - public GetPetByIdRequest withPetId(String petId) { - openApiOperation.withParameter("petId", petId); - return this; - } - - public GetPetByIdRequest withCorrelationIds(String correlationIds) { - openApiOperation.withParameter("correlationIds", correlationIds); - return this; - } - - public GetPetByIdRequest withVerbose(boolean verbose) { - openApiOperation.withParameter("verbose", verbose); - return this; - } - } - - public static abstract class OperationRequestBuilder { - protected final OpenApiOperationBuilder openApiOperation = OpenApiOperationBuilder.operation(getOperationId()); - - public abstract String getOperationId(); - - public OpenApiOperationBuilder build() { - return openApiOperation; - } - } - - public static class PetstoreAction extends OpenApiClientActionBuilder { - private final T operation; - - private PetstoreAction(Endpoint httpClient, OpenApiSpecification specification, T operation) { - super(httpClient, specification); - this.operation = operation; - } - - public OpenApiClientRequestActionBuilder send(UnaryOperator builderProvider) { - var builder = builderProvider.apply(operation); - var send = send(builder.build()); - send.fork(true); - return send; - } - - public OpenApiClientResponseActionBuilder receive() { - return receive(operation.getOperationId(), "200"); - } - } -} diff --git a/test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/gen/OpenapiPetstoreTest.java b/test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/gen/OpenapiPetstoreTest.java deleted file mode 100644 index 4577e64541..0000000000 --- a/test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/gen/OpenapiPetstoreTest.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.citrusframework.openapi.generator.gen; - -import org.citrusframework.TestCaseRunner; -import org.citrusframework.annotations.CitrusResource; -import org.citrusframework.annotations.CitrusTest; -import org.citrusframework.config.CitrusSpringConfig; -import org.citrusframework.endpoint.EndpointConfiguration; -import org.citrusframework.http.client.HttpClient; -import org.citrusframework.http.client.HttpClientBuilder; -import org.citrusframework.http.client.HttpEndpointConfiguration; -import org.citrusframework.http.server.HttpServer; -import org.citrusframework.http.server.HttpServerBuilder; -import org.citrusframework.junit.jupiter.spring.CitrusSpringExtension; -import org.citrusframework.openapi.generator.gen.OpenapiPetstoreTest.Config; -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.junit.jupiter.api.extension.ExtendWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.http.HttpStatus; - -import static org.citrusframework.http.actions.HttpActionBuilder.http; -import static org.citrusframework.message.MessageType.JSON; -import static org.citrusframework.openapi.generator.gen.OpenapiPetstore.openapiPetstore; -import static org.citrusframework.validation.PathExpressionValidationContext.Builder.pathExpression; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.springframework.http.HttpStatus.OK; - -// TODO TAT-1291 can this test be removed? in favor of GetPetByIdIT.java -@ExtendWith(CitrusSpringExtension.class) -@SpringBootTest(classes = {PetStoreBeanConfiguration.class, CitrusSpringConfig.class, Config.class}) -class OpenapiPetstoreTest { - - @BeforeEach - public void beforeTest() { - } - - private final int port = SocketUtils.findAvailableTcpPort(8080); - - @BindToRegistry - private final HttpServer httpServer = new HttpServerBuilder() - .port(port) - .timeout(5000L) - .autoStart(true) - .defaultStatus(HttpStatus.NO_CONTENT) - .build(); - - @BindToRegistry - private final HttpClient httpClient = new HttpClientBuilder() - .requestUrl("http://localhost:%d".formatted(port)) - .build(); - - @Test - @CitrusTest - void testFluentGeneratedOpenapiAction(@CitrusResource TestCaseRunner runner) { - runner.$(openapiPetstore(httpClient) - .getPetById() - .send(request -> request - .withPetId("2002") - .withCorrelationIds("5599") - .withVerbose(true)) - ); - - respondPet(runner); - - runner.$(openapiPetstore(httpClient) - .getPetById() - .receive() - .message() - .validate(pathExpression() - .jsonPath("$.id", "2002") - .jsonPath("$.category.id", "2002") - .jsonPath("$.tags[0].name", "generated") - ) - ); - } - - private void respondPet(TestCaseRunner runner) { - runner.$(http().server(httpServer) - .receive() - .get("/pet/2002") - .message() - .queryParam("verbose", "true") - .header("correlationIds", "5599") - .accept("@contains('application/json')@")); - runner.$(http().server(httpServer) - .send() - .response(OK) - .message() - .body(""" - { - "id": ${petId}, - "name": "citrus:randomEnumValue('hasso','cutie','fluffy')", - "category": { - "id": ${petId}, - "name": "citrus:randomEnumValue('dog', 'cat', 'fish')" - }, - "photoUrls": [ "http://localhost:8080/photos/${petId}" ], - "tags": [ - { - "id": ${petId}, - "name": "generated" - } - ], - "status": "citrus:randomEnumValue('available', 'pending', 'sold')" - } - """) - .contentType("application/json").type(JSON)); - } - - @TestConfiguration - public static class Config { - - @Bean(name = {"applicationServiceClient", "petStoreEndpoint"}) - public HttpClient applicationServiceClient() { - HttpClient client = mock(HttpClient.class); - EndpointConfiguration endpointConfiguration = mock(EndpointConfiguration.class); - when(client.getEndpointConfiguration()).thenReturn(new HttpEndpointConfiguration()); - when(endpointConfiguration.getTimeout()).thenReturn(5000L); - return client; - } - } -}