Search in sources :

Example 21 with EventElement

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

the class Mvp4gConfigurationTest method testValidateSplitterSingle.

@Test
public void testValidateSplitterSingle() throws InvalidMvp4gConfigurationException {
    setEventBus();
    PresenterElement presenter = newPresenter(SimplePresenter01.class, "presenter");
    presenter.setAsync(SingleSplitter.class.getCanonicalName());
    presenters.add(presenter);
    PresenterElement presenterMultiple = newPresenter(SimplePresenter02.class, "presenterMultiple");
    presenterMultiple.setAsync(SingleSplitter.class.getCanonicalName());
    presenterMultiple.setMultiple("true");
    presenters.add(presenterMultiple);
    EventHandlerElement eventHandler = newEventHandler(SimpleEventHandler01.class, "eventHandler");
    eventHandler.setAsync(SingleSplitter.class.getCanonicalName());
    eventHandlers.add(eventHandler);
    EventHandlerElement eventHandlerMultiple = newEventHandler(SimpleEventHandler02.class, "eventHandlerMultiple");
    eventHandlerMultiple.setAsync(SingleSplitter.class.getCanonicalName());
    eventHandlerMultiple.setMultiple("true");
    eventHandlers.add(eventHandlerMultiple);
    EventElement event = new EventElement();
    event.setType("event");
    event.setHandlers(new String[] { "presenter", "eventHandler", "presenterMultiple", "eventHandlerMultiple" });
    event.setBinds(new String[] { "presenter", "eventHandler", "presenterMultiple", "eventHandlerMultiple" });
    event.setActivate(new String[] { "presenter", "eventHandler", "presenterMultiple", "eventHandlerMultiple" });
    event.setDeactivate(new String[] { "presenter", "eventHandler", "presenterMultiple", "eventHandlerMultiple" });
    events.add(event);
    configuration.validateSplitters();
    assertEquals(4, configuration.getSplitters().size());
    SplitterElement splitter;
    Iterator<SplitterElement> it = configuration.getSplitters().iterator();
    List<String> list;
    while (it.hasNext()) {
        splitter = it.next();
        if ("com_mvp4g_client_SingleSplitter0".equals(splitter.getClassName())) {
            list = Arrays.asList("eventHandler");
            assertEquals("com_mvp4g_client_SingleSplitter0", splitter.getName());
            assertNull(splitter.getLoader());
            assertEquals(1, splitter.getHandlers().size());
            assertTrue(splitter.getHandlers().contains(eventHandler));
            Map<EventElement, EventAssociation<String>> events = splitter.getEvents();
            assertEquals(1, events.size());
            EventElement key = events.keySet().iterator().next();
            assertSame(event, key);
            EventAssociation<String> association = events.get(key);
            assertList(list, association.getActivated());
            assertList(list, association.getDeactivated());
            assertList(list, association.getBinds());
            assertList(list, association.getHandlers());
        } else if ("com_mvp4g_client_SingleSplitter1".equals(splitter.getClassName())) {
            list = Arrays.asList("eventHandlerMultiple");
            assertEquals("com_mvp4g_client_SingleSplitter1", splitter.getName());
            assertNull(splitter.getLoader());
            assertEquals(1, splitter.getHandlers().size());
            assertTrue(splitter.getHandlers().contains(eventHandlerMultiple));
            Map<EventElement, EventAssociation<String>> events = splitter.getEvents();
            assertEquals(1, events.size());
            EventElement key = events.keySet().iterator().next();
            assertSame(event, key);
            EventAssociation<String> association = events.get(key);
            assertList(list, association.getActivated());
            assertList(list, association.getDeactivated());
            assertList(list, association.getBinds());
            assertList(list, association.getHandlers());
        } else if ("com_mvp4g_client_SingleSplitter2".equals(splitter.getClassName())) {
            list = Arrays.asList("presenterMultiple");
            assertEquals("com_mvp4g_client_SingleSplitter2", splitter.getName());
            assertNull(splitter.getLoader());
            assertEquals(1, splitter.getHandlers().size());
            assertTrue(splitter.getHandlers().contains(presenterMultiple));
            Map<EventElement, EventAssociation<String>> events = splitter.getEvents();
            assertEquals(1, events.size());
            EventElement key = events.keySet().iterator().next();
            assertSame(event, key);
            EventAssociation<String> association = events.get(key);
            assertList(list, association.getActivated());
            assertList(list, association.getDeactivated());
            assertList(list, association.getBinds());
            assertList(list, association.getHandlers());
        } else if ("com_mvp4g_client_SingleSplitter3".equals(splitter.getClassName())) {
            list = Arrays.asList("presenter");
            assertEquals("com_mvp4g_client_SingleSplitter3", splitter.getName());
            assertNull(splitter.getLoader());
            assertEquals(1, splitter.getHandlers().size());
            assertTrue(splitter.getHandlers().contains(presenter));
            Map<EventElement, EventAssociation<String>> events = splitter.getEvents();
            assertEquals(1, events.size());
            EventElement key = events.keySet().iterator().next();
            assertSame(event, key);
            EventAssociation<String> association = events.get(key);
            assertList(list, association.getActivated());
            assertList(list, association.getDeactivated());
            assertList(list, association.getBinds());
            assertList(list, association.getHandlers());
        } else {
            fail("Unknown splitter");
        }
    }
}
Also used : SingleSplitter(com.mvp4g.client.SingleSplitter) EventElement(com.mvp4g.rebind.config.element.EventElement) EventAssociation(com.mvp4g.rebind.config.element.EventAssociation) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) SplitterElement(com.mvp4g.rebind.config.element.SplitterElement) Map(java.util.Map) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 22 with EventElement

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

