Skip to content

Commit

Permalink
Merge branch 'refs/heads/issue/1156/test_api_generator_TS' into issue…
Browse files Browse the repository at this point in the history
…/1161/fluent-generated-openapi-actions-REBASE

# Conflicts:
#	connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/actions/OpenApiClientRequestActionBuilder.java
#	pom.xml
#	src/manual/connector-openapi.adoc
#	test-api-generator/citrus-test-api-generator-core/pom.xml
#	test-api-generator/citrus-test-api-generator-core/src/main/java/org/citrusframework/openapi/generator/JavaCitrusCodegen.java
#	test-api-generator/citrus-test-api-generator-core/src/main/java/org/citrusframework/openapi/generator/SimpleWsdlToOpenApiTransformer.java
#	test-api-generator/citrus-test-api-generator-core/src/main/resources/java-citrus/api.mustache
#	test-api-generator/citrus-test-api-generator-core/src/main/resources/java-citrus/bean_definition_parser.mustache
#	test-api-generator/citrus-test-api-generator-core/src/main/resources/java-citrus/namespace_handler.mustache
#	test-api-generator/citrus-test-api-generator-core/src/main/resources/java-citrus/test_base.mustache
#	test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/GeneratedApiIT.java
#	test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/GetPetByIdIT.java
#	test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/JavaCitrusCodegenIT.java
#	test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/JavaCitrusCodegenTest.java
#	test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/ServiceLoaderTest.java
#	test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/SpringBeanConfigurationIT.java
#	test-api-generator/citrus-test-api-generator-core/src/test/java/org/citrusframework/openapi/generator/util/TestApiActionBuilderCustomizer.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/apis/multiparttest-rest-resource.yaml
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/apis/petstore.yaml
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/GeneratedApiTest/payloads/getPetByIdControlMessage1.json
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/multiparttest/citrus/MultipartTestAbstractTestRequest.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/multiparttest/citrus/MultipartTestBeanDefinitionParser.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/multiparttest/citrus/extension/MultipartTestNamespaceHandler.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/multiparttest/request/MultiparttestControllerApi.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/petstore/citrus/PetStoreAbstractTestRequest.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/petstore/citrus/PetStoreBeanDefinitionParser.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/petstore/citrus/extension/PetStoreNamespaceHandler.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/petstore/request/PetApi.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/petstore/request/StoreApi.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/petstore/request/UserApi.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/rest/petstore/spring/PetStoreBeanConfiguration.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/soap/bookservice/citrus/OpenApiFromWsdlBeanDefinitionParser.java
#	test-api-generator/citrus-test-api-generator-core/src/test/resources/org/citrusframework/openapi/generator/JavaCitrusCodegenIntegrationTest/expectedgen/soap/bookservice/citrus/extension/OpenApiFromWsdlNamespaceHandler.java
#	test-api-generator/citrus-test-api-generator-maven-plugin/pom.xml
#	test-api-generator/citrus-test-api-generator-maven-plugin/src/main/java/org/citrusframework/maven/plugin/CodeGenMojoWrapper.java
#	test-api-generator/citrus-test-api-generator-maven-plugin/src/main/java/org/citrusframework/maven/plugin/SpringMetaFileGenerator.java
#	test-api-generator/citrus-test-api-generator-maven-plugin/src/main/java/org/citrusframework/maven/plugin/TestApiGeneratorMojo.java
#	test-api-generator/citrus-test-api-generator-maven-plugin/src/test/java/org/citrusframework/maven/plugin/TestApiGeneratorMojoIntegrationTest.java
#	test-api-generator/citrus-test-api-generator-maven-plugin/src/test/java/org/citrusframework/maven/plugin/TestApiGeneratorMojoUnitTest.java
#	test-api-generator/pom.xml
  • Loading branch information
