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);
}
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);
}
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);
}
});
}
Aggregations