Search in sources :

Example 16 with EventElement

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

the class Mvp4gConfigurationTest method validateHistoryName.

@Test
public void validateHistoryName() throws InvalidMvp4gConfigurationException {
    EventElement element = newEvent("forward");
    try {
        configuration.validateHistoryName("!test", element);
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("history name can't start with '" + PlaceService.CRAWLABLE + "' or contain '" + PlaceService.MODULE_SEPARATOR + "'."));
    }
    try {
        configuration.validateHistoryName("/test", element);
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("history name can't start with '" + PlaceService.CRAWLABLE + "' or contain '" + PlaceService.MODULE_SEPARATOR + "'."));
    }
    try {
        configuration.validateHistoryName("te/st", element);
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("history name can't start with '" + PlaceService.CRAWLABLE + "' or contain '" + PlaceService.MODULE_SEPARATOR + "'."));
    }
    configuration.validateHistoryName("test", element);
    configuration.validateHistoryName("tes!t", element);
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) Test(org.junit.Test)

Example 17 with EventElement

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

the class Mvp4gConfigurationTest method testEventWithNoObjectForAutoDisplay.

@Test(expected = InvalidMvp4gConfigurationException.class)
public void testEventWithNoObjectForAutoDisplay() throws InvalidMvp4gConfigurationException {
    ChildModuleElement childModule1 = newChildModule(Modules.ChildModule01.class, "child1");
    childModule1.setEventToDisplayView("testEvent");
    childModules.add(childModule1);
    EventElement event = newEvent("testEvent");
    event.setForwardToModules(new String[] { "child1" });
    events.add(event);
    setEventBus();
    try {
        configuration.validateChildModules();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals("Event testEvent: event must have one and only one an object associated with it as it loads a child view.", e.getMessage());
        throw e;
    }
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) 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 18 with EventElement

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

the class Mvp4gConfigurationTest method testTokenGenerationNotOk.

@Test
public void testTokenGenerationNotOk() {
    EventElement event = new EventElement();
    event.setWithTokenGeneration("true");
    event.setType("event1");
    events.add(event);
    try {
        configuration.validateHistoryConverters();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals("Event event1: you can't generate a token for this event if it has no history converter.", e.getMessage());
    }
    configuration.setModule(oracle.addClass(Modules.Module01.class));
    try {
        configuration.validateHistoryConverters();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals("Event event1: you can't generate a token for this event if it has no history converter.", e.getMessage());
    }
    configuration.setParentEventBus(oracle.addClass(EventBusOk.class));
    try {
        configuration.validateHistoryConverters();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals("Event event1: you can't generate a token for this event if it has no history converter.", e.getMessage());
    }
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) EventBusOk(com.mvp4g.rebind.test_tools.annotation.events.EventBusOk) Test(org.junit.Test)

Example 19 with EventElement

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

the class Mvp4gConfigurationTest method testActivateDeActivateOk.

@Test
public void testActivateDeActivateOk() throws InvalidMvp4gConfigurationException {
    EventBusElement eventBus = new EventBusElement(EventBusWithLookup.class.getName(), BaseEventBus.class.getName(), false);
    configuration.setEventBus(eventBus);
    EventElement event = newEvent("event");
    event.setHandlers(new String[] { "activate1", "deactivate1", "activate2", "deactivate2" });
    events.add(event);
    EventElement event1 = newEvent("event1");
    event1.setActivate(new String[] { "activate1", "activate2" });
    event1.setDeactivate(new String[] { "deactivate1", "deactivate2" });
    events.add(event1);
    PresenterElement activate1 = newPresenter(SimplePresenter01.class, "activate1");
    EventHandlerElement activate2 = newEventHandler(SimpleEventHandler01.class, "activate2");
    PresenterElement deactivate1 = newPresenter(SimplePresenter02.class, "deactivate1");
    EventHandlerElement deactivate2 = newEventHandler(SimpleEventHandler02.class, "deactivate2");
    eventHandlers.add(activate1);
    eventHandlers.add(activate2);
    eventHandlers.add(deactivate1);
    eventHandlers.add(deactivate2);
    configuration.validateEventHandlers();
    List<String> activate = event1.getActivate();
    assertTrue(activate.size() == 2);
    assertEquals(activate.get(0), activate1.getName());
    assertEquals(activate.get(1), activate2.getName());
    List<String> deactivate = event1.getDeactivate();
    assertTrue(deactivate.size() == 2);
    assertEquals(deactivate.get(0), deactivate1.getName());
    assertEquals(deactivate.get(1), deactivate2.getName());
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) EventBusElement(com.mvp4g.rebind.config.element.EventBusElement) EventBusWithLookup(com.mvp4g.client.event.EventBusWithLookup) BaseEventBus(com.mvp4g.client.event.BaseEventBus) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 20 with EventElement

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

