Search in sources :

Example 1 with WebService

use of org.alfasoftware.soapstone.testsupport.WebService in project soapstone by alfasoftware.

the class TestSoapstoneOpenApiReader method setup.

/**
 * Build the {@link SoapstoneConfiguration} for the service the reader should run over
 */
@BeforeClass
public static void setup() {
    DocumentationProvider documentationProvider = new DocumentationProviderBuilder().withMethodDocumentationProvider(method -> Optional.ofNullable(method.getAnnotation(Documentation.class)).map(Documentation::value)).withMethodReturnDocumentationProvider(method -> Optional.ofNullable(method.getAnnotation(Documentation.class)).map(Documentation::returnValue)).withParameterDocumentationProvider(parameter -> Optional.ofNullable(parameter.getAnnotation(Documentation.class)).map(Documentation::value)).withModelDocumentationProvider(annotations -> annotations.stream().filter(Documentation.class::isInstance).findFirst().map(Documentation.class::cast).map(Documentation::value)).build();
    final Pattern tagPattern = Pattern.compile("/(?<tag>.*?)(?:/.*)?");
    Function<String, String> tagProvider = path -> {
        Matcher matcher = tagPattern.matcher(path);
        return matcher.matches() ? matcher.group("tag") : null;
    };
    AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
    ObjectMapper objectMapper = new ObjectMapper().setAnnotationIntrospector(AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector)).configure(FAIL_ON_UNKNOWN_PROPERTIES, false).configure(USE_WRAPPER_NAME_AS_PROPERTY_NAME, true).configure(FAIL_ON_EMPTY_BEANS, false).configure(WRITE_DATES_AS_TIMESTAMPS, false).configure(WRITE_ENUMS_USING_TO_STRING, true).configure(FAIL_ON_UNKNOWN_PROPERTIES, false).setSerializationInclusion(JsonInclude.Include.NON_NULL);
    Map<String, WebServiceClass<?>> webServices = new HashMap<>();
    webServices.put("/path", WebServiceClass.forClass(WebService.class, WebService::new));
    SoapstoneConfiguration soapstoneConfiguration = new SoapstoneConfiguration();
    soapstoneConfiguration.setWebServiceClasses(webServices);
    soapstoneConfiguration.setObjectMapper(objectMapper);
    soapstoneConfiguration.setDocumentationProvider(documentationProvider);
    soapstoneConfiguration.setTagProvider(tagProvider);
    soapstoneConfiguration.setSupportedGetOperations(Pattern.compile("get.*"));
    soapstoneConfiguration.setSupportedDeleteOperations(Pattern.compile("delete.*"));
    soapstoneConfiguration.setSupportedPutOperations(Pattern.compile("put.*"));
    soapstoneConfiguration.setVendor("Geoffrey");
    ModelConverters.getInstance().addConverter(new ParentAwareModelResolver(soapstoneConfiguration));
    SoapstoneOpenApiReader reader = new SoapstoneOpenApiReader(HOST_URL, soapstoneConfiguration);
    reader.setConfiguration(new SwaggerConfiguration());
    openAPI = reader.read(null);
}
Also used : FAIL_ON_EMPTY_BEANS(com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) BeforeClass(org.junit.BeforeClass) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) Parameter(io.swagger.v3.oas.models.parameters.Parameter) WebService(org.alfasoftware.soapstone.testsupport.WebService) HashMap(java.util.HashMap) Operation(io.swagger.v3.oas.models.Operation) Function(java.util.function.Function) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) FAIL_ON_UNKNOWN_PROPERTIES(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) Matcher(java.util.regex.Matcher) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) Schema(io.swagger.v3.oas.models.media.Schema) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) WRITE_ENUMS_USING_TO_STRING(com.fasterxml.jackson.databind.SerializationFeature.WRITE_ENUMS_USING_TO_STRING) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) USE_WRAPPER_NAME_AS_PROPERTY_NAME(com.fasterxml.jackson.databind.MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME) Discriminator(io.swagger.v3.oas.models.media.Discriminator) Matchers.allOf(org.hamcrest.Matchers.allOf) Assert.assertNotNull(org.junit.Assert.assertNotNull) SIMPLE(io.swagger.v3.oas.models.parameters.Parameter.StyleEnum.SIMPLE) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MediaType(io.swagger.v3.oas.models.media.MediaType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) WRITE_DATES_AS_TIMESTAMPS(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) ModelConverters(io.swagger.v3.core.converter.ModelConverters) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) Documentation(org.alfasoftware.soapstone.testsupport.WebService.Documentation) Optional(java.util.Optional) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) Matchers.is(org.hamcrest.Matchers.is) Pattern(java.util.regex.Pattern) Assert.assertEquals(org.junit.Assert.assertEquals) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) WebService(org.alfasoftware.soapstone.testsupport.WebService) Documentation(org.alfasoftware.soapstone.testsupport.WebService.Documentation) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.junit.BeforeClass)

