diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiPathRegistry.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiPathRegistry.java index 1c05877806..6218baaceb 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiPathRegistry.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiPathRegistry.java @@ -16,16 +16,17 @@ package org.citrusframework.openapi; -import static java.lang.String.format; +import org.citrusframework.exceptions.CitrusRuntimeException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import org.citrusframework.exceptions.CitrusRuntimeException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import static java.lang.String.format; /** * A registry to store objects by OpenApi paths. The registry uses a digital tree data structure @@ -187,5 +188,4 @@ class RegistryNode { String path; T value = null; } - } diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiRepository.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiRepository.java index 36f113ea83..083da342ca 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiRepository.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiRepository.java @@ -16,6 +16,11 @@ package org.citrusframework.openapi; +import org.citrusframework.repository.BaseRepository; +import org.citrusframework.spi.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.net.MalformedURLException; import java.net.URL; @@ -24,10 +29,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.citrusframework.repository.BaseRepository; -import org.citrusframework.spi.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * OpenApi repository holding a set of {@link OpenApiSpecification} known in the test scope. @@ -140,7 +141,4 @@ static Optional determineResourceAlias(Resource openApiResource) { public List getOpenApiSpecifications() { return openApiSpecifications; } - - - } diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiResourceLoader.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiResourceLoader.java index 47fe703e7a..39efffc101 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiResourceLoader.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiResourceLoader.java @@ -21,15 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.apicurio.datamodels.Library; import io.apicurio.datamodels.openapi.models.OasDocument; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.util.Objects; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; import org.apache.hc.client5.http.ssl.TrustAllStrategy; import org.apache.hc.core5.http.HttpHeaders; @@ -40,6 +31,16 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.Objects; + /** * Loads Open API specifications from different locations like file resource or web resource. */ @@ -47,7 +48,6 @@ public final class OpenApiResourceLoader { static final RawResolver RAW_RESOLVER = new RawResolver(); - static final OasResolver OAS_RESOLVER = new OasResolver(); /** @@ -59,8 +59,6 @@ private OpenApiResourceLoader() { /** * Loads the specification from a file resource. Either classpath or file system resource path is supported. - * @param resource - * @return */ public static OasDocument fromFile(String resource) { return fromFile(FileUtils.getFileResource(resource), OAS_RESOLVER); @@ -68,8 +66,6 @@ public static OasDocument fromFile(String resource) { /** * Loads the raw specification from a file resource. Either classpath or file system resource path is supported. - * @param resource - * @return */ public static String rawFromFile(String resource) { return fromFile(FileUtils.getFileResource(resource), @@ -78,8 +74,6 @@ public static String rawFromFile(String resource) { /** * Loads the specification from a resource. - * @param resource - * @return */ public static OasDocument fromFile(Resource resource) { return fromFile(resource, OAS_RESOLVER); @@ -87,8 +81,6 @@ public static OasDocument fromFile(Resource resource) { /** * Loads the raw specification from a resource. - * @param resource - * @return */ public static String rawFromFile(Resource resource) { return fromFile(resource, RAW_RESOLVER); @@ -104,8 +96,6 @@ private static T fromFile(Resource resource, Resolver resolver) { /** * Loads specification from given web URL location. - * @param url - * @return */ public static OasDocument fromWebResource(URL url) { return fromWebResource(url, OAS_RESOLVER); @@ -113,8 +103,6 @@ public static OasDocument fromWebResource(URL url) { /** * Loads raw specification from given web URL location. - * @param url - * @return */ public static String rawFromWebResource(URL url) { return fromWebResource(url, RAW_RESOLVER); @@ -129,13 +117,13 @@ private static T fromWebResource(URL url, Resolver resolver) { int status = con.getResponseCode(); if (status > 299) { - throw new IllegalStateException("Failed to retrieve Open API specification: " + url.toString(), + throw new IllegalStateException("Failed to retrieve Open API specification: " + url, new IOException(FileUtils.readToString(con.getErrorStream()))); } else { return resolve(FileUtils.readToString(con.getInputStream()), resolver); } } catch (IOException e) { - throw new IllegalStateException("Failed to retrieve Open API specification: " + url.toString(), e); + throw new IllegalStateException("Failed to retrieve Open API specification: " + url, e); } finally { if (con != null) { con.disconnect(); @@ -145,8 +133,6 @@ private static T fromWebResource(URL url, Resolver resolver) { /** * Loads specification from given web URL location using secured Http connection. - * @param url - * @return */ public static OasDocument fromSecuredWebResource(URL url) { return fromSecuredWebResource(url, OAS_RESOLVER); @@ -154,8 +140,6 @@ public static OasDocument fromSecuredWebResource(URL url) { /** * Loads raw specification from given web URL location using secured Http connection. - * @param url - * @return */ public static String rawFromSecuredWebResource(URL url) { return fromSecuredWebResource(url, RAW_RESOLVER); @@ -180,7 +164,7 @@ private static T fromSecuredWebResource(URL url, Resolver resolver) { int status = con.getResponseCode(); if (status > 299) { - throw new IllegalStateException("Failed to retrieve Open API specification: " + url.toString(), + throw new IllegalStateException("Failed to retrieve Open API specification: " + url, new IOException(FileUtils.readToString(con.getErrorStream()))); } else { return resolve(FileUtils.readToString(con.getInputStream()), resolver); @@ -188,7 +172,7 @@ private static T fromSecuredWebResource(URL url, Resolver resolver) { } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new IllegalStateException("Failed to create https client for ssl connection", e); } catch (IOException e) { - throw new IllegalStateException("Failed to retrieve Open API specification: " + url.toString(), e); + throw new IllegalStateException("Failed to retrieve Open API specification: " + url, e); } finally { if (con != null) { con.disconnect(); @@ -255,5 +239,4 @@ public String resolveFromNode(JsonNode node) { } } } - } diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecification.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecification.java index 918aee6f6c..cd70694f74 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecification.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecification.java @@ -16,26 +16,11 @@ package org.citrusframework.openapi; -import static org.citrusframework.openapi.OpenApiSettings.isGenerateOptionalFieldsGlobally; -import static org.citrusframework.openapi.OpenApiSettings.isRequestValidationEnabledlobally; -import static org.citrusframework.openapi.OpenApiSettings.isResponseValidationEnabledGlobally; -import static org.citrusframework.openapi.OpenApiSettings.isValidateOptionalFieldsGlobally; - import com.atlassian.oai.validator.OpenApiInteractionValidator; import com.atlassian.oai.validator.OpenApiInteractionValidator.Builder; import io.apicurio.datamodels.core.models.common.Info; import io.apicurio.datamodels.openapi.models.OasDocument; import io.apicurio.datamodels.openapi.models.OasOperation; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Supplier; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.http.client.HttpClient; @@ -49,6 +34,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; + +import static org.citrusframework.openapi.OpenApiSettings.isGenerateOptionalFieldsGlobally; +import static org.citrusframework.openapi.OpenApiSettings.isRequestValidationEnabledlobally; +import static org.citrusframework.openapi.OpenApiSettings.isResponseValidationEnabledGlobally; +import static org.citrusframework.openapi.OpenApiSettings.isValidateOptionalFieldsGlobally; + /** * OpenApi specification resolves URL or local file resources to a specification document. *

@@ -209,7 +211,6 @@ public synchronized OasDocument getOpenApiDoc(TestContext context) { } if (resolvedSpecUrl.startsWith(HTTP)) { - URL specWebResource = toSpecUrl(resolvedSpecUrl); if (resolvedSpecUrl.startsWith(HTTPS)) { initApiDoc( @@ -257,10 +258,10 @@ public synchronized OasDocument getOpenApiDoc(TestContext context) { // provided for testing URL toSpecUrl(String resolvedSpecUrl) { try { - return new URL(resolvedSpecUrl); + return URI.create(resolvedSpecUrl).toURL(); } catch (MalformedURLException e) { throw new IllegalStateException( - "Failed to retrieve Open API specification as web resource: " + specUrl, e); + "Failed to retrieve Open API specification as web resource: " + resolvedSpecUrl, e); } } diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationAdapter.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationAdapter.java index fa3eaca62c..011a2dc7fd 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationAdapter.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationAdapter.java @@ -22,22 +22,6 @@ * * @param the type to which the specification is adapted. */ -public class OpenApiSpecificationAdapter { - - private final OpenApiSpecification openApiSpecification; +public record OpenApiSpecificationAdapter(OpenApiSpecification openApiSpecification, T entity) { - private final T entity; - - public OpenApiSpecificationAdapter(OpenApiSpecification openApiSpecification, T entity) { - this.openApiSpecification = openApiSpecification; - this.entity = entity; - } - - public OpenApiSpecification getOpenApiSpecification() { - return openApiSpecification; - } - - public T getEntity() { - return entity; - } } diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationProcessor.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationProcessor.java index b7ca0b5bdc..ceeb9286d5 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationProcessor.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSpecificationProcessor.java @@ -16,12 +16,13 @@ package org.citrusframework.openapi; -import java.util.Map; import org.citrusframework.spi.ResourcePathTypeResolver; import org.citrusframework.spi.TypeResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Map; + /** * Interface for processing OpenAPI specifications. *

diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSupport.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSupport.java index e966960fdf..9020d555e3 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSupport.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/OpenApiSupport.java @@ -16,9 +16,6 @@ package org.citrusframework.openapi; -import java.util.Collection; -import java.util.Map; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -33,6 +30,9 @@ import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.representer.Representer; +import java.util.Collection; +import java.util.Map; + public class OpenApiSupport { private static final ObjectMapper OBJECT_MAPPER; 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 a09be519ea..497676cb5c 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 @@ -17,8 +17,7 @@ package org.citrusframework.openapi; import io.apicurio.datamodels.openapi.models.OasSchema; -import java.util.Map; -import java.util.stream.Collectors; +import jakarta.annotation.Nullable; import org.citrusframework.CitrusSettings; import org.citrusframework.context.TestContext; import org.citrusframework.exceptions.CitrusRuntimeException; @@ -26,6 +25,9 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import java.util.Map; +import java.util.stream.Collectors; + /** * Generates proper payloads and validation expressions based on Open API specification rules. Creates outbound payloads * with generated random test data according to specification and creates inbound payloads with proper validation expressions to @@ -36,9 +38,6 @@ public class OpenApiTestDataGenerator { /** * Creates payload from schema for outbound message. - * @param schema - * @param definitions - * @return */ public static String createOutboundPayload(OasSchema schema, Map definitions, OpenApiSpecification specification) { @@ -81,10 +80,6 @@ public static String createOutboundPayload(OasSchema schema, Map definitions, boolean quotes, OpenApiSpecification specification, TestContext context) { @@ -106,10 +101,6 @@ public static T createRawRandomValueExpression(String name, OasSchema schema /** * Create payload from schema with random values. - * @param schema - * @param definitions - * @param quotes - * @return */ public static String createRandomValueExpression(OasSchema schema, Map definitions, boolean quotes, OpenApiSpecification specification) { @@ -179,9 +170,6 @@ public static T createRawRandomValueExpression(OasSchema schema, Map definitions, OpenApiSpecification specification) { @@ -224,9 +212,6 @@ public static String createInboundPayload(OasSchema schema, Map definitions, boolean quotes, OpenApiSpecification specification, @@ -257,10 +236,6 @@ public static String createValidationExpression(String name, OasSchema schema, M /** * Create validation expression using functions according to schema type and format. - * @param schema - * @param definitions - * @param quotes - * @return */ public static String createValidationExpression(OasSchema schema, Map definitions, boolean quotes, OpenApiSpecification specification) { @@ -307,8 +282,6 @@ public static String createValidationExpression(OasSchema schema, Map schemaForMediaType) { - if (schemaForMediaType.getNode() == null) { + if (schemaForMediaType.node() == null) { // No schema means no payload, no type message.setPayload(null); } else { - if (TEXT_PLAIN_VALUE.equals(schemaForMediaType.getAdapted())) { + if (TEXT_PLAIN_VALUE.equals(schemaForMediaType.adapted())) { // Schema but plain text - message.setPayload(createOutboundPayload(schemaForMediaType.getNode(), + message.setPayload(createOutboundPayload(schemaForMediaType.node(), OasModelHelper.getSchemaDefinitions(oasDocument), openApiSpec)); message.setHeader(HttpMessageHeaders.HTTP_CONTENT_TYPE, TEXT_PLAIN_VALUE); - } else if (APPLICATION_JSON_VALUE.equals(schemaForMediaType.getAdapted())) { + } else if (APPLICATION_JSON_VALUE.equals(schemaForMediaType.adapted())) { // Json Schema - message.setPayload(createOutboundPayload(schemaForMediaType.getNode(), + message.setPayload(createOutboundPayload(schemaForMediaType.node(), OasModelHelper.getSchemaDefinitions(oasDocument), openApiSpec)); message.setHeader(HttpMessageHeaders.HTTP_CONTENT_TYPE, APPLICATION_JSON_VALUE); } diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OasAdapter.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OasAdapter.java index a3f6fa8c52..9933ecebc8 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OasAdapter.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OasAdapter.java @@ -2,23 +2,6 @@ import io.apicurio.datamodels.core.models.Node; -public class OasAdapter { - - private final S node; - - private final T adapted; - - public OasAdapter(S node, T adapted) { - this.node = node; - this.adapted = adapted; - } - - public S getNode() { - return node; - } - - public T getAdapted() { - return adapted; - } +public record OasAdapter(S node, T adapted) { } diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OasModelHelper.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OasModelHelper.java index c15f6c3732..55b03f84f1 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OasModelHelper.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OasModelHelper.java @@ -16,8 +16,6 @@ package org.citrusframework.openapi.model; -import static java.util.Collections.singletonList; - import io.apicurio.datamodels.combined.visitors.CombinedVisitorAdapter; import io.apicurio.datamodels.openapi.models.OasDocument; import io.apicurio.datamodels.openapi.models.OasOperation; @@ -36,6 +34,11 @@ import io.apicurio.datamodels.openapi.v3.models.Oas30Parameter; import io.apicurio.datamodels.openapi.v3.models.Oas30Response; import jakarta.annotation.Nullable; +import org.citrusframework.openapi.model.v2.Oas20ModelHelper; +import org.citrusframework.openapi.model.v3.Oas30ModelHelper; +import org.citrusframework.util.StringUtils; +import org.springframework.http.MediaType; + import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -48,10 +51,8 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; -import org.citrusframework.openapi.model.v2.Oas20ModelHelper; -import org.citrusframework.openapi.model.v3.Oas30ModelHelper; -import org.citrusframework.util.StringUtils; -import org.springframework.http.MediaType; + +import static java.util.Collections.singletonList; public final class OasModelHelper { @@ -306,7 +307,8 @@ public static Optional getResponseForRandomGeneration(OasDocument o // Fallback 4: Pick the first response no matter which schema response = operation.responses.getResponses().stream() .map(resp -> responseMap.get(resp.getStatusCode())) - .filter(Objects::nonNull).findFirst(); + .filter(Objects::nonNull) + .findFirst(); } return response; diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OpenApiVersion.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OpenApiVersion.java index 13e4a74008..f9b9727b4c 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OpenApiVersion.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OpenApiVersion.java @@ -16,12 +16,12 @@ package org.citrusframework.openapi.model; -import java.util.Arrays; - import io.apicurio.datamodels.openapi.models.OasDocument; import io.apicurio.datamodels.openapi.v2.models.Oas20Document; import io.apicurio.datamodels.openapi.v3.models.Oas30Document; +import java.util.Arrays; + /** * List of supported OpenAPI specification versions and their corresponding model document types. */ diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OperationPathAdapter.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OperationPathAdapter.java index 7d943af929..987ed05c90 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OperationPathAdapter.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/OperationPathAdapter.java @@ -16,11 +16,11 @@ package org.citrusframework.openapi.model; -import static java.lang.String.format; - import io.apicurio.datamodels.openapi.models.OasOperation; import org.citrusframework.openapi.OpenApiUtils; +import static java.lang.String.format; + /** * Adapts the different paths associated with an OpenAPI operation to the {@link OasOperation}. * This record holds the API path, context path, full path, and the associated {@link OasOperation} object. diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v2/Oas20ModelHelper.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v2/Oas20ModelHelper.java index 34794a8f71..90cdadacf2 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v2/Oas20ModelHelper.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v2/Oas20ModelHelper.java @@ -26,16 +26,17 @@ import io.apicurio.datamodels.openapi.v2.models.Oas20Response; import io.apicurio.datamodels.openapi.v2.models.Oas20Schema; import io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition; -import java.util.Arrays; import jakarta.annotation.Nullable; +import org.citrusframework.openapi.model.OasAdapter; +import org.citrusframework.openapi.model.OasModelHelper; + +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import org.citrusframework.openapi.model.OasAdapter; -import org.citrusframework.openapi.model.OasModelHelper; public final class Oas20ModelHelper { diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v3/Oas30ModelHelper.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v3/Oas30ModelHelper.java index 1f56f4d4c5..6775c5ad8b 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v3/Oas30ModelHelper.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/model/v3/Oas30ModelHelper.java @@ -26,8 +26,13 @@ import io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody; import io.apicurio.datamodels.openapi.v3.models.Oas30Response; import io.apicurio.datamodels.openapi.v3.models.Oas30Schema; +import org.citrusframework.openapi.model.OasAdapter; +import org.citrusframework.openapi.model.OasModelHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -37,10 +42,6 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; -import org.citrusframework.openapi.model.OasAdapter; -import org.citrusframework.openapi.model.OasModelHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public final class Oas30ModelHelper { @@ -59,11 +60,7 @@ public static String getHost(Oas30Document openApiDoc) { String serverUrl = resolveUrl(openApiDoc.servers.get(0)); if (serverUrl.startsWith("http")) { - try { - return new URL(serverUrl).getHost(); - } catch (MalformedURLException e) { - throw new IllegalStateException(String.format(NO_URL_ERROR_MESSAGE, serverUrl)); - } + return URI.create(serverUrl).getHost(); } return "localhost"; @@ -78,7 +75,7 @@ public static List getSchemes(Oas30Document openApiDoc) { .map(Oas30ModelHelper::resolveUrl) .map(serverUrl -> { try { - return new URL(serverUrl).getProtocol(); + return URI.create(serverUrl).toURL().getProtocol(); } catch (MalformedURLException e) { LOG.warn(String.format(NO_URL_ERROR_MESSAGE, serverUrl)); return null; @@ -98,11 +95,7 @@ public static String getBasePath(Oas30Document openApiDoc) { String serverUrl = resolveUrl(server); if (serverUrl.startsWith("http")) { - try { - basePath = new URL(serverUrl).getPath(); - } catch (MalformedURLException e) { - throw new IllegalStateException(String.format(NO_URL_ERROR_MESSAGE, serverUrl)); - } + basePath = URI.create(serverUrl).getPath(); } else { basePath = serverUrl; } diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/validation/OpenApiRequestValidator.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/validation/OpenApiRequestValidator.java index 6948c793d8..bef2c35230 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/validation/OpenApiRequestValidator.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/validation/OpenApiRequestValidator.java @@ -16,19 +16,20 @@ package org.citrusframework.openapi.validation; -import static org.citrusframework.openapi.OpenApiSettings.isRequestValidationEnabledlobally; - import com.atlassian.oai.validator.OpenApiInteractionValidator; import com.atlassian.oai.validator.model.Request; import com.atlassian.oai.validator.model.SimpleRequest; import com.atlassian.oai.validator.report.ValidationReport; -import java.util.ArrayList; -import java.util.Collection; import org.citrusframework.exceptions.ValidationException; import org.citrusframework.http.message.HttpMessage; import org.citrusframework.http.message.HttpMessageHeaders; import org.citrusframework.openapi.model.OperationPathAdapter; +import java.util.ArrayList; +import java.util.Collection; + +import static org.citrusframework.openapi.OpenApiSettings.isRequestValidationEnabledlobally; + /** * Specific validator that uses atlassian and is responsible for validating HTTP requests * against an OpenAPI specification using the provided {@code OpenApiInteractionValidator}. @@ -83,8 +84,8 @@ Request createRequestFromMessage(OperationPathAdapter operationPathAdapter, value))); httpMessage.getHeaders().forEach((key, value) -> { - if (value instanceof Collection) { - ((Collection) value).forEach( v -> finalRequestBuilder.withHeader(key, v != null ? v.toString() : null)); + if (value instanceof Collection collection) { + collection.forEach( v -> finalRequestBuilder.withHeader(key, v != null ? v.toString() : null)); } else { finalRequestBuilder.withHeader(key, value != null ? value.toString() : null); diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/validation/OpenApiResponseValidator.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/validation/OpenApiResponseValidator.java index db4a41e375..9aba9b0764 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/validation/OpenApiResponseValidator.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/validation/OpenApiResponseValidator.java @@ -16,8 +16,6 @@ package org.citrusframework.openapi.validation; -import static org.citrusframework.openapi.OpenApiSettings.isResponseValidationEnabledGlobally; - import com.atlassian.oai.validator.OpenApiInteractionValidator; import com.atlassian.oai.validator.model.Request.Method; import com.atlassian.oai.validator.model.Response; @@ -28,6 +26,8 @@ import org.citrusframework.openapi.model.OperationPathAdapter; import org.springframework.http.HttpStatusCode; +import static org.citrusframework.openapi.OpenApiSettings.isResponseValidationEnabledGlobally; + /** * Specific validator, that facilitates the use of Atlassian's Swagger Request Validator, * and delegates validation of OpenApi requests to instances of {@link OpenApiRequestValidator}. diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/xml/OpenApi.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/xml/OpenApi.java index f7a12adc9d..41eed4a77e 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/xml/OpenApi.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/xml/OpenApi.java @@ -16,10 +16,6 @@ package org.citrusframework.openapi.xml; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; @@ -46,6 +42,10 @@ import org.citrusframework.xml.actions.Receive; import org.citrusframework.xml.actions.Send; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + @XmlRootElement(name = "openapi") public class OpenApi implements TestActionBuilder, ReferenceResolverAware { diff --git a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/yaml/OpenApi.java b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/yaml/OpenApi.java index 4958fddc26..4a67110219 100644 --- a/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/yaml/OpenApi.java +++ b/connectors/citrus-openapi/src/main/java/org/citrusframework/openapi/yaml/OpenApi.java @@ -16,10 +16,6 @@ package org.citrusframework.openapi.yaml; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import org.citrusframework.TestAction; import org.citrusframework.TestActionBuilder; import org.citrusframework.actions.ReceiveMessageAction; @@ -36,9 +32,13 @@ import org.citrusframework.openapi.actions.OpenApiServerRequestActionBuilder; import org.citrusframework.spi.ReferenceResolver; import org.citrusframework.spi.ReferenceResolverAware; +import org.citrusframework.yaml.actions.Message; import org.citrusframework.yaml.actions.Receive; import org.citrusframework.yaml.actions.Send; -import org.citrusframework.yaml.actions.Message; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; public class OpenApi implements TestActionBuilder, ReferenceResolverAware { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiPathRegistryTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiPathRegistryTest.java index 9d811711f6..d837f1f0ee 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiPathRegistryTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiPathRegistryTest.java @@ -16,10 +16,8 @@ package org.citrusframework.openapi; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; +import org.testng.Assert; +import org.testng.annotations.Test; import java.util.ArrayList; import java.util.HashSet; @@ -28,8 +26,11 @@ import java.util.Random; import java.util.Set; import java.util.stream.Collectors; -import org.testng.Assert; -import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; public class OpenApiPathRegistryTest { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiRepositoryTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiRepositoryTest.java index 9185cc6081..fe61791bf2 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiRepositoryTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiRepositoryTest.java @@ -16,6 +16,15 @@ package org.citrusframework.openapi; +import org.citrusframework.spi.Resource; +import org.testng.annotations.Test; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Optional; + import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -24,14 +33,6 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; -import java.util.Optional; -import org.citrusframework.spi.Resource; -import org.testng.annotations.Test; - public class OpenApiRepositoryTest { private static final String ROOT = "/root"; diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSettingsTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSettingsTest.java index c96cd5f5b6..d4e448ec26 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSettingsTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSettingsTest.java @@ -1,5 +1,10 @@ package org.citrusframework.openapi; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; + import static org.citrusframework.openapi.OpenApiSettings.GENERATE_OPTIONAL_FIELDS_PROPERTY; import static org.citrusframework.openapi.OpenApiSettings.REQUEST_VALIDATION_ENABLED_PROPERTY; import static org.citrusframework.openapi.OpenApiSettings.RESPONSE_VALIDATION_ENABLED_PROPERTY; @@ -8,11 +13,6 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; - public class OpenApiSettingsTest { private final EnvironmentVariables environmentVariables = new EnvironmentVariables(); diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSpecificationAdapterTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSpecificationAdapterTest.java index 6693078ef2..65c1433bc4 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSpecificationAdapterTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSpecificationAdapterTest.java @@ -1,14 +1,14 @@ package org.citrusframework.openapi; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + public class OpenApiSpecificationAdapterTest { @Mock @@ -34,14 +34,14 @@ public void tearDown() throws Exception { @Test public void shouldProvideOpenApiSpecification() { - OpenApiSpecification specification = openApiSpecificationAdapter.getOpenApiSpecification(); + OpenApiSpecification specification = openApiSpecificationAdapter.openApiSpecification(); assertNotNull(specification, "OpenApiSpecification should not be null"); assertEquals(specification, openApiSpecificationMock, "OpenApiSpecification should match the mock"); } @Test public void shouldProvideEntity() { - Object entity = openApiSpecificationAdapter.getEntity(); + Object entity = openApiSpecificationAdapter.entity(); assertNotNull(entity, "Entity should not be null"); assertEquals(entity, entityMock, "Entity should match the mock"); } diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSpecificationTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSpecificationTest.java index 5a8cb34c45..05f22c522a 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSpecificationTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiSpecificationTest.java @@ -1,12 +1,7 @@ package org.citrusframework.openapi; import io.apicurio.datamodels.openapi.models.OasDocument; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import javax.net.ssl.HttpsURLConnection; import org.citrusframework.context.TestContext; -import org.citrusframework.endpoint.EndpointConfiguration; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.http.client.HttpClient; import org.citrusframework.http.client.HttpEndpointConfiguration; @@ -23,12 +18,23 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import javax.net.ssl.HttpsURLConnection; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Optional; import static org.citrusframework.util.FileUtils.readToString; -import static org.mockito.Mockito.*; -import static org.testng.Assert.*; +import static org.mockito.AdditionalAnswers.returnsFirstArg; +import static org.mockito.Mockito.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; public class OpenApiSpecificationTest { @@ -211,21 +217,21 @@ public static Object[][] specSources() { } @Test(dataProvider = "lazyInitializationDataprovider") - public void shouldDisableEnableRequestValidationWhenSet(String requestUrl, String specSource) throws IOException { + public void shouldDisableEnableRequestValidationWhenSet(String requestUrl, String specSource) { // Given OpenApiSpecification specification = new OpenApiSpecification() { + @Override URL toSpecUrl(String resolvedSpecUrl) { return mockUrlConnection(resolvedSpecUrl); } }; + specification.setRequestUrl(requestUrl); specification.setHttpClient("sampleHttpClient"); specification.setSpecUrl(specSource); - when(testContextMock.replaceDynamicContentInString(isA(String.class))).thenAnswer(answer-> - answer.getArgument(0) - ); + when(testContextMock.replaceDynamicContentInString(isA(String.class))).thenAnswer(returnsFirstArg()); when(testContextMock.getReferenceResolver()).thenReturn(referenceResolverMock); when(referenceResolverMock.isResolvable("sampleHttpClient", HttpClient.class)).thenReturn(true); @@ -233,9 +239,6 @@ URL toSpecUrl(String resolvedSpecUrl) { when(httpClient.getEndpointConfiguration()).thenReturn(endpointConfigurationMock); when(endpointConfigurationMock.getRequestUrl()).thenReturn("http://org.citrus.sample"); - boolean sampleHttpCient = testContextMock.getReferenceResolver() - .isResolvable("sampleHttpClient", HttpClient.class); - // When specification.setRequestValidationEnabled(false); @@ -383,5 +386,4 @@ public void shouldReturnSpecUrlInAbsenceOfRequestUrl() { assertEquals(openApiSpecification.getRequestUrl(), "http://or.citrus.sample"); } - } diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiTestDataGeneratorTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiTestDataGeneratorTest.java index 89d19ac670..ab063e27c9 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiTestDataGeneratorTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/OpenApiTestDataGeneratorTest.java @@ -16,17 +16,18 @@ package org.citrusframework.openapi; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; - import com.fasterxml.jackson.core.JsonProcessingException; import io.apicurio.datamodels.openapi.models.OasSchema; -import java.util.Map; import org.citrusframework.openapi.model.OasModelHelper; import org.citrusframework.spi.Resources; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.Map; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; + // TODO: Add more tests public class OpenApiTestDataGeneratorTest { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/groovy/OpenApiClientTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/groovy/OpenApiClientTest.java index b65e3f9ed7..607d1b3c54 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/groovy/OpenApiClientTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/groovy/OpenApiClientTest.java @@ -16,11 +16,6 @@ package org.citrusframework.openapi.groovy; -import java.io.IOException; -import java.util.Map; -import java.util.Queue; -import java.util.concurrent.ArrayBlockingQueue; - import org.citrusframework.TestActor; import org.citrusframework.TestCase; import org.citrusframework.TestCaseMetaInfo; @@ -57,6 +52,11 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.io.IOException; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.ArrayBlockingQueue; + import static org.citrusframework.http.endpoint.builder.HttpEndpoints.http; public class OpenApiClientTest extends AbstractGroovyActionDslTest { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/groovy/OpenApiServerTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/groovy/OpenApiServerTest.java index 6a1ad5bb02..61023c6dcd 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/groovy/OpenApiServerTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/groovy/OpenApiServerTest.java @@ -16,8 +16,6 @@ package org.citrusframework.openapi.groovy; -import java.util.Map; - import org.citrusframework.TestActor; import org.citrusframework.TestCase; import org.citrusframework.TestCaseMetaInfo; @@ -45,6 +43,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.Map; + import static org.citrusframework.endpoint.direct.DirectEndpoints.direct; import static org.citrusframework.http.endpoint.builder.HttpEndpoints.http; import static org.testng.Assert.assertEquals; diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/integration/OpenApiServerIT.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/integration/OpenApiServerIT.java index 03bca16cd3..d29a11f75a 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/integration/OpenApiServerIT.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/integration/OpenApiServerIT.java @@ -165,7 +165,7 @@ public void shouldFailOnWrongQueryIdTypeWithOasDisabled() { assertThrows(TestCaseFailedException.class, () -> then(addPetBuilder)); } - @CitrusTest + @CitrusTest public void shouldSucceedOnWrongQueryIdTypeWithOasDisabled() { variable("petId", "xxx"); diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/OperationPathAdapterTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/OperationPathAdapterTest.java index cec2e46744..7846daf42b 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/OperationPathAdapterTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/OperationPathAdapterTest.java @@ -1,22 +1,14 @@ package org.citrusframework.openapi.model; -import io.apicurio.datamodels.openapi.models.OasOperation; import io.apicurio.datamodels.openapi.v3.models.Oas30Operation; import org.citrusframework.openapi.OpenApiUtils; -import org.citrusframework.openapi.model.OperationPathAdapter; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static java.lang.String.format; -import static org.mockito.Mockito.when; import static org.testng.Assert.assertEquals; public class OperationPathAdapterTest { - @Test public void shouldReturnFormattedStringWhenToStringIsCalled() { // Given diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v2/Oas20ModelHelperTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v2/Oas20ModelHelperTest.java index f57d3c46ce..501c497f7c 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v2/Oas20ModelHelperTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v2/Oas20ModelHelperTest.java @@ -1,8 +1,5 @@ package org.citrusframework.openapi.model.v2; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - import io.apicurio.datamodels.openapi.models.OasResponse; import io.apicurio.datamodels.openapi.models.OasSchema; import io.apicurio.datamodels.openapi.v2.models.Oas20Document; @@ -12,11 +9,15 @@ import io.apicurio.datamodels.openapi.v2.models.Oas20Response; import io.apicurio.datamodels.openapi.v2.models.Oas20Responses; import io.apicurio.datamodels.openapi.v2.models.Oas20Schema; -import java.util.List; -import java.util.Optional; import org.citrusframework.openapi.model.OasModelHelper; import org.testng.annotations.Test; +import java.util.List; +import java.util.Optional; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + public class Oas20ModelHelperTest { @Test diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v3/Oas30ModelHelperTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v3/Oas30ModelHelperTest.java index 9feee74a1a..b26f2f7780 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v3/Oas30ModelHelperTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/model/v3/Oas30ModelHelperTest.java @@ -1,9 +1,5 @@ package org.citrusframework.openapi.model.v3; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; - import io.apicurio.datamodels.openapi.models.OasResponse; import io.apicurio.datamodels.openapi.models.OasSchema; import io.apicurio.datamodels.openapi.v3.models.Oas30Document; @@ -14,13 +10,18 @@ import io.apicurio.datamodels.openapi.v3.models.Oas30Response; import io.apicurio.datamodels.openapi.v3.models.Oas30Responses; import io.apicurio.datamodels.openapi.v3.models.Oas30Schema; -import java.util.Collection; -import java.util.Map; -import java.util.Optional; import org.citrusframework.openapi.model.OasModelHelper; import org.springframework.http.MediaType; import org.testng.annotations.Test; +import java.util.Collection; +import java.util.Map; +import java.util.Optional; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; + public class Oas30ModelHelperTest { @Test diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiRequestValidationProcessorTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiRequestValidationProcessorTest.java index fc72cd5ade..7c7a578106 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiRequestValidationProcessorTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiRequestValidationProcessorTest.java @@ -1,14 +1,5 @@ package org.citrusframework.openapi.validation; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Optional; import org.citrusframework.context.TestContext; import org.citrusframework.http.message.HttpMessage; import org.citrusframework.message.Message; @@ -21,6 +12,16 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + public class OpenApiRequestValidationProcessorTest { @Mock diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiRequestValidatorTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiRequestValidatorTest.java index d1decc05a3..9b97d42b78 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiRequestValidatorTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiRequestValidatorTest.java @@ -4,27 +4,34 @@ import com.atlassian.oai.validator.model.Request; import com.atlassian.oai.validator.model.Request.Method; import com.atlassian.oai.validator.report.ValidationReport; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.citrusframework.exceptions.ValidationException; import org.citrusframework.http.message.HttpMessage; import org.citrusframework.http.message.HttpMessageHeaders; import org.citrusframework.openapi.model.OperationPathAdapter; -import org.citrusframework.openapi.validation.OpenApiRequestValidator; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.springframework.web.bind.annotation.RequestMethod; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; -import static org.testng.Assert.*; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; public class OpenApiRequestValidatorTest { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiResponseValidationProcessorTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiResponseValidationProcessorTest.java index a7aabba892..bd60fd55b6 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiResponseValidationProcessorTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiResponseValidationProcessorTest.java @@ -15,7 +15,12 @@ import java.util.Optional; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class OpenApiResponseValidationProcessorTest { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiResponseValidatorTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiResponseValidatorTest.java index d8d4433447..5bfef2eacb 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiResponseValidatorTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/validation/OpenApiResponseValidatorTest.java @@ -4,24 +4,31 @@ import com.atlassian.oai.validator.model.Request.Method; import com.atlassian.oai.validator.model.Response; import com.atlassian.oai.validator.report.ValidationReport; -import io.apicurio.datamodels.core.models.common.Operation; import io.apicurio.datamodels.openapi.models.OasOperation; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Map; import org.citrusframework.exceptions.ValidationException; import org.citrusframework.http.message.HttpMessage; import org.citrusframework.openapi.model.OperationPathAdapter; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.springframework.http.HttpStatusCode; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Map; + import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; -import static org.testng.Assert.*; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; public class OpenApiResponseValidatorTest { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/xml/OpenApiClientTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/xml/OpenApiClientTest.java index 69805ac452..30ad30e4eb 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/xml/OpenApiClientTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/xml/OpenApiClientTest.java @@ -16,11 +16,6 @@ package org.citrusframework.openapi.xml; -import java.io.IOException; -import java.util.Map; -import java.util.Queue; -import java.util.concurrent.ArrayBlockingQueue; - import org.citrusframework.TestActor; import org.citrusframework.TestCase; import org.citrusframework.TestCaseMetaInfo; @@ -60,6 +55,11 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.io.IOException; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.ArrayBlockingQueue; + import static org.citrusframework.http.endpoint.builder.HttpEndpoints.http; public class OpenApiClientTest extends AbstractXmlActionTest { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/xml/OpenApiServerTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/xml/OpenApiServerTest.java index 9e9a832291..b151699c66 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/xml/OpenApiServerTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/xml/OpenApiServerTest.java @@ -16,8 +16,6 @@ package org.citrusframework.openapi.xml; -import java.util.Map; - import org.citrusframework.TestActor; import org.citrusframework.TestCase; import org.citrusframework.TestCaseMetaInfo; @@ -45,6 +43,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.Map; + import static org.citrusframework.endpoint.direct.DirectEndpoints.direct; import static org.citrusframework.http.endpoint.builder.HttpEndpoints.http; diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/yaml/OpenApiClientTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/yaml/OpenApiClientTest.java index 0b09fa9c52..b5b152d559 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/yaml/OpenApiClientTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/yaml/OpenApiClientTest.java @@ -16,11 +16,6 @@ package org.citrusframework.openapi.yaml; -import java.io.IOException; -import java.util.Map; -import java.util.Queue; -import java.util.concurrent.ArrayBlockingQueue; - import org.citrusframework.TestActor; import org.citrusframework.TestCase; import org.citrusframework.TestCaseMetaInfo; @@ -58,6 +53,11 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.io.IOException; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.ArrayBlockingQueue; + import static org.citrusframework.http.endpoint.builder.HttpEndpoints.http; public class OpenApiClientTest extends AbstractYamlActionTest { diff --git a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/yaml/OpenApiServerTest.java b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/yaml/OpenApiServerTest.java index 2171fac921..723609e773 100644 --- a/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/yaml/OpenApiServerTest.java +++ b/connectors/citrus-openapi/src/test/java/org/citrusframework/openapi/yaml/OpenApiServerTest.java @@ -16,8 +16,6 @@ package org.citrusframework.openapi.yaml; -import java.util.Map; - import org.citrusframework.TestActor; import org.citrusframework.TestCase; import org.citrusframework.TestCaseMetaInfo; @@ -45,6 +43,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.Map; + import static org.citrusframework.endpoint.direct.DirectEndpoints.direct; import static org.citrusframework.http.endpoint.builder.HttpEndpoints.http;