Package org.mojavemvc.core

Examples of org.mojavemvc.core.ActionSignature


        assertNotNull(interceptors);
        assertEquals(1, interceptors.size());
        assertEquals(Interceptor1.class, interceptors.get(0));

        ActionSignature beforeActionMethod = db.getBeforeActionMethodForInterceptor(Interceptor1.class);
        assertNotNull(beforeActionMethod);
        assertEquals("before", beforeActionMethod.methodName());

        beforeActionMethod = db.getBeforeActionMethodForInterceptor(Interceptor2.class);
        assertNotNull(beforeActionMethod);
        assertEquals("before2", beforeActionMethod.methodName());

        ActionSignature afterActionMethod = db.getAfterActionMethodForInterceptor(Interceptor1.class);
        assertNotNull(afterActionMethod);
        assertEquals("after", afterActionMethod.methodName());

        afterActionMethod = db.getAfterActionMethodForInterceptor(Interceptor2.class);
        assertNotNull(afterActionMethod);
        assertEquals("after2", afterActionMethod.methodName());
       
        assertEquals(2, rm.size());
        assertTrue(rm.contains(new MojaveRoute("method-interceptor5", null, null)));
        assertTrue(rm.contains(new MojaveRoute("method-interceptor5", "someAction", null)));
    }
View Full Code Here


        assertNotNull(interceptors);
        assertEquals(1, interceptors.size());
        assertEquals(Interceptor1.class, interceptors.get(0));

        ActionSignature beforeActionMethod = db.getBeforeActionMethodForInterceptor(Interceptor1.class);
        assertNotNull(beforeActionMethod);
        assertEquals("before", beforeActionMethod.methodName());

        beforeActionMethod = db.getBeforeActionMethodForInterceptor(Interceptor2.class);
        assertNotNull(beforeActionMethod);
        assertEquals("before2", beforeActionMethod.methodName());

        beforeActionMethod = db.getBeforeActionMethodForInterceptor(Interceptor3.class);
        assertNotNull(beforeActionMethod);
        assertEquals("before3", beforeActionMethod.methodName());

        ActionSignature afterActionMethod = db.getAfterActionMethodForInterceptor(Interceptor1.class);
        assertNotNull(afterActionMethod);
        assertEquals("after", afterActionMethod.methodName());

        afterActionMethod = db.getAfterActionMethodForInterceptor(Interceptor2.class);
        assertNotNull(afterActionMethod);
        assertEquals("after2", afterActionMethod.methodName());

        afterActionMethod = db.getAfterActionMethodForInterceptor(Interceptor3.class);
        assertNotNull(afterActionMethod);
        assertEquals("after3", afterActionMethod.methodName());
       
        assertEquals(2, rm.size());
        assertTrue(rm.contains(new MojaveRoute("method-interceptor6", null, null)));
        assertTrue(rm.contains(new MojaveRoute("method-interceptor6", "someAction", null)));
    }
View Full Code Here

        assertNotNull(interceptors);
        assertEquals(1, interceptors.size());
        assertEquals(Interceptor1.class, interceptors.get(0));

        ActionSignature beforeActionMethod = db.getBeforeActionMethodForInterceptor(Interceptor1.class);
        assertNotNull(beforeActionMethod);
        assertEquals("before", beforeActionMethod.methodName());

        beforeActionMethod = db.getBeforeActionMethodForInterceptor(Interceptor2.class);
        assertNotNull(beforeActionMethod);
        assertEquals("before2", beforeActionMethod.methodName());

        beforeActionMethod = db.getBeforeActionMethodForInterceptor(Interceptor3.class);
        assertNotNull(beforeActionMethod);
        assertEquals("before3", beforeActionMethod.methodName());

        ActionSignature afterActionMethod = db.getAfterActionMethodForInterceptor(Interceptor1.class);
        assertNotNull(afterActionMethod);
        assertEquals("after", afterActionMethod.methodName());

        afterActionMethod = db.getAfterActionMethodForInterceptor(Interceptor2.class);
        assertNotNull(afterActionMethod);
        assertEquals("after2", afterActionMethod.methodName());

        afterActionMethod = db.getAfterActionMethodForInterceptor(Interceptor3.class);
        assertNotNull(afterActionMethod);
        assertEquals("after3", afterActionMethod.methodName());
       
        assertEquals(11, rm.size());
        assertTrue(rm.contains(new MojaveRoute("interceptor1", "someAction", null)));
        assertTrue(rm.contains(new MojaveRoute("interceptor2", "someAction", null)));
        assertTrue(rm.contains(new MojaveRoute("method-interceptor1", null, null)));
