Search in sources :

Example 11 with EventElement

use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testParentBroadcast.

@Test
public void testParentBroadcast() throws InvalidMvp4gConfigurationException {
    String parentModule = oracle.addClass(Modules.BroadcastModule2.class).getQualifiedSourceName();
    EventElement event = newEvent("testEvent");
    event.setBroadcastTo(TestBroadcast.class.getCanonicalName());
    event.setEventObjectClass(new String[] { String.class.getCanonicalName() });
    events.add(event);
    EventElement event2 = newEvent("testEvent2");
    event2.setBroadcastTo(TestBroadcast2.class.getCanonicalName());
    events.add(event2);
    Map<String, ChildModuleElement> childModuleMap = configuration.getModuleParentEventBusClassMap();
    JClassType parentEventBus = oracle.addClass(EventBusOk.class);
    configuration.setParentEventBus(parentEventBus);
    String currentModule = oracle.addClass(Modules.ModuleWithParent01.class).getQualifiedSourceName();
    ChildModuleElement module = new ChildModuleElement();
    module.setParentEventBus(parentEventBus);
    module.setParentModuleClass(parentModule);
    module.setClassName(currentModule);
    childModuleMap.put(currentModule, module);
    setEventBus();
    configuration.setModule(oracle.findType(Modules.ModuleWithParent01.class.getCanonicalName()));
    List<ChildModuleElement> siblings = configuration.getSiblings();
    assertEquals(0, siblings.size());
    assertFalse(event.hasForwardToParent());
    assertFalse(event2.hasForwardToParent());
    configuration.validateChildModules();
    assertTrue(event.hasForwardToParent());
    assertTrue(event2.hasForwardToParent());
}
Also used : TestBroadcast2(com.mvp4g.rebind.test_tools.annotation.TestBroadcast2) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) 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 12 with EventElement

use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testEventHistoryConverterFails.

@Test(expected = UnknownConfigurationElementException.class)
public void testEventHistoryConverterFails() throws InvalidMvp4gConfigurationException {
    events.add(newEvent("badHistoryConverter"));
    services.add(newService("badHistoryConverter"));
    presenters.add(newPresenter(SimplePresenter01.class, "badHistoryConverter"));
    views.add(newView(SimpleView02.class, "badHistoryConverter"));
    EventElement event = newEvent("testEvent");
    event.setHistory("badView");
    events.add(event);
    setEventBus();
    configuration.validateHistoryConverters();
}
Also used : SimpleView02(com.mvp4g.rebind.test_tools.annotation.views.SimpleView02) EventElement(com.mvp4g.rebind.config.element.EventElement) SimplePresenter01(com.mvp4g.rebind.test_tools.annotation.presenters.SimplePresenter01) Test(org.junit.Test)

Example 13 with EventElement

use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testAutoDisplay.

@Test
public void testAutoDisplay() throws InvalidMvp4gConfigurationException {
    ChildModuleElement childModule1 = newChildModule(Modules.ChildModule01.class, "child1");
    childModules.add(childModule1);
    assertTrue(childModule1.isAutoDisplay());
    EventElement event = newEvent("testEvent");
    event.setForwardToModules(new String[] { "child1" });
    event.setEventObjectClass(new String[] { Object.class.getCanonicalName() });
    events.add(event);
    setEventBus();
    configuration.setModule(oracle.addClass(Modules.ModuleWithParent01.class));
    try {
        configuration.validateChildModules();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals(e.getMessage(), String.format("%s: child module %s doesn't define any event to load its view.", Modules.ModuleWithParent01.class.getCanonicalName(), childModule1.getClassName()));
    }
    childModule1.setAutoDisplay("false");
    configuration.validateChildModules();
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) Modules(com.mvp4g.rebind.test_tools.Modules) OneObject(com.mvp4g.rebind.test_tools.OneObject) ChildModuleElement(com.mvp4g.rebind.config.element.ChildModuleElement) Test(org.junit.Test)

Example 14 with EventElement

use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testBroadcastHandlers.

