This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit e3a922157340c4e41787835852b7ea4bfb050c86 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri May 23 08:07:10 2025 +0200 Fixed test --- .../org/apache/camel/openapi/ComplexTypesTest.java | 161 -------------------- .../openapi/V2SchemaForComplexTypesRequest.json | 158 ------------------- .../openapi/V2SchemaForComplexTypesResponse.json | 101 ------------- .../openapi/V3SchemaForComplexTypesRequest.json | 167 --------------------- .../openapi/V3SchemaForComplexTypesResponse.json | 110 -------------- 5 files changed, 697 deletions(-) diff --git a/components-starter/camel-openapi-java-starter/src/test/java/org/apache/camel/openapi/ComplexTypesTest.java b/components-starter/camel-openapi-java-starter/src/test/java/org/apache/camel/openapi/ComplexTypesTest.java deleted file mode 100644 index f6ca5c5f270..00000000000 --- a/components-starter/camel-openapi-java-starter/src/test/java/org/apache/camel/openapi/ComplexTypesTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.openapi; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.apache.camel.BindToRegistry; -import org.apache.camel.CamelContext; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.engine.DefaultClassResolver; -import org.apache.camel.model.ModelCamelContext; -import org.apache.camel.model.rest.RestBindingMode; -import org.apache.camel.model.rest.RestDefinition; -import org.apache.camel.openapi.model.SampleComplexRequestType; -import org.apache.camel.openapi.model.SampleComplexResponseType; -import org.apache.camel.spring.boot.CamelAutoConfiguration; -import org.apache.camel.test.spring.junit5.CamelSpringBootTest; - -import org.junit.jupiter.api.Test; - -import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONCompareMode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.annotation.DirtiesContext; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.stream.Collectors; - -import io.swagger.v3.oas.models.OpenAPI; - -@DirtiesContext -@CamelSpringBootTest -@SpringBootTest(classes = { CamelAutoConfiguration.class, ComplexTypesTest.class, - ComplexTypesTest.TestConfiguration.class, DummyRestConsumerFactory.class }) -public class ComplexTypesTest { - private static final Logger LOG = LoggerFactory.getLogger(ComplexTypesTest.class); - - @SuppressWarnings("unused") - @BindToRegistry("dummy-rest") - private final DummyRestConsumerFactory factory = new DummyRestConsumerFactory(); - - @Autowired - CamelContext context; - - // ************************************* - // Config - // ************************************* - - @Configuration - public class TestConfiguration { - - @Bean - public RouteBuilder routeBuilder() { - return new RouteBuilder() { - - @Override - public void configure() throws Exception { - rest().securityDefinitions().oauth2("global") - .accessCode("https://AUTHORIZATION_URL", "https://TOKEN_URL") - .withScope("groups", "Required scopes for Camel REST APIs"); - - rest().post("/complexRequest").description("Demo complex request type") - .type(SampleComplexRequestType.class).consumes("application/json").produces("text/plain") - .bindingMode(RestBindingMode.json).responseMessage().code(200) - .message("Receives a complex object as parameter").endResponseMessage() - .outType(SampleComplexResponseType.InnerClass.class).to("direct:request"); - from("direct:request").routeId("complex request type").log("/complex request invoked"); - - rest().get("/complexResponse").description("Demo complex response type") - .type(SampleComplexRequestType.InnerClass.class).consumes("application/json") - .outType(SampleComplexResponseType.class).produces("application/json") - .bindingMode(RestBindingMode.json).responseMessage().code(200) - .message("Returns a complex object").endResponseMessage().to("direct:response"); - - from("direct:response").routeId("complex response type").log("/complex invoked") - .setBody(constant(new SampleComplexResponseType())); - } - }; - } - } - - @Test - public void testV3SchemaForComplexTypesRequest() throws Exception { - checkSchemaGeneration("/complexRequest", "3.0", "V3SchemaForComplexTypesRequest.json"); - } - - @Test - public void testV3SchemaForComplexTypesResponse() throws Exception { - checkSchemaGeneration("/complexResponse", "3.0", "V3SchemaForComplexTypesResponse.json"); - } - - private void checkSchemaGeneration(String uri, String apiVersion, String schemaResource) throws Exception { - BeanConfig config = getBeanConfig(apiVersion); - - List<RestDefinition> rests = ((ModelCamelContext) context).getRestDefinitions().stream() - // So we get the security schema and the route schema - .filter(def -> def.getVerbs().isEmpty() || def.getVerbs().get(0).getPath().equals(uri)) - .collect(Collectors.toList()); - - RestOpenApiReader reader = new RestOpenApiReader(); - OpenAPI openApi = reader.read(context, rests, config, context.getName(), new DefaultClassResolver()); - assertNotNull(openApi); - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - - LOG.info(json); - - json = generify(json); - - InputStream is = getClass().getClassLoader().getResourceAsStream("org/apache/camel/openapi/" + schemaResource); - assertNotNull(is); - String expected = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)).lines() - .collect(Collectors.joining("\n")); - is.close(); - - JSONAssert.assertEquals(expected, json, JSONCompareMode.STRICT); - } - - private BeanConfig getBeanConfig(String apiVersion) { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setTitle("Camel User store"); - config.setLicense("Apache 2.0"); - config.setLicenseUrl("https://www.apache.org/licenses/LICENSE-2.0.html"); - config.setVersion(apiVersion); - return config; - } - - private String generify(String input) { - input = input.replaceAll("\"openapi\" : \"3\\..*\",", "\"openapi\" : \"3.x\","); - input = input.replaceAll("\"swagger\" : \"2\\..*\",", "\"swagger\" : \"2.x\","); - input = input.replaceAll("\"operationId\" : \"verb.*\",", "\"operationId\" : \"verb\","); - input = input.replaceAll("\"x-camelContextId\" : \"camel.*\"", "\"x-camelContextId\" : \"camel\""); - return input; - } -} diff --git a/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V2SchemaForComplexTypesRequest.json b/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V2SchemaForComplexTypesRequest.json deleted file mode 100644 index 54bcc6a854b..00000000000 --- a/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V2SchemaForComplexTypesRequest.json +++ /dev/null @@ -1,158 +0,0 @@ -{ - "swagger" : "2.x", - "host" : "localhost:8080", - "basePath" : "/api", - "schemes" : [ "http" ], - "paths" : { - "/complexRequest" : { - "post" : { - "summary" : "Demo complex request type", - "operationId" : "verb", - "consumes" : [ "application/json" ], - "produces" : [ "text/plain" ], - "parameters" : [ { - "in" : "body", - "name" : "body", - "required" : true, - "schema" : { - "$ref" : "#/definitions/SampleComplexRequestType" - } - } ], - "responses" : { - "200" : { - "description" : "Receives a complex object as parameter", - "schema" : { - "$ref" : "#/definitions/SampleComplexResponseType_InnerClass" - } - } - }, - "x-camelContextId" : "camel" - } - } - }, - "securityDefinitions" : { - "global" : { - "type" : "oauth2", - "authorizationUrl" : "https://AUTHORIZATION_URL", - "tokenUrl" : "https://TOKEN_URL", - "flow" : "accessCode", - "scopes" : { - "groups" : "Required scopes for Camel REST APIs" - } - } - }, - "definitions" : { - "SampleComplexResponseType_InnerClass" : { - "type" : "object", - "properties" : { - "doubleField" : { - "type" : "number", - "format" : "double" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType$InnerClass", - "type" : "string" - } - }, - "CustomData" : { - "type" : "object", - "properties" : { - "customDataField" : { - "type" : "string" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.CustomData", - "type" : "string" - } - }, - "SampleComplexRequestType" : { - "type" : "object", - "required" : [ "mapOfStrings", "requestField1" ], - "properties" : { - "requestField1" : { - "type" : "string" - }, - "requestField2" : { - "type" : "string" - }, - "listOfStrings" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "data" : { - "$ref" : "#/definitions/CustomData" - }, - "mapOfData" : { - "type" : "object", - "additionalProperties" : { - "$ref" : "#/definitions/CustomData" - } - }, - "arrayOfString" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "mapOfMapOfData" : { - "type" : "object", - "additionalProperties" : { - "type" : "object", - "additionalProperties" : { - "$ref" : "#/definitions/CustomData" - } - } - }, - "innerClass" : { - "$ref" : "#/definitions/SampleComplexRequestType_InnerClass" - }, - "listOfListOfData" : { - "type" : "array", - "items" : { - "type" : "array", - "items" : { - "$ref" : "#/definitions/CustomData" - } - } - }, - "listOfData" : { - "type" : "array", - "items" : { - "$ref" : "#/definitions/CustomData" - } - }, - "mapOfStrings" : { - "type" : "object", - "additionalProperties" : { - "type" : "string" - } - }, - "timeUnit" : { - "type" : "string", - "enum" : [ "NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS", "DAYS" ] - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType", - "type" : "string" - } - }, - "SampleComplexRequestType_InnerClass" : { - "type" : "object", - "properties" : { - "longField" : { - "type" : "integer", - "format" : "int64" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType$InnerClass", - "type" : "string" - } - } - } -} diff --git a/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V2SchemaForComplexTypesResponse.json b/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V2SchemaForComplexTypesResponse.json deleted file mode 100644 index c5fc9b0ede1..00000000000 --- a/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V2SchemaForComplexTypesResponse.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "swagger" : "2.x", - "host" : "localhost:8080", - "basePath" : "/api", - "schemes" : [ "http" ], - "paths" : { - "/complexResponse" : { - "get" : { - "summary" : "Demo complex response type", - "operationId" : "verb", - "consumes" : [ "application/json" ], - "produces" : [ "application/json" ], - "parameters" : [ { - "in" : "body", - "name" : "body", - "required" : true, - "schema" : { - "$ref" : "#/definitions/SampleComplexRequestType_InnerClass" - } - } ], - "responses" : { - "200" : { - "description" : "Returns a complex object", - "schema" : { - "$ref" : "#/definitions/SampleComplexResponseType" - } - } - }, - "x-camelContextId" : "camel" - } - } - }, - "securityDefinitions" : { - "global" : { - "type" : "oauth2", - "authorizationUrl" : "https://AUTHORIZATION_URL", - "tokenUrl" : "https://TOKEN_URL", - "flow" : "accessCode", - "scopes" : { - "groups" : "Required scopes for Camel REST APIs" - } - } - }, - "definitions" : { - "SampleComplexResponseType_InnerClass" : { - "type" : "object", - "properties" : { - "doubleField" : { - "type" : "number", - "format" : "double" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType$InnerClass", - "type" : "string" - } - }, - "SampleComplexResponseType" : { - "type" : "object", - "required" : [ "arrayOfStrings", "responseField1" ], - "properties" : { - "innerClass" : { - "$ref" : "#/definitions/SampleComplexResponseType_InnerClass" - }, - "arrayOfStrings" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "month" : { - "type" : "string", - "enum" : [ "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" ] - }, - "responseField2" : { - "type" : "string" - }, - "responseField1" : { - "type" : "string" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType", - "type" : "string" - } - }, - "SampleComplexRequestType_InnerClass" : { - "type" : "object", - "properties" : { - "longField" : { - "type" : "integer", - "format" : "int64" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType$InnerClass", - "type" : "string" - } - } - } -} \ No newline at end of file diff --git a/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V3SchemaForComplexTypesRequest.json b/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V3SchemaForComplexTypesRequest.json deleted file mode 100644 index 245ff25c089..00000000000 --- a/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V3SchemaForComplexTypesRequest.json +++ /dev/null @@ -1,167 +0,0 @@ -{ - "openapi" : "3.x", - "servers" : [ { - "url" : "http://localhost:8080/api" - } ], - "paths" : { - "/complexRequest" : { - "post" : { - "summary" : "Demo complex request type", - "operationId" : "verb", - "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/SampleComplexRequestType" - } - } - }, - "required" : true - }, - "responses" : { - "200" : { - "description" : "Receives a complex object as parameter", - "content" : { - "text/plain" : { - "schema" : { - "$ref" : "#/components/schemas/SampleComplexResponseType_InnerClass" - } - } - } - } - }, - "x-camelContextId" : "camel" - } - } - }, - "components" : { - "schemas" : { - "SampleComplexResponseType_InnerClass" : { - "type" : "object", - "properties" : { - "doubleField" : { - "type" : "number", - "format" : "double" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType$InnerClass", - "type" : "string" - } - }, - "CustomData" : { - "type" : "object", - "properties" : { - "customDataField" : { - "type" : "string" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.CustomData", - "type" : "string" - } - }, - "SampleComplexRequestType" : { - "required" : [ "mapOfStrings", "requestField1" ], - "type" : "object", - "properties" : { - "data" : { - "$ref" : "#/components/schemas/CustomData" - }, - "listOfData" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/CustomData" - } - }, - "listOfListOfData" : { - "type" : "array", - "items" : { - "type" : "array", - "items" : { - "$ref" : "#/components/schemas/CustomData" - } - } - }, - "mapOfData" : { - "type" : "object", - "additionalProperties" : { - "$ref" : "#/components/schemas/CustomData" - } - }, - "mapOfMapOfData" : { - "type" : "object", - "additionalProperties" : { - "type" : "object", - "additionalProperties" : { - "$ref" : "#/components/schemas/CustomData" - } - } - }, - "requestField1" : { - "type" : "string" - }, - "requestField2" : { - "type" : "string" - }, - "listOfStrings" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "arrayOfString" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "mapOfStrings" : { - "type" : "object", - "additionalProperties" : { - "type" : "string" - } - }, - "timeUnit" : { - "type" : "string", - "enum" : [ "NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS", "DAYS" ] - }, - "innerClass" : { - "$ref" : "#/components/schemas/SampleComplexRequestType_InnerClass" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType", - "type" : "string" - } - }, - "SampleComplexRequestType_InnerClass" : { - "type" : "object", - "properties" : { - "longField" : { - "type" : "integer", - "format" : "int64" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType$InnerClass", - "type" : "string" - } - } - }, - "securitySchemes" : { - "global" : { - "type" : "oauth2", - "flows" : { - "authorizationCode" : { - "authorizationUrl" : "https://AUTHORIZATION_URL", - "tokenUrl" : "https://TOKEN_URL", - "scopes" : { - "groups" : "Required scopes for Camel REST APIs" - } - } - } - } - } - } -} \ No newline at end of file diff --git a/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V3SchemaForComplexTypesResponse.json b/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V3SchemaForComplexTypesResponse.json deleted file mode 100644 index 27cfcb248a1..00000000000 --- a/components-starter/camel-openapi-java-starter/src/test/resources/org/apache/camel/openapi/V3SchemaForComplexTypesResponse.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "openapi" : "3.x", - "servers" : [ { - "url" : "http://localhost:8080/api" - } ], - "paths" : { - "/complexResponse" : { - "get" : { - "summary" : "Demo complex response type", - "operationId" : "verb", - "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/SampleComplexRequestType_InnerClass" - } - } - }, - "required" : true - }, - "responses" : { - "200" : { - "description" : "Returns a complex object", - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/SampleComplexResponseType" - } - } - } - } - }, - "x-camelContextId" : "camel" - } - } - }, - "components" : { - "schemas" : { - "SampleComplexResponseType_InnerClass" : { - "type" : "object", - "properties" : { - "doubleField" : { - "type" : "number", - "format" : "double" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType$InnerClass", - "type" : "string" - } - }, - "SampleComplexResponseType" : { - "required" : [ "arrayOfStrings", "responseField1" ], - "type" : "object", - "properties" : { - "responseField1" : { - "type" : "string" - }, - "responseField2" : { - "type" : "string" - }, - "arrayOfStrings" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "month" : { - "type" : "string", - "enum" : [ "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" ] - }, - "innerClass" : { - "$ref" : "#/components/schemas/SampleComplexResponseType_InnerClass" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType", - "type" : "string" - } - }, - "SampleComplexRequestType_InnerClass" : { - "type" : "object", - "properties" : { - "longField" : { - "type" : "integer", - "format" : "int64" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType$InnerClass", - "type" : "string" - } - } - }, - "securitySchemes" : { - "global" : { - "type" : "oauth2", - "flows" : { - "authorizationCode" : { - "authorizationUrl" : "https://AUTHORIZATION_URL", - "tokenUrl" : "https://TOKEN_URL", - "scopes" : { - "groups" : "Required scopes for Camel REST APIs" - } - } - } - } - } - } -} \ No newline at end of file