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(ProviderFactory.class.getName());
EasyMock.expectLastCall().andReturn(ProviderFactory.getInstance()).times(2);
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>();
ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/books", values,
m);
OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
m,
"POST", values, contentTypes,
JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
true);
assertNotNull(ori);
assertEquals("resourceMethod needs to be selected", "postEntity",
ori.getMethodToInvoke().getName());
String value = "<Books><Book><name>The Book</name><id>2</id></Book></Books>";
m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
List<Object> params = JAXRSUtils.processParameters(ori, values, m);
assertEquals(1, params.size());
List<?> books = (List<?>)params.get(0);
assertEquals(1, books.size());
Book book = (Book)books.get(0);