Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3ab734e15f72fa78b6487e4b4a50f751a41bec64 (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
/*******************************************************************************
 * Copyright (c) 2011 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.task;

import junit.framework.Assert;
import org.eclipse.osee.ats.core.AtsTestUtil;
import org.eclipse.osee.ats.core.util.AtsUtilCore;
import org.eclipse.osee.ats.core.workflow.HoursSpentUtil;
import org.eclipse.osee.ats.core.workflow.PercentCompleteTotalUtil;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
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;
import org.junit.AfterClass;
import org.junit.BeforeClass;

/**
 * Test unit for {@link TaskManager}
 * 
 * @author Donald G. Dunne
 */
public class TaskManagerTest extends TaskManager {

   @BeforeClass
   @AfterClass
   public static void cleanup() throws OseeCoreException {
      AtsTestUtil.cleanup();
   }

   @org.junit.Test
   public void testTransitionToCompletedThenInWork() throws OseeCoreException {

      AtsTestUtil.cleanupAndReset("TaskManagerTest - TransitionToCompleted");

      TaskArtifact taskArt = AtsTestUtil.getOrCreateTask();

      // ensure nothing dirty
      AtsTestUtil.validateArtifactCache();

      // transition to Completed
      SkynetTransaction transaction =
         new SkynetTransaction(AtsUtilCore.getAtsBranch(),
            getClass().getSimpleName() + " testTransitionToCompletedThenInWork() 1");
      Result result = TaskManager.transitionToCompleted(taskArt, 0.0, 3, transaction);
      Assert.assertEquals(Result.TrueResult, result);
      transaction.execute();

      Assert.assertEquals(TaskStates.Completed.getPageName(), taskArt.getCurrentStateName());
      Assert.assertEquals(3.0, HoursSpentUtil.getHoursSpentTotal(taskArt));
      Assert.assertEquals("", taskArt.getStateMgr().getAssigneesStr());

      // ensure nothing dirty
      AtsTestUtil.validateArtifactCache();

      // transition back to InWork
      transaction =
         new SkynetTransaction(AtsUtilCore.getAtsBranch(),
            getClass().getSimpleName() + " testTransitionToCompletedThenInWork() 2");
      result = TaskManager.transitionToInWork(taskArt, UserManager.getUser(), 45, .5, transaction);
      Assert.assertEquals(Result.TrueResult, result);
      transaction.execute();

      Assert.assertEquals(TaskStates.InWork.getPageName(), taskArt.getCurrentStateName());
      Assert.assertEquals(3.5, HoursSpentUtil.getHoursSpentTotal(taskArt));
      Assert.assertEquals("Joe Smith", taskArt.getStateMgr().getAssigneesStr());
   }

   @org.junit.Test
   public void testStatusPercentChanged() throws OseeCoreException {

      System.out.println("\n\n...testStatusPercentChanged Start...");

      AtsTestUtil.cleanupAndReset("TaskManagerTest - StatusPercentChanged");

      TaskArtifact taskArt = AtsTestUtil.getOrCreateTask();

      // ensure nothing dirty
      AtsTestUtil.validateArtifactCache();

      // status 34% completed
      SkynetTransaction transaction =
         new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName() + " testStatusPercentChanged() 1");
      Result result = TaskManager.statusPercentChanged(taskArt, 3, 34, transaction);
      Assert.assertEquals(Result.TrueResult, result);
      transaction.execute();

      Assert.assertEquals(TaskStates.InWork.getPageName(), taskArt.getCurrentStateName());
      Assert.assertEquals(3.0, HoursSpentUtil.getHoursSpentTotal(taskArt));
      Assert.assertEquals(34, PercentCompleteTotalUtil.getPercentCompleteTotal(taskArt));
      Assert.assertEquals("Joe Smith", taskArt.getStateMgr().getAssigneesStr());

      // ensure nothing dirty
      AtsTestUtil.validateArtifactCache();

      // status 100% completed
      transaction =
         new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName() + " testStatusPercentChanged() 2");
      result = TaskManager.statusPercentChanged(taskArt, 3, 100, transaction);
      Assert.assertEquals(Result.TrueResult, result);
      transaction.execute();

      Assert.assertEquals(TaskStates.Completed.getPageName(), taskArt.getCurrentStateName());
      Assert.assertEquals(6.0, HoursSpentUtil.getHoursSpentTotal(taskArt));
      Assert.assertEquals(100, PercentCompleteTotalUtil.getPercentCompleteTotal(taskArt));
      Assert.assertEquals("", taskArt.getStateMgr().getAssigneesStr());

      // ensure nothing dirty
      AtsTestUtil.validateArtifactCache();

      // status back to 25%
      transaction =
         new SkynetTransaction(AtsUtilCore.getAtsBranch(), getClass().getSimpleName() + " testStatusPercentChanged() 3");
      result = TaskManager.statusPercentChanged(taskArt, 1, 25, transaction);
      Assert.assertEquals(Result.TrueResult, result);
      transaction.execute();

      Assert.assertEquals(TaskStates.InWork.getPageName(), taskArt.getCurrentStateName());
      Assert.assertEquals(7.0, HoursSpentUtil.getHoursSpentTotal(taskArt));
      Assert.assertEquals(25, PercentCompleteTotalUtil.getPercentCompleteTotal(taskArt));
      Assert.assertEquals("Joe Smith", taskArt.getStateMgr().getAssigneesStr());

      // ensure nothing dirty
      AtsTestUtil.validateArtifactCache();

      System.out.println("...testStatusPercentChanged End...");
   }
}

Back to the top