use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.
the class ProviderFactoryTest method testCustomProviderSortingWIOnly.
@Test
public void testCustomProviderSortingWIOnly() {
ProviderFactory pf = ServerProviderFactory.getInstance();
pf.setUserProviders(Arrays.asList(new DWriterInterceptor(), new CWriterInterceptor(), new AWriterInterceptor(), new BWriterInterceptor()));
Comparator<ProviderInfo<WriterInterceptor>> comp = new Comparator<ProviderInfo<WriterInterceptor>>() {
@Override
public int compare(ProviderInfo<WriterInterceptor> o1, ProviderInfo<WriterInterceptor> o2) {
WriterInterceptor provider1 = o1.getProvider();
WriterInterceptor provider2 = o2.getProvider();
return provider1.getClass().getName().compareTo(provider2.getClass().getName());
}
};
pf.setProviderComparator(comp);
Collection<ProviderInfo<WriterInterceptor>> values = pf.writerInterceptors.values();
assertEquals(4, values.size());
Iterator<ProviderInfo<WriterInterceptor>> iterator = values.iterator();
assertEquals(AWriterInterceptor.class, iterator.next().getProvider().getClass());
assertEquals(BWriterInterceptor.class, iterator.next().getProvider().getClass());
assertEquals(CWriterInterceptor.class, iterator.next().getProvider().getClass());
assertEquals(DWriterInterceptor.class, iterator.next().getProvider().getClass());
}
use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.
the class ProviderFactoryTest method testCustomProviderSortingWithBus.
@Test
public void testCustomProviderSortingWithBus() {
WildcardReader wc1 = new WildcardReader();
WildcardReader2 wc2 = new WildcardReader2();
Bus bus = BusFactory.newInstance().createBus();
bus.setProperty(MessageBodyReader.class.getName(), wc1);
ProviderFactory pf = ServerProviderFactory.createInstance(bus);
pf.registerUserProvider(wc2);
List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders();
assertEquals(11, readers.size());
assertSame(wc2, readers.get(7).getProvider());
assertSame(wc1, readers.get(8).getProvider());
}
use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.
the class ProviderFactoryTest method indexOf.
private int indexOf(List<? extends Object> providerInfos, Class<?> providerType) {
int index = 0;
for (Object pi : providerInfos) {
Object p = ((ProviderInfo<?>) pi).getProvider();
if (p.getClass().isAssignableFrom(providerType)) {
break;
}
index++;
}
return index;
}
use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.
the class ProviderFactoryTest method testCustomProviderSortingParamConverterProvider.
@Test
public void testCustomProviderSortingParamConverterProvider() {
ParamConverterProvider h = new CustomerParameterHandler();
ParamConverterProvider hp = new PriorityCustomerParameterHandler();
ProviderFactory pf = ServerProviderFactory.getInstance();
pf.setUserProviders(Arrays.asList(h, hp));
Comparator<ProviderInfo<ParamConverterProvider>> comp = new Comparator<ProviderInfo<ParamConverterProvider>>() {
@Override
public int compare(ProviderInfo<ParamConverterProvider> o1, ProviderInfo<ParamConverterProvider> o2) {
ParamConverterProvider provider1 = o1.getProvider();
ParamConverterProvider provider2 = o2.getProvider();
return provider1.getClass().getName().compareTo(provider2.getClass().getName());
}
};
pf.setProviderComparator(comp);
ParamConverter<Customer> h2 = pf.createParameterHandler(Customer.class, Customer.class, null, new MessageImpl());
assertSame(h2, h);
}
use of org.apache.cxf.jaxrs.model.ProviderInfo in project cxf by apache.
the class ProviderFactoryTest method testCreateMessageBodyReaderInterceptorWithFaultMessageAndReaderInterceptor.
@Test
public void testCreateMessageBodyReaderInterceptorWithFaultMessageAndReaderInterceptor() throws Exception {
ReaderInterceptor ri = readerInterceptorContext -> readerInterceptorContext.proceed();
ProviderInfo<ReaderInterceptor> pi = new ProviderInfo<>(ri, null, true);
ServerProviderFactory spf = ServerProviderFactory.getInstance();
spf.readerInterceptors.put(new ProviderFactory.NameKey("org.apache.cxf.filter.binding", 1, ri.getClass()), pi);
final Message message = prepareFaultMessage(MediaType.APPLICATION_XML, MediaType.APPLICATION_XML);
List<ReaderInterceptor> interceptors = spf.createMessageBodyReaderInterceptor(Book.class, Book.class, new Annotation[0], MediaType.APPLICATION_XML_TYPE, message, true, null);
assertSame(2, interceptors.size());
}
Aggregations