the class Mvp4gConfigurationTest method testEventBindsAnnotationRestriction.

@Test
public void testEventBindsAnnotationRestriction() throws InvalidMvp4gConfigurationException {
    // checking situation when handlers has the same attributes as binds
    EventElement event = newEvent("testEvent1");
    event.setHandlers(new String[] { "handler1", "handler2" });
    event.setBinds(new String[] { "hander3", "handler1" });
    events.add(event);
    setEventBus();
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Event testEvent1: the same handler handler1 is used in the bind and handlers attributes. If you need handler1 to handle this event, you should remove it from the bind attribute."));
    } finally {
        events.remove(event);
    }
    // checking situation when passive event has some binds
    EventElement event2 = newEvent("testEvent2");
    event2.setBinds(new String[] { "someHandler" });
    event2.setPassive("true");
    events.add(event2);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Passive event can't bind any elements. Remove bind attribute from the testEvent2 event in order to keep it passive."));
    } finally {
        events.remove(event2);
    }
    // checking that combination with broadcastTo and passive event don't lead to exception
    PresenterElement presenter = newPresenter(SimplePresenter01.class, "testPresenter");
    presenter.setMultiple("true");
    presenter.setView("view");
    presenters.add(presenter);
    ViewElement view = newView(SimpleView01.class, "view");
    views.add(view);
    oracle.addClass(TestBroadcast.class);
    EventElement event3 = newEvent("testEvent3");
    event3.setPassive("true");
    event3.setBroadcastTo(TestBroadcast.class.getCanonicalName());
    event3.setGenerate(new String[] { "testPresenter" });
    events.add(event3);
    try {
        assertTrue(event3.isPassive());
        configuration.validateEventHandlers();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Passive event can't have any binds elements. Remove bind annotation from the testEvent3 event in order to keep it passive"));
        fail();
    } finally {
        events.remove(event3);
        presenters.remove(presenter);
    }
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) TestBroadcast(com.mvp4g.rebind.test_tools.annotation.TestBroadcast) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 23 with EventElement

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

the class Mvp4gConfigurationTest method testEventHistoryConverterWrongEventBus.

