use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testPathParametersBean.
@Test
public void testPathParametersBean() throws Exception {
Class<?>[] argType = { Customer.CustomerBean.class };
Method m = Customer.class.getMethod("testPathBean", argType);
MultivaluedMap<String, String> pathTemplates = new MetadataMap<String, String>();
pathTemplates.add("a", "aValue");
pathTemplates.add("b", "123");
MultivaluedMap<String, String> complexPathTemplates = new MetadataMap<String, String>();
complexPathTemplates.add("c", "1");
complexPathTemplates.add("a", "A");
complexPathTemplates.add("b", "123");
complexPathTemplates.add("c", "2");
complexPathTemplates.add("c", "3");
complexPathTemplates.add("d.c", "4");
complexPathTemplates.add("d.a", "B");
complexPathTemplates.add("d.b", "456");
complexPathTemplates.add("d.c", "5");
complexPathTemplates.add("d.c", "6");
complexPathTemplates.add("e.c", "41");
complexPathTemplates.add("e.a", "B1");
complexPathTemplates.add("e.b", "457");
complexPathTemplates.add("e.c", "51");
complexPathTemplates.add("e.c", "61");
complexPathTemplates.add("e.c", "42");
complexPathTemplates.add("e.a", "B2");
complexPathTemplates.add("e.b", "458");
complexPathTemplates.add("e.c", "52");
complexPathTemplates.add("e.c", "62");
complexPathTemplates.add("d.d.c", "7");
complexPathTemplates.add("d.d.a", "C");
complexPathTemplates.add("d.d.b", "789");
complexPathTemplates.add("d.d.c", "8");
complexPathTemplates.add("d.d.c", "9");
complexPathTemplates.add("d.e.c", "71");
complexPathTemplates.add("d.e.a", "C1");
complexPathTemplates.add("d.e.b", "790");
complexPathTemplates.add("d.e.c", "81");
complexPathTemplates.add("d.e.c", "91");
complexPathTemplates.add("d.e.c", "72");
complexPathTemplates.add("d.e.a", "C2");
complexPathTemplates.add("d.e.b", "791");
complexPathTemplates.add("d.e.c", "82");
complexPathTemplates.add("d.e.c", "92");
verifyParametersBean(m, pathTemplates, createMessage(), complexPathTemplates, createMessage());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testFindTargetResourceClassWithSubResource.
@Test
public void testFindTargetResourceClassWithSubResource() throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStore.class);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentTypes = "*/*";
OperationResourceInfo ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books/sub/123", "GET", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("getBook", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books/123/true/chapter/1", "GET", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("getNewBook", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books", "POST", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("addBook", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books", "PUT", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("updateBook", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books/123", "DELETE", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("deleteBook", ori.getMethodToInvoke().getName());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testParamAnnotationOnMethod.
@Test
public void testParamAnnotationOnMethod() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
Message m = createMessage();
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
headers.add("AHeader2", "theAHeader2");
m.put(Message.PROTOCOL_HEADERS, headers);
m.put(Message.QUERY_STRING, "a_value=aValue&query2=b");
JAXRSUtils.injectParameters(ori, c, m);
assertEquals("aValue", c.getQueryParam());
assertEquals("theAHeader2", c.getAHeader2());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testParamAnnotationOnField.
@Test
public void testParamAnnotationOnField() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
Message m = createMessage();
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
headers.add("AHeader", "theAHeader");
m.put(Message.PROTOCOL_HEADERS, headers);
m.put(Message.QUERY_STRING, "b=bValue");
JAXRSUtils.injectParameters(ori, c, m);
assertEquals("bValue", c.getB());
assertEquals("theAHeader", c.getAHeader());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testConversion.
@Test
public void testConversion() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("testConversion", new Class[] { PathSegmentImpl.class, SimpleFactory.class }), cri);
ori.setHttpMethod("GET");
ori.setURITemplate(new URITemplate("{id1}/{id2}"));
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
values.putSingle("id1", "1");
values.putSingle("id2", "2");
Message m = createMessage();
List<Object> params = JAXRSUtils.processParameters(ori, values, m);
PathSegment ps = (PathSegment) params.get(0);
assertEquals("1", ps.getPath());
SimpleFactory sf = (SimpleFactory) params.get(1);
assertEquals(2, sf.getId());
}
Aggregations