Search in sources :

Example 1 with EventHandlerElement

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

the class Mvp4gConfigurationTest method testEventHandlerValidationInvalidEventBus.

@Test
public void testEventHandlerValidationInvalidEventBus() throws InvalidMvp4gConfigurationException {
    ViewElement view = newView(SimpleView02.class, "view");
    views.add(view);
    PresenterElement presenter = newPresenter(SimplePresenter01.class, "testHandler");
    presenter.setView("view");
    presenters.add(presenter);
    EventElement event = newEvent("testEvent");
    event.setHandlers(new String[] { "testHandler" });
    events.add(event);
    EventBusElement eventBus = new EventBusElement(EventBus.class.getName(), BaseEventBus.class.getName(), false);
    configuration.setEventBus(eventBus);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidTypeException e) {
        assertTrue(e.getMessage().contains("Event Bus"));
    }
    presenter.setMultiple(Boolean.TRUE.toString());
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidTypeException e) {
        assertTrue(e.getMessage().contains("Event Bus"));
    }
    events.clear();
    configuration.validateEventHandlers();
    assertTrue(presenters.size() == 0);
    EventHandlerElement eventHandler = newEventHandler(SimpleEventHandler01.class, "testHandler");
    eventHandlers.add(eventHandler);
    events.add(event);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidTypeException e) {
        assertTrue(e.getMessage().contains("Event Bus"));
    }
    eventHandler.setMultiple(Boolean.TRUE.toString());
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidTypeException e) {
        assertTrue(e.getMessage().contains("Event Bus"));
    }
    events.clear();
    configuration.validateEventHandlers();
    assertTrue(eventHandlers.size() == 0);
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) EventBusElement(com.mvp4g.rebind.config.element.EventBusElement) BaseEventBus(com.mvp4g.client.event.BaseEventBus) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) EventBus(com.mvp4g.client.event.EventBus) BaseEventBus(com.mvp4g.client.event.BaseEventBus) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) InvalidTypeException(com.mvp4g.rebind.exception.InvalidTypeException) Test(org.junit.Test)

Example 2 with EventHandlerElement

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

the class Mvp4gConfigurationTest method testGenerateNotMultiple.

@Test
public void testGenerateNotMultiple() throws InvalidMvp4gConfigurationException {
    EventBusElement eventBus = new EventBusElement(EventBusWithLookup.class.getName(), BaseEventBus.class.getName(), false);
    configuration.setEventBus(eventBus);
    EventElement event1 = newEvent("event1");
    event1.setHandlers(new String[] { "generate2" });
    event1.setGenerate(new String[] { "generate1", "generate2" });
    events.add(event1);
    ViewElement view = newView(SimpleView02.class, "view");
    view.setClassName(SimpleView02.class.getCanonicalName());
    views.add(view);
    PresenterElement generate1 = newPresenter(SimplePresenter01.class, "generate1");
    generate1.setView("view");
    EventHandlerElement generate2 = newEventHandler(SimpleEventHandler01.class, "generate2");
    presenters.add(generate1);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Event event1: you can generate only multiple handlers. Did you forget to set the attribute multiple to true for generate1?"));
    }
    presenters.clear();
    eventHandlers.clear();
    eventHandlers.add(generate2);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Event event1: you can generate only multiple handlers. Did you forget to set the attribute multiple to true for generate2?"));
    }
}
Also used : SimpleView02(com.mvp4g.rebind.test_tools.annotation.views.SimpleView02) EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) 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) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 3 with EventHandlerElement

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

the class Mvp4gConfigurationTest method testInjectedServiceRemove.

@Test
public void testInjectedServiceRemove() throws UnknownConfigurationElementException {
    ServiceElement service1 = newService("service1");
    ServiceElement service2 = newService("service2");
    ServiceElement service3 = newService("service3");
    ServiceElement service4 = newService("service4");
    services.add(service1);
    services.add(service2);
    services.add(service3);
    services.add(service4);
    PresenterElement presenter = newPresenter(SimplePresenter01.class, "testPresenter");
    presenter.getInjectedServices().add(new InjectedElement("service1", "setTestService"));
    presenters.add(presenter);
    HistoryConverterElement historyConverter = newHistoryConverter(SimpleHistoryConverter01.class, "testHistoryConverter");
    historyConverter.getInjectedServices().add(new InjectedElement("service2", "setTestService"));
    historyConverters.add(historyConverter);
    EventHandlerElement eventHandlerElement = newEventHandler(SimpleEventHandler01.class, "testEventHandler");
    eventHandlerElement.getInjectedServices().add(new InjectedElement("service3", "setTestService"));
    eventHandlers.add(eventHandlerElement);
    assertEquals(services.size(), 4);
    assertTrue(services.contains(service1));
    assertTrue(services.contains(service2));
    assertTrue(services.contains(service3));
    assertTrue(services.contains(service4));
    configuration.validateServices();
    assertEquals(services.size(), 3);
    assertTrue(services.contains(service1));
    assertTrue(services.contains(service2));
    assertTrue(services.contains(service3));
    assertFalse(services.contains(service4));
}
Also used : HistoryConverterElement(com.mvp4g.rebind.config.element.HistoryConverterElement) InjectedElement(com.mvp4g.rebind.config.element.InjectedElement) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) ServiceElement(com.mvp4g.rebind.config.element.ServiceElement) Test(org.junit.Test)

Example 4 with EventHandlerElement

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

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

Aggregations

EventHandlerElement (com.mvp4g.rebind.config.element.EventHandlerElement)12 PresenterElement (com.mvp4g.rebind.config.element.PresenterElement)11 Test (org.junit.Test)11 EventElement (com.mvp4g.rebind.config.element.EventElement)10 BaseEventBus (com.mvp4g.client.event.BaseEventBus)7 EventBusElement (com.mvp4g.rebind.config.element.EventBusElement)7 EventBusWithLookup (com.mvp4g.client.event.EventBusWithLookup)6 ViewElement (com.mvp4g.rebind.config.element.ViewElement)4 EventAssociation (com.mvp4g.rebind.config.element.EventAssociation)2 SplitterElement (com.mvp4g.rebind.config.element.SplitterElement)2 SingleSplitter (com.mvp4g.client.SingleSplitter)1 EventBus (com.mvp4g.client.event.EventBus)1 HistoryConverterElement (com.mvp4g.rebind.config.element.HistoryConverterElement)1 InjectedElement (com.mvp4g.rebind.config.element.InjectedElement)1 ServiceElement (com.mvp4g.rebind.config.element.ServiceElement)1 InvalidClassException (com.mvp4g.rebind.exception.InvalidClassException)1 InvalidMvp4gConfigurationException (com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException)1 InvalidTypeException (com.mvp4g.rebind.exception.InvalidTypeException)1 OneObject (com.mvp4g.rebind.test_tools.OneObject)1 Splitters (com.mvp4g.rebind.test_tools.Splitters)1