Add collaboration feature
[sdc.git] / openecomp-be / lib / openecomp-core-lib / openecomp-zusammen-lib / openecomp-zusammen-plugin / src / test / java / org / openecomp / core / zusammen / plugin / collaboration / impl / ElementStageStoreImplTest.java
1 package org.openecomp.core.zusammen.plugin.collaboration.impl;
2
3 import com.amdocs.zusammen.datatypes.Id;
4 import com.amdocs.zusammen.datatypes.SessionContext;
5 import com.amdocs.zusammen.datatypes.UserInfo;
6 import com.amdocs.zusammen.datatypes.item.Action;
7 import com.amdocs.zusammen.datatypes.item.ElementContext;
8 import com.amdocs.zusammen.datatypes.item.Resolution;
9 import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
10 import org.mockito.Mock;
11 import org.mockito.MockitoAnnotations;
12 import org.mockito.Spy;
13 import org.openecomp.core.zusammen.plugin.collaboration.TestUtils;
14 import org.openecomp.core.zusammen.plugin.dao.ElementStageRepository;
15 import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
16 import org.openecomp.core.zusammen.plugin.dao.types.StageEntity;
17 import org.testng.annotations.BeforeMethod;
18 import org.testng.annotations.Test;
19
20 import java.util.Date;
21 import java.util.HashSet;
22 import java.util.Optional;
23 import java.util.Set;
24
25 import static org.mockito.Matchers.anyObject;
26 import static org.mockito.Matchers.eq;
27 import static org.mockito.Matchers.same;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
31
32 public class ElementStageStoreImplTest {
33   private static final UserInfo USER = new UserInfo("user");
34   private static final SessionContext context = TestUtils.createSessionContext(USER, "test");
35   private static final ElementContext elementContext =
36       TestUtils.createElementContext(new Id(), new Id());
37
38   @Mock
39   private ElementStageRepository elementStageRepositoryMock;
40   @Spy
41   private ElementStageStoreImpl elementStageStore;
42
43   @BeforeMethod
44   public void setUp() throws Exception {
45     MockitoAnnotations.initMocks(this);
46     when(elementStageStore.getElementStageRepository(anyObject()))
47         .thenReturn(elementStageRepositoryMock);
48   }
49
50   @Test
51   public void testListIds() throws Exception {
52
53   }
54
55   @Test
56   public void testGet() throws Exception {
57
58   }
59
60   @Test
61   public void testGetConflicted() throws Exception {
62
63   }
64
65   @Test
66   public void testHasConflicts() throws Exception {
67
68   }
69
70   @Test
71   public void testListConflictedDescriptors() throws Exception {
72
73   }
74
75   @Test
76   public void testCreate() throws Exception {
77
78   }
79
80   @Test
81   public void testDelete() throws Exception {
82
83   }
84
85   @Test
86   public void testResolveConflictWhenNotStaged() throws Exception {
87     doReturn(Optional.empty())
88         .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
89     elementStageStore
90         .resolveConflict(context, elementContext, new ElementEntity(new Id()), Resolution.YOURS);
91   }
92
93   @Test
94   public void testResolveConflictWhenNotConflicted() throws Exception {
95     Id elementId = new Id();
96     StageEntity<ElementEntity> stagedElement =
97         new StageEntity<>(new ElementEntity(elementId), new Date());
98     doReturn(Optional.of(stagedElement))
99         .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
100     elementStageStore
101         .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);
102   }
103
104   @Test
105   public void testResolveConflictByYours() throws Exception {
106     Id elementId = new Id();
107     StageEntity<ElementEntity> stagedElement =
108         new StageEntity<>(new ElementEntity(elementId), new Date());
109     stagedElement.setAction(Action.UPDATE);
110     stagedElement.setConflicted(true);
111
112     doReturn(Optional.of(stagedElement))
113         .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
114
115     elementStageStore
116         .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);
117
118     verify(elementStageRepositoryMock).markAsNotConflicted(same(context),
119         eq(new ElementEntityContext(USER.getUserName(), elementContext)),
120         same(stagedElement.getEntity()), same(Action.IGNORE));
121   }
122
123   @Test
124   public void testResolveConflictByYoursWithRelated() throws Exception {
125     Id elementId = new Id();
126     StageEntity<ElementEntity> stagedElement =
127         new StageEntity<>(new ElementEntity(elementId), new Date());
128     stagedElement.setAction(Action.UPDATE);
129     stagedElement.setConflicted(true);
130     ElementEntity relatedElement1 = new ElementEntity(new Id());
131     ElementEntity relatedElement2 = new ElementEntity(new Id());
132     ElementEntity relatedElement3 = new ElementEntity(new Id());
133     Set<ElementEntity> relatedElements = new HashSet<>();
134     relatedElements.add(relatedElement1);
135     relatedElements.add(relatedElement2);
136     relatedElements.add(relatedElement3);
137     stagedElement.setConflictDependents(relatedElements);
138
139     doReturn(Optional.of(stagedElement))
140         .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
141
142     elementStageStore
143         .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);
144
145     ElementEntityContext elementEntityContext =
146         new ElementEntityContext(USER.getUserName(), elementContext);
147     verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext),
148         same(stagedElement.getEntity()), same(Action.IGNORE));
149     verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext),
150         same(relatedElement1), same(Action.IGNORE));
151     verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext),
152         same(relatedElement2), same(Action.IGNORE));
153     verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext),
154         same(relatedElement3), same(Action.IGNORE));
155   }
156
157   @Test
158   public void testResolveConflictByTheirs() throws Exception {
159
160   }
161
162   @Test
163   public void testResolveConflictByTheirsWithRelated() throws Exception {
164
165   }
166
167 }