Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorddunne2011-07-08 12:06:12 -0400
committerRyan D. Brooks2011-07-08 12:06:12 -0400
commit822f3c44c61509726a0c5ae71de6d2034e4f47b5 (patch)
treefd278b0aea517cddf6e9c5f470d1e2299a91ed89 /plugins/org.eclipse.osee.ats.core.test
parentdb56dcce4b8c7a8177a94481b8c0617ae3ca8af6 (diff)
downloadorg.eclipse.osee-822f3c44c61509726a0c5ae71de6d2034e4f47b5.tar.gz
org.eclipse.osee-822f3c44c61509726a0c5ae71de6d2034e4f47b5.tar.xz
org.eclipse.osee-822f3c44c61509726a0c5ae71de6d2034e4f47b5.zip
feature: Improve ATS Notifications and added Test Suite
Diffstat (limited to 'plugins/org.eclipse.osee.ats.core.test')
-rw-r--r--plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsCore_PT_Suite.java2
-rw-r--r--plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java107
-rw-r--r--plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtilTest.java55
-rw-r--r--plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsCore_Notify_PT_Suite.java37
-rw-r--r--plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsNotificationManagerTest.java543
-rw-r--r--plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsNotifyUsersTest.java190
-rw-r--r--plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/TestNotificationManager.java45
7 files changed, 967 insertions, 12 deletions
diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsCore_PT_Suite.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsCore_PT_Suite.java
index ec6ef7b92d..98717a0f95 100644
--- a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsCore_PT_Suite.java
+++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsCore_PT_Suite.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.ats.core;
+import org.eclipse.osee.ats.core.notify.AtsCore_Notify_PT_Suite;
import org.eclipse.osee.ats.core.review.AtsCore_Review_PT_Suite;
import org.eclipse.osee.ats.core.task.AtsCore_Task_PT_Suite;
import org.eclipse.osee.ats.core.workflow.transition.AtsCore_Transition_PT_Suite;
@@ -22,6 +23,7 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
AtsTestUtilTest.class,
+ AtsCore_Notify_PT_Suite.class,
AtsCore_Task_PT_Suite.class,
AtsCore_Review_PT_Suite.class,
AtsCore_Transition_PT_Suite.class})
diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java
index 43b0de167f..0a2544feed 100644
--- a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java
+++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtil.java
@@ -16,12 +16,16 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import org.eclipse.osee.ats.core.action.ActionArtifact;
+import org.eclipse.osee.ats.core.action.ActionManager;
import org.eclipse.osee.ats.core.config.ActionableItemArtifact;
import org.eclipse.osee.ats.core.config.TeamDefinitionArtifact;
import org.eclipse.osee.ats.core.review.AbstractReviewArtifact;
import org.eclipse.osee.ats.core.review.DecisionReviewArtifact;
import org.eclipse.osee.ats.core.review.DecisionReviewManager;
import org.eclipse.osee.ats.core.review.DecisionReviewState;
+import org.eclipse.osee.ats.core.review.PeerToPeerReviewArtifact;
+import org.eclipse.osee.ats.core.review.PeerToPeerReviewManager;
import org.eclipse.osee.ats.core.review.ReviewManager;
import org.eclipse.osee.ats.core.task.TaskArtifact;
import org.eclipse.osee.ats.core.team.TeamWorkFlowArtifact;
@@ -36,13 +40,21 @@ import org.eclipse.osee.ats.core.workdef.StateDefinition;
import org.eclipse.osee.ats.core.workdef.WidgetDefinition;
import org.eclipse.osee.ats.core.workdef.WorkDefinition;
import org.eclipse.osee.ats.core.workdef.WorkDefinitionFactory;
-import org.eclipse.osee.ats.core.workflow.ActionArtifact;
+import org.eclipse.osee.ats.core.workflow.ChangeType;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionHelper;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionManager;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionOption;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionResults;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeStateException;
import org.eclipse.osee.framework.core.model.IBasicUser;
import org.eclipse.osee.framework.core.operation.Operations;
+import org.eclipse.osee.framework.core.util.IWorkPage;
+import org.eclipse.osee.framework.core.util.Result;
+import org.eclipse.osee.framework.core.util.WorkPageAdapter;
import org.eclipse.osee.framework.core.util.WorkPageType;
+import org.eclipse.osee.framework.skynet.core.User;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache;
@@ -62,6 +74,7 @@ public class AtsTestUtil {
private static TeamDefinitionArtifact teamDef = null;
private static VersionArtifact verArt1 = null, verArt2 = null;
private static DecisionReviewArtifact decRevArt = null;
+ private static PeerToPeerReviewArtifact peerRevArt = null;
private static TaskArtifact taskArt = null;
private static ActionableItemArtifact testAi = null;
private static ActionArtifact actionArt = null;
@@ -219,6 +232,7 @@ public class AtsTestUtil {
teamDef.setSoleAttributeValue(AtsAttributeTypes.WorkflowDefinition, WORK_DEF_NAME);
teamDef.setSoleAttributeValue(CoreAttributeTypes.Active, true);
teamDef.setSoleAttributeValue(AtsAttributeTypes.TeamUsesVersions, true);
+ teamDef.addRelation(AtsRelationTypes.TeamLead_Lead, UserManager.getUser());
testAi.addRelation(AtsRelationTypes.TeamActionableItem_Team, teamDef);
@@ -232,18 +246,11 @@ public class AtsTestUtil {
getTitle("ver 2.0", postFixName));
verArt2.addRelation(AtsRelationTypes.TeamDefinitionToVersion_TeamDefinition, teamDef);
- teamArt =
- (TeamWorkFlowArtifact) ArtifactTypeManager.addArtifact(AtsArtifactTypes.TeamWorkflow,
- AtsUtilCore.getAtsBranchToken(), getTitle("Team WF", postFixName));
- teamArt.setTeamDefinition(teamDef);
- teamArt.getActionableItemsDam().addActionableItem(testAi);
- teamArt.initializeNewStateMachine(getAnalyzeStateDef(), Arrays.asList((IBasicUser) UserManager.getUser()),
- new Date(), UserManager.getUser());
-
actionArt =
- (ActionArtifact) ArtifactTypeManager.addArtifact(AtsArtifactTypes.Action, AtsUtilCore.getAtsBranchToken(),
- "Test Action");
- actionArt.addRelation(AtsRelationTypes.ActionToWorkflow_WorkFlow, teamArt);
+ ActionManager.createAction(null, getTitle("Team WF", postFixName), "description", ChangeType.Improvement, "1",
+ false, null, Arrays.asList(testAi), new Date(), UserManager.getUser(), null, transaction);
+
+ teamArt = actionArt.getFirstTeam();
testAi.persist(transaction);
teamDef.persist(transaction);
@@ -313,6 +320,9 @@ public class AtsTestUtil {
public static void cleanup() throws OseeCoreException {
SkynetTransaction transaction =
new SkynetTransaction(AtsUtilCore.getAtsBranch(), AtsTestUtil.class.getSimpleName() + " - cleanup");
+ if (peerRevArt != null) {
+ peerRevArt.deleteAndPersist(transaction);
+ }
if (decRevArt != null) {
decRevArt.deleteAndPersist(transaction);
}
@@ -381,4 +391,77 @@ public class AtsTestUtil {
TestUtil.sleep(4000);
}
+ public static Result transitionTo(AtsTestUtilState atsTestUtilState, User user, SkynetTransaction transaction, TransitionOption... transitionOptions) {
+ if (atsTestUtilState == AtsTestUtilState.Analyze && teamArt.isInState(AtsTestUtilState.Analyze)) {
+ return Result.TrueResult;
+ }
+
+ if (atsTestUtilState == AtsTestUtilState.Cancelled) {
+ Result result = transitionToState(teamArt, AtsTestUtilState.Cancelled, user, transaction, transitionOptions);
+ if (result.isFalse()) {
+ return result;
+ }
+ return Result.TrueResult;
+ }
+
+ Result result = transitionToState(teamArt, AtsTestUtilState.Implement, user, transaction, transitionOptions);
+ if (result.isFalse()) {
+ return result;
+ }
+
+ if (atsTestUtilState == AtsTestUtilState.Implement) {
+ return Result.TrueResult;
+ }
+
+ if (atsTestUtilState == AtsTestUtilState.Completed) {
+ result = transitionToState(teamArt, AtsTestUtilState.Completed, user, transaction, transitionOptions);
+ if (result.isFalse()) {
+ return result;
+ }
+
+ }
+ return Result.TrueResult;
+
+ }
+
+ private static Result transitionToState(TeamWorkFlowArtifact teamArt, IWorkPage toState, User user, SkynetTransaction transaction, TransitionOption... transitionOptions) {
+ TransitionHelper helper =
+ new TransitionHelper("Transition to " + toState.getPageName(), Arrays.asList(teamArt), toState.getPageName(),
+ Arrays.asList(user), null, transitionOptions);
+ TransitionManager transitionMgr = new TransitionManager(helper, transaction);
+ TransitionResults results = transitionMgr.handleAll();
+ if (results.isEmpty()) {
+ return Result.TrueResult;
+ }
+ return new Result("Transition Error %s", results.toString());
+ }
+
+ public static class AtsTestUtilState extends WorkPageAdapter {
+ public static AtsTestUtilState Analyze = new AtsTestUtilState("Analyze", WorkPageType.Working);
+ public static AtsTestUtilState Implement = new AtsTestUtilState("Implement", WorkPageType.Working);
+ public static AtsTestUtilState Completed = new AtsTestUtilState("Completed", WorkPageType.Completed);
+ public static AtsTestUtilState Cancelled = new AtsTestUtilState("Cancelled", WorkPageType.Cancelled);
+
+ private AtsTestUtilState(String pageName, WorkPageType workPageType) {
+ super(AtsTestUtilState.class, pageName, workPageType);
+ }
+
+ public static AtsTestUtilState valueOf(String pageName) {
+ return WorkPageAdapter.valueOfPage(AtsTestUtilState.class, pageName);
+ }
+
+ public static List<AtsTestUtilState> values() {
+ return WorkPageAdapter.pages(AtsTestUtilState.class);
+ }
+ }
+
+ public static PeerToPeerReviewArtifact getOrCreatePeerReview(ReviewBlockType none, AtsTestUtilState relatedToState, SkynetTransaction transaction) throws OseeCoreException {
+ ensureLoaded();
+ if (peerRevArt == null) {
+ peerRevArt =
+ PeerToPeerReviewManager.createNewPeerToPeerReview(teamArt,
+ AtsTestUtil.class.getSimpleName() + " Test Decision Review", relatedToState.getPageName(), transaction);
+ }
+ return peerRevArt;
+ }
}
diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtilTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtilTest.java
index 52a922385e..294d797ec8 100644
--- a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtilTest.java
+++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/AtsTestUtilTest.java
@@ -11,8 +11,15 @@
package org.eclipse.osee.ats.core;
import junit.framework.Assert;
+import org.eclipse.osee.ats.core.team.TeamState;
+import org.eclipse.osee.ats.core.team.TeamWorkFlowArtifact;
+import org.eclipse.osee.ats.core.util.AtsUtilCore;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionOption;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeStateException;
+import org.eclipse.osee.framework.core.util.Result;
+import org.eclipse.osee.framework.skynet.core.UserManager;
+import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
/**
* Test unit for {@link AtsTestUtil}
@@ -36,9 +43,57 @@ public class AtsTestUtilTest extends AtsTestUtil {
AtsTestUtil.validateArtifactCache();
+ Assert.assertNotNull(AtsTestUtil.getTeamWf());
+ Assert.assertNotNull(AtsTestUtil.getTeamWf().getStateDefinition());
+
AtsTestUtil.cleanup();
AtsTestUtil.validateArtifactCache();
}
+ @org.junit.Test
+ public void testTransitionTo() throws OseeCoreException {
+
+ AtsTestUtil.cleanupAndReset("AtsTestUtilTest");
+
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+ Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Analyze.getPageName());
+
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), "test");
+
+ Result result =
+ AtsTestUtil.transitionTo(AtsTestUtilState.Implement, UserManager.getUser(), transaction,
+ TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
+ Assert.assertEquals(Result.TrueResult, result);
+ Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Implement.getPageName());
+
+ result =
+ AtsTestUtil.transitionTo(AtsTestUtilState.Completed, UserManager.getUser(), transaction,
+ TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
+ Assert.assertEquals(Result.TrueResult, result);
+ Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Completed.getPageName());
+
+ teamArt.reloadAttributesAndRelations();
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testTransitionToCancelled() throws OseeCoreException {
+
+ AtsTestUtil.cleanupAndReset("AtsTestUtilTest");
+
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+ Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Analyze.getPageName());
+
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), "test");
+
+ Result result =
+ AtsTestUtil.transitionTo(AtsTestUtilState.Cancelled, UserManager.getUser(), transaction,
+ TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
+ Assert.assertEquals(Result.TrueResult, result);
+ Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Cancelled.getPageName());
+
+ teamArt.reloadAttributesAndRelations();
+ AtsTestUtil.cleanup();
+ }
}
diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsCore_Notify_PT_Suite.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsCore_Notify_PT_Suite.java
new file mode 100644
index 0000000000..10b8f97246
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsCore_Notify_PT_Suite.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.core.notify;
+
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({AtsNotifyUsersTest.class, AtsNotificationManagerTest.class})
+/**
+ * This test suite contains tests that must be run against demo database as Plugin JUnit (PT)
+ *
+ * @author Donald G. Dunne
+ */
+public class AtsCore_Notify_PT_Suite {
+ @BeforeClass
+ public static void setUp() throws Exception {
+ OseeProperties.setIsInTest(true);
+ System.out.println("\n\nBegin " + AtsCore_Notify_PT_Suite.class.getSimpleName());
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ System.out.println("End " + AtsCore_Notify_PT_Suite.class.getSimpleName());
+ }
+}
diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsNotificationManagerTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsNotificationManagerTest.java
new file mode 100644
index 0000000000..5b27c9ce39
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsNotificationManagerTest.java
@@ -0,0 +1,543 @@
+/*
+ * Created on Jul 5, 2011
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.ats.core.notify;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.ats.core.AtsTestUtil;
+import org.eclipse.osee.ats.core.AtsTestUtil.AtsTestUtilState;
+import org.eclipse.osee.ats.core.action.ActionArtifact;
+import org.eclipse.osee.ats.core.action.ActionManager;
+import org.eclipse.osee.ats.core.review.PeerToPeerReviewArtifact;
+import org.eclipse.osee.ats.core.review.PeerToPeerReviewManager;
+import org.eclipse.osee.ats.core.review.PeerToPeerReviewState;
+import org.eclipse.osee.ats.core.review.role.Role;
+import org.eclipse.osee.ats.core.review.role.UserRole;
+import org.eclipse.osee.ats.core.review.role.UserRoleManager;
+import org.eclipse.osee.ats.core.team.TeamState;
+import org.eclipse.osee.ats.core.team.TeamWorkFlowArtifact;
+import org.eclipse.osee.ats.core.type.AtsRelationTypes;
+import org.eclipse.osee.ats.core.util.AtsUtilCore;
+import org.eclipse.osee.ats.core.workdef.ReviewBlockType;
+import org.eclipse.osee.ats.core.workflow.ChangeType;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionOption;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.IBasicUser;
+import org.eclipse.osee.framework.core.util.Result;
+import org.eclipse.osee.framework.skynet.core.User;
+import org.eclipse.osee.framework.skynet.core.UserManager;
+import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
+import org.eclipse.osee.support.test.util.DemoUsers;
+import org.junit.AfterClass;
+
+/**
+ * Test unit for (@link AtsNotificationManager}
+ *
+ * @author Donald G. Dunne
+ */
+public class AtsNotificationManagerTest {
+
+ @AfterClass
+ public static void cleanup() throws OseeCoreException {
+ User user = UserManager.getUser(DemoUsers.Alex_Kay);
+ user.setSoleAttributeValue(CoreAttributeTypes.Email, "");
+ user.deleteRelations(AtsRelationTypes.SubscribedUser_Artifact);
+ user.persist(AtsNotificationManagerTest.class.getSimpleName());
+
+ AtsNotificationManager.setInTest(true);
+ AtsNotificationManager.setIsProduction(false);
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testOriginatorNotification() throws OseeCoreException {
+
+ //---------------------------------------------------
+ // Test that notifications sent if originator changes
+ //---------------------------------------------------
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.start(mgr, true);
+ AtsNotificationManager.setInTest(false);
+ // create new action which should reset originator cache in notification manager
+ AtsTestUtil.cleanupAndReset(AtsNotificationManagerTest.class.getSimpleName());
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+
+ // verify no notification events yet
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+
+ // set valid email for Alex_Kay
+ UserManager.getUser(DemoUsers.Alex_Kay).setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ UserManager.getUser(DemoUsers.Alex_Kay).persist(getClass().getSimpleName());
+
+ // reset the originator
+ teamArt.setCreatedBy(UserManager.getUser(DemoUsers.Alex_Kay), false, new Date());
+ // persist will kick event which will log the notification event and send
+ teamArt.persist("Change originator");
+
+ // verify notification exists now
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertTrue(mgr.getNotificationEvents().iterator().next().getDescription().startsWith(
+ "You have been set as the originator"));
+
+ //---------------------------------------------------
+ // Test that NO notifications sent if in test mode
+ //---------------------------------------------------
+
+ // reset the originator back to joe smith
+ teamArt.setCreatedBy(UserManager.getUser(DemoUsers.Joe_Smith), false, new Date());
+ // persist will kick event which will log the notification event and send
+ teamArt.persist("Change originator");
+ AtsNotificationManager.setInTest(true);
+ mgr.clear();
+
+ // verify no notification events yet
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+
+ // set valid email for Alex_Kay
+ UserManager.getUser(DemoUsers.Alex_Kay).setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ UserManager.getUser(DemoUsers.Alex_Kay).persist(getClass().getSimpleName());
+
+ // reset the originator
+ teamArt.setCreatedBy(UserManager.getUser(DemoUsers.Alex_Kay), false, new Date());
+ // persist will kick event which will log the notification event and send
+ teamArt.persist("Change originator");
+
+ // verify NO notification exists now
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+
+ //---------------------------------------------------
+ // Test that NO notifications sent if user email is invalid
+ //---------------------------------------------------
+
+ // reset the originator back to joe smith
+ teamArt.setCreatedBy(UserManager.getUser(DemoUsers.Joe_Smith), false, new Date());
+ // persist will kick event which will log the notification event and send
+ teamArt.persist("Change originator");
+ AtsNotificationManager.setInTest(true);
+ mgr.clear();
+
+ // verify no notification events yet
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+
+ // set invalid email for Alex_Kay
+ UserManager.getUser(DemoUsers.Alex_Kay).deleteAttributes(CoreAttributeTypes.Email);
+ UserManager.getUser(DemoUsers.Alex_Kay).persist(getClass().getSimpleName());
+
+ // reset the originator
+ teamArt.setCreatedBy(UserManager.getUser(DemoUsers.Alex_Kay), false, new Date());
+ // persist will kick event which will log the notification event and send
+ teamArt.persist("Change originator");
+
+ // verify NO notification exists now
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testAddAssigneeNotification() throws OseeCoreException {
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.setNotificationManager(mgr);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ // create new action
+ AtsTestUtil.cleanupAndReset(AtsNotificationManagerTest.class.getSimpleName());
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+
+ // verify no notification events yet
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+
+ // set valid email for Alex_Kay
+ List<IBasicUser> users = new ArrayList<IBasicUser>();
+ User Alex_Kay = UserManager.getUser(DemoUsers.Alex_Kay);
+ Alex_Kay.setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ users.add(Alex_Kay);
+
+ User Jason_Michael = UserManager.getUser(DemoUsers.Jason_Michael);
+ users.add(Jason_Michael);
+
+ User Inactive_Steve = UserManager.getUser(DemoUsers.Inactive_Steve);
+ Inactive_Steve.setSoleAttributeValue(CoreAttributeTypes.Email, "inactive.steve@boeing.com");
+ users.add(Inactive_Steve);
+
+ // current assignee shouldn't be emailed
+ UserManager.getUser().setEmail("joe.smith@boeing.com");
+ users.add(UserManager.getUser());
+
+ teamArt.getStateMgr().addAssignees(users);
+
+ // verify notification exists now only for active, valid email Alex, not for others
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertTrue(mgr.getNotificationEvents().iterator().next().getDescription().startsWith(
+ "You have been set as the assignee"));
+ // but all 4 are now assigned
+ Assert.assertEquals(4, teamArt.getStateMgr().getAssignees().size());
+
+ for (IBasicUser user : users) {
+ UserManager.getUser(user).reloadAttributesAndRelations();
+ }
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testSetAssigneeNotification() throws OseeCoreException {
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.setNotificationManager(mgr);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ // create new action
+ AtsTestUtil.cleanupAndReset(AtsNotificationManagerTest.class.getSimpleName());
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+ Assert.assertEquals("Joe should be assigned; currently = " + teamArt.getStateMgr().getAssigneesStr(), 1,
+ teamArt.getStateMgr().getAssignees().size());
+
+ // set valid email for Alex_Kay and add as assignee
+ User Alex_Kay = UserManager.getUser(DemoUsers.Alex_Kay);
+ Alex_Kay.setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ Alex_Kay.persist(getClass().getSimpleName());
+ teamArt.getStateMgr().addAssignee(Alex_Kay);
+ teamArt.persist(getClass().getSimpleName());
+ Assert.assertEquals("Alex and Joe should be assigned; currently = " + teamArt.getStateMgr().getAssigneesStr(), 2,
+ teamArt.getStateMgr().getAssignees().size());
+ mgr.clear();
+
+ // verify no notification events yet
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+
+ List<IBasicUser> usersToSet = new ArrayList<IBasicUser>();
+ User Jason_Michael = UserManager.getUser(DemoUsers.Jason_Michael);
+ Jason_Michael.setEmail("jason.michael@boeing.com");
+ usersToSet.add(Jason_Michael);
+
+ User Inactive_Steve = UserManager.getUser(DemoUsers.Inactive_Steve);
+ Inactive_Steve.setSoleAttributeValue(CoreAttributeTypes.Email, "inactive.steve@boeing.com");
+ usersToSet.add(Inactive_Steve);
+
+ // current assignee and Alex_Kay shouldn't be emailed cause they were already assigned
+ UserManager.getUser().setEmail("joe.smith@boeing.com");
+ usersToSet.add(UserManager.getUser());
+ usersToSet.add(Alex_Kay);
+
+ teamArt.getStateMgr().setAssignees(usersToSet);
+
+ // verify notification exists now only for Jason_Michael, not for others
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertTrue(mgr.getNotificationEvents().iterator().next().getDescription().startsWith(
+ "You have been set as the assignee"));
+ // but all 4 are now assigned
+ Assert.assertEquals(4, teamArt.getStateMgr().getAssignees().size());
+
+ for (IBasicUser user : usersToSet) {
+ UserManager.getUser(user).reloadAttributesAndRelations();
+ }
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testCompletedNotification() throws OseeCoreException {
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.setNotificationManager(mgr);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ // create new action
+ AtsTestUtil.cleanupAndReset(getClass().getSimpleName());
+
+ // set originator as Alex Kay
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+ teamArt.setCreatedBy(UserManager.getUser(DemoUsers.Alex_Kay), false, new Date());
+ teamArt.persist(getClass().getSimpleName() + " - set originator");
+
+ // set alex kay having valid email address
+ User user = UserManager.getUser(DemoUsers.Alex_Kay);
+ user.setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ user.persist(getClass().getSimpleName() + "- set alex email address");
+ mgr.clear();
+
+ // verify no notification events yet
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName());
+ Result result =
+ AtsTestUtil.transitionTo(AtsTestUtilState.Completed, UserManager.getUser(), transaction,
+ TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
+ Assert.assertEquals(Result.TrueResult, result);
+ Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Completed.getPageName());
+ transaction.execute();
+
+ // verify notification to originator
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertTrue(mgr.getNotificationEvents().iterator().next().getDescription().endsWith("is [Completed]"));
+
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testCancelledNotification() throws OseeCoreException {
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.setNotificationManager(mgr);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ // create new action
+ AtsTestUtil.cleanupAndReset(getClass().getSimpleName());
+
+ // set originator as Alex Kay
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+ teamArt.setCreatedBy(UserManager.getUser(DemoUsers.Alex_Kay), false, new Date());
+ teamArt.persist(getClass().getSimpleName() + " - set originator");
+
+ // set alex kay having valid email address
+ User user = UserManager.getUser(DemoUsers.Alex_Kay);
+ user.setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ user.persist(getClass().getSimpleName() + "-set key email address");
+ mgr.clear();
+
+ // verify no notification events yet
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName());
+ Result result =
+ AtsTestUtil.transitionTo(AtsTestUtilState.Cancelled, UserManager.getUser(), transaction,
+ TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
+ Assert.assertEquals(Result.TrueResult, result);
+ Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Cancelled.getPageName());
+ transaction.execute();
+
+ // verify notification to originator
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertTrue(mgr.getNotificationEvents().iterator().next().getDescription().startsWith(
+ "[Team Workflow] titled [AtsTestUtil - Team WF [AtsNotificationManagerTest]] was [Cancelled] from the [Analyze]"));
+
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testSubscribedTeam() throws OseeCoreException {
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.setNotificationManager(mgr);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ // create new action
+ AtsTestUtil.cleanupAndReset(getClass().getSimpleName());
+
+ // setup alex email and subscribe for team definition
+ User alex = UserManager.getUser(DemoUsers.Alex_Kay);
+ alex.setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ alex.persist(getClass().getSimpleName() + "- set alex email address");
+
+ AtsTestUtil.getTestTeamDef().setRelations(AtsRelationTypes.SubscribedUser_User, Arrays.asList(alex));
+ AtsTestUtil.getTestTeamDef().persist(getClass().getSimpleName() + " - add teamDef subscription");
+
+ mgr.clear();
+
+ // create another action
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName());
+ ActionArtifact actionArt =
+ ActionManager.createAction(null, getClass().getSimpleName() + " - testSubscribedTeam", "description",
+ ChangeType.Improvement, "1", false, null, Arrays.asList(AtsTestUtil.getTestAi()), new Date(),
+ UserManager.getUser(), null, transaction);
+
+ // verify notification to subscriber
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertTrue(mgr.getNotificationEvents().iterator().next().getDescription().startsWith(
+ "You have subscribed for email notification for Team "));
+
+ actionArt.getTeams().iterator().next().deleteAndPersist();
+ actionArt.deleteAndPersist();
+ User user = UserManager.getUser(DemoUsers.Alex_Kay);
+ user.setSoleAttributeValue(CoreAttributeTypes.Email, "");
+ user.deleteRelations(AtsRelationTypes.SubscribedUser_Artifact);
+ user.persist(AtsNotificationManagerTest.class.getSimpleName());
+
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testSubscribedActionableItem() throws OseeCoreException {
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.setNotificationManager(mgr);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ // create new action
+ AtsTestUtil.cleanupAndReset(getClass().getSimpleName());
+
+ // setup alex email and subscribe for AI
+ User alex = UserManager.getUser(DemoUsers.Alex_Kay);
+ alex.setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ alex.persist(getClass().getSimpleName() + "- set alex email address");
+
+ AtsTestUtil.getTestAi().setRelations(AtsRelationTypes.SubscribedUser_User, Arrays.asList(alex));
+ AtsTestUtil.getTestAi().persist(getClass().getSimpleName() + " - add AI subscription");
+
+ mgr.clear();
+
+ // create another action
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName());
+ ActionArtifact actionArt =
+ ActionManager.createAction(null, getClass().getSimpleName() + " - testSubscribedAI", "description",
+ ChangeType.Improvement, "1", false, null, Arrays.asList(AtsTestUtil.getTestAi()), new Date(),
+ UserManager.getUser(), null, transaction);
+
+ // verify notification to subscriber
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertTrue(mgr.getNotificationEvents().iterator().next().getDescription().startsWith(
+ "You have subscribed for email notification for Actionable Item "));
+
+ actionArt.getTeams().iterator().next().deleteAndPersist();
+ actionArt.deleteAndPersist();
+ User user = UserManager.getUser(DemoUsers.Alex_Kay);
+ user.setSoleAttributeValue(CoreAttributeTypes.Email, "");
+ user.deleteRelations(AtsRelationTypes.SubscribedUser_Artifact);
+ user.persist(AtsNotificationManagerTest.class.getSimpleName());
+
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testSubscribedWorkflow() throws OseeCoreException {
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.setNotificationManager(mgr);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ // create new action
+ AtsTestUtil.cleanupAndReset(getClass().getSimpleName());
+
+ // setup alex email and subscribe for AI
+ User alex = UserManager.getUser(DemoUsers.Alex_Kay);
+ alex.setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ alex.persist(getClass().getSimpleName() + "- set alex email address");
+
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+
+ teamArt.setRelations(AtsRelationTypes.SubscribedUser_User, Arrays.asList(alex));
+ teamArt.persist(getClass().getSimpleName() + " - add Workflow subscription");
+
+ mgr.clear();
+
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName());
+ Result result =
+ AtsTestUtil.transitionTo(AtsTestUtilState.Implement, UserManager.getUser(), transaction,
+ TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
+ Assert.assertEquals(Result.TrueResult, result);
+ transaction.execute();
+
+ // verify notification to workflow subscriber
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertEquals(
+ "[Team Workflow] titled [AtsTestUtil - Team WF [AtsNotificationManagerTest]] transitioned to [Implement] and you subscribed for notification.",
+ mgr.getNotificationEvents().iterator().next().getDescription());
+
+ AtsTestUtil.cleanup();
+ }
+
+ @org.junit.Test
+ public void testReviewersCompleted() throws OseeCoreException {
+
+ // create a test notification manager
+ TestNotificationManager mgr = new TestNotificationManager();
+ // restart notification manager with this one and set to NotInTest (cause normally, testing has notification system OFF)
+ AtsNotificationManager.setNotificationManager(mgr);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ // create new action
+ AtsTestUtil.cleanupAndReset(getClass().getSimpleName());
+
+ // setup alex email and subscribe for AI
+ User alex = UserManager.getUser(DemoUsers.Alex_Kay);
+ alex.setSoleAttributeValue(CoreAttributeTypes.Email, "alex.kay@boeing.com");
+ alex.persist(getClass().getSimpleName() + "- set alex email address");
+
+ User kay = UserManager.getUser(DemoUsers.Kay_Jones);
+ kay.setSoleAttributeValue(CoreAttributeTypes.Email, "kay.jones@boeing.com");
+ kay.persist(getClass().getSimpleName() + "- set kay email address");
+
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName());
+ PeerToPeerReviewArtifact peerArt =
+ AtsTestUtil.getOrCreatePeerReview(ReviewBlockType.None, AtsTestUtilState.Analyze, transaction);
+ List<UserRole> roles = new ArrayList<UserRole>();
+ UserRole author = new UserRole(Role.Author, alex);
+ roles.add(author);
+ UserRole moderator = new UserRole(Role.Moderator, kay);
+ roles.add(moderator);
+ UserRole reviewer1 = new UserRole(Role.Reviewer, UserManager.getUser());
+ roles.add(reviewer1);
+ UserRole reviewer2 = new UserRole(Role.Reviewer, UserManager.getUser(DemoUsers.Jason_Michael));
+ roles.add(reviewer2);
+
+ Result result =
+ PeerToPeerReviewManager.transitionTo(peerArt, PeerToPeerReviewState.Review, roles, null,
+ UserManager.getUser(), false, transaction);
+ Assert.assertEquals(Result.TrueResult, result);
+ peerArt.persist(transaction);
+ transaction.execute();
+ mgr.clear();
+
+ // complete reviewer1 role
+ transaction =
+ new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName() + " - update reviewer 1");
+ UserRoleManager roleMgr = new UserRoleManager(peerArt);
+ reviewer1.setHoursSpent(1.0);
+ reviewer1.setCompleted(true);
+ roleMgr.addOrUpdateUserRole(reviewer1);
+ roleMgr.saveToArtifact(transaction);
+ transaction.execute();
+
+ // no notifications sent
+ Assert.assertEquals(0, mgr.getNotificationEvents().size());
+
+ // complete reviewer2 role
+ transaction =
+ new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName() + " - update reviewer 2");
+ reviewer2.setHoursSpent(1.0);
+ reviewer2.setCompleted(true);
+ roleMgr.addOrUpdateUserRole(reviewer2);
+ roleMgr.saveToArtifact(transaction);
+ peerArt.persist(transaction);
+ transaction.execute();
+
+ // notification sent to author/moderator
+ Assert.assertEquals(1, mgr.getNotificationEvents().size());
+ Assert.assertTrue(mgr.getNotificationEvents().iterator().next().getDescription().equals(
+ "You are Author/Moderator of [PeerToPeer Review] titled [AtsTestUtil Test Decision Review] which has been reviewed by all reviewers"));
+ // email both moderator and author
+ Assert.assertEquals(2, mgr.getNotificationEvents().iterator().next().getUsers().size());
+ peerArt.deleteAndPersist();
+ AtsTestUtil.cleanup();
+ }
+}
diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsNotifyUsersTest.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsNotifyUsersTest.java
new file mode 100644
index 0000000000..be6573dcc2
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/AtsNotifyUsersTest.java
@@ -0,0 +1,190 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.core.notify;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.osee.ats.core.AtsTestUtil;
+import org.eclipse.osee.ats.core.team.TeamState;
+import org.eclipse.osee.ats.core.team.TeamWorkFlowArtifact;
+import org.eclipse.osee.ats.core.util.AtsUtilCore;
+import org.eclipse.osee.ats.core.util.SubscribeManager;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionHelper;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionManager;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionOption;
+import org.eclipse.osee.ats.core.workflow.transition.TransitionResults;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.IBasicUser;
+import org.eclipse.osee.framework.skynet.core.User;
+import org.eclipse.osee.framework.skynet.core.UserManager;
+import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
+import org.eclipse.osee.framework.skynet.core.utility.OseeNotificationEvent;
+import org.eclipse.osee.support.test.util.DemoUsers;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test unit for {@link AtsNotifyUsers}
+ *
+ * @author Donald G. Dunne
+ */
+public class AtsNotifyUsersTest {
+ @BeforeClass
+ public static void setup() throws OseeCoreException {
+ AtsTestUtil.cleanupAndReset(AtsNotificationManagerTest.class.getSimpleName());
+ }
+
+ @AfterClass
+ public static void cleanup() throws OseeCoreException {
+ UserManager.getUser(DemoUsers.Jason_Michael).reloadAttributesAndRelations();
+ UserManager.getUser(DemoUsers.Kay_Jones).reloadAttributesAndRelations();
+ UserManager.getUser(DemoUsers.Alex_Kay).reloadAttributesAndRelations();
+ UserManager.getUser(DemoUsers.Joe_Smith).reloadAttributesAndRelations();
+ UserManager.getUser(DemoUsers.Inactive_Steve).reloadAttributesAndRelations();
+ AtsTestUtil.cleanup();
+ }
+
+ @Test
+ public void testNotify() throws OseeCoreException {
+ User jason_ValidEmail = UserManager.getUser(DemoUsers.Jason_Michael);
+ jason_ValidEmail.setEmail("jason@boeing.com");
+ User alex_NoValidEmail = UserManager.getUser(DemoUsers.Alex_Kay);
+ alex_NoValidEmail.setEmail("");
+ User kay_ValidEmail = UserManager.getUser(DemoUsers.Kay_Jones);
+ kay_ValidEmail.setEmail("kay@boeing.com");
+ User joeSmith_CurrentUser = UserManager.getUser(DemoUsers.Joe_Smith);
+ joeSmith_CurrentUser.setEmail("joe@boeing.com");
+ User inactiveSteve = UserManager.getUser(DemoUsers.Inactive_Steve);
+ inactiveSteve.setEmail("inactiveSteves@boeing.com");
+
+ TestNotificationManager notifyManager = new TestNotificationManager();
+ AtsNotificationManager.setNotificationManager(notifyManager);
+ AtsNotificationManager.setInTest(false);
+ AtsNotificationManager.setIsProduction(true);
+
+ SkynetTransaction transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName());
+ TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
+ teamArt.setName(AtsNotifyUsersTest.class.getSimpleName());
+ teamArt.internalSetCreatedBy(kay_ValidEmail);
+ List<IBasicUser> assignees = new ArrayList<IBasicUser>();
+ assignees.addAll(Arrays.asList(inactiveSteve, alex_NoValidEmail, jason_ValidEmail, kay_ValidEmail,
+ joeSmith_CurrentUser));
+ teamArt.getStateMgr().setAssignees(assignees);
+ teamArt.persist(transaction);
+ transaction.execute();
+
+ notifyManager.clear();
+ AtsNotificationManager.notify(teamArt, AtsNotifyType.Originator);
+ Assert.assertEquals(1, notifyManager.getNotificationEvents().size());
+ OseeNotificationEvent event = notifyManager.getNotificationEvents().get(0);
+ Assert.assertEquals(AtsNotifyType.Originator.name(), event.getType());
+ Assert.assertEquals(kay_ValidEmail, event.getUsers().iterator().next());
+ Assert.assertEquals(
+ "You have been set as the originator of [Team Workflow] state [Analyze] titled [AtsNotifyUsersTest]",
+ event.getDescription());
+
+ notifyManager.clear();
+ teamArt.internalSetCreatedBy(inactiveSteve);
+ teamArt.persist(getClass().getSimpleName());
+ AtsNotificationManager.notify(teamArt, AtsNotifyType.Originator);
+ Assert.assertEquals(0, notifyManager.getNotificationEvents().size());
+ teamArt.internalSetCreatedBy(kay_ValidEmail);
+ teamArt.persist(getClass().getSimpleName());
+
+ notifyManager.clear();
+ AtsNotificationManager.notify(teamArt, AtsNotifyType.Assigned);
+ Assert.assertEquals(1, notifyManager.getNotificationEvents().size());
+ event = notifyManager.getNotificationEvents().get(0);
+ Assert.assertEquals(AtsNotifyType.Assigned.name(), event.getType());
+ // joe smith should be removed from list cause it's current user
+ // alex should be removed cause not valid email
+ List<IBasicUser> expected = new ArrayList<IBasicUser>();
+ expected.add(jason_ValidEmail);
+ expected.add(kay_ValidEmail);
+ List<IBasicUser> users = new ArrayList<IBasicUser>();
+ users.addAll(event.getUsers());
+ Assert.assertTrue(org.eclipse.osee.framework.jdk.core.util.Collections.isEqual(expected, users));
+ Assert.assertEquals(
+ "You have been set as the assignee of [Team Workflow] in state [Analyze] titled [AtsNotifyUsersTest]",
+ event.getDescription());
+
+ notifyManager.clear();
+ AtsNotificationManager.notify(teamArt, Collections.singleton((IBasicUser) jason_ValidEmail), AtsNotifyType.Assigned);
+ Assert.assertEquals(1, notifyManager.getNotificationEvents().size());
+ event = notifyManager.getNotificationEvents().get(0);
+ Assert.assertEquals(AtsNotifyType.Assigned.name(), event.getType());
+ // only alex should be emailed cause sent in list
+ Assert.assertEquals(Collections.singleton(jason_ValidEmail), event.getUsers());
+ Assert.assertEquals(
+ "You have been set as the assignee of [Team Workflow] in state [Analyze] titled [AtsNotifyUsersTest]",
+ event.getDescription());
+
+ notifyManager.clear();
+ SubscribeManager.toggleSubscribe(teamArt);
+ transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), "AtsNotifyUsersTests.toggle.subscribed");
+ SubscribeManager.addSubscribed(teamArt, inactiveSteve, transaction);
+ transaction.execute();
+ AtsNotificationManager.notify(teamArt, AtsNotifyType.Subscribed);
+ Assert.assertEquals(1, notifyManager.getNotificationEvents().size());
+ event = notifyManager.getNotificationEvents().get(0);
+ Assert.assertEquals(AtsNotifyType.Subscribed.name(), event.getType());
+ Assert.assertEquals(UserManager.getUser(), event.getUsers().iterator().next());
+ Assert.assertEquals(
+ "[Team Workflow] titled [AtsNotifyUsersTest] transitioned to [Analyze] and you subscribed for notification.",
+ event.getDescription());
+ SubscribeManager.toggleSubscribe(teamArt);
+
+ notifyManager.clear();
+ AtsNotificationManager.notify(teamArt, AtsNotifyType.Completed);
+ Assert.assertEquals(0, notifyManager.getNotificationEvents().size());
+
+ notifyManager.clear();
+ teamArt.getStateMgr().initializeStateMachine(TeamState.Completed);
+ AtsNotificationManager.notify(teamArt, AtsNotifyType.Completed);
+ event = notifyManager.getNotificationEvents().get(0);
+ Assert.assertEquals(AtsNotifyType.Completed.name(), event.getType());
+ Assert.assertEquals(kay_ValidEmail, event.getUsers().iterator().next());
+ Assert.assertEquals("[Team Workflow] titled [AtsNotifyUsersTest] is [Completed]", event.getDescription());
+
+ notifyManager.clear();
+ teamArt.internalSetCreatedBy(inactiveSteve);
+ teamArt.persist(getClass().getSimpleName());
+ teamArt.getStateMgr().initializeStateMachine(TeamState.Completed);
+ AtsNotificationManager.notify(teamArt, AtsNotifyType.Completed);
+ Assert.assertEquals(0, notifyManager.getNotificationEvents().size());
+ teamArt.internalSetCreatedBy(kay_ValidEmail);
+ teamArt.persist(getClass().getSimpleName());
+
+ notifyManager.clear();
+ teamArt.getStateMgr().initializeStateMachine(TeamState.Analyze);
+ TransitionHelper helper =
+ new TransitionHelper(getClass().getSimpleName(), Arrays.asList(teamArt), TeamState.Cancelled.getPageName(),
+ null, "this is the reason", TransitionOption.OverrideTransitionValidityCheck);
+ transaction = new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName());
+ TransitionManager transitionMgr = new TransitionManager(helper, transaction);
+ TransitionResults results = transitionMgr.handleAll();
+ transaction.execute();
+ Assert.assertTrue("Transition should have no errors", results.isEmpty());
+
+ Assert.assertEquals(1, notifyManager.getNotificationEvents().size());
+ event = notifyManager.getNotificationEvents().get(0);
+ Assert.assertEquals(AtsNotifyType.Cancelled.name(), event.getType());
+ Assert.assertEquals(kay_ValidEmail, event.getUsers().iterator().next());
+ Assert.assertTrue(event.getDescription().startsWith(
+ "[Team Workflow] titled [AtsNotifyUsersTest] was [Cancelled] from the [Analyze] state on"));
+ Assert.assertTrue(event.getDescription().endsWith(".<br>Reason: [this is the reason]"));
+
+ }
+}
diff --git a/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/TestNotificationManager.java b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/TestNotificationManager.java
new file mode 100644
index 0000000000..c610bd6d0b
--- /dev/null
+++ b/plugins/org.eclipse.osee.ats.core.test/src/org/eclipse/osee/ats/core/notify/TestNotificationManager.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.ats.core.notify;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.osee.framework.skynet.core.utility.INotificationManager;
+import org.eclipse.osee.framework.skynet.core.utility.OseeNotificationEvent;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class TestNotificationManager implements INotificationManager {
+
+ private final List<OseeNotificationEvent> notificationEvents = new ArrayList<OseeNotificationEvent>();
+
+ @Override
+ public void addNotificationEvent(OseeNotificationEvent notificationEvent) {
+ notificationEvents.add(notificationEvent);
+ }
+
+ @Override
+ public void clear() {
+ notificationEvents.clear();
+ }
+
+ @Override
+ public List<OseeNotificationEvent> getNotificationEvents() {
+ return notificationEvents;
+ }
+
+ @Override
+ public void sendNotifications() {
+ // do nothings
+ }
+
+}

Back to the top