use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class FormEncodingProviderTest method testWriteMultipleValues.
@Test
public void testWriteMultipleValues() throws Exception {
MultivaluedMap<String, String> mvMap = new MetadataMap<String, String>();
mvMap.add("a", "a1");
mvMap.add("a", "a2");
FormEncodingProvider<MultivaluedMap<?, ?>> ferp = new FormEncodingProvider<MultivaluedMap<?, ?>>();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ferp.writeTo(mvMap, MultivaluedMap.class, MultivaluedMap.class, new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE, new MetadataMap<String, Object>(), bos);
String result = bos.toString();
assertEquals("Wrong value", "a=a1&a=a2", result);
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSServiceFactoryBeanTest method testNoSubResources.
@Test
public void testNoSubResources() throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setEnableStaticResolution(true);
sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStoreNoSubResource.class);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
assertEquals(1, resources.size());
// Verify root ClassResourceInfo: BookStoreNoSubResource
ClassResourceInfo rootCri = resources.get(0);
assertNotNull(rootCri.getURITemplate());
URITemplate template = rootCri.getURITemplate();
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
assertTrue(template.match("/bookstore/books/123", values));
assertFalse(rootCri.hasSubResources());
MethodDispatcher md = rootCri.getMethodDispatcher();
assertEquals(7, md.getOperationResourceInfos().size());
Set<OperationResourceInfo> ops = md.getOperationResourceInfos();
assertTrue("No operation found", verifyOp(ops, "getBook", "GET", false));
assertTrue("No operation found", verifyOp(ops, "getBookStoreInfo", "GET", false));
assertTrue("No operation found", verifyOp(ops, "getBooks", "GET", false));
assertTrue("No operation found", verifyOp(ops, "getBookJSON", "GET", false));
assertTrue("No operation found", verifyOp(ops, "addBook", "POST", false));
assertTrue("No operation found", verifyOp(ops, "updateBook", "PUT", false));
assertTrue("No operation found", verifyOp(ops, "deleteBook", "DELETE", false));
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class SelectMethodCandidatesTest method testSelectBar.
@Test
public void testSelectBar() throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(org.apache.cxf.jaxrs.resources.TestResource.class);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentTypes = "*/*";
String acceptContentTypes = "application/bar,application/foo;q=0.8";
MetadataMap<String, String> values = new MetadataMap<String, String>();
OperationResourceInfo ori = findTargetResourceClass(resources, null, "/1/2/3/d/custom", "GET", values, contentTypes, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals("readBar", ori.getMethodToInvoke().getName());
acceptContentTypes = "application/foo,application/bar;q=0.8";
ori = findTargetResourceClass(resources, null, "/1/2/3/d/custom", "GET", values, contentTypes, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals("readFoo", ori.getMethodToInvoke().getName());
acceptContentTypes = "application/foo;q=0.5,application/bar";
ori = findTargetResourceClass(resources, null, "/1/2/3/d/custom", "GET", values, contentTypes, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals("readBar", ori.getMethodToInvoke().getName());
acceptContentTypes = "application/foo,application/bar;q=0.5";
ori = findTargetResourceClass(resources, null, "/1/2/3/d/custom", "GET", values, contentTypes, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals("readFoo", ori.getMethodToInvoke().getName());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class SelectMethodCandidatesTest method doTestRootResourcesWithSameName.
private void doTestRootResourcesWithSameName(String path, String methodName, Class<?> expectedRoot) throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(RootResource.class, RootResource2.class, RootResource3.class);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
assertEquals(3, resources.size());
String contentTypes = "text/xml";
String acceptContentTypes = "text/xml";
Message m = prepareMessage();
MetadataMap<String, String> values = new MetadataMap<String, String>();
OperationResourceInfo ori = findTargetResourceClass(resources, m, path, "PUT", values, contentTypes, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals("resourceMethod needs to be selected", methodName, ori.getMethodToInvoke().getName());
assertSame(expectedRoot, ori.getClassResourceInfo().getServiceClass());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class SelectMethodCandidatesTest method testFindTargetResourceClassWithTemplates.
@Test
public void testFindTargetResourceClassWithTemplates() throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(org.apache.cxf.jaxrs.resources.TestResource.class);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentTypes = "*/*";
String acceptContentTypes = "application/xml";
// If acceptContentTypes does not specify a specific Mime type, the
// method is declared with a most specific ProduceMime type is selected.
MetadataMap<String, String> values = new MetadataMap<String, String>();
OperationResourceInfo ori = findTargetResourceClass(resources, createMessage(), "/1/2/3/d", "GET", values, contentTypes, Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
assertNotNull(ori);
assertEquals("listMethod needs to be selected", "listMethod", ori.getMethodToInvoke().getName());
acceptContentTypes = "application/xml,application/json;q=0.8";
ori = findTargetResourceClass(resources, null, "/1/2/3/d/1", "GET", values, contentTypes, JAXRSUtils.parseMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals("readMethod needs to be selected", "readMethod", ori.getMethodToInvoke().getName());
contentTypes = "application/xml";
acceptContentTypes = "application/xml";
ori = findTargetResourceClass(resources, null, "/1/2/3/d/1", "GET", values, contentTypes, Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
assertNotNull(ori);
assertEquals("readMethod needs to be selected", "readMethod", ori.getMethodToInvoke().getName());
contentTypes = "application/json";
acceptContentTypes = "application/json";
ori = findTargetResourceClass(resources, null, "/1/2/3/d/1/bar/baz/baz", "GET", values, contentTypes, Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
assertNotNull(ori);
assertEquals("readMethod2 needs to be selected", "readMethod2", ori.getMethodToInvoke().getName());
contentTypes = "application/json";
acceptContentTypes = "application/json";
ori = findTargetResourceClass(resources, null, "/1/2/3/d/1", "GET", values, contentTypes, Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
assertNotNull(ori);
assertEquals("unlimitedPath needs to be selected", "unlimitedPath", ori.getMethodToInvoke().getName());
ori = findTargetResourceClass(resources, null, "/1/2/3/d/1/2", "GET", values, contentTypes, Collections.singletonList(MediaType.valueOf(acceptContentTypes)));
assertNotNull(ori);
assertEquals("limitedPath needs to be selected", "limitedPath", ori.getMethodToInvoke().getName());
}
Aggregations