use of org.glassfish.jersey.model.ContractProvider in project jersey by jersey.
the class CommonConfigTest method testRegisterClassContracts.
@Test
@SuppressWarnings("unchecked")
public void testRegisterClassContracts() throws Exception {
try {
final Class clazz = null;
//noinspection ConstantConditions
config.register(clazz, ReaderInterceptor.class);
fail("Cannot register null.");
} catch (final IllegalArgumentException e) {
// OK.
}
config.register(ComplexEmptyProvider.class, ReaderInterceptor.class, ContainerRequestFilter.class, WriterInterceptor.class);
final ContractProvider contractProvider = config.getComponentBag().getModel(ComplexEmptyProvider.class);
final Set<Class<?>> contracts = contractProvider.getContracts();
assertEquals(2, contracts.size());
assertTrue(ReaderInterceptor.class + " is not registered.", contracts.contains(ReaderInterceptor.class));
assertTrue(ContainerRequestFilter.class + " is not registered.", contracts.contains(ContainerRequestFilter.class));
assertFalse(WriterInterceptor.class + " should not be registered.", contracts.contains(WriterInterceptor.class));
assertTrue(config.getInstances().isEmpty());
assertTrue(config.getClasses().contains(ComplexEmptyProvider.class));
}
use of org.glassfish.jersey.model.ContractProvider in project jersey by jersey.
the class CommonConfigTest method testRegisterInstance.
@Test
public void testRegisterInstance() throws Exception {
try {
config.register(null);
fail("Cannot register null.");
} catch (final IllegalArgumentException e) {
// OK.
}
final ComplexEmptyProvider[] ceps = new ComplexEmptyProvider[2];
for (int i = 0; i < 2; i++) {
ceps[i] = new ComplexEmptyProvider();
config.register(ceps[i]);
}
final ContractProvider contractProvider = config.getComponentBag().getModel(ComplexEmptyProvider.class);
final Set<Class<?>> contracts = contractProvider.getContracts();
assertEquals(3, contracts.size());
assertTrue(contracts.contains(ReaderInterceptor.class));
assertTrue(contracts.contains(ContainerRequestFilter.class));
assertTrue(contracts.contains(ExceptionMapper.class));
assertTrue(config.isRegistered(ComplexEmptyProvider.class));
assertTrue(config.isRegistered(ceps[0]));
assertFalse(config.isRegistered(ceps[1]));
}
use of org.glassfish.jersey.model.ContractProvider in project jersey by jersey.
the class CommonConfigTest method testRegisterInstanceBingingPriority.
@Test
public void testRegisterInstanceBingingPriority() throws Exception {
try {
config.register(null, Priorities.USER);
fail("Cannot register null.");
} catch (final IllegalArgumentException e) {
// OK.
}
final Class<ComplexEmptyProvider> providerClass = ComplexEmptyProvider.class;
for (final int priority : new int[] { Priorities.USER, Priorities.AUTHENTICATION }) {
config.register(providerClass, priority);
final CommonConfig commonConfig = config;
final ContractProvider contractProvider = commonConfig.getComponentBag().getModel(providerClass);
final Set<Class<?>> contracts = contractProvider.getContracts();
// Feature is not there.
assertEquals(3, contracts.size());
assertTrue(contracts.contains(ReaderInterceptor.class));
assertTrue(contracts.contains(ContainerRequestFilter.class));
assertTrue(contracts.contains(ExceptionMapper.class));
// All priorities are the same.
assertEquals(Priorities.USER, contractProvider.getPriority(ReaderInterceptor.class));
assertEquals(Priorities.USER, contractProvider.getPriority(ContainerRequestFilter.class));
assertEquals(Priorities.USER, contractProvider.getPriority(ExceptionMapper.class));
}
}
use of org.glassfish.jersey.model.ContractProvider in project jersey by jersey.
the class CommonConfigTest method testRegisterClass.
@Test
public void testRegisterClass() throws Exception {
try {
final Class clazz = null;
//noinspection ConstantConditions
config.register(clazz);
fail("Cannot register null.");
} catch (final IllegalArgumentException e) {
// OK.
}
for (int i = 0; i < 2; i++) {
config.register(ComplexEmptyProvider.class);
}
final ContractProvider contractProvider = config.getComponentBag().getModel(ComplexEmptyProvider.class);
final Set<Class<?>> contracts = contractProvider.getContracts();
assertEquals(3, contracts.size());
assertTrue(contracts.contains(ReaderInterceptor.class));
assertTrue(contracts.contains(ContainerRequestFilter.class));
assertTrue(contracts.contains(ExceptionMapper.class));
assertTrue(config.isRegistered(ComplexEmptyProvider.class));
}
use of org.glassfish.jersey.model.ContractProvider in project jersey by jersey.
the class CommonConfigTest method testRegisterClassInstanceBindingPriorityClash.
@Test
public void testRegisterClassInstanceBindingPriorityClash() throws Exception {
final ComplexEmptyProvider complexEmptyProvider = new ComplexEmptyProvider();
config.register(ComplexEmptyProvider.class, Priorities.AUTHENTICATION);
config.register(complexEmptyProvider, Priorities.USER);
assertTrue(config.getClasses().contains(ComplexEmptyProvider.class));
assertFalse(config.getInstances().contains(complexEmptyProvider));
final ComponentBag componentBag = config.getComponentBag();
final ContractProvider contractProvider = componentBag.getModel(ComplexEmptyProvider.class);
final Set<Class<?>> contracts = contractProvider.getContracts();
// Feature is not there.
assertEquals(3, contracts.size());
assertTrue(contracts.contains(ReaderInterceptor.class));
assertTrue(contracts.contains(ContainerRequestFilter.class));
assertTrue(contracts.contains(ExceptionMapper.class));
// All priorities are the same.
assertEquals(Priorities.AUTHENTICATION, contractProvider.getPriority(ReaderInterceptor.class));
assertEquals(Priorities.AUTHENTICATION, contractProvider.getPriority(ContainerRequestFilter.class));
assertEquals(Priorities.AUTHENTICATION, contractProvider.getPriority(ExceptionMapper.class));
}
Aggregations