the class Mvp4gConfigurationTest method testSplitterLoaders.

@Test
public void testSplitterLoaders() throws InvalidMvp4gConfigurationException {
    setEventBus();
    oracle.addClass(Loaders.Loader1.class);
    oracle.addClass(Loaders.Loader2.class);
    oracle.addClass(Splitters.SplitterWithLoader.class);
    oracle.addClass(Splitters.SplitterWithSameLoader1.class);
    oracle.addClass(Splitters.SplitterWithSameLoader2.class);
    PresenterElement presenter1 = newPresenter(SimplePresenter01.class, "presenter1");
    presenter1.setAsync(Splitters.SplitterWithLoader.class.getCanonicalName());
    presenters.add(presenter1);
    PresenterElement presenter2 = newPresenter(SimplePresenter02.class, "presenter2");
    presenter2.setAsync(Splitters.SplitterWithSameLoader1.class.getCanonicalName());
    presenters.add(presenter2);
    PresenterElement presenter3 = newPresenter(SimplePresenter03.class, "presenter3");
    presenter3.setAsync(Splitters.SplitterWithSameLoader2.class.getCanonicalName());
    presenters.add(presenter3);
    EventElement event = new EventElement();
    event.setHandlers(new String[] { "presenter1", "presenter2", "presenter3" });
    configuration.getEvents().add(event);
    configuration.validateSplitters();
    assertEquals(3, configuration.getSplitters().size());
    String loader1Name = "loader" + Loaders.Loader1.class.getCanonicalName().replace(".", "_");
    String loader2Name = "loader" + Loaders.Loader2.class.getCanonicalName().replace(".", "_");
    String splitter1Name = Splitters.SplitterWithLoader.class.getCanonicalName().replace(".", "_");
    String splitter2Name = Splitters.SplitterWithSameLoader1.class.getCanonicalName().replace(".", "_");
    String splitter3Name = Splitters.SplitterWithSameLoader2.class.getCanonicalName().replace(".", "_");
    Set<SplitterElement> splitters = configuration.getSplitters();
    Iterator<SplitterElement> itSplitter = splitters.iterator();
    SplitterElement splitter;
    String splitterName;
    while (itSplitter.hasNext()) {
        splitter = itSplitter.next();
        splitterName = splitter.getName();
        if (splitter1Name.equals(splitterName)) {
            assertEquals(splitter.getLoader(), loader1Name);
        } else if (splitter2Name.equals(splitterName)) {
            assertEquals(splitter.getLoader(), loader2Name);
        } else if (splitter3Name.equals(splitterName)) {
            assertEquals(splitter.getLoader(), loader2Name);
        } else {
            fail("Unknown splitter " + splitterName);
        }
    }
    Set<LoaderElement> loaders = configuration.getLoaders();
    assertEquals(2, loaders.size());
    Iterator<LoaderElement> it = loaders.iterator();
    LoaderElement next;
    String name;
    while (it.hasNext()) {
        next = it.next();
        name = next.getName();
        if (name.equals(loader1Name)) {
            assertEquals(Loaders.Loader1.class.getCanonicalName(), next.getClassName());
        } else if (name.equals(loader2Name)) {
            assertEquals(Loaders.Loader2.class.getCanonicalName(), next.getClassName());
        } else {
            fail("Unknown loader " + next.getName());
        }
    }
}
Also used : Loaders(com.mvp4g.rebind.test_tools.Loaders) SplitterElement(com.mvp4g.rebind.config.element.SplitterElement) LoaderElement(com.mvp4g.rebind.config.element.LoaderElement) EventElement(com.mvp4g.rebind.config.element.EventElement) Splitters(com.mvp4g.rebind.test_tools.Splitters) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) 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