diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/dsl/JsonSupport.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/dsl/JsonSupport.java index 683c52e1f1..3545a3aad1 100644 --- a/validation/citrus-validation-json/src/main/java/org/citrusframework/dsl/JsonSupport.java +++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/dsl/JsonSupport.java @@ -19,6 +19,8 @@ package org.citrusframework.dsl; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.citrusframework.message.builder.ObjectMappingPayloadBuilder; import org.citrusframework.validation.json.JsonMappingValidationProcessor; import org.citrusframework.validation.json.JsonMessageValidationContext; @@ -44,4 +46,24 @@ public static JsonMessageValidationContext.Builder json() { public static JsonMappingValidationProcessor.Builder validate(Class type) { return JsonMappingValidationProcessor.Builder.validate(type); } + + /** + * Static builder method constructing a mapping payload builder. + * @param payload + * @return + */ + public static ObjectMappingPayloadBuilder marshal(Object payload) { + return new ObjectMappingPayloadBuilder(payload); + } + + + /** + * Static builder method constructing a mapping payload builder. + * @param payload + * @param mapper + * @return + */ + public static ObjectMappingPayloadBuilder marshal(Object payload, ObjectMapper mapper) { + return new ObjectMappingPayloadBuilder(payload, mapper); + } } diff --git a/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/schema/JsonSchemaFilter.java b/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/schema/JsonSchemaFilter.java index 7429919748..443033abfb 100644 --- a/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/schema/JsonSchemaFilter.java +++ b/validation/citrus-validation-json/src/main/java/org/citrusframework/validation/json/schema/JsonSchemaFilter.java @@ -16,6 +16,11 @@ package org.citrusframework.validation.json.schema; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.json.JsonSchemaRepository; import org.citrusframework.json.schema.SimpleJsonSchema; @@ -23,13 +28,6 @@ import org.citrusframework.validation.json.JsonMessageValidationContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.util.StringUtils; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; /** * This class is responsible for filtering {@link SimpleJsonSchema}s based on a {@link JsonMessageValidationContext}. @@ -61,20 +59,14 @@ public List filter(List schemaRepositori private List getSchemaFromContext(JsonMessageValidationContext jsonMessageValidationContext, ReferenceResolver referenceResolver) { - try { - SimpleJsonSchema simpleJsonSchema = - referenceResolver.resolve(jsonMessageValidationContext.getSchema(), SimpleJsonSchema.class); + SimpleJsonSchema simpleJsonSchema = + referenceResolver.resolve(jsonMessageValidationContext.getSchema(), SimpleJsonSchema.class); - if (logger.isDebugEnabled()) { - logger.debug("Found specified schema: \"" + jsonMessageValidationContext.getSchema() + "\"."); - } - - return Collections.singletonList(simpleJsonSchema); - } catch (NoSuchBeanDefinitionException e) { - throw new CitrusRuntimeException( - "Could not find the specified schema: \"" + jsonMessageValidationContext.getSchema() + "\".", - e); + if (logger.isDebugEnabled()) { + logger.debug("Found specified schema: \"" + jsonMessageValidationContext.getSchema() + "\"."); } + + return Collections.singletonList(simpleJsonSchema); } private List filterByRepositoryName(List schemaRepositories, @@ -101,10 +93,10 @@ private List mergeRepositories(List sche } private boolean isSchemaSpecified(JsonMessageValidationContext context) { - return StringUtils.hasText(context.getSchema()); + return context.getSchema() != null && !context.getSchema().isEmpty() && !context.getSchema().isBlank(); } private boolean isSchemaRepositorySpecified(JsonMessageValidationContext context) { - return StringUtils.hasText(context.getSchemaRepository()); + return context.getSchemaRepository() != null && !context.getSchemaRepository().isEmpty() && !context.getSchemaRepository().isBlank(); } } diff --git a/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/schema/JsonSchemaFilterTest.java b/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/schema/JsonSchemaFilterTest.java index 562c590768..90c933b40c 100644 --- a/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/schema/JsonSchemaFilterTest.java +++ b/validation/citrus-validation-json/src/test/java/org/citrusframework/validation/json/schema/JsonSchemaFilterTest.java @@ -20,14 +20,13 @@ import java.util.Collections; import java.util.List; -import org.citrusframework.spi.ReferenceResolver; import org.citrusframework.exceptions.CitrusRuntimeException; import org.citrusframework.json.JsonSchemaRepository; import org.citrusframework.json.schema.SimpleJsonSchema; +import org.citrusframework.spi.ReferenceResolver; import org.citrusframework.validation.json.JsonMessageValidationContext; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -193,7 +192,7 @@ public void testNoSchemaFoundThrowsException() { //Setup application validationContext when(referenceResolverMock.resolve(validationContext.getSchema(), SimpleJsonSchema.class)) - .thenThrow(NoSuchBeanDefinitionException.class); + .thenThrow(CitrusRuntimeException.class); //WHEN jsonSchemaFilter.filter(schemaRepositories, validationContext, referenceResolverMock);