//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>();
ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d", values,
new MessageImpl());
OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
createMessage(),
"GET", values, contentTypes,
Collections.singletonList(MediaType.valueOf(acceptContentTypes)), true);
assertNotNull(ori);
assertEquals("listMethod needs to be selected", "listMethod",
ori.getMethodToInvoke().getName());
acceptContentTypes = "application/xml,application/json;q=0.8";
resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values,
new MessageImpl());
ori = JAXRSUtils.findTargetMethod(resource,
createMessage(),
"GET", values, contentTypes,
JAXRSUtils.parseMediaTypes(acceptContentTypes), true);
assertNotNull(ori);
assertEquals("readMethod needs to be selected", "readMethod",
ori.getMethodToInvoke().getName());
contentTypes = "application/xml";
acceptContentTypes = "application/xml";
resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values, new MessageImpl());
ori = JAXRSUtils.findTargetMethod(resource,
createMessage(),
"GET", values, contentTypes,
Collections.singletonList(MediaType.valueOf(acceptContentTypes))
, true);
assertNotNull(ori);
assertEquals("readMethod needs to be selected", "readMethod",
ori.getMethodToInvoke().getName());
contentTypes = "application/json";
acceptContentTypes = "application/json";
resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1/bar/baz/baz", values,
new MessageImpl());
ori = JAXRSUtils.findTargetMethod(resource,
createMessage(),
"GET", values, contentTypes,
Collections.singletonList(MediaType.valueOf(acceptContentTypes)),
true);
assertNotNull(ori);
assertEquals("readMethod2 needs to be selected", "readMethod2",
ori.getMethodToInvoke().getName());
contentTypes = "application/json";
acceptContentTypes = "application/json";
resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values, new MessageImpl());
ori = JAXRSUtils.findTargetMethod(resource,
createMessage(),
"GET", values, contentTypes,
Collections.singletonList(MediaType.valueOf(acceptContentTypes)),
true);
assertNotNull(ori);
assertEquals("unlimitedPath needs to be selected", "unlimitedPath",
ori.getMethodToInvoke().getName());
resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1/2", values, new MessageImpl());
ori = JAXRSUtils.findTargetMethod(resource,
createMessage(),
"GET", values, contentTypes,
Collections.singletonList(MediaType.valueOf(acceptContentTypes)),
true);
assertNotNull(ori);
assertEquals("limitedPath needs to be selected", "limitedPath",
ori.getMethodToInvoke().getName());
}