Search in sources :

Example 1 with Modules

use of com.mvp4g.rebind.test_tools.Modules in project mvp4g by mvp4g.

the class EventsAnnotationsLoaderTest method testEventBusWithSameChild.

@Test(expected = Mvp4gAnnotationException.class)
public void testEventBusWithSameChild() throws Mvp4gAnnotationException {
    try {
        List<JClassType> annotedClasses = new ArrayList<JClassType>();
        JClassType type = oracle.addClass(Events.EventBusWithSameChild.class);
        annotedClasses.add(type);
        loader.load(annotedClasses, configuration);
    } catch (Mvp4gAnnotationException e) {
        assertTrue(e.getMessage().contains("You can't have two child modules describing the same module: " + Modules.Module01.class.getCanonicalName()));
        throw e;
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) Events(com.mvp4g.rebind.test_tools.annotation.Events) Modules(com.mvp4g.rebind.test_tools.Modules) ChildModules(com.mvp4g.client.annotation.module.ChildModules) Mvp4gAnnotationException(com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException) Test(org.junit.Test)

Example 2 with Modules

use of com.mvp4g.rebind.test_tools.Modules in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testFindChildModuleSameHistory.

@Test(expected = InvalidMvp4gConfigurationException.class)
public void testFindChildModuleSameHistory() throws InvalidMvp4gConfigurationException {
    setEventBus();
    ChildModuleElement childModule1 = newChildModule(Modules.ModuleWithParent01.class, "child1");
    childModules.add(childModule1);
    ChildModuleElement childModule2 = new ChildModuleElement();
    childModule2.setName("child2");
    childModule2.setClassName(Modules.ModuleWithParent01.class.getCanonicalName());
    childModules.add(childModule2);
    JClassType module = oracle.findType(Mvp4gModule.class.getCanonicalName());
    configuration.setModule(module);
    try {
        configuration.findChildModuleHistoryNameAndLoader();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        String.format("Module %s: You can't have two child modules with the same history name \"%s\".", module.getQualifiedSourceName(), "moduleWithParent");
        throw e;
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) Mvp4gModule(com.mvp4g.client.Mvp4gModule) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) Modules(com.mvp4g.rebind.test_tools.Modules) ChildModuleElement(com.mvp4g.rebind.config.element.ChildModuleElement) Test(org.junit.Test)

Example 3 with Modules

use of com.mvp4g.rebind.test_tools.Modules in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testChildModulesBroadcast.

@Test
public void testChildModulesBroadcast() throws InvalidMvp4gConfigurationException {
    oracle.addClass(TestBroadcast.class);
    ChildModuleElement childModule = new ChildModuleElement();
    childModule.setName("child");
    Class<?> c = Modules.BroadcastModule.class;
    oracle.addClass(c);
    childModule.setClassName(c.getCanonicalName());
    childModule.setAutoDisplay("false");
    childModules.add(childModule);
    ChildModuleElement childModule2 = new ChildModuleElement();
    childModule2.setName("child2");
    c = Modules.BroadcastModule2.class;
    oracle.addClass(c);
    childModule2.setClassName(c.getCanonicalName());
    childModule2.setAutoDisplay("false");
    childModules.add(childModule2);
    ChildModuleElement childModule3 = new ChildModuleElement();
    childModule3.setName("child3");
    c = Modules.BroadcastModule2.class;
    childModule3.setClassName(c.getCanonicalName());
    childModule3.setAutoDisplay("false");
    childModules.add(childModule3);
    EventElement event = newEvent("testEvent");
    event.setBroadcastTo(TestBroadcast.class.getCanonicalName());
    event.setForwardToModules(new String[0]);
    events.add(event);
    EventElement event2 = newEvent("testEvent2");
    event2.setBroadcastTo(TestBroadcast2.class.getCanonicalName());
    event2.setForwardToModules(new String[] { "child3" });
    events.add(event2);
    setEventBus();
    configuration.validateChildModules();
    List<String> modules = event.getForwardToModules();
    assertEquals(3, modules.size());
    assertEquals("child", modules.get(0));
    assertEquals("child3", modules.get(1));
    assertEquals("child2", modules.get(2));
    modules = event2.getForwardToModules();
    assertEquals(2, modules.size());
    assertEquals("child3", modules.get(0));
    assertEquals("child2", modules.get(1));
}
Also used : TestBroadcast2(com.mvp4g.rebind.test_tools.annotation.TestBroadcast2) EventElement(com.mvp4g.rebind.config.element.EventElement) TestBroadcast(com.mvp4g.rebind.test_tools.annotation.TestBroadcast) Modules(com.mvp4g.rebind.test_tools.Modules) ChildModuleElement(com.mvp4g.rebind.config.element.ChildModuleElement) Test(org.junit.Test)

Example 4 with Modules

use of com.mvp4g.rebind.test_tools.Modules in project mvp4g by mvp4g.

the class EventsAnnotationsLoaderTest method testEventBusWithSiblingOk.

@Test
public void testEventBusWithSiblingOk() throws Mvp4gAnnotationException {
    List<JClassType> annotedClasses = new ArrayList<JClassType>();
    annotedClasses.add(oracle.addClass(PresenterWithName.class));
    new PresenterAnnotationsLoader().load(annotedClasses, configuration);
    annotedClasses.clear();
    JClassType type = oracle.addClass(Events.EventBusWithSiblings.class);
    annotedClasses.add(type);
    loader.load(annotedClasses, configuration);
    Set<ChildModuleElement> childModules = configuration.getChildModules();
    assertEquals(0, childModules.size());
    Set<EventElement> events = configuration.getEvents();
    assertEquals(2, events.size());
    List<String> modules;
    for (EventElement e : events) {
        modules = e.getForwardToModules();
        if ("event1".equals(e.getType())) {
            assertEquals(1, modules.size());
            assertEquals(Modules.Module01.class.getCanonicalName(), modules.get(0));
            assertFalse(e.hasForwardToParent());
        } else if ("event2".equals(e.getType())) {
            assertEquals(2, modules.size());
            assertEquals(Modules.ModuleWithParent01.class.getCanonicalName(), modules.get(0));
            assertEquals(Modules.Module01.class.getCanonicalName(), modules.get(1));
        } else {
            fail("Unknown event name");
        }
    }
}
Also used : PresenterWithName(com.mvp4g.rebind.test_tools.annotation.presenters.PresenterWithName) Modules(com.mvp4g.rebind.test_tools.Modules) ChildModules(com.mvp4g.client.annotation.module.ChildModules) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) Events(com.mvp4g.rebind.test_tools.annotation.Events) Test(org.junit.Test)

