summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2017-12-25 15:05:31 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-25 14:24:44 +0000
commit05c625fb9c3673d6c60511958f7e051257247c2b (patch)
tree28df153c7f9bdfd5b5682a6ff4cbeced23f30d3c /openecomp-be/lib
parent22f1220c2dda43e3dcbadd70180db521a7984d1d (diff)
Refactor list revisions api
Remove zusammen-api dependency in versioning-api, enhance version zusammen dao impl UT. Issue-ID: SDC-779 Change-Id: Ic792462eac52f1f5129f92ce80d3deb641c90916 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/pom.xml5
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java11
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java75
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java23
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java33
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/TestUtil.java14
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java252
7 files changed, 272 insertions, 141 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/pom.xml
index ee59b5bf77..a1337f6c95 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/pom.xml
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/pom.xml
@@ -24,11 +24,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.openecomp.sdc</groupId>
- <artifactId>openecomp-sdc-versioning-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
<groupId>org.openecomp.sdc.core</groupId>
<artifactId>openecomp-facade-api</artifactId>
<version>${project.version}</version>
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java
index 35c07cbee0..694c35ebbe 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java
@@ -15,11 +15,10 @@ import com.amdocs.zusammen.datatypes.item.ItemVersion;
import com.amdocs.zusammen.datatypes.item.ItemVersionData;
import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
import com.amdocs.zusammen.datatypes.item.Resolution;
+import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import com.amdocs.zusammen.datatypes.itemversion.Tag;
-import org.openecomp.sdc.versioning.dao.types.Revision;
import java.util.Collection;
-import java.util.List;
import java.util.Optional;
public interface ZusammenAdaptor {
@@ -95,11 +94,11 @@ public interface ZusammenAdaptor {
void resolveElementConflict(SessionContext context, ElementContext elementContext,
ZusammenElement element, Resolution resolution);
- Collection<HealthInfo> checkHealth(SessionContext context);
+ void revert(SessionContext context, Id itemId, Id versionId, Id revisionId);
- String getVersion(SessionContext context);
+ ItemVersionRevisions listRevisions(SessionContext context, Id itemId, Id versionId);
- void revert(SessionContext sessionContext, String itemId, String versionId, String revisionId);
+ Collection<HealthInfo> checkHealth(SessionContext context);
- List<Revision> listRevisions(SessionContext sessionContext, String itemId, String versionId);
+ String getVersion(SessionContext context);
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java
index 9bdbfd681c..6f4352b10e 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java
@@ -20,11 +20,9 @@ import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import com.amdocs.zusammen.datatypes.itemversion.Tag;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.core.zusammen.db.ZusammenConnector;
-import org.openecomp.sdc.versioning.dao.types.Revision;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
@@ -108,7 +106,8 @@ public class ZusammenAdaptorImpl implements ZusammenAdaptor {
}
@Override
- public Optional<ElementConflict> getElementConflict(SessionContext context, ElementContext elementContext,
+ public Optional<ElementConflict> getElementConflict(SessionContext context,
+ ElementContext elementContext,
Id elementId) {
return Optional.ofNullable(connector.getElementConflict(context, elementContext, elementId));
}
@@ -184,7 +183,7 @@ public class ZusammenAdaptorImpl implements ZusammenAdaptor {
@Override
public Optional<ItemVersion> getFirstVersion(SessionContext context, Id itemId) {
Collection<ItemVersion> versions = connector.listPublicVersions(context, itemId);
- if (versions == null || versions.size() == 0) {
+ if (versions == null || versions.isEmpty()) {
return Optional.empty();
}
List<ItemVersion> itemVersions = new ArrayList<>(versions);
@@ -242,18 +241,6 @@ public class ZusammenAdaptorImpl implements ZusammenAdaptor {
connector.resetVersionHistory(context, itemId, versionId, changeRef);
}
- /*@Override
- public void revertVersionToRevision(SessionContext context, Id itemId, Id versionId,
- Id revisionId) {
- connector.resetVersionRevision(context, itemId, versionId, revisionId);
- }*/
-
- /*@Override
- public ItemVersionRevisions listVersionRevisions(SessionContext context, Id itemId, Id
- versionId) {
- return connector.listVersionRevisions(context, itemId, versionId);
- }*/
-
@Override
public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) {
connector.publishVersion(context, itemId, versionId, message);
@@ -270,63 +257,23 @@ public class ZusammenAdaptorImpl implements ZusammenAdaptor {
}
@Override
- public Collection<HealthInfo> checkHealth(SessionContext context) {
- return connector.checkHealth(context);
+ public void revert(SessionContext context, Id itemId, Id versionId, Id revisionId) {
+ connector.revertVersionRevision(context, itemId, versionId, revisionId);
}
@Override
- public String getVersion(SessionContext sessionContext) {
- return connector.getVersion(sessionContext);
+ public ItemVersionRevisions listRevisions(SessionContext context, Id itemId, Id versionId) {
+ return connector.listVersionRevisions(context, itemId, versionId);
}
@Override
- public void revert(SessionContext sessionContext, String itemId, String versionId,
- String revisionId) {
- connector.revertVersionRevision(sessionContext, new Id(itemId), new Id(versionId),
- new Id(revisionId));
+ public Collection<HealthInfo> checkHealth(SessionContext context) {
+ return connector.checkHealth(context);
}
@Override
- public List<Revision> listRevisions(SessionContext sessionContext, String itemId,
- String versionId) {
- List<Revision> revisions = new ArrayList<>();
- ItemVersionRevisions itemVersionRevisions =
- connector.listVersionRevisions(sessionContext, new Id(itemId), new Id
- (versionId));
- if(itemVersionRevisions == null || itemVersionRevisions.getItemVersionRevisions()==null ||
- itemVersionRevisions.getItemVersionRevisions().size()==0) {
- return revisions;
- }
- else{
- revisions = itemVersionRevisions.getItemVersionRevisions().stream().map
- (revision -> {
- Revision rev = new Revision();
- rev.setId(revision.getRevisionId().getValue());
- rev.setTime(revision.getTime());
- rev.setUser(revision.getUser());
- rev.setMessage(revision.getMessage());
- return rev;
- }).collect(Collectors.toList());
- revisions.sort(new Comparator<Revision>() {
- @Override
- public int compare(Revision o1, Revision o2) {
- if(o1.getTime().before(o2.getTime())) return 1;
- else return -1;
- }
- });
- // when creating a new item an initial version is created with
- // invalid data. this revision is not an applicable revision.
- //the logic of identifying this revision is:
- //1- only the first version of item has this issue
- //2- only in the first item version there are 2 revisions created
- //3- the second revision is in format "Initial {vlm/vsp}: {name of the vlm/vsp}
- //4- only if a revision in this format exists we remove the first revision.
- if(revisions.size()>1 && revisions.get(revisions.size()-2).getMessage().matches("Initial " +
- ".*:.*")){
- revisions.remove(revisions.size()-1);
- }
- return revisions;
- }
+ public String getVersion(SessionContext context) {
+ return connector.getVersion(context);
}
private static void sortItemVersionListByModificationTimeDescOrder(
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java
index 4690d75a68..418da9a770 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java
@@ -36,6 +36,7 @@ import com.amdocs.zusammen.datatypes.item.ItemVersion;
import com.amdocs.zusammen.datatypes.item.ItemVersionData;
import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
import com.amdocs.zusammen.datatypes.item.Resolution;
+import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import com.amdocs.zusammen.datatypes.itemversion.Tag;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.core.utilities.file.FileContentHandler;
@@ -46,7 +47,6 @@ import org.openecomp.sdc.model.impl.zusammen.ServiceModelDaoZusammenImpl;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.tosca.services.YamlUtil;
-import org.openecomp.sdc.versioning.dao.types.Revision;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -55,7 +55,6 @@ import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -255,7 +254,7 @@ public class ServiceModelDaoFactoryTest {
ElementContext elementContext,
Id parentElementId, String elementName) {
- if(elementName.equals(ElementType.VspModel.name())){
+ if (elementName.equals(ElementType.VspModel.name())) {
return elementInfoMap.values();
}
@@ -267,11 +266,11 @@ public class ServiceModelDaoFactoryTest {
ElementContext elementContext,
Id parentElementId, String elementName) {
- if(elementName.equals(ElementType.Templates.name())){
- return Optional.ofNullable(elementInfoMap.get("null" + elementName));
- }else if(elementName.equals(ElementType.Artifacts.name())) {
- return Optional.ofNullable(elementInfoMap.get("null" + elementName));
- }
+ if (elementName.equals(ElementType.Templates.name())) {
+ return Optional.ofNullable(elementInfoMap.get("null" + elementName));
+ } else if (elementName.equals(ElementType.Artifacts.name())) {
+ return Optional.ofNullable(elementInfoMap.get("null" + elementName));
+ }
return Optional.empty();
}
@@ -382,14 +381,14 @@ public class ServiceModelDaoFactoryTest {
}
@Override
- public void revert(SessionContext sessionContext, String itemId, String versionId,
- String revisionId) {
+ public void revert(SessionContext sessionContext, Id itemId, Id versionId,
+ Id revisionId) {
}
@Override
- public List<Revision> listRevisions(SessionContext sessionContext, String itemId,
- String versionId) {
+ public ItemVersionRevisions listRevisions(SessionContext sessionContext, Id itemId,
+ Id versionId) {
return null;
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java
index 195973bf5c..32c17dbfce 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java
@@ -7,6 +7,7 @@ import com.amdocs.zusammen.datatypes.item.ItemVersion;
import com.amdocs.zusammen.datatypes.item.ItemVersionData;
import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
import com.amdocs.zusammen.datatypes.item.SynchronizationStatus;
+import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
@@ -18,6 +19,7 @@ import org.openecomp.sdc.versioning.dao.types.SynchronizationState;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionState;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -110,18 +112,27 @@ public class VersionZusammenDaoImpl implements VersionDao {
@Override
public void revert(String itemId, Version version, String revisionId) {
- zusammenAdaptor.revert(createSessionContext(), itemId, version.getId(), revisionId);
+ zusammenAdaptor.revert(createSessionContext(), new Id(itemId), new Id(version.getId()),
+ new Id(revisionId));
}
@Override
public List<Revision> listRevisions(String itemId, Version version) {
- return zusammenAdaptor.listRevisions(createSessionContext(), itemId, version.getId());
+ ItemVersionRevisions itemVersionRevisions = zusammenAdaptor
+ .listRevisions(createSessionContext(), new Id(itemId), new Id(version.getId()));
+
+ return itemVersionRevisions == null || itemVersionRevisions.getItemVersionRevisions() == null ||
+ itemVersionRevisions.getItemVersionRevisions().isEmpty()
+ ? new ArrayList<>()
+ : itemVersionRevisions.getItemVersionRevisions().stream()
+ .map(this::convertRevision)
+ .sorted(this::compareRevisionsTime)
+ .collect(Collectors.toList());
}
private void updateVersionStatus(SessionContext context, Id itemId, Id versionId,
VersionState versionState, ItemVersion itemVersion) {
- if (versionState.getSynchronizationState() != SynchronizationState.UpToDate ||
- versionState.isDirty()) {
+ if (versionState.getSynchronizationState() != SynchronizationState.UpToDate) {
String versionStatus = zusammenAdaptor.getPublicVersion(context, itemId, versionId)
.getData().getInfo().getProperty(ZusammenProperty.STATUS);
itemVersion.getData().getInfo().addProperty(ZusammenProperty.STATUS, versionStatus);
@@ -162,4 +173,18 @@ public class VersionZusammenDaoImpl implements VersionDao {
.withMessage("Version state is unknown").build());
}
}
+
+ private Revision convertRevision(
+ com.amdocs.zusammen.datatypes.itemversion.Revision zusammenRevision) {
+ Revision revision = new Revision();
+ revision.setId(zusammenRevision.getRevisionId().getValue());
+ revision.setTime(zusammenRevision.getTime());
+ revision.setUser(zusammenRevision.getUser());
+ revision.setMessage(zusammenRevision.getMessage());
+ return revision;
+ }
+
+ private int compareRevisionsTime(Revision revision1, Revision revision2) {
+ return revision1.getTime().before(revision2.getTime()) ? 1 : -1;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/TestUtil.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/TestUtil.java
new file mode 100644
index 0000000000..232ded05b1
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/TestUtil.java
@@ -0,0 +1,14 @@
+package org.openecomp.sdc.versioning.dao.impl.zusammen;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.UserInfo;
+
+public class TestUtil {
+
+ public static SessionContext createZusammenContext(String user) {
+ SessionContext sessionContext = new SessionContext();
+ sessionContext.setUser(new UserInfo(user));
+ sessionContext.setTenant("dox");
+ return sessionContext;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java
index 1f1efdf6cb..76e1fe56b6 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java
@@ -2,35 +2,37 @@ package org.openecomp.sdc.versioning.dao.impl.zusammen;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
-import com.amdocs.zusammen.datatypes.UserInfo;
import com.amdocs.zusammen.datatypes.item.Info;
import com.amdocs.zusammen.datatypes.item.ItemVersion;
import com.amdocs.zusammen.datatypes.item.ItemVersionData;
import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
import com.amdocs.zusammen.datatypes.item.SynchronizationStatus;
+import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.versioning.dao.types.Revision;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
+import static org.openecomp.sdc.versioning.dao.impl.zusammen.TestUtil.createZusammenContext;
public class VersionZusammenDaoImplTest {
@@ -47,6 +49,18 @@ public class VersionZusammenDaoImplTest {
}
@Test
+ public void testListWhenNone() throws Exception {
+ String itemId = "itemId";
+
+ doReturn(new ArrayList<>()).when(zusammenAdaptorMock)
+ .listPublicVersions(eq(createZusammenContext(USER)), eq(new Id(itemId)));
+
+ List<Version> versions = versionDao.list(itemId);
+
+ Assert.assertTrue(versions.isEmpty());
+ }
+
+ @Test
public void testList() throws Exception {
String itemId = "itemId";
Id versionId1 = new Id("v1_id");
@@ -55,12 +69,12 @@ public class VersionZusammenDaoImplTest {
List<ItemVersion> zusammenVersions = Stream.of(
createZusammenVersion(versionId1, null, "version desc", "1.0", VersionStatus.Certified),
- createZusammenVersion(versionId2, versionId1, "version desc", "2.0", VersionStatus.Certified
- ),
+ createZusammenVersion(versionId2, versionId1, "version desc", "2.0",
+ VersionStatus.Certified),
createZusammenVersion(versionId3, versionId2, "version desc", "3.0", VersionStatus.Draft))
.collect(Collectors.toList());
doReturn(zusammenVersions).when(zusammenAdaptorMock)
- .listPublicVersions(eq(createZusammenContext()), eq(new Id(itemId)));
+ .listPublicVersions(eq(createZusammenContext(USER)), eq(new Id(itemId)));
List<Version> versions = versionDao.list(itemId);
Assert.assertEquals(versions.size(), 3);
@@ -72,7 +86,7 @@ public class VersionZusammenDaoImplTest {
: versionId2.getValue().equals(version.getId())
? 1
: 2;
- assetVersionEquals(version, zusammenVersions.get(zusammenVersionIndex));
+ assetVersionEquals(version, zusammenVersions.get(zusammenVersionIndex), null);
}
}
@@ -94,20 +108,20 @@ public class VersionZusammenDaoImplTest {
version.setDescription("version description");
version.setStatus(VersionStatus.Draft);
- doReturn(new Id("versionId")).when(zusammenAdaptorMock)
- .createVersion(eq(createZusammenContext()), eq(new Id(itemId)),
- baseId == null ? isNull(Id.class) : eq(new Id(baseId)), any(ItemVersionData.class));
-
ArgumentCaptor<ItemVersionData> capturedZusammenVersion =
ArgumentCaptor.forClass(ItemVersionData.class);
- versionDao.create(itemId, version);
-
- verify(zusammenAdaptorMock)
- .createVersion(eq(createZusammenContext()), eq(new Id(itemId)),
+ String versionId = "versionId";
+ doReturn(new Id(versionId)).when(zusammenAdaptorMock)
+ .createVersion(eq(createZusammenContext(USER)), eq(new Id(itemId)),
baseId == null ? isNull(Id.class) : eq(new Id(baseId)),
capturedZusammenVersion.capture());
+
+ versionDao.create(itemId, version);
+
+ Assert.assertEquals(version.getId(), versionId);
+
Info capturedInfo = capturedZusammenVersion.getValue().getInfo();
Assert.assertEquals(capturedInfo.getName(), version.getName());
Assert.assertEquals(capturedInfo.getDescription(), version.getDescription());
@@ -134,8 +148,8 @@ public class VersionZusammenDaoImplTest {
versionDao.update(itemId, version);
verify(zusammenAdaptorMock)
- .updateVersion(eq(createZusammenContext()), eq(new Id(itemId)), eq(new Id(version.getId())),
- capturedZusammenVersion.capture());
+ .updateVersion(eq(createZusammenContext(USER)), eq(new Id(itemId)),
+ eq(new Id(version.getId())), capturedZusammenVersion.capture());
Info capturedInfo = capturedZusammenVersion.getValue().getInfo();
Assert.assertEquals(capturedInfo.getName(), version.getName());
@@ -155,11 +169,11 @@ public class VersionZusammenDaoImplTest {
}
@Test
- public void testGet() throws Exception {
+ public void testGetSynced() throws Exception {
String itemId = "itemId";
String versionId = "versionId";
- SessionContext zusammenContext = createZusammenContext();
+ SessionContext zusammenContext = createZusammenContext(USER);
Id itemIdObj = new Id(itemId);
Id versionIdObj = new Id(versionId);
@@ -169,13 +183,41 @@ public class VersionZusammenDaoImplTest {
doReturn(zusammenPrivateVersion).when(zusammenAdaptorMock)
.getVersion(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
- doReturn(new ItemVersionStatus(SynchronizationStatus.UP_TO_DATE, true))
- .when(zusammenAdaptorMock)
+ ItemVersionStatus zusammenVersionStatus =
+ new ItemVersionStatus(SynchronizationStatus.UP_TO_DATE, true);
+ doReturn(zusammenVersionStatus).when(zusammenAdaptorMock)
.getVersionStatus(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+ Optional<Version> version = versionDao.get(itemId, new Version(versionId));
+
+ Assert.assertTrue(version.isPresent());
+ assetVersionEquals(version.get(), zusammenPrivateVersion, zusammenVersionStatus);
+ }
+
+ @Test
+ public void testGetOutOfSync() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+
+ SessionContext zusammenContext = createZusammenContext(USER);
+ Id itemIdObj = new Id(itemId);
+ Id versionIdObj = new Id(versionId);
+
+ ItemVersion zusammenPrivateVersion =
+ createZusammenVersion(versionIdObj, new Id("baseId"), "version desc updated", "2.0",
+ VersionStatus.Draft);
+ doReturn(zusammenPrivateVersion).when(zusammenAdaptorMock)
+ .getVersion(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ ItemVersionStatus zusammenVersionStatus =
+ new ItemVersionStatus(SynchronizationStatus.OUT_OF_SYNC, true);
+ doReturn(zusammenVersionStatus).when(zusammenAdaptorMock)
+ .getVersionStatus(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ VersionStatus statusOnPublic = VersionStatus.Certified;
ItemVersion zusammenPublicVersion =
createZusammenVersion(versionIdObj, new Id("baseId"), "version desc", "2.0",
- VersionStatus.Certified);
+ statusOnPublic);
doReturn(zusammenPublicVersion).when(zusammenAdaptorMock)
.getPublicVersion(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
@@ -183,58 +225,129 @@ public class VersionZusammenDaoImplTest {
Assert.assertTrue(version.isPresent());
zusammenPrivateVersion.getData().getInfo()
- .addProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS,
- VersionStatus.Certified.name());
- assetVersionEquals(version.get(), zusammenPrivateVersion);
+ .addProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS, statusOnPublic.name());
+ assetVersionEquals(version.get(), zusammenPrivateVersion, zusammenVersionStatus);
}
- // TODO: 12/20/2017 complete tests
- /* @Test
- public void testDelete() throws Exception {
+ @Test
+ public void testGetMerging() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+
+ SessionContext zusammenContext = createZusammenContext(USER);
+ Id itemIdObj = new Id(itemId);
+ Id versionIdObj = new Id(versionId);
+
+ ItemVersion zusammenPrivateVersion =
+ createZusammenVersion(versionIdObj, new Id("baseId"), "version desc", "2.0",
+ VersionStatus.Draft);
+ doReturn(zusammenPrivateVersion).when(zusammenAdaptorMock)
+ .getVersion(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ ItemVersionStatus zusammenVersionStatus =
+ new ItemVersionStatus(SynchronizationStatus.MERGING, true);
+ doReturn(zusammenVersionStatus).when(zusammenAdaptorMock)
+ .getVersionStatus(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+ ItemVersion zusammenPublicVersion =
+ createZusammenVersion(versionIdObj, new Id("baseId"), "version desc", "2.0",
+ VersionStatus.Draft);
+ doReturn(zusammenPublicVersion).when(zusammenAdaptorMock)
+ .getPublicVersion(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ Optional<Version> version = versionDao.get(itemId, new Version(versionId));
+
+ Assert.assertTrue(version.isPresent());
+ assetVersionEquals(version.get(), zusammenPrivateVersion, zusammenVersionStatus);
}
@Test
public void testPublish() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ String message = "publish message";
+
+ versionDao.publish(itemId, new Version(versionId), message);
+ verify(zusammenAdaptorMock)
+ .publishVersion(eq(createZusammenContext(USER)), eq(new Id(itemId)), eq(new Id(versionId)),
+ eq(message));
}
@Test
public void testSync() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+
+ versionDao.sync(itemId, new Version(versionId));
+ verify(zusammenAdaptorMock)
+ .syncVersion(eq(createZusammenContext(USER)), eq(new Id(itemId)), eq(new Id(versionId)));
}
@Test
public void testForceSync() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+
+ versionDao.forceSync(itemId, new Version(versionId));
+ verify(zusammenAdaptorMock)
+ .forceSyncVersion(eq(createZusammenContext(USER)), eq(new Id(itemId)),
+ eq(new Id(versionId)));
}
@Test
public void testRevert() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ String revisionId = "revisionId";
+
+ versionDao.revert(itemId, new Version(versionId), revisionId);
+ verify(zusammenAdaptorMock)
+ .revert(eq(createZusammenContext(USER)), eq(new Id(itemId)), eq(new Id(versionId)),
+ eq(new Id(revisionId)));
}
@Test
- public void testListRevisions() throws Exception {
+ public void testListRevisionsWhenNone() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
- }*/
+ List<Revision> revisions = versionDao.listRevisions(itemId, new Version(versionId));
- private void assetVersionEquals(Version version, ItemVersion zusammenVersion) {
- Assert.assertEquals(version.getId(), zusammenVersion.getId().getValue());
- Assert.assertEquals(version.getBaseId(),
- zusammenVersion.getBaseId() == null ? null : zusammenVersion.getBaseId().getValue());
- Info info = zusammenVersion.getData().getInfo();
- Assert.assertEquals(version.getName(), info.getName());
- Assert.assertEquals(version.getDescription(), info.getDescription());
- Assert.assertEquals(version.getStatus(),
- VersionStatus.valueOf(info.getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)));
- String label = info.getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL).toString();
- Assert
- .assertEquals(version.getMajor(), Integer.parseInt(label.substring(0, label.indexOf('.'))));
- Assert.assertEquals(version.getMinor(),
- Integer.parseInt(label.substring(label.indexOf('.') + 1, label.length())));
- Assert.assertEquals(version.getCreationTime(), zusammenVersion.getCreationTime());
- Assert.assertEquals(version.getModificationTime(), zusammenVersion.getModificationTime());
+ Assert.assertTrue(revisions.isEmpty());
+ }
+
+ @Test
+ public void testListRevisions() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+
+ long currentTime = System.currentTimeMillis();
+ Date rev4time = new Date(currentTime); // latest
+ Date rev3time = new Date(currentTime - 1);
+ Date rev2time = new Date(currentTime - 2);
+ Date rev1time = new Date(currentTime - 3); // oldest
+ List<com.amdocs.zusammen.datatypes.itemversion.Revision> zusammenRevisions = Stream.of(
+ createZusammenRevision("rev4", "forth rev", "user1", rev4time),
+ createZusammenRevision("rev1", "first rev", "user2", rev1time),
+ createZusammenRevision("rev3", "third rev", "user2", rev3time),
+ createZusammenRevision("rev2", "second rev", "user1", rev2time))
+ .collect(Collectors.toList());
+ ItemVersionRevisions toBeReturned = new ItemVersionRevisions();
+ toBeReturned.setItemVersionRevisions(zusammenRevisions);
+ doReturn(toBeReturned).when(zusammenAdaptorMock)
+ .listRevisions(eq(createZusammenContext(USER)), eq(new Id(itemId)), eq(new Id(versionId)));
+
+ List<Revision> revisions = versionDao.listRevisions(itemId, new Version(versionId));
+
+ Assert.assertEquals(revisions.size(), 4);
+ assertRevisionEquals(revisions.get(0), zusammenRevisions.get(0)); // rev4 - latest
+ assertRevisionEquals(revisions.get(1), zusammenRevisions.get(2)); // rev3
+ assertRevisionEquals(revisions.get(2), zusammenRevisions.get(3)); // rev2
+ assertRevisionEquals(revisions.get(3), zusammenRevisions.get(1)); // rev1 - oldest
}
private ItemVersion createZusammenVersion(Id id, Id baseId, String description, String label,
@@ -255,11 +368,50 @@ public class VersionZusammenDaoImplTest {
return version;
}
- private SessionContext createZusammenContext() {
- SessionContext sessionContext = new SessionContext();
- sessionContext.setUser(new UserInfo(USER));
- sessionContext.setTenant("dox");
- return sessionContext;
+ private void assetVersionEquals(Version version, ItemVersion zusammenVersion,
+ ItemVersionStatus zusammenVersionStatus) {
+ Assert.assertEquals(version.getId(), zusammenVersion.getId().getValue());
+ Assert.assertEquals(version.getBaseId(),
+ zusammenVersion.getBaseId() == null ? null : zusammenVersion.getBaseId().getValue());
+ Info info = zusammenVersion.getData().getInfo();
+ Assert.assertEquals(version.getName(), info.getName());
+ Assert.assertEquals(version.getDescription(), info.getDescription());
+ Assert.assertEquals(version.getStatus(),
+ VersionStatus.valueOf(info.getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)));
+ String label = info.getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL).toString();
+ Assert
+ .assertEquals(version.getMajor(), Integer.parseInt(label.substring(0, label.indexOf('.'))));
+ Assert.assertEquals(version.getMinor(),
+ Integer.parseInt(label.substring(label.indexOf('.') + 1, label.length())));
+ Assert.assertEquals(version.getCreationTime(), zusammenVersion.getCreationTime());
+ Assert.assertEquals(version.getModificationTime(), zusammenVersion.getModificationTime());
+
+ if (zusammenVersionStatus != null) {
+ Assert.assertEquals(version.getState().isDirty(), zusammenVersionStatus.isDirty());
+ Assert.assertEquals(version.getState().getSynchronizationState().toString(),
+ zusammenVersionStatus.getSynchronizationStatus().toString());
+ }
+ }
+
+ private com.amdocs.zusammen.datatypes.itemversion.Revision createZusammenRevision(String id,
+ String message,
+ String user,
+ Date time) {
+ com.amdocs.zusammen.datatypes.itemversion.Revision revision = new com.amdocs.zusammen
+ .datatypes.itemversion.Revision();
+ revision.setRevisionId(new Id(id));
+ revision.setMessage(message);
+ revision.setUser(user);
+ revision.setTime(time);
+ return revision;
}
+ private void assertRevisionEquals(
+ Revision revision,
+ com.amdocs.zusammen.datatypes.itemversion.Revision zusammenRevision) {
+ Assert.assertEquals(revision.getId(), zusammenRevision.getRevisionId().getValue());
+ Assert.assertEquals(revision.getMessage(), zusammenRevision.getMessage());
+ Assert.assertEquals(revision.getUser(), zusammenRevision.getUser());
+ Assert.assertEquals(revision.getTime(), zusammenRevision.getTime());
+ }
} \ No newline at end of file