Search in sources :

Example 1 with SplitterElement

use of com.mvp4g.rebind.config.element.SplitterElement 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)

Example 2 with SplitterElement

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

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

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