Example 5 with Modules

use of com.mvp4g.rebind.test_tools.Modules in project mvp4g by mvp4g.

the class EventsAnnotationsLoaderTest method testEventBusWithChildrenOk.

@Test
public void testEventBusWithChildrenOk() throws Mvp4gAnnotationException {
    List<JClassType> annotedClasses = new ArrayList<JClassType>();
    annotedClasses.add(oracle.addClass(PresenterWithName.class));
    new PresenterAnnotationsLoader().load(annotedClasses, configuration);
    annotedClasses.clear();
    JClassType type = oracle.addClass(Events.EventBusWithChildren.class);
    annotedClasses.add(type);
    loader.load(annotedClasses, configuration);
    Set<ChildModuleElement> childModules = configuration.getChildModules();
    assertEquals(2, childModules.size());
    for (ChildModuleElement child : childModules) {
        if (Modules.Module01.class.getCanonicalName().equals(child.getClassName())) {
            assertTrue(child.isAsync());
            assertTrue(child.isAutoDisplay());
            assertEquals("event1", child.getEventToDisplayView());
        } else if (Modules.ModuleWithParent01.class.getCanonicalName().equals(child.getClassName())) {
            assertFalse(child.isAsync());
            assertFalse(child.isAutoDisplay());
        } else {
            fail("Unknown child module");
        }
    }
    Set<EventElement> events = configuration.getEvents();
    assertEquals(4, events.size());
    List<String> modules;
    for (EventElement e : events) {
        if ("event1".equals(e.getType())) {
        } else if ("event2".equals(e.getType())) {
            modules = e.getForwardToModules();
            assertEquals(1, modules.size());
            assertEquals(Modules.Module01.class.getCanonicalName().replace(".", "_"), modules.get(0));
            assertFalse(e.hasForwardToParent());
        } else if ("event3".equals(e.getType())) {
            modules = e.getForwardToModules();
            assertEquals(2, modules.size());
            assertEquals(Modules.ModuleWithParent01.class.getCanonicalName().replace(".", "_"), modules.get(0));
            assertEquals(Modules.Module01.class.getCanonicalName().replace(".", "_"), modules.get(1));
            assertFalse(e.hasForwardToParent());
        } else if ("event4".equals(e.getType())) {
            assertTrue(e.hasForwardToParent());
        } else {
            fail("Unknown event name");
        }
    }
}
Also used : PresenterWithName(com.mvp4g.rebind.test_tools.annotation.presenters.PresenterWithName) Modules(com.mvp4g.rebind.test_tools.Modules) ChildModules(com.mvp4g.client.annotation.module.ChildModules) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) Events(com.mvp4g.rebind.test_tools.annotation.Events) Test(org.junit.Test)

Aggregations

Modules (com.mvp4g.rebind.test_tools.Modules)5 Test (org.junit.Test)5 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)4 ChildModules (com.mvp4g.client.annotation.module.ChildModules)3 Events (com.mvp4g.rebind.test_tools.annotation.Events)3 ChildModuleElement (com.mvp4g.rebind.config.element.ChildModuleElement)2 PresenterWithName (com.mvp4g.rebind.test_tools.annotation.presenters.PresenterWithName)2 Mvp4gModule (com.mvp4g.client.Mvp4gModule)1 EventElement (com.mvp4g.rebind.config.element.EventElement)1 InvalidMvp4gConfigurationException (com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException)1 Mvp4gAnnotationException (com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException)1 TestBroadcast (com.mvp4g.rebind.test_tools.annotation.TestBroadcast)1 TestBroadcast2 (com.mvp4g.rebind.test_tools.annotation.TestBroadcast2)1