use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class JAXBElementProviderTest method testSingleJAXBContext.
@Test
public void testSingleJAXBContext() throws Exception {
ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(JAXBResource.class, JAXBResource.class, true, true);
JAXBElementProvider<Book> provider = new JAXBElementProvider<Book>();
provider.setSingleJaxbContext(true);
provider.init(Collections.singletonList(cri));
JAXBContext bookContext = provider.getJAXBContext(Book.class, Book.class);
assertNotNull(bookContext);
JAXBContext superBookContext = provider.getJAXBContext(SuperBook.class, SuperBook.class);
assertSame(bookContext, superBookContext);
JAXBContext book2Context = provider.getJAXBContext(Book2.class, Book2.class);
assertSame(bookContext, book2Context);
}
use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class ProviderFactoryTest method testGetComplexProvider2.
@Test
public void testGetComplexProvider2() throws Exception {
ServerProviderFactory pf = ServerProviderFactory.getInstance();
pf.registerUserProvider(new ComplexMessageBodyReader());
MessageBodyReader<Book> reader = pf.createMessageBodyReader(Book.class, Book.class, null, MediaType.APPLICATION_JSON_TYPE, new MessageImpl());
assertTrue(ComplexMessageBodyReader.class == reader.getClass());
}
use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class SelectMethodCandidatesTest method doTestGenericSuperType.
private void doTestGenericSuperType(Class<?> serviceClass, String methodName) throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(serviceClass);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentTypes = "text/xml";
String acceptContentTypes = "text/xml";
Message m = new MessageImpl();
m.put(Message.CONTENT_TYPE, "text/xml");
Exchange ex = new ExchangeImpl();
ex.setInMessage(m);
m.setExchange(ex);
Endpoint e = EasyMock.createMock(Endpoint.class);
e.isEmpty();
EasyMock.expectLastCall().andReturn(true).anyTimes();
e.size();
EasyMock.expectLastCall().andReturn(0).anyTimes();
e.getEndpointInfo();
EasyMock.expectLastCall().andReturn(null).anyTimes();
e.get(ServerProviderFactory.class.getName());
EasyMock.expectLastCall().andReturn(ServerProviderFactory.getInstance()).times(3);
e.get("org.apache.cxf.jaxrs.comparator");
EasyMock.expectLastCall().andReturn(null);
EasyMock.replay(e);
ex.put(Endpoint.class, e);
MetadataMap<String, String> values = new MetadataMap<String, String>();
OperationResourceInfo ori = findTargetResourceClass(resources, m, "/books", methodName, values, contentTypes, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals("resourceMethod needs to be selected", methodName.toLowerCase() + "Entity", ori.getMethodToInvoke().getName());
String value = "<Book><name>The Book</name><id>2</id></Book>";
m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
List<Object> params = JAXRSUtils.processParameters(ori, values, m);
assertEquals(1, params.size());
Book book = (Book) params.get(0);
assertNotNull(book);
assertEquals(2L, book.getId());
assertEquals("The Book", book.getName());
}
use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class ResponseImplTest method testGetEntity.
@Test
public void testGetEntity() {
final Book book = new Book();
Response r = Response.ok().entity(book).build();
assertSame(book, r.getEntity());
}
use of org.apache.cxf.jaxrs.resources.Book in project cxf by apache.
the class JSONProviderTest method testDoNotEscapeForwardSlashes.
@Test
public void testDoNotEscapeForwardSlashes() throws Exception {
JSONProvider<Book> provider = new JSONProvider<Book>();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(new Book("http://cxf", 123), Book.class, Book.class, new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos);
assertTrue(bos.toString().contains("\"name\":\"http://cxf\""));
}
Aggregations