summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-plugin/src/test/java/org/openecomp/core/zusammen/plugin/collaboration/impl/ElementStageStoreImplTest.java
blob: 7f137b01b088aa54b77f5790106cf51ae077f91f (plain)
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
package org.openecomp.core.zusammen.plugin.collaboration.impl;

import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.UserInfo;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.Resolution;
import com.amdocs.zusammen.plugin.statestore.cassandra.dao.types.ElementEntityContext;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.openecomp.core.zusammen.plugin.collaboration.TestUtils;
import org.openecomp.core.zusammen.plugin.dao.ElementStageRepository;
import org.openecomp.core.zusammen.plugin.dao.types.ElementEntity;
import org.openecomp.core.zusammen.plugin.dao.types.StageEntity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.Date;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class ElementStageStoreImplTest {
  private static final UserInfo USER = new UserInfo("user");
  private static final SessionContext context = TestUtils.createSessionContext(USER, "test");
  private static final ElementContext elementContext =
      TestUtils.createElementContext(new Id(), new Id());

  @Mock
  private ElementStageRepository elementStageRepositoryMock;
  @Spy
  private ElementStageStoreImpl elementStageStore;

  @BeforeMethod
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(elementStageStore.getElementStageRepository(anyObject()))
        .thenReturn(elementStageRepositoryMock);
  }

  @Test
  public void testListIds() throws Exception {

  }

  @Test
  public void testGet() throws Exception {

  }

  @Test
  public void testGetConflicted() throws Exception {

  }

  @Test
  public void testHasConflicts() throws Exception {

  }

  @Test
  public void testListConflictedDescriptors() throws Exception {

  }

  @Test
  public void testCreate() throws Exception {

  }

  @Test
  public void testDelete() throws Exception {

  }

  @Test
  public void testResolveConflictWhenNotStaged() throws Exception {
    doReturn(Optional.empty())
        .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
    elementStageStore
        .resolveConflict(context, elementContext, new ElementEntity(new Id()), Resolution.YOURS);
  }

  @Test
  public void testResolveConflictWhenNotConflicted() throws Exception {
    Id elementId = new Id();
    StageEntity<ElementEntity> stagedElement =
        new StageEntity<>(new ElementEntity(elementId), new Date());
    doReturn(Optional.of(stagedElement))
        .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());
    elementStageStore
        .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);
  }

  @Test
  public void testResolveConflictByYours() throws Exception {
    Id elementId = new Id();
    StageEntity<ElementEntity> stagedElement =
        new StageEntity<>(new ElementEntity(elementId), new Date());
    stagedElement.setAction(Action.UPDATE);
    stagedElement.setConflicted(true);

    doReturn(Optional.of(stagedElement))
        .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());

    elementStageStore
        .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);

    verify(elementStageRepositoryMock).markAsNotConflicted(same(context),
        eq(new ElementEntityContext(USER.getUserName(), elementContext)),
        same(stagedElement.getEntity()), same(Action.IGNORE));
  }

  @Test
  public void testResolveConflictByYoursWithRelated() throws Exception {
    Id elementId = new Id();
    StageEntity<ElementEntity> stagedElement =
        new StageEntity<>(new ElementEntity(elementId), new Date());
    stagedElement.setAction(Action.UPDATE);
    stagedElement.setConflicted(true);
    ElementEntity relatedElement1 = new ElementEntity(new Id());
    ElementEntity relatedElement2 = new ElementEntity(new Id());
    ElementEntity relatedElement3 = new ElementEntity(new Id());
    Set<ElementEntity> relatedElements = new HashSet<>();
    relatedElements.add(relatedElement1);
    relatedElements.add(relatedElement2);
    relatedElements.add(relatedElement3);
    stagedElement.setConflictDependents(relatedElements);

    doReturn(Optional.of(stagedElement))
        .when(elementStageRepositoryMock).get(anyObject(), anyObject(), anyObject());

    elementStageStore
        .resolveConflict(context, elementContext, new ElementEntity(elementId), Resolution.YOURS);

    ElementEntityContext elementEntityContext =
        new ElementEntityContext(USER.getUserName(), elementContext);
    verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext),
        same(stagedElement.getEntity()), same(Action.IGNORE));
    verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext),
        same(relatedElement1), same(Action.IGNORE));
    verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext),
        same(relatedElement2), same(Action.IGNORE));
    verify(elementStageRepositoryMock).markAsNotConflicted(same(context), eq(elementEntityContext),
        same(relatedElement3), same(Action.IGNORE));
  }

  @Test
  public void testResolveConflictByTheirs() throws Exception {

  }

  @Test
  public void testResolveConflictByTheirsWithRelated() throws Exception {

  }

}