public void testPluginConfigComparator() {
String me = ME + "-testPluginConfigConparator";
log.info("start");
PluginConfigComparator upComparator = new PluginConfigComparator(this.glob, true);
PluginConfigComparator downComparator = new PluginConfigComparator(this.glob, false);
PluginConfig config1 = new PluginConfig(this.glob, "test:PLUGIN1", true, "org.universe.Plugin1");
RunLevelAction action = new RunLevelAction(this.glob, "LOAD", 3, -1, null, 5);
config1.addAction(action);
action = new RunLevelAction(this.glob, "STOP", -1, 2, null, 4);
config1.addAction(action);
PluginConfig config2 = new PluginConfig(this.glob, "test:PLUGIN2", true, "org.universe.Plugin2");
action = new RunLevelAction(this.glob, "LOAD", 3, -1, null, 5);
config2.addAction(action);
action = new RunLevelAction(this.glob, "STOP", -1, 2, null, 4);
config2.addAction(action);
int cmp = upComparator.compare(config1, config2);
assertTrue(me + " number of actions", cmp < 0);
cmp = downComparator.compare(config1, config2);
assertTrue(me + " number of actions", cmp > 0);
PluginConfig config3 = new PluginConfig(this.glob, "test:PLUGIN3", true, "org.universe.Plugin3");
action = new RunLevelAction(this.glob, "LOAD", 2, -1, null, 3);
config3.addAction(action);
action = new RunLevelAction(this.glob, "STOP", -1, 1, null, 3);
config3.addAction(action);
cmp = upComparator.compare(config1, config3);
assertTrue(me + " number of actions", cmp > 0);
cmp = downComparator.compare(config1, config3);
assertTrue(me + " number of actions", cmp < 0);
PluginConfig config4 = new PluginConfig(this.glob, "test:PLUGIN4", true, "org.universe.Plugin4");
action = new RunLevelAction(this.glob, "LOAD", 2, -1, null, 4);
config4.addAction(action);
action = new RunLevelAction(this.glob, "STOP", -1, 1, null, 4);
config4.addAction(action);
cmp = upComparator.compare(config3, config4);
assertTrue(me + " number of actions", cmp < 0);
cmp = downComparator.compare(config3, config4);
assertTrue(me + " number of actions", cmp < 0);
try {
cmp = upComparator.compare(config3, (PluginConfig)null);
assertTrue(me + " number of actions", true);
}
catch (ClassCastException ex) {
log.info("exception is OK and expected in this context");
}
try {
cmp = upComparator.compare(config3, (PluginConfig)null);
assertTrue(me + " number of actions", true);
}
catch (ClassCastException ex) {
log.info("exception is OK and expected in this context");
}
try {
cmp = upComparator.compare((PluginConfig)null, config4);
assertTrue(me + " number of actions", true);
}
catch (ClassCastException ex) {
log.info("exception is OK and expected in this context");
}
try {
cmp = downComparator.compare((PluginConfig)null, config4);
assertTrue(me + " number of actions", true);
}
catch (ClassCastException ex) {
log.info("exception is OK and expected in this context");
}