diff options
author | donald.g.dunne | 2014-08-19 03:10:44 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2014-09-29 22:55:23 +0000 |
commit | 1c33a705cf7938d1b54025530e1680b78ac3abe0 (patch) | |
tree | 6e9f0efddc8138cd448cbb4a869a0101f824039a /plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse | |
parent | 926511e9a869dd0d169958de9cc973232da50577 (diff) | |
download | org.eclipse.osee-1c33a705cf7938d1b54025530e1680b78ac3abe0.tar.gz org.eclipse.osee-1c33a705cf7938d1b54025530e1680b78ac3abe0.tar.xz org.eclipse.osee-1c33a705cf7938d1b54025530e1680b78ac3abe0.zip |
feature[ats_ATS64164]: CPA: ATS Notify add WorkItemNotificationProcessorTest
Change-Id: I4af772f7feebbd4327a275e290d4a017b5986bd6
Diffstat (limited to 'plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse')
3 files changed, 372 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/AllAtsImplTestSuite.java b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/AllAtsImplTestSuite.java index ff82c4bfcdd..505daf8f210 100644 --- a/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/AllAtsImplTestSuite.java +++ b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/AllAtsImplTestSuite.java @@ -11,6 +11,7 @@ package org.eclipse.osee.ats.impl; import org.eclipse.osee.ats.impl.internal.model.ModelTestSuite; +import org.eclipse.osee.ats.impl.internal.notify.AtsImpl_Notify_Suite; import org.eclipse.osee.ats.impl.internal.workdef.WorkDefTestSuite; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -19,7 +20,7 @@ import org.junit.runners.Suite; * @author Donald G. Dunne */ @RunWith(Suite.class) -@Suite.SuiteClasses({WorkDefTestSuite.class, ModelTestSuite.class}) +@Suite.SuiteClasses({WorkDefTestSuite.class, ModelTestSuite.class, AtsImpl_Notify_Suite.class}) public class AllAtsImplTestSuite { // Test Suite } diff --git a/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/notify/AtsImpl_Notify_Suite.java b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/notify/AtsImpl_Notify_Suite.java new file mode 100644 index 00000000000..5638a54a986 --- /dev/null +++ b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/notify/AtsImpl_Notify_Suite.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * 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.impl.internal.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; + +/** + * @author Donald G. Dunne + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({WorkItemNotificationProcessorTest.class}) +public class AtsImpl_Notify_Suite { + @BeforeClass + public static void setUp() throws Exception { + OseeProperties.setIsInTest(true); + System.out.println("\n\nBegin " + AtsImpl_Notify_Suite.class.getSimpleName()); + } + + @AfterClass + public static void tearDown() throws Exception { + System.out.println("End " + AtsImpl_Notify_Suite.class.getSimpleName()); + } +} diff --git a/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/notify/WorkItemNotificationProcessorTest.java b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/notify/WorkItemNotificationProcessorTest.java new file mode 100644 index 00000000000..c3a3fde5eca --- /dev/null +++ b/plugins/org.eclipse.osee.ats.impl.test/src/org/eclipse/osee/ats/impl/internal/notify/WorkItemNotificationProcessorTest.java @@ -0,0 +1,335 @@ +/******************************************************************************* + * Copyright (c) 2014 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.impl.internal.notify; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.eclipse.osee.ats.api.ai.IAtsActionableItem; +import org.eclipse.osee.ats.api.data.AtsAttributeTypes; +import org.eclipse.osee.ats.api.notify.AtsNotificationCollector; +import org.eclipse.osee.ats.api.notify.AtsNotificationEvent; +import org.eclipse.osee.ats.api.notify.AtsNotifyType; +import org.eclipse.osee.ats.api.notify.AtsWorkItemNotificationEvent; +import org.eclipse.osee.ats.api.review.IAtsPeerToPeerReview; +import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; +import org.eclipse.osee.ats.api.team.IAtsWorkItemFactory; +import org.eclipse.osee.ats.api.user.IAtsUser; +import org.eclipse.osee.ats.api.user.IAtsUserService; +import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition; +import org.eclipse.osee.ats.api.workdef.IAttributeResolver; +import org.eclipse.osee.ats.api.workdef.StateType; +import org.eclipse.osee.ats.api.workflow.IAtsTeamWorkflow; +import org.eclipse.osee.ats.api.workflow.state.IAtsStateManager; +import org.eclipse.osee.ats.impl.IAtsServer; +import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; +import org.eclipse.osee.orcs.OrcsApi; +import org.junit.Assert; +import org.junit.Before; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Test unit for {@link WorkItemNotificationProcessor} + * + * @author Donald G. Dunne + */ +public class WorkItemNotificationProcessorTest { + + // @formatter:off + @Mock IAtsUser joeSmith_CurrentUser, kay_ValidEmail, jason_ValidEmail, alex_NoValidEmail, inactiveSteve; + @Mock IAtsTeamWorkflow teamWf; + @Mock IAtsPeerToPeerReview peerReview; + @Mock IAtsStateManager stateMgr; + @Mock IAtsServer atsServer; + @Mock OrcsApi orcsApi; + @Mock IAtsWorkItemFactory workItemFactory; + @Mock IAtsUserService userService; + @Mock IAttributeResolver attrResolver; + @Mock IAtsStateDefinition stateDef; + @Mock IAtsTeamDefinition teamDef; + @Mock IAtsActionableItem ai; + + // @formatter:on + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + + setupUser(joeSmith_CurrentUser, "ABNRvbZxXHICYklfslwA", "Joe Smith", "joe@boeing.com", "Joe Smith", true, false); + setupUser(kay_ValidEmail, "ABNRvuB8x3VARkkn3YAA", "Kay Jones", "kay@boeing.com", "Kay Jones", true, false); + setupUser(jason_ValidEmail, "ABNRvuHWtXAdxbG3mUAA", "Jason Michael", "jason@boeing.com", "Jason Michael", true, + false); + setupUser(alex_NoValidEmail, "ABNRvuKDIWOcPDe4X0wA", "Alex Kay", "", "Alex Kay", true, false); + setupUser(inactiveSteve, "ABNRvuRG6jKwKnEoX4gA", "Inactive Steve", "insactiveSteve@boeing.com", "Inactive Steve", + false, false); + + when(teamWf.getName()).thenReturn(WorkItemNotificationProcessorTest.class.getSimpleName() + "-testNotify"); + List<IAtsUser> assignees = new ArrayList<IAtsUser>(); + assignees.addAll(Arrays.asList(inactiveSteve, alex_NoValidEmail, jason_ValidEmail, kay_ValidEmail, + joeSmith_CurrentUser)); + String atsId = "ATS003"; + when(teamWf.getAtsId()).thenReturn(atsId); + when(workItemFactory.getWorkItemByAtsId(atsId)).thenReturn(teamWf); + when(attrResolver.getSoleAttributeValue(teamWf, AtsAttributeTypes.LegacyPcrId, "")).thenReturn(atsId); + when(atsServer.getConfigValue(eq("ActionUrl"))).thenReturn("http://ats/action/UUID/"); + when(teamWf.getGuid()).thenReturn("myguid"); + when(teamWf.getArtifactTypeName()).thenReturn("Team Workflow"); + when(teamWf.getStateMgr()).thenReturn(stateMgr); + when(stateMgr.getCurrentStateName()).thenReturn("Analyze"); + when(stateMgr.getAssignees()).thenReturn(assignees); + + when(teamWf.getStateDefinition()).thenReturn(stateDef); + when(teamWf.getTeamDefinition()).thenReturn(teamDef); + Set<IAtsActionableItem> ais = new HashSet<IAtsActionableItem>(); + ais.add(ai); + when(teamWf.getActionableItems()).thenReturn(ais); + + } + + @org.junit.Test + public void testNotifyOriginator() throws OseeCoreException { + + WorkItemNotificationProcessor processor = + new WorkItemNotificationProcessor(atsServer, workItemFactory, userService, attrResolver); + AtsNotificationCollector notifications = new AtsNotificationCollector(); + AtsWorkItemNotificationEvent event = new AtsWorkItemNotificationEvent(); + event.setFromUserId(joeSmith_CurrentUser.getUserId()); + event.setNotifyType(AtsNotifyType.Originator); + event.getAtsIds().add(teamWf.getAtsId()); + when(teamWf.getCreatedBy()).thenReturn(kay_ValidEmail); + + processor.run(notifications, event); + + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + AtsNotificationEvent notifyEvent = notifications.getNotificationEvents().get(0); + Assert.assertEquals(AtsNotifyType.Originator.name(), notifyEvent.getType()); + Assert.assertEquals(kay_ValidEmail.getUserId(), notifyEvent.getUserIds().iterator().next()); + Assert.assertEquals( + "You have been set as the originator of [Team Workflow] state [Analyze] titled [WorkItemNotificationProcessorTest-testNotify]", + notifyEvent.getDescription()); + + notifications = new AtsNotificationCollector(); + when(teamWf.getCreatedBy()).thenReturn(inactiveSteve); + processor.run(notifications, event); + Assert.assertEquals(0, notifications.getNotificationEvents().size()); + + } + + @org.junit.Test + public void testNotifyAssignee() throws OseeCoreException { + + WorkItemNotificationProcessor processor = + new WorkItemNotificationProcessor(atsServer, workItemFactory, userService, attrResolver); + AtsNotificationCollector notifications = new AtsNotificationCollector(); + AtsWorkItemNotificationEvent event = new AtsWorkItemNotificationEvent(); + event.setFromUserId(joeSmith_CurrentUser.getUserId()); + event.setNotifyType(AtsNotifyType.Assigned); + event.getAtsIds().add(teamWf.getAtsId()); + event.getUserIds().add(kay_ValidEmail.getUserId()); + + processor.run(notifications, event); + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + AtsNotificationEvent notifyEvent = notifications.getNotificationEvents().get(0); + Assert.assertEquals(AtsNotifyType.Assigned.name(), notifyEvent.getType()); + + // joe smith should be removed from list cause it's current user + // alex should be removed cause not valid email + List<String> expectedUserIds = new ArrayList<String>(); + expectedUserIds.add(jason_ValidEmail.getUserId()); + expectedUserIds.add(kay_ValidEmail.getUserId()); + List<IAtsUser> users = new ArrayList<IAtsUser>(); + for (String userId : event.getUserIds()) { + users.add(userService.getUserById(userId)); + } + event.getUserIds().clear(); + + notifications = new AtsNotificationCollector(); + processor.run(notifications, event); + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + notifyEvent = notifications.getNotificationEvents().get(0); + + Assert.assertTrue(org.eclipse.osee.framework.jdk.core.util.Collections.isEqual(expectedUserIds, + notifyEvent.getUserIds())); + Assert.assertEquals( + "You have been set as the assignee of [Team Workflow] in state [Analyze] titled [WorkItemNotificationProcessorTest-testNotify]", + notifyEvent.getDescription()); + + notifications = new AtsNotificationCollector(); + event.getUserIds().add(jason_ValidEmail.getUserId()); + processor.run(notifications, event); + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + notifyEvent = notifications.getNotificationEvents().get(0); + + Assert.assertEquals(AtsNotifyType.Assigned.name(), notifyEvent.getType()); + // only alex should be emailed cause sent in list + Assert.assertEquals(1, notifyEvent.getUserIds().size()); + Assert.assertEquals(jason_ValidEmail.getUserId(), notifyEvent.getUserIds().iterator().next()); + Assert.assertEquals( + "You have been set as the assignee of [Team Workflow] in state [Analyze] titled [WorkItemNotificationProcessorTest-testNotify]", + notifyEvent.getDescription()); + } + + @org.junit.Test + public void testNotifySubscribe() throws OseeCoreException { + + when(userService.getSubscribed(teamWf)).thenReturn(Arrays.asList(kay_ValidEmail)); + AtsWorkItemNotificationEvent event = new AtsWorkItemNotificationEvent(); + event.setFromUserId(joeSmith_CurrentUser.getUserId()); + event.setNotifyType(AtsNotifyType.Subscribed); + event.getAtsIds().add(teamWf.getAtsId()); + + WorkItemNotificationProcessor processor = + new WorkItemNotificationProcessor(atsServer, workItemFactory, userService, attrResolver); + AtsNotificationCollector notifications = new AtsNotificationCollector(); + processor.run(notifications, event); + + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + AtsNotificationEvent notifyEvent = notifications.getNotificationEvents().get(0); + + Assert.assertEquals(AtsNotifyType.Subscribed.name(), notifyEvent.getType()); + // only alex should be emailed cause sent in list + Assert.assertEquals(1, notifyEvent.getUserIds().size()); + Assert.assertEquals(kay_ValidEmail.getUserId(), notifyEvent.getUserIds().iterator().next()); + Assert.assertEquals( + "[Team Workflow] titled [WorkItemNotificationProcessorTest-testNotify] transitioned to [Analyze] and you subscribed for notification.", + notifyEvent.getDescription()); + + } + + @org.junit.Test + public void testNotifyCompleted() throws OseeCoreException { + + AtsWorkItemNotificationEvent event = new AtsWorkItemNotificationEvent(); + event.setFromUserId(joeSmith_CurrentUser.getUserId()); + event.setNotifyType(AtsNotifyType.Completed); + event.getAtsIds().add(teamWf.getAtsId()); + when(teamWf.isTask()).thenReturn(false); + when(stateDef.getStateType()).thenReturn(StateType.Completed); + when(teamWf.getCreatedBy()).thenReturn(inactiveSteve); + when(stateMgr.getCurrentStateName()).thenReturn("Completed"); + + WorkItemNotificationProcessor processor = + new WorkItemNotificationProcessor(atsServer, workItemFactory, userService, attrResolver); + AtsNotificationCollector notifications = new AtsNotificationCollector(); + + processor.run(notifications, event); + Assert.assertEquals(0, notifications.getNotificationEvents().size()); + + notifications = new AtsNotificationCollector(); + when(teamWf.getCreatedBy()).thenReturn(kay_ValidEmail); + processor.run(notifications, event); + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + AtsNotificationEvent notifyEvent = notifications.getNotificationEvents().get(0); + Assert.assertEquals(AtsNotifyType.Completed.name(), notifyEvent.getType()); + Assert.assertEquals(kay_ValidEmail.getUserId(), notifyEvent.getUserIds().iterator().next()); + Assert.assertEquals("[Team Workflow] titled [WorkItemNotificationProcessorTest-testNotify] is [Completed]", + notifyEvent.getDescription()); + + notifications = new AtsNotificationCollector(); + when(teamWf.getCreatedBy()).thenReturn(inactiveSteve); + Assert.assertEquals(0, notifications.getNotificationEvents().size()); + + } + + @org.junit.Test + public void testNotifyCancelled() throws OseeCoreException { + + AtsWorkItemNotificationEvent event = new AtsWorkItemNotificationEvent(); + event.setFromUserId(joeSmith_CurrentUser.getUserId()); + event.setNotifyType(AtsNotifyType.Cancelled); + event.getAtsIds().add(teamWf.getAtsId()); + when(teamWf.isTask()).thenReturn(false); + when(stateDef.getStateType()).thenReturn(StateType.Cancelled); + when(teamWf.getCreatedBy()).thenReturn(inactiveSteve); + when(teamWf.getCancelledReason()).thenReturn("this is the reason"); + when(teamWf.getCancelledFromState()).thenReturn("Analyze"); + when(stateMgr.getCurrentStateName()).thenReturn("Cancelled"); + + WorkItemNotificationProcessor processor = + new WorkItemNotificationProcessor(atsServer, workItemFactory, userService, attrResolver); + AtsNotificationCollector notifications = new AtsNotificationCollector(); + + processor.run(notifications, event); + Assert.assertEquals(0, notifications.getNotificationEvents().size()); + + notifications = new AtsNotificationCollector(); + when(teamWf.getCreatedBy()).thenReturn(kay_ValidEmail); + processor.run(notifications, event); + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + AtsNotificationEvent notifyEvent = notifications.getNotificationEvents().get(0); + Assert.assertEquals(AtsNotifyType.Cancelled.name(), notifyEvent.getType()); + Assert.assertEquals(kay_ValidEmail.getUserId(), notifyEvent.getUserIds().iterator().next()); + Assert.assertTrue(notifyEvent.getDescription().startsWith( + "[Team Workflow] titled [WorkItemNotificationProcessorTest-testNotify] was [Cancelled] from the [Analyze] state on")); + Assert.assertTrue(notifyEvent.getDescription().endsWith(".<br>Reason: [this is the reason]")); + + notifications = new AtsNotificationCollector(); + when(teamWf.getCreatedBy()).thenReturn(inactiveSteve); + Assert.assertEquals(0, notifications.getNotificationEvents().size()); + + } + + @org.junit.Test + public void testNotifySubscribedTeamOrAi() throws OseeCoreException { + + AtsWorkItemNotificationEvent event = new AtsWorkItemNotificationEvent(); + event.setFromUserId(joeSmith_CurrentUser.getUserId()); + event.setNotifyType(AtsNotifyType.SubscribedTeamOrAi); + event.getAtsIds().add(teamWf.getAtsId()); + when(teamWf.isTeamWorkflow()).thenReturn(true); + when(stateDef.getStateType()).thenReturn(StateType.Working); + when(stateMgr.getCurrentStateName()).thenReturn(StateType.Working.name()); + + WorkItemNotificationProcessor processor = + new WorkItemNotificationProcessor(atsServer, workItemFactory, userService, attrResolver); + + AtsNotificationCollector notifications = new AtsNotificationCollector(); + processor.run(notifications, event); + when(teamDef.getSubscribed()).thenReturn(new ArrayList<IAtsUser>()); + when(ai.getSubscribed()).thenReturn(new ArrayList<IAtsUser>()); + Assert.assertEquals(0, notifications.getNotificationEvents().size()); + + notifications = new AtsNotificationCollector(); + when(teamDef.getSubscribed()).thenReturn(Arrays.asList(kay_ValidEmail)); + when(ai.getSubscribed()).thenReturn(new ArrayList<IAtsUser>()); + processor.run(notifications, event); + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + + notifications = new AtsNotificationCollector(); + when(teamDef.getSubscribed()).thenReturn(new ArrayList<IAtsUser>()); + when(ai.getSubscribed()).thenReturn(Arrays.asList(kay_ValidEmail)); + processor.run(notifications, event); + Assert.assertEquals(1, notifications.getNotificationEvents().size()); + + notifications = new AtsNotificationCollector(); + when(teamDef.getSubscribed()).thenReturn(Arrays.asList(jason_ValidEmail)); + when(ai.getSubscribed()).thenReturn(Arrays.asList(kay_ValidEmail)); + processor.run(notifications, event); + Assert.assertEquals(2, notifications.getNotificationEvents().size()); + + } + + private void setupUser(IAtsUser user, String guid, String name, String email, String userId, boolean active, boolean admin) { + when(user.getGuid()).thenReturn(guid); + when(user.getName()).thenReturn(name); + when(user.getEmail()).thenReturn(email); + when(user.isActive()).thenReturn(active); + when(user.getUserId()).thenReturn(userId); + + when(userService.getUserById(userId)).thenReturn(user); + } + +} |