View Full Code Here

        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());

        assertEquals(TestHttpMethodController.class, db.getControllerClass("TestHttpMethodController"));

        ActionSignature sig = db.getHttpMethodActionSignature(TestHttpMethodController.class, HttpMethod.GET);
        assertNotNull(sig);
        assertTrue(sig instanceof HttpMethodActionSignature);
        assertEquals("getAction", sig.methodName());

        sig = db.getHttpMethodActionSignature(TestHttpMethodController.class, HttpMethod.POST);
        assertNotNull(sig);
        assertTrue(sig instanceof HttpMethodActionSignature);
        assertEquals("postAction", sig.methodName());

        sig = db.getHttpMethodActionSignature(TestHttpMethodController.class, HttpMethod.PUT);
        assertNotNull(sig);
        assertTrue(sig instanceof HttpMethodActionSignature);
        assertEquals("putAction", sig.methodName());

        sig = db.getHttpMethodActionSignature(TestHttpMethodController.class, HttpMethod.DELETE);
        assertNotNull(sig);
        assertTrue(sig instanceof HttpMethodActionSignature);
        assertEquals("deleteAction", sig.methodName());

        sig = db.getHttpMethodActionSignature(TestHttpMethodController.class, HttpMethod.OPTIONS);
        assertNotNull(sig);
        assertTrue(sig instanceof HttpMethodActionSignature);
        assertEquals("optionsAction", sig.methodName());

        sig = db.getHttpMethodActionSignature(TestHttpMethodController.class, HttpMethod.HEAD);
        assertNotNull(sig);
        assertTrue(sig instanceof HttpMethodActionSignature);
        assertEquals("headAction", sig.methodName());

        sig = db.getHttpMethodActionSignature(TestHttpMethodController.class, HttpMethod.TRACE);
        assertNotNull(sig);
        assertTrue(sig instanceof HttpMethodActionSignature);
        assertEquals("traceAction", sig.methodName());
       
        assertEquals(1, rm.size());
        assertTrue(rm.contains(new MojaveRoute("TestHttpMethodController", null, null)));
    }
View Full Code Here

        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());

        assertEquals(TestHttpMethodController2.class, db.getControllerClass("TestHttpMethodController2"));

        ActionSignature sig = db.getHttpMethodActionSignature(TestHttpMethodController2.class, HttpMethod.GET);
        assertNotNull(sig);
        assertTrue(sig instanceof HttpMethodActionSignature);
        assertEquals("getAction", sig.methodName());

        List<Class<?>> interceptors = db.getInterceptorsForHttpMethodAction(TestHttpMethodController2.class,
                HttpMethod.GET);
        assertNotNull(interceptors);
        assertEquals(1, interceptors.size());
        assertEquals(Interceptor1.class, interceptors.get(0));

        sig = db.getHttpMethodActionSignature(TestHttpMethodController2.class, HttpMethod.POST);
        assertNotNull(sig);
        assertEquals("postAction", sig.methodName());

        interceptors = db.getInterceptorsForHttpMethodAction(TestHttpMethodController2.class, HttpMethod.POST);
        assertNotNull(interceptors);
        assertEquals(2, interceptors.size());
        assertEquals(Interceptor1.class, interceptors.get(0));
View Full Code Here

public class TestBaseActionSignature {
   
