use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class WadlGeneratorConfigurationLoaderTest method testLoadConfigClass.
@Test
public void testLoadConfigClass() throws URISyntaxException {
final ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.property(ServerProperties.WADL_GENERATOR_CONFIG, MyWadlGeneratorConfig.class.getName());
final InjectionManager locator = InjectionManagerFactory.createInjectionManager(resourceConfig.getProperties());
final WadlGenerator wadlGenerator = WadlGeneratorConfigLoader.loadWadlGeneratorsFromConfig(resourceConfig.getProperties()).createWadlGenerator(locator);
Assert.assertEquals(MyWadlGenerator.class, wadlGenerator.getClass());
}
use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class SubResourceProgrammaticTest method testComplex.
@Test
public void testComplex() throws ExecutionException, InterruptedException {
ApplicationHandler handler = new ApplicationHandler(new ResourceConfig(RootResource.class));
int singletonCounter = 0;
_test(handler, "/root/complex/", "inflector");
_test(handler, "/root/complex/singleton", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration/iteration", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration-class", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration-instance", "singleton:0");
_test(handler, "/root/complex/standard", "standard:0");
_test(handler, "/root/complex/standard/iteration", "standard:0");
_test(handler, "/root/complex/singleton-method/", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton/iteration/iteration-standard", "standard:0");
_test(handler, "/root/complex/standard/iteration/iteration-singleton", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard", "standard:0");
_test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration", "standard:0");
_test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration" + "/iteration-singleton/iteration-class", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration" + "/iteration-singleton/iteration-class/iteration-instance", "singleton:0");
_test(handler, "/root/complex/standard/iteration/iteration-singleton", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton-method/", "singleton:" + singletonCounter++);
_test(handler, "/root/complex/singleton", "singleton:" + singletonCounter++);
_test(handler, "/root/complex", "inflector");
}
use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class SubResourceProgrammaticTest method testInvalidSubResource.
@Test
public void testInvalidSubResource() throws ExecutionException, InterruptedException {
ApplicationHandler handler = new ApplicationHandler(new ResourceConfig(WrongResource.class));
_test(handler, "/wrong", "ok");
try {
final ContainerResponse response = handler.apply(RequestContextBuilder.from("/wrong/locator", "GET").build()).get();
assertEquals(500, response.getStatus());
fail("Should throw exception caused by validation errors of Sub Resource.");
} catch (Throwable e) {
// ok - Should throw exception caused by validation errors of Sub Resource.
}
}
use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class ValidatorTest method testDisableFailOnErrors.
@Test
public void testDisableFailOnErrors() throws ExecutionException, InterruptedException {
final ResourceConfig rc = new ResourceConfig(AmbiguousLocatorResource1.class, AmbiguousLocatorResource2.class, AmbiguousParameterResource.class, AmbiguousResource1.class, AmbiguousResource2.class, ConcreteGenericArrayResource.class, ConcreteParameterizedTypeResource.class, EmptyResource.class, GenericArrayResource.class, MethodAndLocatorResource.class, MethodAndLocatorResource2.class, MyBeanParam.class, ParameterizedTypeResource.class, PercentEncodedCaseSensitiveTest.class, PercentEncodedTest.class, ResourceAsProvider.class, ResourceMethodWithVoidReturnType.class, ResourceRoot.class, ResourceRootNotUnique.class, ResourceSubPathRoot.class, ResourceWithMultipleScopes.class, TestAmbiguousParams.class, TestAsyncGetRMReturningVoid.class, TestEmptyPathSegment.class, TestEntityParamOnSRL.class, TestGetRMConsumingEntity.class, TestGetRMConsumingFormParam.class, TestGetRMReturningVoid.class, TestGetSRMConsumingEntity.class, TestGetSRMConsumingFormParam.class, TestGetSRMReturningVoid.class, TestMoreThanOneEntity.class, TestMultipleHttpMethodDesignatorsRM.class, TestMultipleHttpMethodDesignatorsSRM.class, TestNonConflictingHttpMethodDelete.class, TestNonPublicRM.class, TestRelaxedProducesConsumesParserRules.class, TestRootResourceNonAmbigCtors.class, TestSRLReturningVoid.class, TwoLocatorsResource.class, TypeVariableResource.class, UniqueResource.class, // we should still be able to invoke a GET on this one.
TestDisableValidationFailOnErrorResource.class);
rc.property(ServerProperties.RESOURCE_VALIDATION_IGNORE_ERRORS, true);
ApplicationHandler ah = new ApplicationHandler(rc);
final ContainerRequest request = RequestContextBuilder.from("/test-disable-validation-fail-on-error", "GET").build();
ContainerResponse response = ah.apply(request).get();
assertEquals(200, response.getStatus());
assertEquals("PASSED", response.getEntity());
}
use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.
the class ChildResourceTest method createApplication.
private ApplicationHandler createApplication() {
final Resource.Builder rootBuilder = Resource.builder("root");
rootBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {
@Override
public String apply(ContainerRequestContext requestContext) {
return "root-get";
}
});
rootBuilder.addChildResource("child").addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {
@Override
public String apply(ContainerRequestContext requestContext) {
return "sub-get";
}
}).build();
Resource.Builder anotherChildBuilder = Resource.builder("another-child");
anotherChildBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {
@Override
public String apply(ContainerRequestContext requestContext) {
return "another-child-get";
}
});
rootBuilder.addChildResource(anotherChildBuilder.build());
Resource resource = rootBuilder.build();
ResourceConfig resourceConfig = new ResourceConfig().registerResources(resource);
return new ApplicationHandler(resourceConfig);
}
Aggregations