use of com.mvp4g.rebind.config.element.PresenterElement 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());
}
use of com.mvp4g.rebind.config.element.PresenterElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testInjectedServiceValidationSucceeds.
@Test
public void testInjectedServiceValidationSucceeds() throws UnknownConfigurationElementException {
services.add(newService("testService"));
PresenterElement presenter = newPresenter(SimplePresenter01.class, "testPresenter");
presenter.getInjectedServices().add(new InjectedElement("testService", "setTestService"));
presenters.add(presenter);
HistoryConverterElement historyConverter = newHistoryConverter(SimpleHistoryConverter01.class, "testHistoryConverter");
historyConverter.getInjectedServices().add(new InjectedElement("testService", "setTestService"));
historyConverters.add(historyConverter);
configuration.validateServices();
}
use of com.mvp4g.rebind.config.element.PresenterElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testInstantiateViewAtStart.
@Test
public void testInstantiateViewAtStart() throws InvalidMvp4gConfigurationException {
ViewElement view1 = newView(SimpleView02.class, "view1");
view1.setClassName(SimpleView02.class.getCanonicalName());
views.add(view1);
ViewElement view2 = newView(SimpleView03.class, "view2");
view2.setClassName(SimpleView03.class.getCanonicalName());
views.add(view2);
ViewElement view3 = newView(SimpleView04.class, "view3");
view3.setClassName(SimpleView04.class.getCanonicalName());
views.add(view3);
PresenterElement presenter = new PresenterElement();
presenter.setName("presenter1");
Class<?> c = SimplePresenter01.class;
presenter.setClassName(c.getCanonicalName());
oracle.addClass(c);
presenter.setView("view1");
presenters.add(presenter);
PresenterElement presenter2 = new PresenterElement();
presenter2.setName("presenter2");
c = PresenterWithService.class;
presenter2.setClassName(c.getCanonicalName());
oracle.addClass(c);
presenter2.setView("view2");
presenter2.setMultiple("true");
presenters.add(presenter2);
PresenterElement presenter3 = new PresenterElement();
presenter3.setName("presenter3");
c = Presenters.AsyncPresenter.class;
oracle.addClass(c);
presenter3.setClassName(c.getCanonicalName());
presenter3.setView("view3");
presenter3.setAsync("true");
presenters.add(presenter3);
EventElement event = newEvent("event");
event.setHandlers(new String[] { "presenter1", "presenter2", "presenter3" });
events.add(event);
setEventBus();
configuration.validateEventHandlers();
assertTrue(view1.isInstantiateAtStart());
assertFalse(view2.isInstantiateAtStart());
assertFalse(view3.isInstantiateAtStart());
}
use of com.mvp4g.rebind.config.element.PresenterElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testEventHandlerValidationSucceedsNoInjectedView.
@Test
public void testEventHandlerValidationSucceedsNoInjectedView() throws InvalidMvp4gConfigurationException {
ViewElement view = newView(SimpleView01.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);
setEventBus();
configuration.validateEventHandlers();
assertFalse(presenter.hasInverseView());
}
use of com.mvp4g.rebind.config.element.PresenterElement 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));
}
Aggregations