@Test(expected = InvalidTypeException.class)
public void testEventHistoryConverterWrongEventBus() throws InvalidMvp4gConfigurationException {
    try {
        HistoryConverterElement hc = new HistoryConverterElement();
        hc.setName("testHistoryConverter");
        Class<?> c = HistoryConverters.HistoryConverterWithLookup.class;
        oracle.addClass(c);
        hc.setClassName(c.getCanonicalName());
        historyConverters.add(hc);
        EventElement event = newEvent("testEvent");
        event.setHistory("testHistoryConverter");
        events.add(event);
        EventBusElement eventBus = new EventBusElement(EventBus.class.getName(), BaseEventBus.class.getName(), false);
        configuration.setEventBus(eventBus);
        configuration.validateHistoryConverters();
        fail();
    } catch (InvalidTypeException e) {
        assertTrue(e.getMessage().contains("Event Bus"));
        throw e;
    }
}
Also used : HistoryConverterElement(com.mvp4g.rebind.config.element.HistoryConverterElement) EventElement(com.mvp4g.rebind.config.element.EventElement) EventBusElement(com.mvp4g.rebind.config.element.EventBusElement) BaseEventBus(com.mvp4g.client.event.BaseEventBus) EventBus(com.mvp4g.client.event.EventBus) BaseEventBus(com.mvp4g.client.event.BaseEventBus) InvalidTypeException(com.mvp4g.rebind.exception.InvalidTypeException) Test(org.junit.Test)

Example 24 with EventElement

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

the class Mvp4gConfigurationTest method testChildViewLoadEvent.

@Test
public void testChildViewLoadEvent() throws InvalidMvp4gConfigurationException {
    ChildModuleElement childModule = newChildModule(Modules.ChildModule01.class, "child");
    childModule.setEventToDisplayView("testEvent");
    configuration.getOthersEventBusClassMap().put(Modules.ChildModule01.class.getCanonicalName(), oracle.addClass(EventBusOk.class));
    childModules.add(childModule);
    EventElement event = newEvent("testEvent");
    event.setForwardToModules(new String[] { "child" });
    event.setEventObjectClass(new String[] { String.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("Child Module %s: event %s can not load child module's start view. Can not convert %s to %s.", childModule.getClassName(), "testEvent", SimpleView.class.getCanonicalName(), String.class.getCanonicalName()));
    }
    event = newEvent("testEvent");
    event.setForwardToModules(new String[] { "child" });
    event.setEventObjectClass(new String[] { Object.class.getCanonicalName() });
    events.clear();
    events.add(event);
    configuration.validateChildModules();
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) Modules(com.mvp4g.rebind.test_tools.Modules) EventBusOk(com.mvp4g.rebind.test_tools.annotation.events.EventBusOk) SimpleView(com.mvp4g.rebind.test_tools.annotation.views.SimpleView) OneObject(com.mvp4g.rebind.test_tools.OneObject) ChildModuleElement(com.mvp4g.rebind.config.element.ChildModuleElement) Test(org.junit.Test)

Example 25 with EventElement

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

the class Mvp4gConfigurationTest method testEventHistoryConverterWrongInterface.

@Test(expected = InvalidClassException.class)
public void testEventHistoryConverterWrongInterface() throws InvalidMvp4gConfigurationException {
    HistoryConverterElement hc = new HistoryConverterElement();
    hc.setName("testHistoryConverter");
    hc.setClassName(Object.class.getName());
    historyConverters.add(hc);
    EventElement event = newEvent("testEvent");
    event.setHistory("testHistoryConverter");
    events.add(event);
    setEventBus();
    configuration.validateHistoryConverters();
}
Also used : HistoryConverterElement(com.mvp4g.rebind.config.element.HistoryConverterElement) EventElement(com.mvp4g.rebind.config.element.EventElement) OneObject(com.mvp4g.rebind.test_tools.OneObject) 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