1 package org.openecomp.core.zusammen.plugin.collaboration.impl;
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;
20 import java.util.Date;
21 import java.util.HashSet;
22 import java.util.Optional;
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;
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());
39 private ElementStageRepository elementStageRepositoryMock;
41 private ElementStageStoreImpl elementStageStore;
44 public void setUp() throws Exception {
45 MockitoAnnotations.initMocks(this);
46 when(elementStageStore.getElementStageRepository(anyObject()))
47 .thenReturn(elementStageRepositoryMock);
51 public void testListIds() throws Exception {
56 public void testGet() throws Exception {
61 public void testGetConflicted() throws Exception {
66 public void testHasConflicts() throws Exception {
71 public void testListConflictedDescriptors() throws Exception {
76 public void testCreate() throws Exception {
81 public void testDelete() throws Exception {
86 public void testResolveConflictWhenNotStaged() throws Exception {
87 doReturn(Optional.empty())
88 .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
90 .resolveConflict(context, elementContext, new ElementEntity(new Id()), Resolution.YOURS);
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());
101 .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);
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);
112 doReturn(Optional.of(stagedElement))
113 .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
116 .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);
118 verify(elementStageRepositoryMock).markAsNotConflicted(same(context),
119 eq(new ElementEntityContext(USER.getUserName(), elementContext)),
120 same(stagedElement.getEntity()), same(Action.IGNORE));
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);
139 doReturn(Optional.of(stagedElement))
140 .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
143 .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);
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));
158 public void testResolveConflictByTheirs() throws Exception {
163 public void testResolveConflictByTheirsWithRelated() throws Exception {