Search in sources :

Example 1 with EventAssociation

use of com.mvp4g.rebind.config.element.EventAssociation 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 2 with EventAssociation

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

the class Mvp4gConfigurationTest method testValidateSplitterTogether.

@Test
public void testValidateSplitterTogether() throws InvalidMvp4gConfigurationException {
    setEventBus();
    String splitterName = oracle.addClass(Splitters.SimpleSplitter.class).getQualifiedSourceName();
    PresenterElement presenter = newPresenter(SimplePresenter01.class, "presenter");
    presenter.setAsync(splitterName);
    presenters.add(presenter);
    PresenterElement presenterMultiple = newPresenter(SimplePresenter02.class, "presenterMultiple");
    presenterMultiple.setAsync(splitterName);
    presenterMultiple.setMultiple("true");
    presenters.add(presenterMultiple);
    EventHandlerElement eventHandler = newEventHandler(SimpleEventHandler01.class, "eventHandler");
    eventHandler.setAsync(splitterName);
    eventHandlers.add(eventHandler);
    EventHandlerElement eventHandlerMultiple = newEventHandler(SimpleEventHandler02.class, "eventHandlerMultiple");
    eventHandlerMultiple.setAsync(splitterName);
    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" });
    event.setGenerate(new String[] { "presenterMultiple", "eventHandlerMultiple" });
    events.add(event);
    configuration.validateSplitters();
    splitterName = Splitters.SimpleSplitter.class.getCanonicalName().replace(".", "_");
    assertEquals(1, configuration.getSplitters().size());
    SplitterElement splitter = configuration.getSplitters().iterator().next();
    assertEquals(splitterName, splitter.getClassName());
    assertEquals(splitterName, splitter.getName());
    assertNull(splitter.getLoader());
    assertEquals(4, splitter.getHandlers().size());
    assertTrue(splitter.getHandlers().contains(eventHandler));
    assertTrue(splitter.getHandlers().contains(presenter));
    assertTrue(splitter.getHandlers().contains(eventHandlerMultiple));
    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);
    List<String> list = Arrays.asList("eventHandler", "eventHandlerMultiple", "presenter", "presenterMultiple");
    assertCollection(list, association.getActivated());
    assertCollection(list, association.getDeactivated());
    assertCollection(list, association.getBinds());
    assertCollection(list, association.getHandlers());
    assertCollection(Arrays.asList("eventHandlerMultiple", "presenterMultiple"), association.getGenerate());
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) EventAssociation(com.mvp4g.rebind.config.element.EventAssociation) Splitters(com.mvp4g.rebind.test_tools.Splitters) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) SplitterElement(com.mvp4g.rebind.config.element.SplitterElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Aggregations

EventAssociation (com.mvp4g.rebind.config.element.EventAssociation)2 EventElement (com.mvp4g.rebind.config.element.EventElement)2 EventHandlerElement (com.mvp4g.rebind.config.element.EventHandlerElement)2 PresenterElement (com.mvp4g.rebind.config.element.PresenterElement)2 SplitterElement (com.mvp4g.rebind.config.element.SplitterElement)2 Test (org.junit.Test)2 SingleSplitter (com.mvp4g.client.SingleSplitter)1 Splitters (com.mvp4g.rebind.test_tools.Splitters)1 Map (java.util.Map)1