Search in sources :

Example 1 with Chapter

use of org.apache.cxf.jaxrs.resources.Chapter in project cxf by apache.

the class SelectMethodCandidatesTest method testFindFromAbstractGenericClass3.

@Test
public void testFindFromAbstractGenericClass3() throws Exception {
    JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
    sf.setResourceClasses(BookEntity.class);
    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", "PUT", values, contentTypes, sortMediaTypes(acceptContentTypes));
    assertNotNull(ori);
    assertEquals("resourceMethod needs to be selected", "putEntity", ori.getMethodToInvoke().getName());
    String value = "<Chapter><title>The Book</title><id>2</id></Chapter>";
    m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
    List<Object> params = JAXRSUtils.processParameters(ori, values, m);
    assertEquals(1, params.size());
    Chapter c = (Chapter) params.get(0);
    assertNotNull(c);
    assertEquals(2L, c.getId());
    assertEquals("The Book", c.getTitle());
}
Also used : ServerProviderFactory(org.apache.cxf.jaxrs.provider.ServerProviderFactory) Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Chapter(org.apache.cxf.jaxrs.resources.Chapter) Exchange(org.apache.cxf.message.Exchange) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Endpoint(org.apache.cxf.endpoint.Endpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)1 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)1 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)1 ServerProviderFactory (org.apache.cxf.jaxrs.provider.ServerProviderFactory)1 Chapter (org.apache.cxf.jaxrs.resources.Chapter)1 Exchange (org.apache.cxf.message.Exchange)1 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)1 Message (org.apache.cxf.message.Message)1 MessageImpl (org.apache.cxf.message.MessageImpl)1 Test (org.junit.Test)1