modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java | 280 +++++----- 1 file changed, 142 insertions(+), 138 deletions(-)
New commits: commit e74f850fe1148baa791169ee3c3accf8dae1021c Author: Stefan Negrea snegrea@redhat.com Date: Sat Jun 22 10:59:11 2013 -0500
Fix failing tests due to inconsistent setup and usage of entities.
diff --git a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java index 9b16178..150b121 100644 --- a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java +++ b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/alert/AlertDefinitionWithComplexNotificationsTest.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Random; import java.util.Set;
import javax.persistence.EntityManager; @@ -82,8 +83,8 @@ import org.rhq.enterprise.server.util.ResourceTreeHelper; * !!! implementation heavily relies (i.e. Before/AfterClass and instance variables that span all tests). * !!! The work needed to get it to work in a similar fashion was large, and Arquillian 2 promises to perhaps * !!! honor the testNg lifecycle. So, for now, I've basically condensed this into one large test to - * !!! get it running. Sorry Lukas :( - * + * !!! get it running. Sorry Lukas :( + * * * @author Lukas Krejci */ @@ -133,13 +134,13 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes testNotificationsCopiedOnGroupMemberAddition();
System.out.println("Running test: testCorrectSubjectPassedOnResourceLevelAlertDefinitionCreation"); - testCorrectSubjectPassedOnResourceLevelAlertDefinitionCreation(); + testCorrectSubjectPassedOnResourceLevelAlertDefCreation();
System.out.println("Running test: testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation"); - testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation(); + testCorrectSubjectPassedOnGroupLevelAlertDefCreation();
System.out.println("Running test: testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation"); - testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation(); + testCorrectSubjectPassedOnTemplateLevelAlertDefCreation();
System.out.println("Running test: testNoValidationWhenNoNotificationUpdateOnResourceLevel"); testNoValidationWhenNoNotificationUpdateOnResourceLevel(); @@ -162,7 +163,6 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes } catch (Exception e) { e.printStackTrace(); throw e; - } finally { logout(); cleanDB(); @@ -239,7 +239,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes unprepareServerPluginService();
JavaArchive archive = ShrinkWrap.create(JavaArchive.class); - //archive.addClass(TestAlertSender.class); + archive.addClass(TestAlertSender.class); URL res = this.getClass().getClassLoader().getResource("test-alert-sender-serverplugin.xml"); archive.addAsResource(res, "META-INF/rhq-serverplugin.xml");
@@ -250,6 +250,8 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes //the alert sender plugin manager needs the plugins in the database... serverPlugin = TestServerPluginService.getPlugin(pluginFile.toURI().toURL()); em.persist(serverPlugin); + + em.flush(); } }); } @@ -289,7 +291,8 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
executeInTransaction(false, new TransactionCallback() { public void execute() throws Exception { - em.createQuery("delete from AlertNotification an where an.senderName like '" + universalName + "%'") + em.createQuery( + "delete from AlertNotification an where an.senderName like '" + TestAlertSender.NAME + "%'") .executeUpdate(); em.createQuery("delete from AlertCondition ac where ac.name like '" + universalName + "%'") .executeUpdate(); @@ -330,7 +333,12 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
//@AfterMethod(alwaysRun = true) private void logout() throws Exception { - SessionManager.getInstance().invalidate(subject.getSessionId()); + if (subject != null) { + SessionManager.getInstance().invalidate(subject.getSessionId()); + } else { + System.err + .println("Empty subject, the setup failed horribly. Not throwing an exception to allow the database clean."); + } }
private Resource getCopyTestsResource() throws Exception { @@ -365,7 +373,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
final Resource res = getCopyTestsResource();
- //apply the template manually - this is done in server-agent back-and-forth that we + //apply the template manually - this is done in server-agent back-and-forth that we //don't test here and which is complex to mock out. //this method has to be called using the overlord subject LookupUtil.getAlertTemplateManager().updateAlertDefinitionsForResource( @@ -431,15 +439,14 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes .getGroupAlertDefinition().getId()); }
- private void testCorrectSubjectPassedOnResourceLevelAlertDefinitionCreation() throws Exception { + private void testCorrectSubjectPassedOnResourceLevelAlertDefCreation() throws Exception { TestAlertSender.setExpectedSubject(subject);
AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();
Resource res = resources.iterator().next();
- AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnResourceLevelAlertDefinitionCreation", - false); + AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnResourceLevelAlertDef", false); def.setResource(res);
def = adm.createAlertDefinitionInNewTransaction(subject, def, res.getId(), true); @@ -453,13 +460,12 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
//@Test(dependsOnMethods = { "testNotificationsCopiedOnAlertTemplateApplication", // "testNotificationsCopiedOnGroupMemberAddition" }) - private void testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation() throws Exception { + private void testCorrectSubjectPassedOnGroupLevelAlertDefCreation() throws Exception { TestAlertSender.setExpectedSubject(subject);
GroupAlertDefinitionManagerLocal gadm = LookupUtil.getGroupAlertDefinitionManager();
- AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation", - false); + AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnGroupLevelAlertDef", false); def.setGroup(resourceGroup);
int id = gadm.createGroupAlertDefinitions(subject, def, resourceGroup.getId()); @@ -477,13 +483,12 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes
//@Test(dependsOnMethods = { "testNotificationsCopiedOnAlertTemplateApplication", // "testNotificationsCopiedOnGroupMemberAddition" }) - private void testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation() throws Exception { + private void testCorrectSubjectPassedOnTemplateLevelAlertDefCreation() throws Exception { TestAlertSender.setExpectedSubject(subject);
AlertTemplateManagerLocal atm = LookupUtil.getAlertTemplateManager();
- AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation", - false); + AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnTemplateLevelAlertDef", false); def.setGroup(resourceGroup);
int id = atm.createAlertTemplate(subject, def, resourceType.getId()); @@ -599,9 +604,6 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes AlertDefinition foundDef = foundDefs.get(0);
AlertNotification newNotif = createAlertNotificationForTest(foundDef, false); - //just add some dummy config property so that the 2 notifs are distinguishable from each other - //and are saved separately - newNotif.getConfiguration().put(new PropertySimple("foo-resource", "bar"));
adm.updateAlertDefinition(subject, resourceLevelAlertDefinitionId, foundDef, false);
@@ -628,9 +630,6 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes AlertDefinition foundDef = foundDefs.get(0);
AlertNotification newNotif = createAlertNotificationForTest(foundDef, false); - //just add some dummy config property so that the 2 notifs are distinguishable from each other - //and are saved separately - newNotif.getConfiguration().put(new PropertySimple("foo-group", "bar"));
GroupAlertDefinitionManagerLocal gadm = LookupUtil.getGroupAlertDefinitionManager(); gadm.updateGroupAlertDefinitions(subject, foundDef, true); @@ -660,9 +659,6 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes AlertDefinition foundDef = foundDefs.get(0);
AlertNotification newNotif = createAlertNotificationForTest(foundDef, false); - //just add some dummy config property so that the 2 notifs are distinguishable from each other - //and are saved separately - newNotif.getConfiguration().put(new PropertySimple("foo-template", "bar"));
AlertTemplateManagerLocal atm = LookupUtil.getAlertTemplateManager(); atm.updateAlertTemplate(subject, foundDef, true); @@ -685,6 +681,8 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes } else { em.remove(o2); } + + em.flush(); } }); } catch (Exception e) { @@ -700,7 +698,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes ret.setRecoveryId(0);
AlertCondition ac = new AlertCondition(); - ac.setName(universalName); + ac.setName(universalName + ":" + name); ac.setCategory(AlertConditionCategory.THRESHOLD); ac.setComparator(">"); ac.setThreshold(0.75D); @@ -732,10 +730,16 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes }
private AlertNotification createAlertNotificationForTest(AlertDefinition alertDefinition, boolean precanned) { - AlertNotification notif = new AlertNotification("Test Alert Sender"); + AlertNotification notif = new AlertNotification(TestAlertSender.NAME);
Configuration alertConfig = new Configuration();
+ //generate random property so that the notifications are distinguishable from each other + //and are saved separately + Random randomGenerator = new Random(); + String randomValue = randomGenerator.nextInt(100) + " - " + randomGenerator.nextInt(200); + alertConfig.put(new PropertySimple(randomValue, randomValue)); + if (precanned) { alertConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE)); @@ -847,7 +851,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes }
///** -// * +// * // * // * @author Lukas Krejci // */ @@ -859,7 +863,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // private enum ParentType { // GROUP, TEMPLATE // } -// +// // private String universalName; // // private Server server; @@ -879,10 +883,10 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // private int groupLevelAlertDefinitionId; // private int templateLevelAlertDefinitionId; // private Resource copyTestsResource; -// +// // private TestAlertSenderPluginService alertSenderService; // private TestServerCommunicationsService agentService; -// +// // @BeforeClass // public void prepareDB() { // executeInTransaction(new TransactionCallback() { @@ -893,14 +897,14 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // universalName = getClass().getName(); // // agent = new Agent("localhost", "localhost", 0, "foo", "bar"); -// +// // server = new Server(); // server.setAddress("localhost"); // server.setName("localhost"); // server.setOperationMode(OperationMode.NORMAL); -// +// // server.setAgents(Collections.singletonList(agent)); -// +// // role = new Role(universalName); // role.addPermission(Permission.MANAGE_INVENTORY); // role.addPermission(Permission.MANAGE_SETTINGS); @@ -917,7 +921,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // resources = new LinkedHashSet<Resource>(); // for (int i = 0; i < 10; ++i) { // Resource res = createResourceForTest(universalName + i); -// +// // resources.add(res); // // resourceGroup.addExplicitResource(res); @@ -972,18 +976,18 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // alertSenderService = new TestAlertSenderPluginService(); // prepareCustomServerPluginService(alertSenderService); // alertSenderService.masterConfig.getPluginDirectory().mkdirs(); -// +// // alertSenderService.startMasterPluginContainer(); -// +// // agentService = prepareForTestAgents(); // } // // @AfterMethod // public void containerTearDown() throws Exception { // unprepareServerPluginService(); -// unprepareForTestAgents(); +// unprepareForTestAgents(); // } -// +// // @AfterClass(alwaysRun = true) // public void cleanDB() throws Exception { // for (Object o : junk) { @@ -1004,8 +1008,8 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // removeNoExceptions(role); // removeNoExceptions(server); // removeNoExceptions(agent); -// -// removeNoExceptions(serverPlugin); +// +// removeNoExceptions(serverPlugin); // } // // @BeforeMethod @@ -1023,7 +1027,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // private Resource getCopyTestsResource() throws Exception { // if (copyTestsResource == null) { // final String keyAndName = universalName + "-copyTests"; -// +// // LookupUtil.getResourceManager().createResource(subject, createResourceForTest(keyAndName), Resource.ROOT_ID); // // //ok, now the new resource should contain the alert definition defined by the template @@ -1031,45 +1035,45 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // crit.addFilterResourceKey(keyAndName); // crit.fetchExplicitGroups(true); //so that cleanup works // crit.fetchAlertDefinitions(true); //so that cleanup works -// +// // List<Resource> foundResources = LookupUtil.getResourceManager().findResourcesByCriteria(subject, crit); -// +// // assertEquals("A new resource should have been created", 1, foundResources.size()); -// +// // Resource res = foundResources.get(0); // resources.add(res); -// +// // copyTestsResource = res; // } -// +// // return copyTestsResource; // } -// +// // public void testNotificationsCopiedOnAlertTemplateApplication() throws Exception { // TestAlertSender.setExpectedSubject(null); // TestAlertSender.resetValidateMethodCallCount(); -// +// // Resource res = getCopyTestsResource(); -// -// //apply the template manually - this is done in server-agent back-and-forth that we +// +// //apply the template manually - this is done in server-agent back-and-forth that we // //don't test here and which is complex to mock out. // //this method has to be called using the overlord subject // LookupUtil.getAlertTemplateManager().updateAlertDefinitionsForResource(LookupUtil.getSubjectManager().getOverlord(), res.getId()); -// +// // assertEquals("No validation should occur on the copied notifications", 0, TestAlertSender.getValidateMethodCallCount()); // // AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager(); // AlertDefinitionCriteria adCrit = new AlertDefinitionCriteria(); // adCrit.addFilterResourceIds(res.getId()); // adCrit.fetchAlertNotifications(true); -// +// // List<AlertDefinition> foundAlertDefs = adm.findAlertDefinitionsByCriteria(subject, adCrit); -// junk.addAll(foundAlertDefs); -// +// junk.addAll(foundAlertDefs); +// // assertEquals("The new resource should have an alert definition obtained from the template.", 1, foundAlertDefs.size()); -// +// // AlertDefinition defWithNotifications = foundAlertDefs.get(0); -// +// // testSingleDependentAlertDefinition(defWithNotifications, ParentType.TEMPLATE, defWithNotifications.getParentId()); // } // @@ -1077,24 +1081,24 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // public void testNotificationsCopiedOnGroupMemberAddition() throws Exception { // TestAlertSender.setExpectedSubject(null); // TestAlertSender.resetValidateMethodCallCount(); -// +// // Resource res = getCopyTestsResource(); -// +// // LookupUtil.getResourceGroupManager().addResourcesToGroup(subject, resourceGroup.getId(), new int[] { res.getId() }); -// +// // assertEquals("No validation should occur on the copied notifications", 0, TestAlertSender.getValidateMethodCallCount()); // // AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager(); // AlertDefinitionCriteria adCrit = new AlertDefinitionCriteria(); // adCrit.addFilterResourceIds(res.getId()); // adCrit.fetchAlertNotifications(true); -// +// // List<AlertDefinition> foundAlertDefs = adm.findAlertDefinitionsByCriteria(subject, adCrit); -// junk.addAll(foundAlertDefs); -// +// junk.addAll(foundAlertDefs); +// // //1 from the group, 1 from the template // assertEquals("The new resource should have an alert definition obtained from the group.", 2, foundAlertDefs.size()); -// +// // AlertDefinition groupOriginatingDef = null; // for(AlertDefinition d : foundAlertDefs) { // if ((universalName + " group").equals(d.getName())) { @@ -1102,9 +1106,9 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // break; // } // } -// +// // assertNotNull("The alert definition originating from the group not present on the resource.", groupOriginatingDef); -// +// // testSingleDependentAlertDefinition(groupOriginatingDef, ParentType.GROUP, groupOriginatingDef.getGroupAlertDefinition().getId()); // } // @@ -1120,9 +1124,9 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // // int id = adm.createAlertDefinition(subject, def, res.getId(), true); // def.setId(id); -// +// // resourceLevelAlertDefinitionId = id; -// +// // junk.add(def); // // testMainAlertDefinition(id); @@ -1139,11 +1143,11 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // // int id = gadm.createGroupAlertDefinitions(subject, def, resourceGroup.getId()); // def.setId(id); -// +// // groupLevelAlertDefinitionId = id; -// +// // junk.add(def); -// +// // testMainAlertDefinition(id); // List<AlertDefinition> deps = testDependentAlertDefinitions(id, ParentType.GROUP); // @@ -1163,7 +1167,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // def.setId(id); // // templateLevelAlertDefinitionId = id; -// +// // junk.add(def); // // testMainAlertDefinition(id); @@ -1176,105 +1180,105 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // public void testNoValidationWhenNoNotificationUpdateOnResourceLevel() throws Exception { // TestAlertSender.setExpectedSubject(subject); // TestAlertSender.resetValidateMethodCallCount(); -// +// // AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager(); -// +// // AlertDefinitionCriteria crit = new AlertDefinitionCriteria(); // crit.addFilterId(resourceLevelAlertDefinitionId); // crit.fetchAlertNotifications(true); // crit.fetchConditions(true); -// +// // List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit); -// +// // assertEquals("Failed to find the previously created resource level alert definition.", 1, foundDefs.size()); -// +// // AlertDefinition foundDef = foundDefs.get(0); -// +// // foundDef.setEnabled(true); -// +// // adm.updateAlertDefinition(subject, resourceLevelAlertDefinitionId, foundDef, false); -// +// // assertEquals("The notification validation method shouldn't have been called", 0, TestAlertSender.getValidateMethodCallCount()); // } -// +// // @Test(dependsOnMethods = "testCorrectSubjectPassedOnGroupLevelAlertDefinitionCreation") // public void testNoValidationWhenNoNotificationUpdateOnGroupLevel() throws Exception { // TestAlertSender.setExpectedSubject(subject); // TestAlertSender.resetValidateMethodCallCount(); -// +// // AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager(); -// +// // AlertDefinitionCriteria crit = new AlertDefinitionCriteria(); // crit.addFilterId(groupLevelAlertDefinitionId); // crit.fetchAlertNotifications(true); // crit.fetchConditions(true); -// +// // List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit); -// +// // assertEquals("Failed to find the previously created group level alert definition.", 1, foundDefs.size()); -// +// // AlertDefinition foundDef = foundDefs.get(0); -// +// // foundDef.setEnabled(true); -// +// // GroupAlertDefinitionManagerLocal gadm = LookupUtil.getGroupAlertDefinitionManager(); // gadm.updateGroupAlertDefinitions(subject, foundDef, true); -// +// // assertEquals("The notification validation method shouldn't have been called", 0, TestAlertSender.getValidateMethodCallCount()); // } -// +// // @Test(dependsOnMethods = "testCorrectSubjectPassedOnTemplateLevelAlertDefinitionCreation") // public void testNoValidationWhenNoNotificationUpdateOnTemplateLevel() throws Exception { // TestAlertSender.setExpectedSubject(subject); // TestAlertSender.resetValidateMethodCallCount(); -// +// // AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager(); -// +// // AlertDefinitionCriteria crit = new AlertDefinitionCriteria(); // crit.addFilterId(templateLevelAlertDefinitionId); // crit.fetchAlertNotifications(true); // crit.fetchConditions(true); -// +// // List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit); -// +// // assertEquals("Failed to find the previously created resource level alert definition.", 1, foundDefs.size()); -// +// // AlertDefinition foundDef = foundDefs.get(0); -// +// // foundDef.setEnabled(true); -// +// // AlertTemplateManagerLocal atm = LookupUtil.getAlertTemplateManager(); -// +// // atm.updateAlertTemplate(subject, foundDef, true); -// +// // assertEquals("The notification validation method shouldn't have been called", 0, TestAlertSender.getValidateMethodCallCount()); // } -// +// // @Test(dependsOnMethods = "testNoValidationWhenNoNotificationUpdateOnResourceLevel") // public void testCorrectSubjectPassedOnResourceLevelAlertDefinitionUpdate() throws Exception { // TestAlertSender.setExpectedSubject(subject); // TestAlertSender.resetValidateMethodCallCount(); -// +// // AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager(); -// +// // AlertDefinitionCriteria crit = new AlertDefinitionCriteria(); // crit.addFilterId(resourceLevelAlertDefinitionId); // crit.fetchAlertNotifications(true); // crit.fetchConditions(true); -// +// // List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit); -// +// // assertEquals("Failed to find the previously created resource level alert definition.", 1, foundDefs.size()); -// +// // AlertDefinition foundDef = foundDefs.get(0); // // AlertNotification newNotif = createAlertNotificationForTest(foundDef, false); // //just add some dummy config property so that the 2 notifs are distinguishable from each other // //and are saved separately // newNotif.getConfiguration().put(new PropertySimple("foo-resource", "bar")); -// +// // adm.updateAlertDefinition(subject, resourceLevelAlertDefinitionId, foundDef, false); -// +// // assertEquals("Validation should have been called for a new notification during alert def update", 1, TestAlertSender.getValidateMethodCallCount()); // } // @@ -1282,28 +1286,28 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // public void testCorrectSubjectPassedOnGroupLevelAlertDefinitionUpdate() throws Exception { // TestAlertSender.setExpectedSubject(subject); // TestAlertSender.resetValidateMethodCallCount(); -// +// // AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager(); -// +// // AlertDefinitionCriteria crit = new AlertDefinitionCriteria(); // crit.addFilterId(groupLevelAlertDefinitionId); // crit.fetchAlertNotifications(true); // crit.fetchConditions(true); -// +// // List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit); -// +// // assertEquals("Failed to find the previously created group level alert definition.", 1, foundDefs.size()); -// +// // AlertDefinition foundDef = foundDefs.get(0); // // AlertNotification newNotif = createAlertNotificationForTest(foundDef, false); // //just add some dummy config property so that the 2 notifs are distinguishable from each other // //and are saved separately // newNotif.getConfiguration().put(new PropertySimple("foo-group", "bar")); -// +// // GroupAlertDefinitionManagerLocal gadm = LookupUtil.getGroupAlertDefinitionManager(); // gadm.updateGroupAlertDefinitions(subject, foundDef, true); -// +// // //notice that the validation should be called just once, even though in effect we're creating 11 notifs // //1 for group and 10 for its members. // assertEquals("Validation should have been called for a new notification during alert def update", 1, TestAlertSender.getValidateMethodCallCount()); @@ -1313,28 +1317,28 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // public void testCorrectSubjectPassedOnTemplateLevelAlertDefinitionUpdate() throws Exception { // TestAlertSender.setExpectedSubject(subject); // TestAlertSender.resetValidateMethodCallCount(); -// +// // AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager(); -// +// // AlertDefinitionCriteria crit = new AlertDefinitionCriteria(); // crit.addFilterId(templateLevelAlertDefinitionId); // crit.fetchAlertNotifications(true); // crit.fetchConditions(true); -// +// // List<AlertDefinition> foundDefs = adm.findAlertDefinitionsByCriteria(subject, crit); -// +// // assertEquals("Failed to find the previously created template level alert definition.", 1, foundDefs.size()); -// +// // AlertDefinition foundDef = foundDefs.get(0); // // AlertNotification newNotif = createAlertNotificationForTest(foundDef, false); // //just add some dummy config property so that the 2 notifs are distinguishable from each other // //and are saved separately // newNotif.getConfiguration().put(new PropertySimple("foo-template", "bar")); -// +// // AlertTemplateManagerLocal atm = LookupUtil.getAlertTemplateManager(); // atm.updateAlertTemplate(subject, foundDef, true); -// +// // //notice that the validation should be called just once, even though in effect we're creating 11 notifs // //1 for template and 10 for its members. // assertEquals("Validation should have been called for a new notification during alert def update", 1, TestAlertSender.getValidateMethodCallCount()); @@ -1379,34 +1383,34 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // // private AlertNotification createAlertNotificationForTest(AlertDefinition alertDefinition, boolean precanned) { // AlertNotification notif = new AlertNotification("Test Alert Sender"); -// +// // Configuration alertConfig = new Configuration(); -// +// // if (precanned) { // alertConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE)); // } else { // alertConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, "persistent")); // alertConfig.put(new PropertySimple(TestAlertSender.EPHEMERAL_PROPERTY_NAME, "ephemeral")); // } -// +// // Configuration extraConfig = new Configuration(); -// +// // if (precanned) { // extraConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE)); // } else { // extraConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, "persistent")); // extraConfig.put(new PropertySimple(TestAlertSender.EPHEMERAL_PROPERTY_NAME, "ephemeral")); // } -// +// // notif.setConfiguration(alertConfig); // notif.setExtraConfiguration(extraConfig); -// +// // alertDefinition.addAlertNotification(notif); // notif.setAlertDefinition(alertDefinition); -// +// // return notif; // } -// +// // private void testMainAlertDefinition(int id) { // AlertDefinitionCriteria crit = new AlertDefinitionCriteria(); // crit.addFilterId(id); @@ -1443,9 +1447,9 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // } else if (parentType == ParentType.GROUP) { // crit.addFilterGroupAlertDefinitionId(expectedParentId); // } -// +// // crit.fetchAlertNotifications(true); -// +// // List<AlertDefinition> checkList = // LookupUtil.getAlertDefinitionManager().findAlertDefinitionsByCriteria(subject, crit); // @@ -1458,7 +1462,7 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // // return checkList; // } -// +// // private void testSingleDependentAlertDefinition(AlertDefinition alertDef, ParentType parentType, int expectedParentId) { // assertEquals("There should be exactly 1 notification on the definition " + alertDef, 1, alertDef // .getAlertNotifications().size()); @@ -1476,13 +1480,13 @@ public class AlertDefinitionWithComplexNotificationsTest extends AbstractEJB3Tes // assertEquals("The parent id has unexpected value", Integer.valueOf(expectedParentId), alertDef.getParentId()); // } // } -// +// // private Resource createResourceForTest(String resourceKey) { // Resource res = new ResourceBuilder().createPlatform().withRandomUuid().withResourceKey(resourceKey) // .withResourceType(resourceType).withName(resourceKey) // .withInventoryStatus(InventoryStatus.COMMITTED).build(); -// res.setAgent(agent); -// +// res.setAgent(agent); +// // return res; // } //}
rhq-commits@lists.fedorahosted.org