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);
}
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?"));
}
}
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));
}
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());
}
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");
}
}
}
Aggregations