Example 2 with WebService

use of org.alfasoftware.soapstone.testsupport.WebService in project soapstone by alfasoftware.

the class TestSoapstoneOpenApiReaderWithTypeNameProvider method setup.

/**
 * Build the {@link SoapstoneConfiguration} for the service the reader should run over
 */
@BeforeClass
public static void setup() {
    DocumentationProvider documentationProvider = new DocumentationProviderBuilder().withMethodDocumentationProvider(method -> Optional.ofNullable(method.getAnnotation(Documentation.class)).map(Documentation::value)).withMethodReturnDocumentationProvider(method -> Optional.ofNullable(method.getAnnotation(Documentation.class)).map(Documentation::returnValue)).withParameterDocumentationProvider(parameter -> Optional.ofNullable(parameter.getAnnotation(Documentation.class)).map(Documentation::value)).withModelDocumentationProvider(annotations -> annotations.stream().filter(Documentation.class::isInstance).findFirst().map(Documentation.class::cast).map(Documentation::value)).build();
    final Pattern tagPattern = Pattern.compile("/(?<tag>.*?)(?:/.*)?");
    Function<String, String> tagProvider = path -> {
        Matcher matcher = tagPattern.matcher(path);
        return matcher.matches() ? matcher.group("tag") : null;
    };
    AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
    AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
    ObjectMapper objectMapper = new ObjectMapper().setAnnotationIntrospector(AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector)).configure(FAIL_ON_UNKNOWN_PROPERTIES, false).configure(USE_WRAPPER_NAME_AS_PROPERTY_NAME, true).configure(FAIL_ON_EMPTY_BEANS, false).configure(WRITE_DATES_AS_TIMESTAMPS, false).configure(WRITE_ENUMS_USING_TO_STRING, true).configure(FAIL_ON_UNKNOWN_PROPERTIES, false).setSerializationInclusion(JsonInclude.Include.NON_NULL);
    Map<String, WebServiceClass<?>> webServices = new HashMap<>();
    webServices.put("/path", WebServiceClass.forClass(WebService.class, WebService::new));
    SoapstoneConfiguration soapstoneConfiguration = new SoapstoneConfiguration();
    soapstoneConfiguration.setWebServiceClasses(webServices);
    soapstoneConfiguration.setObjectMapper(objectMapper);
    soapstoneConfiguration.setDocumentationProvider(documentationProvider);
    soapstoneConfiguration.setTagProvider(tagProvider);
    soapstoneConfiguration.setTypeNameProvider(cls -> "sfx");
    soapstoneConfiguration.setSupportedGetOperations(Pattern.compile("get.*"));
    soapstoneConfiguration.setSupportedDeleteOperations(Pattern.compile("delete.*"));
    soapstoneConfiguration.setSupportedPutOperations(Pattern.compile("put.*"));
    soapstoneConfiguration.setVendor("Geoffrey");
    ModelConverters.getInstance().addConverter(new ParentAwareModelResolver(soapstoneConfiguration));
    SoapstoneOpenApiReader reader = new SoapstoneOpenApiReader(HOST_URL, soapstoneConfiguration);
    reader.setConfiguration(new SwaggerConfiguration());
    openAPI = reader.read(null);
}
Also used : FAIL_ON_EMPTY_BEANS(com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) BeforeClass(org.junit.BeforeClass) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) WebService(org.alfasoftware.soapstone.testsupport.WebService) HashMap(java.util.HashMap) Function(java.util.function.Function) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) FAIL_ON_UNKNOWN_PROPERTIES(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) Matcher(java.util.regex.Matcher) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) Schema(io.swagger.v3.oas.models.media.Schema) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) WRITE_ENUMS_USING_TO_STRING(com.fasterxml.jackson.databind.SerializationFeature.WRITE_ENUMS_USING_TO_STRING) USE_WRAPPER_NAME_AS_PROPERTY_NAME(com.fasterxml.jackson.databind.MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME) Discriminator(io.swagger.v3.oas.models.media.Discriminator) Matchers.allOf(org.hamcrest.Matchers.allOf) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) WRITE_DATES_AS_TIMESTAMPS(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) ModelConverters(io.swagger.v3.core.converter.ModelConverters) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) Documentation(org.alfasoftware.soapstone.testsupport.WebService.Documentation) Optional(java.util.Optional) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) Matchers.is(org.hamcrest.Matchers.is) Pattern(java.util.regex.Pattern) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) WebService(org.alfasoftware.soapstone.testsupport.WebService) Documentation(org.alfasoftware.soapstone.testsupport.WebService.Documentation) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) JaxbAnnotationIntrospector(com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.junit.BeforeClass)

