use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class SelectMethodCandidatesTest method doTestConsumesResource.
private void doTestConsumesResource(Class<?> resourceClass, String ct, String expectedMethodName) throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(resourceClass);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentType = ct == null ? "application/xml" : ct;
String acceptContentTypes = "*/*";
Message m = new MessageImpl();
m.put(Message.CONTENT_TYPE, contentType);
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(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>();
OperationResourceInfo ori = findTargetResourceClass(resources, m, "/", "POST", values, contentType, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals(expectedMethodName, ori.getMethodToInvoke().getName());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class SelectMethodCandidatesTest method testFindFromAbstractGenericImpl5.
@Test
public void testFindFromAbstractGenericImpl5() throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(ConcreteRestController.class);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
Message m = createMessage();
m.put(Message.CONTENT_TYPE, "text/xml");
MetadataMap<String, String> values = new MetadataMap<String, String>();
OperationResourceInfo ori = findTargetResourceClass(resources, m, "/", "POST", values, "text/xml", sortMediaTypes("*/*"));
assertNotNull(ori);
assertEquals("resourceMethod needs to be selected", "add", ori.getMethodToInvoke().getName());
String value = "<concreteRestResource><name>The Book</name></concreteRestResource>";
m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
List<Object> params = JAXRSUtils.processParameters(ori, values, m);
assertEquals(1, params.size());
ConcreteRestResource book = (ConcreteRestResource) params.get(0);
assertNotNull(book);
assertEquals("The Book", book.getName());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class SelectMethodCandidatesTest method doTestProducesResource.
private void doTestProducesResource(Class<?> resourceClass, String path, String acceptContentTypes, String expectedResponseType, String expectedMethodName) throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(resourceClass);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentType = "*/*";
Message m = new MessageImpl();
m.put(Message.CONTENT_TYPE, contentType);
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(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>();
Map<ClassResourceInfo, MultivaluedMap<String, String>> mResources = JAXRSUtils.selectResourceClass(resources, path, m);
OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, m, "GET", values, contentType, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals(expectedMethodName, ori.getMethodToInvoke().getName());
assertEquals(expectedResponseType, m.getExchange().get(Message.CONTENT_TYPE));
}
use of org.apache.cxf.jaxrs.impl.MetadataMap 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.impl.MetadataMap in project cxf by apache.
the class AttachmentTest method createAttachment.
private Attachment createAttachment(String id) {
MetadataMap<String, String> map = new MetadataMap<String, String>();
map.add("foo", "bar");
return new Attachment(id, new DataHandler(new ByteArrayDataSource(new byte[] { 1 }, "application/octet-stream")), map);
}
Aggregations