use of com.mvp4g.rebind.config.element.EventElement 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");
}
}
}
use of com.mvp4g.rebind.config.element.EventElement 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);
}
}
use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testEventHistoryConverterWrongEventBus.
@Test(expected = InvalidTypeException.class)
public void testEventHistoryConverterWrongEventBus() throws InvalidMvp4gConfigurationException {
try {
HistoryConverterElement hc = new HistoryConverterElement();
hc.setName("testHistoryConverter");
Class<?> c = HistoryConverters.HistoryConverterWithLookup.class;
oracle.addClass(c);
hc.setClassName(c.getCanonicalName());
historyConverters.add(hc);
EventElement event = newEvent("testEvent");
event.setHistory("testHistoryConverter");
events.add(event);
EventBusElement eventBus = new EventBusElement(EventBus.class.getName(), BaseEventBus.class.getName(), false);
configuration.setEventBus(eventBus);
configuration.validateHistoryConverters();
fail();
} catch (InvalidTypeException e) {
assertTrue(e.getMessage().contains("Event Bus"));
throw e;
}
}
use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testChildViewLoadEvent.
@Test
public void testChildViewLoadEvent() throws InvalidMvp4gConfigurationException {
ChildModuleElement childModule = newChildModule(Modules.ChildModule01.class, "child");
childModule.setEventToDisplayView("testEvent");
configuration.getOthersEventBusClassMap().put(Modules.ChildModule01.class.getCanonicalName(), oracle.addClass(EventBusOk.class));
childModules.add(childModule);
EventElement event = newEvent("testEvent");
event.setForwardToModules(new String[] { "child" });
event.setEventObjectClass(new String[] { String.class.getCanonicalName() });
events.add(event);
setEventBus();
configuration.setModule(oracle.addClass(Modules.ModuleWithParent01.class));
try {
configuration.validateChildModules();
fail();
} catch (InvalidMvp4gConfigurationException e) {
assertEquals(e.getMessage(), String.format("Child Module %s: event %s can not load child module's start view. Can not convert %s to %s.", childModule.getClassName(), "testEvent", SimpleView.class.getCanonicalName(), String.class.getCanonicalName()));
}
event = newEvent("testEvent");
event.setForwardToModules(new String[] { "child" });
event.setEventObjectClass(new String[] { Object.class.getCanonicalName() });
events.clear();
events.add(event);
configuration.validateChildModules();
}
use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testEventHistoryConverterWrongInterface.
@Test(expected = InvalidClassException.class)
public void testEventHistoryConverterWrongInterface() throws InvalidMvp4gConfigurationException {
HistoryConverterElement hc = new HistoryConverterElement();
hc.setName("testHistoryConverter");
hc.setClassName(Object.class.getName());
historyConverters.add(hc);
EventElement event = newEvent("testEvent");
event.setHistory("testHistoryConverter");
events.add(event);
setEventBus();
configuration.validateHistoryConverters();
}
Aggregations