Skip to main content
summaryrefslogtreecommitdiffstats
blob: ad89903115e8d3e5171b7acc81c954e45dfd49dd (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
/*******************************************************************************
 * 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.client.integration.tests.ats.core.client;

import org.eclipse.osee.ats.api.workdef.ReviewBlockType;
import org.eclipse.osee.ats.api.workflow.transition.TransitionOption;
import org.eclipse.osee.ats.client.integration.tests.AtsClientService;
import org.eclipse.osee.ats.core.client.team.TeamWorkFlowArtifact;
import org.eclipse.osee.ats.core.client.util.AtsChangeSet;
import org.eclipse.osee.ats.core.workflow.state.TeamState;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.util.Result;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.junit.Assert;

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

   @org.junit.After
   public void validateCleanup() throws OseeCoreException {
      AtsTestUtil.validateObjectsNull();
   }

   @org.junit.Test
   public void testCleanupAndReset() throws OseeCoreException {
      boolean exceptionThrown = false;
      try {
         Assert.assertNull(AtsTestUtil.getWorkDef());
      } catch (OseeStateException ex) {
         Assert.assertEquals(ex.getMessage(), "Must call cleanAndReset before using this method");
         exceptionThrown = true;
      }
      Assert.assertTrue("Exeception should have been thrown", exceptionThrown);

      AtsTestUtil.cleanupAndReset("AtsTestUtilTest");

      AtsTestUtil.validateArtifactCache();

      Assert.assertNotNull(AtsTestUtil.getTeamWf());
      Assert.assertNotNull(AtsTestUtil.getTeamWf().getStateDefinition());
      String atsId = AtsTestUtil.getTeamWf().getAtsId();
      Assert.assertTrue(atsId.startsWith("ATS"));

      AtsTestUtil.cleanup();

      AtsTestUtil.validateArtifactCache();
   }

   @org.junit.Test
   public void testCreateAndCleanupWithBranch() throws Exception {
      AtsTestUtil.cleanupAndReset(getClass().getSimpleName() + "-testCleanupAndResetWithBranch");
      Result result = AtsTestUtil.createWorkingBranchFromTeamWf();
      Assert.assertTrue(result.getText(), result.isTrue());
      Thread.sleep(2000);
      Branch branch = AtsTestUtil.getTeamWf().getWorkingBranch();
      Assert.assertNotNull(branch);
      AtsTestUtil.cleanup();
      Assert.assertTrue(branch.isDeleted());
   }

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

      AtsTestUtil.cleanupAndReset("AtsTestUtilTest.testGetTeamWf2");
      AtsTestUtil.validateArtifactCache();

      Assert.assertNotNull(AtsTestUtil.getTeamWf2());
      Assert.assertNotNull(AtsTestUtil.getTeamWf2().getStateDefinition());
      Assert.assertNotSame(AtsTestUtil.getTeamWf(), AtsTestUtil.getTeamWf2());
      Assert.assertNotSame(AtsTestUtil.getActionArt(), AtsTestUtil.getActionArt2());
      Assert.assertNotSame(AtsTestUtil.getTeamWf().getActionableItemsDam().getActionableItems().iterator().next(),
         AtsTestUtil.getTeamWf2().getActionableItemsDam().getActionableItems().iterator().next());

      AtsTestUtil.cleanup();

      AtsTestUtil.validateArtifactCache();
   }

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

      AtsTestUtil.cleanupAndReset("AtsTestUtilTest.testGetTeamWf2");
      AtsTestUtil.validateArtifactCache();

      Assert.assertNotNull(AtsTestUtil.getTeamWf4());
      Assert.assertNotNull(AtsTestUtil.getTeamWf4().getStateDefinition());
      Assert.assertNotSame(AtsTestUtil.getTeamWf(), AtsTestUtil.getTeamWf4());
      Assert.assertNotSame(AtsTestUtil.getActionArt(), AtsTestUtil.getActionArt4());
      Assert.assertNotSame(AtsTestUtil.getTeamWf().getActionableItemsDam().getActionableItems().iterator().next(),
         AtsTestUtil.getTeamWf4().getActionableItemsDam().getActionableItems().iterator().next());
      Assert.assertEquals(AtsClientService.get().getVersionService().getTargetedVersion(AtsTestUtil.getTeamWf4()),
         AtsTestUtil.getVerArt4());

      AtsTestUtil.cleanup();

      AtsTestUtil.validateArtifactCache();
   }

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

      AtsTestUtil.cleanupAndReset("AtsTestUtilTest.testGetDecisionReview");
      AtsTestUtil.validateArtifactCache();

      AtsChangeSet changes = new AtsChangeSet(getClass().getSimpleName());
      Assert.assertNotNull(AtsTestUtil.getOrCreateDecisionReview(ReviewBlockType.Commit, AtsTestUtilState.Analyze,
         changes));
      changes.execute();

      AtsTestUtil.cleanup();

      AtsTestUtil.validateArtifactCache();
   }

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

      AtsTestUtil.cleanupAndReset("AtsTestUtilTest.testGetPeerReview");
      AtsTestUtil.validateArtifactCache();

      AtsChangeSet changes = new AtsChangeSet("testGetPeerReview");
      Assert.assertNotNull(AtsTestUtil.getOrCreatePeerReview(ReviewBlockType.Commit, AtsTestUtilState.Analyze, changes));
      changes.execute();

      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.getName());

      AtsChangeSet changes = new AtsChangeSet("test");

      Result result =
         AtsTestUtil.transitionTo(AtsTestUtilState.Implement, AtsClientService.get().getUserService().getCurrentUser(),
            changes, TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
      Assert.assertEquals(Result.TrueResult, result);
      Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Implement.getName());

      result =
         AtsTestUtil.transitionTo(AtsTestUtilState.Completed, AtsClientService.get().getUserService().getCurrentUser(),
            changes, TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
      Assert.assertEquals(Result.TrueResult, result);
      Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Completed.getName());

      teamArt.reloadAttributesAndRelations();

      changes.execute();

      AtsTestUtil.cleanup();
   }

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

      AtsTestUtil.cleanupAndReset("AtsTestUtilTest");

      TeamWorkFlowArtifact teamArt = AtsTestUtil.getTeamWf();
      Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Analyze.getName());

      AtsChangeSet changes = new AtsChangeSet("test");

      Result result =
         AtsTestUtil.transitionTo(AtsTestUtilState.Cancelled, AtsClientService.get().getUserService().getCurrentUser(),
            changes, TransitionOption.OverrideAssigneeCheck, TransitionOption.OverrideTransitionValidityCheck);
      Assert.assertEquals(Result.TrueResult, result);
      Assert.assertEquals(teamArt.getCurrentStateName(), TeamState.Cancelled.getName());

      teamArt.reloadAttributesAndRelations();

      changes.execute();

      AtsTestUtil.cleanup();
   }
}

Back to the top