@Test
public void testBroadcastHandlers() throws InvalidMvp4gConfigurationException {
    oracle.addClass(TestBroadcast.class);
    ViewElement view = newView(SimpleView01.class, "view");
    views.add(view);
    PresenterElement presenter = new PresenterElement();
    presenter.setName("presenter");
    Class<?> c = Presenters.BroadcastPresenter.class;
    presenter.setClassName(c.getCanonicalName());
    oracle.addClass(c);
    presenter.setView("view");
    presenters.add(presenter);
    PresenterElement presenter2 = new PresenterElement();
    presenter2.setName("presenter2");
    c = Presenters.BroadcastPresenter2.class;
    presenter2.setClassName(c.getCanonicalName());
    oracle.addClass(c);
    presenter2.setView("view");
    presenters.add(presenter2);
    PresenterElement presenter3 = new PresenterElement();
    presenter3.setName("presenter3");
    c = Presenters.BroadcastPresenter2.class;
    presenter3.setClassName(c.getCanonicalName());
    presenter3.setView("view");
    presenters.add(presenter3);
    EventElement event = newEvent("event");
    event.setBroadcastTo(TestBroadcast.class.getCanonicalName());
    event.setHandlers(new String[0]);
    events.add(event);
    EventElement event2 = newEvent("event2");
    event2.setBroadcastTo(TestBroadcast2.class.getCanonicalName());
    event2.setHandlers(new String[] { "presenter3" });
    events.add(event2);
    setEventBus();
    configuration.validateEventHandlers();
    List<String> handlers = event.getHandlers();
    assertEquals(3, handlers.size());
    assertEquals("presenter3", handlers.get(0));
    assertEquals("presenter2", handlers.get(1));
    assertEquals("presenter", handlers.get(2));
    handlers = event2.getHandlers();
    assertEquals(2, handlers.size());
    assertEquals("presenter3", handlers.get(0));
    assertEquals("presenter2", handlers.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) Presenters(com.mvp4g.rebind.test_tools.annotation.Presenters) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 15 with EventElement

use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testTokenGenerationOk.

// ------------------------------------------------------------------------------
@Test
public void testTokenGenerationOk() throws InvalidMvp4gConfigurationException {
    EventElement event = new EventElement();
    event.setWithTokenGeneration("true");
    event.setType("event1");
    event.setHistory("history");
    events.add(event);
    event = new EventElement();
    event.setWithTokenGeneration("true");
    event.setType("event2");
    event.setForwardToParent("true");
    events.add(event);
    HistoryConverterElement hc1 = newHistoryConverter(SimpleHistoryConverter01.class, "history");
    historyConverters.add(hc1);
    configuration.setModule(oracle.addClass(Modules.Module01.class));
    setEventBus();
    configuration.setParentEventBus(oracle.addClass(EventBusOk.class));
    configuration.validateHistoryConverters();
}
Also used : HistoryConverterElement(com.mvp4g.rebind.config.element.HistoryConverterElement) EventElement(com.mvp4g.rebind.config.element.EventElement) EventBusOk(com.mvp4g.rebind.test_tools.annotation.events.EventBusOk) Test(org.junit.Test)

Aggregations

EventElement (com.mvp4g.rebind.config.element.EventElement)56 Test (org.junit.Test)55 PresenterElement (com.mvp4g.rebind.config.element.PresenterElement)22 InvalidMvp4gConfigurationException (com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException)18 OneObject (com.mvp4g.rebind.test_tools.OneObject)15 ChildModuleElement (com.mvp4g.rebind.config.element.ChildModuleElement)12 ViewElement (com.mvp4g.rebind.config.element.ViewElement)12 Modules (com.mvp4g.rebind.test_tools.Modules)12 BaseEventBus (com.mvp4g.client.event.BaseEventBus)11 EventBusElement (com.mvp4g.rebind.config.element.EventBusElement)11 EventHandlerElement (com.mvp4g.rebind.config.element.EventHandlerElement)10 EventBusWithLookup (com.mvp4g.client.event.EventBusWithLookup)8 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)6 InvalidTypeException (com.mvp4g.rebind.exception.InvalidTypeException)5 TestBroadcast (com.mvp4g.rebind.test_tools.annotation.TestBroadcast)5 HistoryConverterElement (com.mvp4g.rebind.config.element.HistoryConverterElement)4 TestBroadcast2 (com.mvp4g.rebind.test_tools.annotation.TestBroadcast2)4 EventBusOk (com.mvp4g.rebind.test_tools.annotation.events.EventBusOk)4 SimpleView02 (com.mvp4g.rebind.test_tools.annotation.views.SimpleView02)4 EventBus (com.mvp4g.client.event.EventBus)3