Example 3 with WebService

use of org.alfasoftware.soapstone.testsupport.WebService in project soapstone by alfasoftware.

the class TestSoapstoneService method configure.

@Override
protected Application configure() {
    Map<String, WebServiceClass<?>> webServices = new HashMap<>();
    webServices.put("/path", WebServiceClass.forClass(WebService.class, WebService::new));
    SoapstoneService service = new SoapstoneServiceBuilder(webServices).withVendor(VENDOR).withExceptionMapper(EXCEPTION_MAPPER).withSupportedGetOperations("get.*").withSupportedPutOperations("put.*").withSupportedDeleteOperations("delete.*").withTagProvider(TAG_PROVIDER).build();
    return new ResourceConfig().registerInstances(service).register(LoggingFilter.class).register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(mock(HttpServletRequest.class)).to(HttpServletRequest.class);
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) WebService(org.alfasoftware.soapstone.testsupport.WebService) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) LoggingFilter(org.glassfish.jersey.filter.LoggingFilter) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Aggregations

HashMap (java.util.HashMap)3 WebService (org.alfasoftware.soapstone.testsupport.WebService)3 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)2 FAIL_ON_UNKNOWN_PROPERTIES (com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)2 USE_WRAPPER_NAME_AS_PROPERTY_NAME (com.fasterxml.jackson.databind.MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 FAIL_ON_EMPTY_BEANS (com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS)2 WRITE_DATES_AS_TIMESTAMPS (com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)2 WRITE_ENUMS_USING_TO_STRING (com.fasterxml.jackson.databind.SerializationFeature.WRITE_ENUMS_USING_TO_STRING)2 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)2 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)2 JaxbAnnotationIntrospector (com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector)2 ModelConverters (io.swagger.v3.core.converter.ModelConverters)2 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)2 OpenAPI (io.swagger.v3.oas.models.OpenAPI)2 Discriminator (io.swagger.v3.oas.models.media.Discriminator)2 Schema (io.swagger.v3.oas.models.media.Schema)2 Map (java.util.Map)2 Optional (java.util.Optional)2