Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5d9cee09efae35b97646f93a1c554dd084260f60 (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
/*******************************************************************************
 * Copyright (c) 2013 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.model;

import org.junit.Assert;
import org.eclipse.osee.ats.api.workdef.IAtsCompositeLayoutItem;
import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinition;
import org.eclipse.osee.ats.api.workdef.RuleDefinitionOption;
import org.eclipse.osee.ats.api.workdef.StateColor;
import org.eclipse.osee.ats.api.workdef.StateType;
import org.eclipse.osee.ats.impl.internal.AtsWorkDefinitionServiceImpl;
import org.eclipse.osee.ats.impl.internal.workdef.model.CompositeLayoutItem;
import org.eclipse.osee.ats.impl.internal.workdef.model.DecisionReviewDefinition;
import org.eclipse.osee.ats.impl.internal.workdef.model.LayoutItem;
import org.eclipse.osee.ats.impl.internal.workdef.model.PeerReviewDefinition;
import org.eclipse.osee.ats.impl.internal.workdef.model.StateDefinition;
import org.eclipse.osee.ats.impl.internal.workdef.model.WidgetDefinition;
import org.eclipse.osee.ats.impl.internal.workdef.model.WorkDefinition;
import org.junit.Test;

public class StateDefinitionTest {

   @Test
   public void testToString() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertEquals("[endorse][null]", def.toString());
      def.setStateType(StateType.Working);
      Assert.assertEquals("[endorse][Working]", def.toString());
   }

   @Test
   public void testGetStateItems() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertEquals(0, def.getLayoutItems().size());
      def.getLayoutItems().add(new LayoutItem("item"));
      Assert.assertEquals(1, def.getLayoutItems().size());
   }

   @Test
   public void testAddRemoveRule() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertEquals(0, def.getRules().size());
      def.addRule("rule");
      Assert.assertEquals(1, def.getRules().size());
      def.addRule(RuleDefinitionOption.AddDecisionValidateBlockingReview.name());
      Assert.assertEquals(2, def.getRules().size());

      Assert.assertTrue(def.hasRule(RuleDefinitionOption.AddDecisionValidateBlockingReview.name()));
      Assert.assertFalse(def.hasRule(RuleDefinitionOption.AddDecisionValidateNonBlockingReview.name()));

      def.removeRule(RuleDefinitionOption.AddDecisionValidateBlockingReview.name());
      Assert.assertFalse(def.hasRule(RuleDefinitionOption.AddDecisionValidateBlockingReview.name()));
   }

   @Test
   public void testGetSetStateType() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertNull(def.getStateType());
      def.setStateType(StateType.Working);
      Assert.assertEquals(StateType.Working, def.getStateType());
   }

   @Test
   public void testGetSetOrdinal() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertEquals(0, def.getOrdinal());
      def.setOrdinal(3);
      Assert.assertEquals(3, def.getOrdinal());
   }

   @Test
   public void testGetToStates() {
      StateDefinition endorse = new StateDefinition("endorse");
      StateDefinition analyze = new StateDefinition("endorse");
      StateDefinition completed = new StateDefinition("endorse");
      endorse.getToStates().add(analyze);
      endorse.getToStates().add(completed);
      Assert.assertTrue(endorse.getToStates().contains(analyze));
      Assert.assertTrue(endorse.getToStates().contains(completed));
   }

   @Test
   public void testGetPageName() {
      StateDefinition endorse = new StateDefinition("endorse");
      Assert.assertEquals("endorse", endorse.getName());
   }

   @Test
   public void testGetSetWorkDefinition() {
      WorkDefinition workDef = new WorkDefinition("mine");
      StateDefinition state = new StateDefinition("endorse");
      Assert.assertNull(state.getWorkDefinition());
      state.setWorkDefinition(workDef);
      Assert.assertEquals(workDef, state.getWorkDefinition());

      Assert.assertEquals("mine.endorse", state.getFullName());
   }

   @Test
   public void testStateType() {
      StateDefinition state = new StateDefinition("endorse");
      state.setStateType(StateType.Working);

      Assert.assertTrue(state.getStateType().isWorkingState());
      Assert.assertFalse(state.getStateType().isCancelledState());
      Assert.assertFalse(state.getStateType().isCompletedState());
      Assert.assertFalse(state.getStateType().isCompletedOrCancelledState());

      state.setStateType(StateType.Completed);
      Assert.assertTrue(StateType.Completed.isCompletedState());
      Assert.assertTrue(StateType.Completed.isCompletedOrCancelledState());

      state.setStateType(StateType.Cancelled);
      Assert.assertTrue(StateType.Cancelled.isCancelledState());
      Assert.assertTrue(StateType.Cancelled.isCompletedOrCancelledState());
   }

   @Test
   public void testGetOverrideAttributeValidationStates() {
      StateDefinition endorse = new StateDefinition("endorse");
      StateDefinition analyze = new StateDefinition("endorse");
      StateDefinition completed = new StateDefinition("endorse");
      endorse.getOverrideAttributeValidationStates().add(analyze);
      endorse.getOverrideAttributeValidationStates().add(completed);
      Assert.assertTrue(endorse.getOverrideAttributeValidationStates().contains(analyze));
      Assert.assertTrue(endorse.getOverrideAttributeValidationStates().contains(completed));
   }

   @Test
   public void testGetWidgetsFromStateItems() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertEquals(0, new AtsWorkDefinitionServiceImpl().getWidgetsFromLayoutItems(def).size());

      IAtsWidgetDefinition widget1 = new WidgetDefinition("item 1");
      def.getLayoutItems().add(widget1);

      IAtsCompositeLayoutItem stateItem2 = new CompositeLayoutItem(2);
      def.getLayoutItems().add(stateItem2);
      IAtsWidgetDefinition widget2 = new WidgetDefinition("item 2");
      stateItem2.getaLayoutItems().add(widget2);
      IAtsWidgetDefinition widget3 = new WidgetDefinition("item 3");
      stateItem2.getaLayoutItems().add(widget3);

      CompositeLayoutItem stateItem3 = new CompositeLayoutItem(2);
      stateItem2.getaLayoutItems().add(stateItem3);
      // StateItem is an base class, so it's widgets won't be seen
      LayoutItem widget4 = new LayoutItem("item 4");
      stateItem3.getaLayoutItems().add(widget4);

      Assert.assertEquals(3, new AtsWorkDefinitionServiceImpl().getWidgetsFromLayoutItems(def).size());
   }

   @Test
   public void testGetDecisionReviews() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertEquals(0, def.getDecisionReviews().size());
      def.getDecisionReviews().add(new DecisionReviewDefinition("review 1"));
      def.getDecisionReviews().add(new DecisionReviewDefinition("review 2"));
      Assert.assertEquals(2, def.getDecisionReviews().size());
   }

   @Test
   public void testGetPeerReviews() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertEquals(0, def.getPeerReviews().size());
      def.getPeerReviews().add(new PeerReviewDefinition("review 1"));
      def.getPeerReviews().add(new PeerReviewDefinition("review 2"));
      Assert.assertEquals(2, def.getPeerReviews().size());
   }

   @Test
   public void testGetSetPercentWeight() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertEquals(0, def.getStateWeight());
      def.setStateWeight(34);
      Assert.assertEquals(34, def.getStateWeight());

   }

   @Test
   public void testGetSetRecommendedPercentComplete() {
      StateDefinition endorse = new StateDefinition("endorse");
      Assert.assertEquals((Integer) null, endorse.getRecommendedPercentComplete());
      endorse.setRecommendedPercentComplete(34);
      Assert.assertEquals((Integer) 34, endorse.getRecommendedPercentComplete());
   }

   @Test
   public void testGetSetColor() {
      StateDefinition endorse = new StateDefinition("endorse");
      Assert.assertNull(endorse.getColor());
      endorse.setColor(StateColor.BLUE);
      Assert.assertEquals(StateColor.BLUE, endorse.getColor());
   }

   @Test
   public void testHasWidgetNamed() {
      StateDefinition def = new StateDefinition("endorse");
      Assert.assertFalse(new AtsWorkDefinitionServiceImpl().hasWidgetNamed(def, "item 2"));

      IAtsCompositeLayoutItem stateItem2 = new CompositeLayoutItem(2);
      def.getLayoutItems().add(stateItem2);
      IAtsWidgetDefinition widget2 = new WidgetDefinition("item 2");
      stateItem2.getaLayoutItems().add(widget2);
      IAtsWidgetDefinition widget3 = new WidgetDefinition("item 3");
      stateItem2.getaLayoutItems().add(widget3);

      Assert.assertFalse(new AtsWorkDefinitionServiceImpl().hasWidgetNamed(def, "item 45"));
      Assert.assertTrue(new AtsWorkDefinitionServiceImpl().hasWidgetNamed(def, "item 2"));
   }

   @Test
   public void testEqualsObject() {
      StateDefinition obj = new StateDefinition("hello");
      Assert.assertTrue(obj.equals(obj));

      StateDefinition obj2 = new StateDefinition("hello");

      Assert.assertTrue(obj.equals(obj2));
      Assert.assertFalse(obj.equals(null));
      Assert.assertFalse(obj.equals("str"));

      StateDefinition obj3 = new StateDefinition("hello");
      obj3.setName(null);
      Assert.assertFalse(obj.equals(obj3));
      Assert.assertFalse(obj3.equals(obj));

      StateDefinition obj4 = new StateDefinition("hello");
      obj4.setName(null);
      Assert.assertFalse(obj3.equals(obj4));
   }

   @Test
   public void testHashCode() {
      StateDefinition obj = new StateDefinition("hello");
      Assert.assertEquals(99162353, obj.hashCode());

      obj = new StateDefinition("hello");
      obj.setName(null);
      Assert.assertEquals(31, obj.hashCode());
   }

}

Back to the top