summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/pom.xml21
-rw-r--r--openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoFactoryImpl.java3
-rw-r--r--openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImpl.java14
-rw-r--r--openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/test/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImplTest.java134
4 files changed, 165 insertions, 7 deletions
diff --git a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/pom.xml b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/pom.xml
index 62b4b1c52b..63bbd5791d 100644
--- a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/pom.xml
+++ b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/pom.xml
@@ -9,6 +9,10 @@
<version>1.5.1-SNAPSHOT</version>
</parent>
+ <properties>
+ <groove-all.version>2.4.10</groove-all.version>
+ </properties>
+
<artifactId>openecomp-conflict-core</artifactId>
<dependencies>
<dependency>
@@ -31,5 +35,22 @@
<artifactId>openecomp-sdc-vendor-license-core</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>${groove-all.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoFactoryImpl.java b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoFactoryImpl.java
index 23c90a9044..1ae13b8c48 100644
--- a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoFactoryImpl.java
@@ -24,11 +24,12 @@ package org.openecomp.conflicts.dao.impl.zusammen;
import org.openecomp.conflicts.dao.ConflictsDao;
import org.openecomp.conflicts.dao.ConflictsDaoFactory;
import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
+import org.openecomp.core.zusammen.api.ZusammenUtil;
public class ConflictsDaoFactoryImpl extends ConflictsDaoFactory {
private static final ConflictsDao INSTANCE = new
- ConflictsDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface());
+ ConflictsDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface(), ZusammenUtil::createSessionContext);
@Override
public ConflictsDao createInterface() {
diff --git a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImpl.java b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImpl.java
index 713f193ddf..ecc0a3c7ab 100644
--- a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImpl.java
+++ b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/main/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImpl.java
@@ -29,6 +29,7 @@ import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.Item;
import com.amdocs.zusammen.datatypes.item.ItemVersion;
import com.amdocs.zusammen.datatypes.item.Resolution;
+import java.util.function.Supplier;
import org.openecomp.conflicts.dao.ConflictsDao;
import org.openecomp.conflicts.types.Conflict;
import org.openecomp.conflicts.types.ConflictResolution;
@@ -41,20 +42,21 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.*;
import org.openecomp.sdc.versioning.dao.types.Version;
import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
public class ConflictsDaoImpl implements ConflictsDao {
private final ZusammenAdaptor zusammenAdaptor;
+ private final Supplier<SessionContext> sessionContextProvider;
- public ConflictsDaoImpl(ZusammenAdaptor zusammenAdaptor) {
+ public ConflictsDaoImpl(ZusammenAdaptor zusammenAdaptor, Supplier<SessionContext> sessionContextProvider) {
this.zusammenAdaptor = zusammenAdaptor;
+ this.sessionContextProvider = sessionContextProvider;
}
@Override
public boolean isConflicted(String itemId, Version version) {
com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict itemVersionConflict =
zusammenAdaptor
- .getVersionConflict(createSessionContext(), new Id(itemId), new Id(version.getId()));
+ .getVersionConflict(sessionContextProvider.get(), new Id(itemId), new Id(version.getId()));
return !(itemVersionConflict == null
|| (itemVersionConflict.getVersionDataConflict() == null
&& itemVersionConflict.getElementConflictInfos().isEmpty()));
@@ -64,12 +66,12 @@ public class ConflictsDaoImpl implements ConflictsDao {
public ItemVersionConflict getConflict(String itemId, Version version) {
return new ItemVersionConflictConvertorFromZusammen().convert(itemId, version,
zusammenAdaptor
- .getVersionConflict(createSessionContext(), new Id(itemId), new Id(version.getId())));
+ .getVersionConflict(sessionContextProvider.get(), new Id(itemId), new Id(version.getId())));
}
@Override
public Conflict getConflict(String itemId, Version version, String conflictId) {
- return zusammenAdaptor.getElementConflict(createSessionContext(),
+ return zusammenAdaptor.getElementConflict(sessionContextProvider.get(),
new ElementContext(new Id(itemId), new Id(version.getId())), new Id(conflictId))
.map(elementConflict -> convertElementConflict(conflictId, elementConflict))
.orElse(null);
@@ -78,7 +80,7 @@ public class ConflictsDaoImpl implements ConflictsDao {
@Override
public void resolveConflict(String itemId, Version version, String conflictId,
ConflictResolution conflictResolution) {
- SessionContext context = createSessionContext();
+ SessionContext context = sessionContextProvider.get();
ElementContext elementContext = new ElementContext(new Id(itemId), new Id(version.getId()));
// TODO: 7/31/2017 when 'OTHER' resolution will be supported - populate zusammen element with it
diff --git a/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/test/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImplTest.java b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/test/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImplTest.java
new file mode 100644
index 0000000000..cb912642bd
--- /dev/null
+++ b/openecomp-be/lib/openecomp-conflict-lib/openecomp-conflict-core/src/test/java/org/openecomp/conflicts/dao/impl/zusammen/ConflictsDaoImplTest.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.conflicts.dao.impl.zusammen;
+
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflictInfo;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict;
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.item.ElementContext;
+import com.amdocs.zusammen.datatypes.item.Info;
+import com.amdocs.zusammen.datatypes.item.ItemVersionDataConflict;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.function.Supplier;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.conflicts.types.Conflict;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.types.ElementPropertyName;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class ConflictsDaoImplTest {
+
+ private static final String ITEM_ID = "itemId";
+ private static final String CONFLICT_ID = "conflictId";
+ private static final Object PROPERTY = "itemVersion";
+
+ @Mock
+ private ZusammenAdaptor zusammenAdaptor;
+ @Mock
+ private Version version;
+ @Mock
+ private Supplier<SessionContext> sessionContextSupplier;
+ @Mock
+ private SessionContext sessionContext;
+ @Mock
+ private ItemVersionConflict itemVersionConflict;
+ @Mock
+ private ItemVersionDataConflict versionDataConflict;
+ @Mock
+ private Collection<ElementConflictInfo> conflictsInfos;
+ @Mock
+ private Element element;
+ @Mock
+ private Info info;
+
+
+ @Test
+ public void shouldItemBeConflicted() {
+ ConflictsDaoImpl conflictsDao = new ConflictsDaoImpl(zusammenAdaptor, sessionContextSupplier);
+ Mockito.when(sessionContextSupplier.get()).thenReturn(sessionContext);
+ Mockito.when(zusammenAdaptor
+ .getVersionConflict(Mockito.any(SessionContext.class), Mockito.any(Id.class), Mockito.any(Id.class)))
+ .thenReturn(itemVersionConflict);
+ Mockito.when(itemVersionConflict.getVersionDataConflict()).thenReturn(versionDataConflict);
+ Mockito.when(itemVersionConflict.getElementConflictInfos()).thenReturn(conflictsInfos);
+
+ boolean conflicted = conflictsDao.isConflicted(ITEM_ID, version);
+ Assert.assertTrue(conflicted);
+ }
+
+ @Test
+ public void shouldItemBeNotConflicted() {
+ ConflictsDaoImpl conflictsDao = new ConflictsDaoImpl(zusammenAdaptor, sessionContextSupplier);
+ Mockito.when(sessionContextSupplier.get()).thenReturn(sessionContext);
+ Mockito.when(zusammenAdaptor
+ .getVersionConflict(Mockito.any(SessionContext.class), Mockito.any(Id.class), Mockito.any(Id.class)))
+ .thenReturn(itemVersionConflict);
+ Mockito.when(itemVersionConflict.getVersionDataConflict()).thenReturn(null);
+
+ boolean conflicted = conflictsDao.isConflicted(ITEM_ID, version);
+ Assert.assertFalse(conflicted);
+ }
+
+ @Test
+ public void shouldGetItemVersionConflict() {
+ ConflictsDaoImpl conflictsDao = new ConflictsDaoImpl(zusammenAdaptor, sessionContextSupplier);
+ Mockito.when(sessionContextSupplier.get()).thenReturn(sessionContext);
+ Mockito.when(zusammenAdaptor
+ .getVersionConflict(Mockito.any(SessionContext.class), Mockito.any(Id.class), Mockito.any(Id.class)))
+ .thenReturn(itemVersionConflict);
+ Mockito.when(itemVersionConflict.getVersionDataConflict()).thenReturn(versionDataConflict);
+ Mockito.when(itemVersionConflict.getElementConflictInfos()).thenReturn(conflictsInfos);
+ org.openecomp.conflicts.types.ItemVersionConflict conflict = conflictsDao.getConflict(ITEM_ID, version);
+ Assert.assertNotNull(conflict);
+ }
+
+ @Test
+ public void shouldGetConflict() {
+ ConflictsDaoImpl conflictsDao = new ConflictsDaoImpl(zusammenAdaptor, sessionContextSupplier);
+ Mockito.when(sessionContextSupplier.get()).thenReturn(sessionContext);
+ Optional<ElementConflict> elementConflict = Optional.ofNullable(getElementConflict());
+ Mockito.when(zusammenAdaptor
+ .getElementConflict(Mockito.any(SessionContext.class), Mockito.any(ElementContext.class),
+ Mockito.any(Id.class))).thenReturn(elementConflict);
+ Mockito.when(itemVersionConflict.getVersionDataConflict()).thenReturn(versionDataConflict);
+ Mockito.when(itemVersionConflict.getElementConflictInfos()).thenReturn(conflictsInfos);
+ Conflict conflict = conflictsDao.getConflict(ITEM_ID, version, CONFLICT_ID);
+ Assert.assertNotNull(conflict);
+ }
+
+ private ElementConflict getElementConflict() {
+ Mockito.when(element.getInfo()).thenReturn(info);
+ Mockito.when(info.getProperty(ElementPropertyName.elementType.name())).thenReturn(PROPERTY);
+
+ ElementConflict elementConflict = new ElementConflict();
+ elementConflict.setLocalElement(element);
+ return elementConflict;
+ }
+} \ No newline at end of file