Search in sources :

Example 6 with EventHandlerElement

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

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

Example 8 with EventHandlerElement

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

the class Mvp4gConfigurationTest method testGenerate.

@Test
public void testGenerate() 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(SimpleView01.class, "view");
    views.add(view);
    PresenterElement generate1 = newPresenter(SimplePresenter01.class, "generate1");
    generate1.setView("view");
    EventHandlerElement generate2 = newEventHandler(SimpleEventHandler01.class, "generate2");
    presenters.add(generate1);
    eventHandlers.add(generate2);
    generate1.setMultiple(Boolean.TRUE.toString());
    generate2.setMultiple(Boolean.TRUE.toString());
    configuration.validateEventHandlers();
    List<String> generate = event1.getGenerate();
    assertEquals(2, generate.size());
    assertEquals(generate.get(0), generate1.getName());
    assertEquals(generate.get(1), generate2.getName());
    List<String> handlers = event1.getHandlers();
    assertEquals(1, handlers.size());
    assertEquals(generate2.getName(), handlers.get(0));
}
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) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 9 with EventHandlerElement

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

the class Mvp4gConfigurationTest method testActivateDeActivateMultiple.

@Test
public void testActivateDeActivateMultiple() throws InvalidMvp4gConfigurationException {
    EventBusElement eventBus = new EventBusElement(EventBusWithLookup.class.getName(), BaseEventBus.class.getName(), false);
    configuration.setEventBus(eventBus);
    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);
    activate1.setMultiple(Boolean.TRUE.toString());
    activate2.setMultiple(Boolean.TRUE.toString());
    deactivate1.setMultiple(Boolean.TRUE.toString());
    deactivate2.setMultiple(Boolean.TRUE.toString());
    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 10 with EventHandlerElement

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

the class Mvp4gConfigurationTest method newEventHandler.

private EventHandlerElement newEventHandler(Class<? extends BaseEventHandler<? extends EventBus>> c, String name) {
    EventHandlerElement eventHandler = new EventHandlerElement();
    eventHandler.setName(name);
    oracle.addClass(c);
    eventHandler.setClassName(c.getCanonicalName());
    return eventHandler;
}
Also used : EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement)

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