    @Test
    public void noParameters() {

        ActionSignature sig = new BaseActionSignature(1, "testAction", new Class[] {},
                new Annotation[][] {}, new Annotation[]{});

        assertEquals(0, sig.parameterTypes().length);
        assertEquals(0, sig.getArgs(new HashMap<String, Object>(), null).length);
    }
View Full Code Here

    }

    @Test
    public void getArgsWithStringArrayParameters() {

        ActionSignature sig = new BaseActionSignature(1, "testAction", new Class[] { String.class, Integer.class,
                Double.class, Date.class, Long.class, InputStream.class },
                new Annotation[][] { { createParam("p1") }, { createParam("p2") },
                { createParam("p3") }, { createParam("p4") }, { createParam("p5") }, { createResource() } },
                new Annotation[]{});

        InputStream in = Mockito.mock(InputStream.class);
       
        Map<String, String[]> parameterMap = new HashMap<String, String[]>();
        parameterMap.put("p1", new String[] { "hello" });
        parameterMap.put("p2", new String[] { "123" });
        parameterMap.put("p3", new String[] { "1.23" });
        parameterMap.put("p4", new String[] { "2011-03-01" });
        parameterMap.put("p5", new String[] { "123456" });

        Class<?>[] paramTypes = sig.parameterTypes();
        assertEquals(6, paramTypes.length);
        assertEquals(String.class, paramTypes[0]);
        assertEquals(Integer.class, paramTypes[1]);
        assertEquals(Double.class, paramTypes[2]);
        assertEquals(Date.class, paramTypes[3]);
        assertEquals(Long.class, paramTypes[4]);
        assertEquals(InputStream.class, paramTypes[5]);
       
        Object[] args = sig.getArgs(parameterMap, in);
        assertEquals(6, args.length);
        assertEquals("hello", args[0]);
        assertEquals(123, args[1]);
        assertEquals(1.23, args[2]);
        assertEquals(Date.valueOf("2011-03-01"), args[3]);
View Full Code Here

    }

    @Test
    public void getArgsWithObjectParameters() {

        ActionSignature sig = new BaseActionSignature(1, "testAction", new Class[] { String.class, Integer.class,
                Double.class, Date.class, SomeUserDefinedType.class, Long.class }, new Annotation[][] { { createParam("p1") },
                { createParam("p2") }, { createParam("p3") }, { createParam("p4") }, { createParam("p5") },
                { createParam("p6") } }, new Annotation[]{});

        SomeUserDefinedType userDefinedType = new SomeUserDefinedType();

        Map<String, Object> parameterMap = new HashMap<String, Object>();
        parameterMap.put("p1", "hello");
        parameterMap.put("p2", 123);
        parameterMap.put("p3", 1.23);
        parameterMap.put("p4", Date.valueOf("2011-03-01"));
        parameterMap.put("p5", userDefinedType);
        parameterMap.put("p6", 123456L);

        Class<?>[] paramTypes = sig.parameterTypes();
        assertEquals(6, paramTypes.length);
        assertEquals(String.class, paramTypes[0]);
        assertEquals(Integer.class, paramTypes[1]);
        assertEquals(Double.class, paramTypes[2]);
        assertEquals(Date.class, paramTypes[3]);
        assertEquals(SomeUserDefinedType.class, paramTypes[4]);
        assertEquals(Long.class, paramTypes[5]);
       
        Object[] args = sig.getArgs(parameterMap, null);
        assertEquals(6, args.length);
        assertEquals("hello", args[0]);
        assertEquals(123, args[1]);
        assertEquals(1.23, args[2]);
        assertEquals(Date.valueOf("2011-03-01"), args[3]);
View Full Code Here

        controllerClasses.add(cntrl.getClass());
        ControllerDatabase db = newControllerDatabase(controllerClasses);

        FastClass fastClass = FastClass.create(clazz);
        int fastIndex = fastClass.getIndex(methodName, new Class<?>[] {});
        ActionSignature sig = mock(ActionSignature.class);
        when(sig.fastIndex()).thenReturn(fastIndex);
        when(sig.parameterTypes()).thenReturn(new Class<?>[] {});
        when(sig.methodName()).thenReturn(methodName);
        when(sig.getArgs(parametersMap, req.getInputStream())).thenReturn(new Object[] {});
       
        if (action == null) {
            when(sig.getInterceptorClasses(db, cntrl.getClass(), "")).thenReturn(
                    db.getInterceptorsForDefaultAction(cntrl.getClass()));
        } else {
            when(sig.getInterceptorClasses(db, cntrl.getClass(), action)).thenReturn(
                    db.getInterceptorsForAction(cntrl.getClass(), action));
        }
       
        when(sig.marshall(anyObject())).thenAnswer(new Answer<View>() {
            @Override
            public View answer(InvocationOnMock invocation) throws Throwable {
                return (View)invocation.getArguments()[0];
            }
        });
View Full Code Here

TOP

Related Classes of org.mojavemvc.core.ActionSignature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.