use of com.mvp4g.rebind.config.element.ChildModuleElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testChildModulesRemove.
@Test
public void testChildModulesRemove() throws InvalidMvp4gConfigurationException {
ChildModuleElement childModule1 = newChildModule(Modules.ChildModule01.class, "child1");
childModule1.setEventToDisplayView("testEvent");
childModules.add(childModule1);
configuration.getOthersEventBusClassMap().put(Modules.ChildModule01.class.getCanonicalName(), oracle.addClass(EventBusOk.class));
ChildModuleElement childModule2 = newChildModule(Modules.ChildModule02.class, "child2");
childModules.add(childModule2);
EventElement event = newEvent("testEvent");
event.setForwardToModules(new String[] { "child1" });
event.setEventObjectClass(new String[] { Object.class.getCanonicalName() });
events.add(event);
builder.expectWarn("Module Mvp4gModule: the child module child2 is not loaded by any of the event of this module. You should remove it if it is not used by another child module (ie used for sibling communication).", null);
logger = builder.createLogger();
configuration.setLogger(logger);
setEventBus();
assertEquals(2, childModules.size());
assertTrue(childModules.contains(childModule1));
assertTrue(childModules.contains(childModule2));
configuration.validateChildModules();
assertEquals(2, childModules.size());
assertTrue(childModules.contains(childModule1));
assertTrue(childModules.contains(childModule2));
logger.assertCorrectLogEntries();
}
use of com.mvp4g.rebind.config.element.ChildModuleElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testForwardParentModule.
@Test
public void testForwardParentModule() throws InvalidMvp4gConfigurationException {
String parentModule = oracle.addClass(Modules.Module01.class).getQualifiedSourceName();
EventElement event = newEvent("testEvent");
event.setForwardToModules(new String[] { parentModule });
event.setEventObjectClass(new String[] { String.class.getCanonicalName() });
events.add(event);
Map<String, ChildModuleElement> childModuleMap = configuration.getModuleParentEventBusClassMap();
JClassType parentEventBus = oracle.addClass(EventBusOk.class);
configuration.setParentEventBus(parentEventBus);
String currentModule = oracle.addClass(Modules.ModuleWithParent01.class).getQualifiedSourceName();
ChildModuleElement module = new ChildModuleElement();
module.setParentEventBus(parentEventBus);
module.setParentModuleClass(parentModule);
module.setClassName(currentModule);
childModuleMap.put(currentModule, module);
setEventBus();
configuration.setModule(oracle.findType(Modules.ModuleWithParent01.class.getCanonicalName()));
List<ChildModuleElement> siblings = configuration.getSiblings();
assertEquals(0, siblings.size());
assertFalse(event.hasForwardToParent());
configuration.validateChildModules();
assertTrue(event.hasForwardToParent());
}
use of com.mvp4g.rebind.config.element.ChildModuleElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testParentBroadcast.
@Test
public void testParentBroadcast() throws InvalidMvp4gConfigurationException {
String parentModule = oracle.addClass(Modules.BroadcastModule2.class).getQualifiedSourceName();
EventElement event = newEvent("testEvent");
event.setBroadcastTo(TestBroadcast.class.getCanonicalName());
event.setEventObjectClass(new String[] { String.class.getCanonicalName() });
events.add(event);
EventElement event2 = newEvent("testEvent2");
event2.setBroadcastTo(TestBroadcast2.class.getCanonicalName());
events.add(event2);
Map<String, ChildModuleElement> childModuleMap = configuration.getModuleParentEventBusClassMap();
JClassType parentEventBus = oracle.addClass(EventBusOk.class);
configuration.setParentEventBus(parentEventBus);
String currentModule = oracle.addClass(Modules.ModuleWithParent01.class).getQualifiedSourceName();
ChildModuleElement module = new ChildModuleElement();
module.setParentEventBus(parentEventBus);
module.setParentModuleClass(parentModule);
module.setClassName(currentModule);
childModuleMap.put(currentModule, module);
setEventBus();
configuration.setModule(oracle.findType(Modules.ModuleWithParent01.class.getCanonicalName()));
List<ChildModuleElement> siblings = configuration.getSiblings();
assertEquals(0, siblings.size());
assertFalse(event.hasForwardToParent());
assertFalse(event2.hasForwardToParent());
configuration.validateChildModules();
assertTrue(event.hasForwardToParent());
assertTrue(event2.hasForwardToParent());
}
use of com.mvp4g.rebind.config.element.ChildModuleElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testAutoDisplay.
@Test
public void testAutoDisplay() throws InvalidMvp4gConfigurationException {
ChildModuleElement childModule1 = newChildModule(Modules.ChildModule01.class, "child1");
childModules.add(childModule1);
assertTrue(childModule1.isAutoDisplay());
EventElement event = newEvent("testEvent");
event.setForwardToModules(new String[] { "child1" });
event.setEventObjectClass(new String[] { Object.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("%s: child module %s doesn't define any event to load its view.", Modules.ModuleWithParent01.class.getCanonicalName(), childModule1.getClassName()));
}
childModule1.setAutoDisplay("false");
configuration.validateChildModules();
}
use of com.mvp4g.rebind.config.element.ChildModuleElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testChildModuleLoaders.
@Test
public void testChildModuleLoaders() throws InvalidMvp4gConfigurationException {
setEventBus();
oracle.addClass(Loaders.Loader1.class);
oracle.addClass(Loaders.Loader2.class);
oracle.addClass(Modules.ModuleWithLoader.class);
oracle.addClass(Modules.ModuleWithSameLoader1.class);
oracle.addClass(Modules.ModuleWithSameLoader2.class);
oracle.addClass(Modules.Module01.class);
ChildModuleElement withLoader = new ChildModuleElement();
withLoader.setName("withLoader");
withLoader.setClassName(Modules.ModuleWithLoader.class.getCanonicalName());
childModules.add(withLoader);
ChildModuleElement withSameLoader1 = new ChildModuleElement();
withSameLoader1.setName("withSameLoader1");
withSameLoader1.setClassName(Modules.ModuleWithSameLoader1.class.getCanonicalName());
childModules.add(withSameLoader1);
ChildModuleElement withSameLoader2 = new ChildModuleElement();
withSameLoader2.setName("withSameLoader2");
withSameLoader2.setClassName(Modules.ModuleWithSameLoader2.class.getCanonicalName());
childModules.add(withSameLoader2);
ChildModuleElement noLoader = new ChildModuleElement();
noLoader.setName("noLoader");
noLoader.setClassName(Modules.Module01.class.getCanonicalName());
childModules.add(noLoader);
configuration.findChildModuleHistoryNameAndLoader();
String loader1Name = "loader" + Loaders.Loader1.class.getCanonicalName().replace(".", "_");
String loader2Name = "loader" + Loaders.Loader2.class.getCanonicalName().replace(".", "_");
assertEquals(loader1Name, withLoader.getLoader());
assertEquals(loader2Name, withSameLoader1.getLoader());
assertEquals(loader2Name, withSameLoader2.getLoader());
assertNull(noLoader.getLoader());
Set<LoaderElement> loaders = configuration.getLoaders();
assertEquals(2, loaders.size());
Iterator<LoaderElement> it = loaders.iterator();
LoaderElement next;
String name;
while (it.hasNext()) {
next = it.next();
name = next.getName();
if (name.equals(loader1Name)) {
assertEquals(Loaders.Loader1.class.getCanonicalName(), next.getClassName());
} else if (name.equals(loader2Name)) {
assertEquals(Loaders.Loader2.class.getCanonicalName(), next.getClassName());
} else {
fail("Unknown loader " + next.getName());
}
}
}
Aggregations