Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3539da02fa58866b002b96aad0f7edb59eb6138d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
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 Peer 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();
   }
}

Back to the top