Search in sources :

Example 41 with OperationResourceInfo

use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.

the class UriInfoImplTest method testGetMatchedURIsSubResourceLocator.

@Test
public void testGetMatchedURIsSubResourceLocator() throws Exception {
    System.out.println("testGetMatchedURIsSubResourceLocator");
    Message m = mockMessage("http://localhost:8080/app", "/foo/sub");
    OperationResourceInfoStack oriStack = new OperationResourceInfoStack();
    ClassResourceInfo rootCri = getCri(RootResource.class, true);
    OperationResourceInfo rootOri = getOri(rootCri, "getSubResourceLocator");
    MethodInvocationInfo miInfo = new MethodInvocationInfo(rootOri, RootResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    ClassResourceInfo subCri = getCri(SubResource.class, false);
    OperationResourceInfo subOri = getOri(subCri, "getFromSub");
    miInfo = new MethodInvocationInfo(subOri, SubResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    m.put(OperationResourceInfoStack.class, oriStack);
    UriInfoImpl u = new UriInfoImpl(m);
    List<String> matchedUris = getMatchedURIs(u);
    assertEquals(2, matchedUris.size());
    assertEquals("foo/sub", matchedUris.get(0));
    assertEquals("foo", matchedUris.get(1));
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ArrayList(java.util.ArrayList) OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo) Test(org.junit.Test)

Example 42 with OperationResourceInfo

use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.

the class UriInfoImplTest method testGetMatchedURIsRootSub.

@Test
public void testGetMatchedURIsRootSub() throws Exception {
    System.out.println("testGetMatchedURIsRootSub");
    Message m = mockMessage("http://localhost:8080/app", "/foo/bar");
    OperationResourceInfoStack oriStack = new OperationResourceInfoStack();
    ClassResourceInfo cri = getCri(RootResource.class, true);
    OperationResourceInfo ori = getOri(cri, "getSubMethod");
    MethodInvocationInfo miInfo = new MethodInvocationInfo(ori, RootResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    m.put(OperationResourceInfoStack.class, oriStack);
    UriInfoImpl u = new UriInfoImpl(m);
    List<String> matchedUris = getMatchedURIs(u);
    assertEquals(2, matchedUris.size());
    assertEquals("foo/bar", matchedUris.get(0));
    assertEquals("foo", matchedUris.get(1));
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo) Test(org.junit.Test)

Example 43 with OperationResourceInfo

use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.

the class ResourceUtilsTest method testClassResourceInfoWithOverride.

@Test
public void testClassResourceInfoWithOverride() throws Exception {
    ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(ExampleImpl.class, ExampleImpl.class, true, true);
    assertNotNull(cri);
    Method m = ExampleImpl.class.getMethod("get");
    OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
    assertNotNull(ori);
    assertEquals("GET", ori.getHttpMethod());
}
Also used : ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 44 with OperationResourceInfo

use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.

the class ResourceUtilsTest method testGenericClassResourceInfoWithBridgeMethod.

@Test
public void testGenericClassResourceInfoWithBridgeMethod() throws Exception {
    ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(GenericExampleBridgeImpl.class, GenericExampleBridgeImpl.class, true, true);
    assertNotNull(cri);
    assertEquals(1, cri.getMethodDispatcher().getOperationResourceInfos().size());
    Method m = GenericExampleBridgeImpl.class.getMethod("get");
    OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
    assertNotNull(ori);
    assertEquals("GET", ori.getHttpMethod());
    m = Arrays.stream(GenericExampleBridgeImpl.class.getMethods()).filter(method -> method.getName().equals("get")).filter(Method::isBridge).findAny().orElse(null);
    ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
    assertNotNull(ori);
    assertEquals("GET", ori.getHttpMethod());
}
Also used : ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 45 with OperationResourceInfo

use of org.apache.cxf.jaxrs.model.OperationResourceInfo in project cxf by apache.

the class ResourceUtilsTest method testClassResourceInfoWithOverriddenMethods.

@Test
public void testClassResourceInfoWithOverriddenMethods() throws Exception {
    ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(OverriddenInterfaceImpl.class, OverriddenInterfaceImpl.class, true, true);
    assertNotNull(cri);
    Method notSynthetic = OverriddenInterfaceImpl.class.getMethod("read", new Class[] { String.class });
    assertFalse(notSynthetic.isSynthetic());
    cri.hasSubResources();
    final Set<OperationResourceInfo> oris = cri.getMethodDispatcher().getOperationResourceInfos();
    assertEquals("there must be one read method", 1, oris.size());
    assertEquals(notSynthetic, oris.iterator().next().getMethodToInvoke());
}
Also used : ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)130 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)105 Message (org.apache.cxf.message.Message)72 Test (org.junit.Test)70 Method (java.lang.reflect.Method)53 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)40 Customer (org.apache.cxf.jaxrs.Customer)22 ArrayList (java.util.ArrayList)13 List (java.util.List)13 Endpoint (org.apache.cxf.endpoint.Endpoint)13 MessageImpl (org.apache.cxf.message.MessageImpl)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)11 Response (javax.ws.rs.core.Response)11 URITemplate (org.apache.cxf.jaxrs.model.URITemplate)11 Exchange (org.apache.cxf.message.Exchange)11 MediaType (javax.ws.rs.core.MediaType)10 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)10 MethodDispatcher (org.apache.cxf.jaxrs.model.MethodDispatcher)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)7