Skip to main content
summaryrefslogtreecommitdiffstats
blob: e004ddb565ad70edf7083409f7e9cfb85717f59a (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
/*******************************************************************************
 * 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.orcs.core.internal.relation;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.eclipse.osee.framework.core.data.IRelationType;
import org.eclipse.osee.framework.core.enums.DirtyState;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.enums.RelationSide;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.orcs.core.ds.RelationData;
import org.eclipse.osee.orcs.data.RelationTypes;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

/**
 * Test Case for {@link Relation}
 *
 * @author Roberto E. Escobar
 */
public class RelationTest {

   private static final long TYPE_UUID = 123124514L;

   // @formatter:off
   @Mock private RelationTypes relationTypes;
   @Mock RelationData data;
   // @formatter:on

   private Relation relation;

   @Before
   public void init() {
      MockitoAnnotations.initMocks(this);

      relation = new Relation(relationTypes, data);

      when(data.getTypeUuid()).thenReturn(TYPE_UUID);
   }

   @Test
   public void testDelete() {
      assertFalse(relation.isDirty());
      relation.delete();

      verify(data).setModType(ModificationType.DELETED);
      when(data.isDirty()).thenReturn(true);
      assertTrue(relation.isDirty());
   }

   @Test
   public void testGetSetRationale() {
      assertFalse(relation.isDirty());
      Mockito.when(data.getRationale()).thenReturn("rationale");

      String rationale = relation.getRationale();

      verify(data).getRationale();
      assertEquals("rationale", rationale);
      assertFalse(relation.isDirty());

      relation.setRationale("new rationale");
      verify(data).setRationale("new rationale");
      verify(data).setModType(ModificationType.MODIFIED);
      when(data.isDirty()).thenReturn(true);
      assertTrue(relation.isDirty());
   }

   @Test
   public void testGetRelationType() throws OseeCoreException {
      relation.getRelationType();

      verify(relationTypes).get(TYPE_UUID);
   }

   @Test
   public void testGetModificationType() {
      relation.getModificationType();
      verify(data).getModType();
   }

   @Test
   public void testGetOrcsData() {
      assertEquals(data, relation.getOrcsData());
   }

   @Test
   public void testDirty() {
      when(data.calculateDirtyState(true)).thenReturn(DirtyState.OTHER_CHANGES);
      when(data.isDirty()).thenReturn(true);
      relation.setDirty();
      assertTrue(relation.isDirty());
      verify(data, times(1)).calculateDirtyState(true);

      when(data.calculateDirtyState(false)).thenReturn(DirtyState.CLEAN);
      when(data.isDirty()).thenReturn(false);
      relation.clearDirty();
      assertFalse(relation.isDirty());
      verify(data, times(1)).calculateDirtyState(false);
   }

   @Test
   public void testGetLocalIdForSide() {
      when(data.getArtIdOn(RelationSide.SIDE_A)).thenReturn(45);
      when(data.getArtIdOn(RelationSide.SIDE_B)).thenReturn(33);

      assertEquals(45, relation.getLocalIdForSide(RelationSide.SIDE_A).intValue());
      assertEquals(33, relation.getLocalIdForSide(RelationSide.SIDE_B).intValue());
   }

   @Test
   public void testIsDeleteD() {
      when(data.getModType()).thenReturn(ModificationType.ARTIFACT_DELETED);
      assertTrue(relation.isDeleted());

      when(data.getModType()).thenReturn(ModificationType.DELETED);
      assertTrue(relation.isDeleted());

      when(data.getModType()).thenReturn(ModificationType.MODIFIED);
      assertFalse(relation.isDeleted());
   }

   @Test
   public void testIsOfType() throws OseeCoreException {
      IRelationType type1 = mock(IRelationType.class);
      IRelationType type2 = mock(IRelationType.class);

      when(relationTypes.get(TYPE_UUID)).thenReturn(type1);

      assertTrue(relation.isOfType(type1));
      assertFalse(relation.isOfType(type2));
   }

}

Back to the top