use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testWrongEventLoadConfigEvent.
@Test
public void testWrongEventLoadConfigEvent() throws InvalidMvp4gConfigurationException {
configuration.setHistory(null);
EventElement e = newEvent("event");
e.setEventObjectClass(new String[] { Object.class.getCanonicalName() });
events.add(e);
ChildModulesElement childModules = new ChildModulesElement();
configuration.setLoadChildConfig(childModules);
childModules.setBeforeEvent("event");
try {
configuration.validateEvents();
fail();
} catch (InvalidMvp4gConfigurationException ex) {
assertEquals(String.format("%s: %s event %s can't have any object associated with it.", childModules.getTagName(), "Before", "event"), ex.getMessage());
}
childModules = new ChildModulesElement();
configuration.setLoadChildConfig(childModules);
childModules.setAfterEvent("event");
try {
configuration.validateEvents();
fail();
} catch (InvalidMvp4gConfigurationException ex) {
assertEquals(String.format("%s: %s event %s can't have any object associated with it.", childModules.getTagName(), "After", "event"), ex.getMessage());
}
childModules = new ChildModulesElement();
configuration.setLoadChildConfig(childModules);
childModules.setErrorEvent("event");
try {
configuration.validateEvents();
fail();
} catch (InvalidMvp4gConfigurationException ex) {
assertEquals("childModules: Error event event can only be associated with one and only one object with type java.lang.Throwable", ex.getMessage());
}
}
use of com.mvp4g.rebind.config.element.EventElement 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());
}
use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testEventHandlerValidationInvalidView.
@Test
public void testEventHandlerValidationInvalidView() throws InvalidMvp4gConfigurationException {
ViewElement view = newView(SimpleView02.class, "view");
view.setClassName(Integer.class.getName());
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);
try {
setEventBus();
configuration.validateEventHandlers();
fail();
} catch (InvalidTypeException e) {
assertTrue(e.getMessage().contains("View"));
}
presenter.setMultiple(Boolean.TRUE.toString());
try {
setEventBus();
configuration.validateEventHandlers();
fail();
} catch (InvalidTypeException e) {
assertTrue(e.getMessage().contains("View"));
}
}
use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testEventHandlerValidationFails.
@Test(expected = UnknownConfigurationElementException.class)
public void testEventHandlerValidationFails() throws InvalidMvp4gConfigurationException {
views.add(newView(SimpleView02.class, "badHandler"));
services.add(newService("badHandler"));
events.add(newEvent("badHanlder"));
historyConverters.add(newHistoryConverter(SimpleHistoryConverter01.class, "badHanlder"));
EventElement event = newEvent("testEvent");
event.setHandlers(new String[] { "badHandler" });
events.add(event);
setEventBus();
configuration.validateEventHandlers();
}
use of com.mvp4g.rebind.config.element.EventElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testMissingChildModule.
@Test
public void testMissingChildModule() throws InvalidMvp4gConfigurationException {
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("Event testEvent: No instance of child has been found. Is this module a child module, a parent module or a silbling module? If it's supposed to be a child module, have you forgotten to add it to @ChildModules of your event bus interface?", e.getMessage());
}
}
Aggregations