Search in sources :

Example 16 with PresenterElement

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

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

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

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

the class Mvp4gConfigurationTest method testEventHandlerRemove.

@Test
public void testEventHandlerRemove() throws InvalidMvp4gConfigurationException {
    ViewElement view = newView(SimpleView01.class, "view");
    views.add(view);
    PresenterElement presenter1 = newPresenter(SimplePresenter01.class, "presenter1");
    presenter1.setView("view");
    presenters.add(presenter1);
    PresenterElement presenter2 = newPresenter(SimplePresenter02.class, "presenter2");
    presenter2.setView("view");
    presenters.add(presenter2);
    PresenterElement presenter3 = newPresenter(SimplePresenter03.class, "presenter3");
    presenter3.setView("view");
    presenter3.setMultiple("true");
    presenters.add(presenter3);
    PresenterElement presenter4 = newPresenter(SimplePresenter04.class, "presenter4");
    presenter4.setView("view");
    presenters.add(presenter4);
    EventHandlerElement handler1 = newEventHandler(SimpleEventHandler01.class, "handler1");
    eventHandlers.add(handler1);
    EventHandlerElement handler2 = newEventHandler(SimpleEventHandler02.class, "handler2");
    eventHandlers.add(handler2);
    EventHandlerElement handler3 = newEventHandler(SimpleEventHandler03.class, "handler3");
    handler3.setMultiple("true");
    eventHandlers.add(handler3);
    EventHandlerElement handler4 = newEventHandler(SimpleEventHandler04.class, "handler4");
    eventHandlers.add(handler4);
    EventElement event = newEvent("testEvent");
    event.setHandlers(new String[] { "presenter1", "handler1" });
    event.setGenerate(new String[] { "presenter3", "handler3" });
    event.setBinds(new String[] { "presenter4", "handler4" });
    events.add(event);
    setEventBus();
    assertEquals(4, presenters.size());
    assertTrue(presenters.contains(presenter1));
    assertTrue(presenters.contains(presenter2));
    assertEquals(4, eventHandlers.size());
    assertTrue(eventHandlers.contains(handler1));
    assertTrue(eventHandlers.contains(handler2));
    configuration.validateEventHandlers();
    assertEquals(3, presenters.size());
    assertTrue(presenters.contains(presenter1));
    assertFalse(presenters.contains(presenter2));
    assertEquals(3, eventHandlers.size());
    assertTrue(eventHandlers.contains(handler1));
    assertFalse(eventHandlers.contains(handler2));
    presenter2.setMultiple(Boolean.TRUE.toString());
    presenters.add(presenter2);
    handler2.setMultiple(Boolean.TRUE.toString());
    eventHandlers.add(handler2);
    assertEquals(4, presenters.size());
    assertTrue(presenters.contains(presenter1));
    assertTrue(presenters.contains(presenter2));
    assertEquals(4, eventHandlers.size());
    assertTrue(eventHandlers.contains(handler1));
    assertTrue(eventHandlers.contains(handler2));
    configuration.validateEventHandlers();
    assertEquals(4, presenters.size());
    assertTrue(presenters.contains(presenter1));
    assertTrue(presenters.contains(presenter2));
    assertEquals(4, eventHandlers.size());
    assertTrue(eventHandlers.contains(handler1));
    assertTrue(eventHandlers.contains(handler2));
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 20 with PresenterElement

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

the class Mvp4gConfigurationTest method testValidateSplitterStartPresenter.

@Test
public void testValidateSplitterStartPresenter() {
    setEventBus();
    PresenterElement presenter = newPresenter(SimplePresenter01.class, "presenter");
    configuration.getStart().setPresenter("presenter");
    presenter.setAsync("true");
    presenters.add(presenter);
    EventElement event = new EventElement();
    event.setType("event");
    event.setHandlers(new String[] { "presenter" });
    events.add(event);
    try {
        configuration.validateSplitters();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals("Presenter presenter: start presenter can't be loaded asynchronously. Async attribute must not be set.", e.getMessage());
    }
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Aggregations

PresenterElement (com.mvp4g.rebind.config.element.PresenterElement)34 Test (org.junit.Test)32 EventElement (com.mvp4g.rebind.config.element.EventElement)22 ViewElement (com.mvp4g.rebind.config.element.ViewElement)14 EventHandlerElement (com.mvp4g.rebind.config.element.EventHandlerElement)11 BaseEventBus (com.mvp4g.client.event.BaseEventBus)8 EventBusElement (com.mvp4g.rebind.config.element.EventBusElement)8 EventBusWithLookup (com.mvp4g.client.event.EventBusWithLookup)7 InvalidTypeException (com.mvp4g.rebind.exception.InvalidTypeException)4 SimpleView02 (com.mvp4g.rebind.test_tools.annotation.views.SimpleView02)4 EventBus (com.mvp4g.client.event.EventBus)3 InjectedElement (com.mvp4g.rebind.config.element.InjectedElement)3 SplitterElement (com.mvp4g.rebind.config.element.SplitterElement)3 InvalidMvp4gConfigurationException (com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException)3 Splitters (com.mvp4g.rebind.test_tools.Splitters)3 Presenters (com.mvp4g.rebind.test_tools.annotation.Presenters)3 SimplePresenter01 (com.mvp4g.rebind.test_tools.annotation.presenters.SimplePresenter01)3 PresenterInterface (com.mvp4g.client.presenter.PresenterInterface)2 EventAssociation (com.mvp4g.rebind.config.element.EventAssociation)2 HistoryConverterElement (com.mvp4g.rebind.config.element.HistoryConverterElement)2