Sterchi Daniel committed Jul 5, 2024
2 parents 276fb14 + d1b04d7 commit e951bbb
Show file tree
Hide file tree
Showing 67 changed files with 1,196 additions and 517 deletions.
2 changes: 1 addition & 1 deletion .github/project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Citrus Framework
release:
current-version: 4.2.0
current-version: 4.2.1
next-version: 4.3.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ http\://www.citrusframework.org/schema/docker/config/citrus-docker-config-4.0.1.
http\://www.citrusframework.org/schema/docker/config/citrus-docker-config-4.0.2.xsd=org/citrusframework/schema/citrus-docker-config-4.0.2.xsd
http\://www.citrusframework.org/schema/docker/config/citrus-docker-config-4.1.0.xsd=org/citrusframework/schema/citrus-docker-config-4.1.0.xsd
http\://www.citrusframework.org/schema/docker/config/citrus-docker-config-4.1.1.xsd=org/citrusframework/schema/citrus-docker-config-4.1.1.xsd
http\://www.citrusframework.org/schema/docker/config/citrus-docker-config-4.3.0-SNAPSHOT.xsd=org/citrusframework/schema/citrus-docker-config-4.3.0-SNAPSHOT.xsd
http\://www.citrusframework.org/schema/docker/config/citrus-docker-config-4.2.0.xsd=org/citrusframework/schema/citrus-docker-config-4.2.0.xsd
http\://www.citrusframework.org/schema/docker/config/citrus-docker-config-4.2.1.xsd=org/citrusframework/schema/citrus-docker-config-4.2.1.xsd
http\://www.citrusframework.org/schema/docker/config/citrus-docker-config-4.3.0-SNAPSHOT.xsd=org/citrusframework/schema/citrus-docker-config-4.3.0-SNAPSHOT.xsd
http\://www.citrusframework.org/schema/docker/config/citrus-docker-config.xsd=org/citrusframework/schema/citrus-docker-config.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-2.3.xsd=com/consol/citrus/schema/citrus-docker-testcase-2.3.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-2.4.xsd=com/consol/citrus/schema/citrus-docker-testcase-2.4.xsd
Expand Down Expand Up @@ -75,6 +76,7 @@ http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-4.
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-4.0.2.xsd=org/citrusframework/schema/citrus-docker-testcase-4.0.2.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-4.1.0.xsd=org/citrusframework/schema/citrus-docker-testcase-4.1.0.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-4.1.1.xsd=org/citrusframework/schema/citrus-docker-testcase-4.1.1.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-4.3.0-SNAPSHOT.xsd=org/citrusframework/schema/citrus-docker-testcase-4.3.0-SNAPSHOT.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-4.2.0.xsd=org/citrusframework/schema/citrus-docker-testcase-4.2.0.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-4.2.1.xsd=org/citrusframework/schema/citrus-docker-testcase-4.2.1.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase-4.3.0-SNAPSHOT.xsd=org/citrusframework/schema/citrus-docker-testcase-4.3.0-SNAPSHOT.xsd
http\://www.citrusframework.org/schema/docker/testcase/citrus-docker-testcase.xsd=org/citrusframework/schema/citrus-docker-testcase.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-confi
http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config-4.0.2.xsd=org/citrusframework/schema/citrus-kubernetes-config-4.0.2.xsd
http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config-4.1.0.xsd=org/citrusframework/schema/citrus-kubernetes-config-4.1.0.xsd
http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config-4.1.1.xsd=org/citrusframework/schema/citrus-kubernetes-config-4.1.1.xsd
http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config-4.3.0-SNAPSHOT.xsd=org/citrusframework/schema/citrus-kubernetes-config-4.3.0-SNAPSHOT.xsd
http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config-4.2.0.xsd=org/citrusframework/schema/citrus-kubernetes-config-4.2.0.xsd
http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config-4.2.1.xsd=org/citrusframework/schema/citrus-kubernetes-config-4.2.1.xsd
http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config-4.3.0-SNAPSHOT.xsd=org/citrusframework/schema/citrus-kubernetes-config-4.3.0-SNAPSHOT.xsd
http\://www.citrusframework.org/schema/kubernetes/config/citrus-kubernetes-config.xsd=org/citrusframework/schema/citrus-kubernetes-config.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-2.7.1.xsd=com/consol/citrus/schema/citrus-kubernetes-testcase-2.7.1.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-2.7.2.xsd=com/consol/citrus/schema/citrus-kubernetes-testcase-2.7.2.xsd
Expand Down Expand Up @@ -59,6 +60,7 @@ http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-tes
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-4.0.2.xsd=org/citrusframework/schema/citrus-kubernetes-testcase-4.0.2.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-4.1.0.xsd=org/citrusframework/schema/citrus-kubernetes-testcase-4.1.0.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-4.1.1.xsd=org/citrusframework/schema/citrus-kubernetes-testcase-4.1.1.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-4.3.0-SNAPSHOT.xsd=org/citrusframework/schema/citrus-kubernetes-testcase-4.3.0-SNAPSHOT.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-4.2.0.xsd=org/citrusframework/schema/citrus-kubernetes-testcase-4.2.0.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-4.2.1.xsd=org/citrusframework/schema/citrus-kubernetes-testcase-4.2.1.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase-4.3.0-SNAPSHOT.xsd=org/citrusframework/schema/citrus-kubernetes-testcase-4.3.0-SNAPSHOT.xsd
http\://www.citrusframework.org/schema/kubernetes/testcase/citrus-kubernetes-testcase.xsd=org/citrusframework/schema/citrus-kubernetes-testcase.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<k8s:result>
{
"result": {
"clientVersion": "6.12.0",
"clientVersion": "6.13.0",
"apiVersion": "${apiVersion}",
"kind":"Info",
"masterUrl": "@matches('http://(kubernetes\\.docker\\.internal|localhost):[0-9]+/')@",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<data>{
"command": "info",
"result": {
"clientVersion": "6.12.0",
"clientVersion": "6.13.0",
"apiVersion": "${apiVersion}",
"kind":"Info",
"masterUrl": "@matches('http://(kubernetes\\.docker\\.internal|localhost):[0-9]+/')@",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static String createRandomValueExpression(
}

if (schema.format != null && schema.format.equals("date")) {
payload.append("citrus:currentDate()");
payload.append("citrus:currentDate('yyyy-MM-dd')");
} else if (schema.format != null && schema.format.equals("date-time")) {
payload.append("citrus:currentDate('yyyy-MM-dd'T'hh:mm:ss')");
} else if (StringUtils.hasText(schema.pattern)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static Map<String, OasSchema> getRequiredHeaders(Oas30Response response)

return response.headers.entrySet()
.stream()
.filter(entry -> entry.getValue().required)
.filter(entry -> Boolean.TRUE.equals(entry.getValue().required))
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().schema));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.citrusframework.openapi.actions;

import org.citrusframework.context.TestContext;
import org.citrusframework.http.message.HttpMessage;
import org.citrusframework.message.Message;
import org.citrusframework.openapi.OpenApiSpecification;
import org.citrusframework.spi.Resources;
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.citrusframework.openapi.actions.OpenApiActionBuilder.openapi;

public class OpenApiClientRequestMessageBuilderTest {

private final OpenApiSpecification petstoreSpec = OpenApiSpecification.from(
Resources.create("classpath:org/citrusframework/openapi/petstore/petstore-derivation-for-message-builder-test.json"));


@Test
public void shouldAddRandomDataForOperation() {
Message message = openapi()
.specification(petstoreSpec)
.client()
.send("addPet") // operationId
.build()
.getMessageBuilder()
.build(new TestContext(), "");
Assert.assertTrue(message instanceof HttpMessage);
HttpMessage httpMessage = (HttpMessage) message;
// test payload
Object payload = httpMessage.getPayload();
Assert.assertNotNull(payload);
Assert.assertTrue(payload instanceof String);
// test header
Object header = httpMessage.getHeader("X-SAMPLE-HEADER");
Assert.assertNotNull(header);
}

@Test
public void shouldAddCustomDataForOperation() {
String body = "{\"a\":\"b\"}";
String sampleHeader = "X-SAMPLE-HEADER-VALUE";
Message message = openapi()
.specification(petstoreSpec)
.client()
.send("addPet") // operationId
.message()
.body(body)
.header("X-SAMPLE-HEADER", sampleHeader)
.build()
.getMessageBuilder()
.build(new TestContext(), "");
Assert.assertTrue(message instanceof HttpMessage);
HttpMessage httpMessage = (HttpMessage) message;
// test payload
Object payload = httpMessage.getPayload();
Assert.assertEquals(payload, body);
// test header
Object header = httpMessage.getHeader("X-SAMPLE-HEADER");
Assert.assertEquals(header, sampleHeader);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.citrusframework.openapi.model.v3;

import io.apicurio.datamodels.openapi.models.OasSchema;
import io.apicurio.datamodels.openapi.v3.models.Oas30Header;
import io.apicurio.datamodels.openapi.v3.models.Oas30Response;
import io.apicurio.datamodels.openapi.v3.models.Oas30Schema;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Map;

public class Oas30ModelHelperTest {

@Test
public void shouldNotFindRequiredHeadersWithoutRequiredAttribute() {
var header = new Oas30Header("X-TEST");
header.schema = new Oas30Schema();
header.required = null; // explicitely assigned because this is test case
var response = new Oas30Response("200");
response.headers.put(header.getName(), header);

Map<String, OasSchema> result = Oas30ModelHelper.getRequiredHeaders(response);

Assert.assertEquals(result.size(), 0);
}

@Test
public void shouldFindRequiredHeaders() {
var header = new Oas30Header("X-TEST");
header.schema = new Oas30Schema();
header.required = Boolean.TRUE; // explicitely assigned because this is test case
var response = new Oas30Response("200");
response.headers.put(header.getName(), header);

Map<String, OasSchema> result = Oas30ModelHelper.getRequiredHeaders(response);

Assert.assertEquals(result.size(), 1);
Assert.assertSame(result.get(header.getName()), header.schema);
}

@Test
public void shouldNotFindOptionalHeaders() {
var header = new Oas30Header("X-TEST");
header.schema = new Oas30Schema();
header.required = Boolean.FALSE; // explicitely assigned because this is test case
var response = new Oas30Response("200");
response.headers.put(header.getName(), header);

Map<String, OasSchema> result = Oas30ModelHelper.getRequiredHeaders(response);

Assert.assertEquals(result.size(), 0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"openapi": "3.0.2",
"info": {
"title": "Swagger Petstore",
"version": "1.0.1",
"description": "This is a sample server Petstore server.",
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"servers": [
{
"url": "http://localhost/petstore/v3"
}
],
"paths": {
"/pet": {
"post": {
"requestBody": {
"description": "Pet object that needs to be added to the store",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
},
"application/xml": {
"schema": {
"$ref": "#/components/schemas/Pet"
}
}
},
"required": true
},
"parameters": [
{
"name": "X-SAMPLE-HEADER",
"required": true,
"in": "header",
"schema": {
"type": "string"
}
},
{
"name": "sample-param",
"required": true,
"in": "query",
"schema": {
"type": "string"
}
}
],
"tags": [
"pet"
],
"responses": {
"201": {
"description": "Created"
},
"405": {
"description": "Invalid input"
}
},
"operationId": "addPet",
"summary": "Add a new pet to the store",
"description": ""
}
}
},
"components": {
"schemas": {
"Category": {
"type": "object",
"properties": {
"id": {
"format": "int64",
"type": "integer"
},
"name": {
"type": "string"
}
},
"xml": {
"name": "Category"
}
},
"Tag": {
"type": "object",
"properties": {
"id": {
"format": "int64",
"type": "integer"
},
"name": {
"type": "string"
}
},
"xml": {
"name": "Tag"
}
},
"Pet": {
"required": [
"category",
"name",
"status"
],
"type": "object",
"properties": {
"id": {
"format": "int64",
"type": "integer"
},
"category": {
"$ref": "#/components/schemas/Category"
},
"name": {
"type": "string",
"example": "doggie"
},
"photoUrls": {
"type": "array",
"items": {
"type": "string"
},
"xml": {
"name": "photoUrl",
"wrapped": true
}
},
"tags": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Tag"
},
"xml": {
"name": "tag",
"wrapped": true
}
},
"status": {
"description": "pet status in the store",
"enum": [
"available",
"pending",
"sold"
],
"type": "string"
}
},
"xml": {
"name": "Pet"
}
}
}
},
"tags": [
{
"name": "pet",
"description": "Everything about your Pets"
}
]
}
Loading

0 comments on commit e951bbb

Please sign in to comment.