Package org.mojavemvc.core

Examples of org.mojavemvc.core.ControllerDatabase


    public void testHttpMethodController() {

        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestHttpMethodController.class);
        FakeRouteMap rm = new FakeRouteMap();
        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());
View Full Code Here


    public void testHttpMethodController2() {

        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestHttpMethodController2.class);
        FakeRouteMap rm = new FakeRouteMap();
        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));
        assertEquals(Interceptor2.class, interceptors.get(1));
       
View Full Code Here

    public void testHttpMethodController3() {

        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestHttpMethodController3.class);
        FakeRouteMap rm = new FakeRouteMap();
        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());

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

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

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

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

        interceptors = db.getInterceptorsForHttpMethodAction(TestHttpMethodController3.class, HttpMethod.POST);
        assertNotNull(interceptors);
        assertEquals(2, interceptors.size());
        assertEquals(Interceptor1.class, interceptors.get(0));
        assertEquals(Interceptor2.class, interceptors.get(1));

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

        interceptors = db.getInterceptorsForHttpMethodAction(TestHttpMethodController3.class, HttpMethod.PUT);
        assertNotNull(interceptors);
        assertEquals(2, interceptors.size());
        assertEquals(Interceptor1.class, interceptors.get(0));
        assertEquals(Interceptor2.class, interceptors.get(1));
       
View Full Code Here

    public void testParamPathController1() {
       
        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestParamPathController1.class);
        FakeRouteMap rm = new FakeRouteMap();
        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());
       
        assertEquals(TestParamPathController1.class, db.getControllerClass("TestParamPathController1"));
        assertEquals(1, rm.size());
        assertTrue(rm.contains(new MojaveRoute("TestParamPathController1", "getAction", "to/:name")));
    }
View Full Code Here

    public void testParamPathController2() {
       
        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestParamPathController2.class);
        FakeRouteMap rm = new FakeRouteMap();
        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());
       
        assertEquals(TestParamPathController2.class, db.getControllerClass("TestParamPathController2"));
        assertEquals(1, rm.size());
        assertTrue(rm.contains(new MojaveRoute("TestParamPathController2", "getAction", ":name/:location<[a-z]+>")));
    }
View Full Code Here

    public void testParamPathController3() {
       
        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestParamPathController3.class);
        FakeRouteMap rm = new FakeRouteMap();
        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());
       
        assertEquals(TestParamPathController3.class, db.getControllerClass("TestParamPathController3"));
        assertEquals(1, rm.size());
        assertTrue(rm.contains(new MojaveRoute("TestParamPathController3", null, ":name")));
    }
View Full Code Here

    public void testParamPathController4() {
       
        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestParamPathController4.class);
        FakeRouteMap rm = new FakeRouteMap();
        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());
       
        assertEquals(TestParamPathController4.class, db.getControllerClass("TestParamPathController4"));
        assertEquals(1, rm.size());
        assertTrue(rm.contains(new MojaveRoute("TestParamPathController4", null, ":name")));
    }
View Full Code Here

    public void testParamPathAndHttpMethodController() {
       
        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestParamPathAndHttpMethodController.class);
        FakeRouteMap rm = new FakeRouteMap();
        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());
       
        assertEquals(TestParamPathAndHttpMethodController.class, db.getControllerClass("param-and-http"));
        assertEquals(2, rm.size());
        assertTrue(rm.contains(new MojaveRoute("param-and-http", null, "client/all")));
        assertTrue(rm.contains(new MojaveRoute("param-and-http", null, "client/:id")));
    }
View Full Code Here

        Set<Class<?>> controllerClasses = new HashSet<Class<?>>();
        controllerClasses.add(TestController.class);
        controllerClasses.add(TestStartupController.class);
        FakeRouteMap rm = new FakeRouteMap();
        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, rm,
                new HashMap<String, EntityMarshaller>());

        FastClass fc = db.getFastClass(TestController.class);
        assertNotNull(fc);
        assertEquals(TestController.class, fc.getJavaClass());
        fc = db.getFastClass(TestStartupController.class);
        assertNotNull(fc);
        assertEquals(TestStartupController.class, fc.getJavaClass());

        assertEquals(TestController.class, db.getControllerClass("test"));
        assertEquals(TestStartupController.class, db.getControllerClass("startup"));
        assertEquals(TestController.class, db.getDefaultControllerClass());

        ActionSignature sig = db.getActionMethodSignature(TestController.class, "test1");
        assertEquals("testAction", sig.methodName());
        sig = db.getActionMethodSignature(TestController.class, "with-param");
        assertEquals("withParamAction", sig.methodName());
        sig = db.getActionMethodSignature(TestController.class, "another-param");
        assertEquals("anotherParamAction", sig.methodName());
        sig = db.getActionMethodSignature(TestController.class, "some-service");
        assertEquals("someServiceAction", sig.methodName());
        sig = db.getActionMethodSignature(TestController.class, "test-annotation");
        assertEquals("doAnnotationTest", sig.methodName());

        ActionSignature beforeActionMethod = db.getBeforeActionMethodFor(TestController.class);
        assertNotNull(beforeActionMethod);
        assertEquals("doSomethingBefore", beforeActionMethod.methodName());

        ActionSignature afterActionMethod = db.getAfterActionMethodFor(TestController.class);
        assertNotNull(afterActionMethod);
        assertEquals("doSomethingAfter", afterActionMethod.methodName());

        ActionSignature defaultActionSignature = db.getDefaultActionMethodFor(TestController.class);
        assertNotNull(defaultActionSignature);
        assertTrue(defaultActionSignature instanceof DefaultActionSignature);
        assertEquals("defaultAction", defaultActionSignature.methodName());

        ActionSignature afterConstructMethod = db.getAfterConstructMethodFor(TestController.class);
        assertNotNull(afterConstructMethod);
        assertEquals("init", afterConstructMethod.methodName());

        afterConstructMethod = db.getAfterConstructMethodFor(TestStartupController.class);
        assertNotNull(afterConstructMethod);
        assertEquals("init2", afterConstructMethod.methodName());

        Set<Class<?>> initControllers = db.getInitControllers();
        assertNotNull(initControllers);
        assertEquals(1, initControllers.size());
        assertEquals(TestStartupController.class, initControllers.iterator().next());
       
        assertEquals(12, rm.size());
View Full Code Here

    @Test
    public void testConstructWithInheritance() {

        Set<Class<?>> controllerClasses = new HashSet<Class<?>>( );
        controllerClasses.add( TestChildClass.class );
        ControllerDatabase db = new MappedControllerDatabase(controllerClasses, new FakeRouteMap(),
                new HashMap<String, EntityMarshaller>());
       
        assertEquals( TestChildClass.class, db.getControllerClass("child"));
        assertEquals( TestChildClass.class, db.getDefaultControllerClass( ));
       
        ActionSignature sig = db.getActionMethodSignature(TestChildClass.class, "test");
        assertEquals( "testAction", sig.methodName() );
       
        ActionSignature defaultActionMethod = db.getDefaultActionMethodFor(TestChildClass.class);
        assertNotNull( defaultActionMethod );
        assertEquals( "defaultAction", defaultActionMethod.methodName( ) );
       
        ActionSignature beforeActionMethod = db.getBeforeActionMethodFor(TestChildClass.class);
        assertNotNull( beforeActionMethod );
        assertEquals( "doSomethingBefore", beforeActionMethod.methodName( ) );
    }
View Full Code Here

TOP

Related Classes of org.mojavemvc.core.ControllerDatabase

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.