aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2017-12-20 14:30:43 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-21 11:12:33 +0000
commit8e9c0653dd6c6862123c9609ae34e1206d86456e (patch)
tree5eeef00ec0677133baa439ca8d7ffd7aca4804b6 /openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test
parent785ebcc95de3e064e843bec04ba7a209d854fc7c (diff)
Add collaboration feature
Issue-ID: SDC-767 Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test')
-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.java265
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java124
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java399
3 files changed, 743 insertions, 45 deletions
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
new file mode 100644
index 0000000000..1f1efdf6cb
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java
@@ -0,0 +1,265 @@
+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 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.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.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;
+
+public class VersionZusammenDaoImplTest {
+
+ private static final String USER = "user1";
+ @Mock
+ private ZusammenAdaptor zusammenAdaptorMock;
+ @InjectMocks
+ private VersionZusammenDaoImpl versionDao;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ SessionContextProviderFactory.getInstance().createInterface().create(USER);
+ }
+
+ @Test
+ public void testList() throws Exception {
+ String itemId = "itemId";
+ Id versionId1 = new Id("v1_id");
+ Id versionId2 = new Id("v2_id");
+ Id versionId3 = new Id("v3_id");
+
+ List<ItemVersion> zusammenVersions = Stream.of(
+ createZusammenVersion(versionId1, null, "version desc", "1.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)));
+
+ List<Version> versions = versionDao.list(itemId);
+ Assert.assertEquals(versions.size(), 3);
+
+ int zusammenVersionIndex;
+ for (Version version : versions) {
+ zusammenVersionIndex = versionId1.getValue().equals(version.getId())
+ ? 0
+ : versionId2.getValue().equals(version.getId())
+ ? 1
+ : 2;
+ assetVersionEquals(version, zusammenVersions.get(zusammenVersionIndex));
+ }
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ testCreate(null);
+ }
+
+ @Test
+ public void testCreateBasedOn() throws Exception {
+ testCreate("baseId");
+ }
+
+ private void testCreate(String baseId) {
+ String itemId = "itemId";
+ Version version = new Version(1, 0);
+ version.setBaseId(baseId);
+ version.setName("version name");
+ 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)),
+ baseId == null ? isNull(Id.class) : eq(new Id(baseId)),
+ capturedZusammenVersion.capture());
+
+ Info capturedInfo = capturedZusammenVersion.getValue().getInfo();
+ Assert.assertEquals(capturedInfo.getName(), version.getName());
+ Assert.assertEquals(capturedInfo.getDescription(), version.getDescription());
+ Assert.assertEquals(VersionStatus
+ .valueOf(capturedInfo.getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)),
+ version.getStatus());
+ Assert.assertEquals(capturedInfo.getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL),
+ version.toString());
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ String itemId = "itemId";
+ Version version = new Version(1, 0);
+ version.setId("versionId");
+ version.setBaseId("baseId");
+ version.setName("version name");
+ version.setDescription("version description");
+ version.setStatus(VersionStatus.Certified);
+
+ ArgumentCaptor<ItemVersionData> capturedZusammenVersion =
+ ArgumentCaptor.forClass(ItemVersionData.class);
+
+ versionDao.update(itemId, version);
+
+ verify(zusammenAdaptorMock)
+ .updateVersion(eq(createZusammenContext()), eq(new Id(itemId)), eq(new Id(version.getId())),
+ capturedZusammenVersion.capture());
+
+ Info capturedInfo = capturedZusammenVersion.getValue().getInfo();
+ Assert.assertEquals(capturedInfo.getName(), version.getName());
+ Assert.assertEquals(capturedInfo.getDescription(), version.getDescription());
+ Assert.assertEquals(VersionStatus
+ .valueOf(capturedInfo.getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)),
+ version.getStatus());
+ Assert.assertEquals(capturedInfo.getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL),
+ version.toString());
+ }
+
+ @Test
+ public void testGetNonExisting() throws Exception {
+ Optional<Version> version = versionDao.get("itemId", new Version("versionId"));
+
+ Assert.assertEquals(version, Optional.empty());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+
+ SessionContext zusammenContext = createZusammenContext();
+ 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));
+
+ doReturn(new ItemVersionStatus(SynchronizationStatus.UP_TO_DATE, true))
+ .when(zusammenAdaptorMock)
+ .getVersionStatus(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ ItemVersion zusammenPublicVersion =
+ createZusammenVersion(versionIdObj, new Id("baseId"), "version desc", "2.0",
+ VersionStatus.Certified);
+ doReturn(zusammenPublicVersion).when(zusammenAdaptorMock)
+ .getPublicVersion(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ Optional<Version> version = versionDao.get(itemId, new Version(versionId));
+
+ Assert.assertTrue(version.isPresent());
+ zusammenPrivateVersion.getData().getInfo()
+ .addProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS,
+ VersionStatus.Certified.name());
+ assetVersionEquals(version.get(), zusammenPrivateVersion);
+ }
+
+ // TODO: 12/20/2017 complete tests
+ /* @Test
+ public void testDelete() throws Exception {
+
+ }
+
+ @Test
+ public void testPublish() throws Exception {
+
+ }
+
+ @Test
+ public void testSync() throws Exception {
+
+ }
+
+ @Test
+ public void testForceSync() throws Exception {
+
+ }
+
+ @Test
+ public void testRevert() throws Exception {
+
+ }
+
+ @Test
+ public void testListRevisions() throws Exception {
+
+ }*/
+
+ 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());
+ }
+
+ private ItemVersion createZusammenVersion(Id id, Id baseId, String description, String label,
+ VersionStatus status) {
+ ItemVersion version = new ItemVersion();
+ version.setId(id);
+ version.setBaseId(baseId);
+ Info info = new Info();
+ info.setName(id + "_name");
+ info.setDescription(description);
+ info.addProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL, label);
+ info.addProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS, status.name());
+ ItemVersionData data = new ItemVersionData();
+ data.setInfo(info);
+ version.setData(data);
+ version.setCreationTime(new Date());
+ version.setModificationTime(new Date());
+ return version;
+ }
+
+ private SessionContext createZusammenContext() {
+ SessionContext sessionContext = new SessionContext();
+ sessionContext.setUser(new UserInfo(USER));
+ sessionContext.setTenant("dox");
+ return sessionContext;
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java
new file mode 100644
index 0000000000..755bfb4442
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java
@@ -0,0 +1,124 @@
+package org.openecomp.sdc.versioning.impl;
+
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.itempermissions.PermissionsServices;
+import org.openecomp.sdc.notification.services.SubscriptionService;
+import org.openecomp.sdc.versioning.dao.ItemDao;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.Item;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+public class ItemManagerImplTest {
+
+ @Mock
+ private ItemDao itemDao;
+ @Mock
+ private PermissionsServices permissionsServices;
+ @Mock
+ private SubscriptionService subscriptionService;
+ @InjectMocks
+ private ItemManagerImpl itemManager;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testList() throws Exception {
+ doReturn(Stream.of(
+ createItem("item1", "A"),
+ createItem("item2", "B"),
+ createItem("item3", "B"),
+ createItem("item4", "A"))
+ .collect(Collectors.toList())).when(itemDao).list();
+
+ Collection<Item> items = itemManager.list(item -> "B".equals(item.getType()));
+ Assert.assertEquals(items.size(), 2);
+ Assert.assertTrue(items.stream().anyMatch(item -> "item2".equals(item.getName())));
+ Assert.assertTrue(items.stream().anyMatch(item -> "item3".equals(item.getName())));
+ }
+
+ @Test
+ public void testGetNotExisting() throws Exception {
+ Item item = itemManager.get("item1");
+ Assert.assertNull(item);
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ Item toBeReturned = new Item();
+ toBeReturned.setId("itemId");
+ doReturn(toBeReturned).when(itemDao).get(any(Item.class));
+
+ Item item = itemManager.get("itemId");
+ Assert.assertEquals(item.getId(), "itemId");
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ SessionContextProviderFactory.getInstance().createInterface().create("user1");
+
+ Item toBeReturned = new Item();
+ toBeReturned.setId("itemId");
+ doReturn(toBeReturned).when(itemDao).create(any(Item.class));
+
+ Item item = itemManager.create(createItem("item1", "A"));
+ Assert.assertEquals(item.getId(), "itemId");
+ }
+
+ @Test
+ public void testUpdateNotExistingVersionStatus() throws Exception {
+ itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ verify(itemDao, never()).update(any(Item.class));
+ }
+
+ @Test
+ public void testUpdateVersionStatusWhenNone() throws Exception {
+ Item item = new Item();
+ item.setId("itemId");
+ doReturn(item).when(itemDao).get(any(Item.class));
+
+ itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ verify(itemDao).update(item);
+ Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 1);
+ Assert.assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
+ }
+
+ @Test
+ public void testUpdateVersionStatus() throws Exception {
+ Item item = new Item();
+ item.setId("itemId");
+ item.getVersionStatusCounters().put(VersionStatus.Certified, 2);
+ item.getVersionStatusCounters().put(VersionStatus.Draft, 5);
+ doReturn(item).when(itemDao).get(any(Item.class));
+
+ itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ verify(itemDao).update(item);
+ Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
+ Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 4);
+ }
+
+ private Item createItem(String name, String type) {
+ Item item = new Item();
+ item.setId(name);
+ item.setName(name);
+ item.setType(type);
+ return item;
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
index d35de4f3d1..2d1109abe6 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
@@ -21,39 +21,326 @@
package org.openecomp.sdc.versioning.impl;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.versioning.dao.VersionInfoDao;
-import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
-import org.openecomp.sdc.versioning.dao.types.UserCandidateVersion;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.VersionCalculator;
+import org.openecomp.sdc.versioning.dao.VersionDao;
+import org.openecomp.sdc.versioning.dao.types.Revision;
+import org.openecomp.sdc.versioning.dao.types.SynchronizationState;
import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
-import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
+import org.openecomp.sdc.versioning.dao.types.VersionState;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.VersionInfo;
-import org.openecomp.sdc.versioning.types.VersionableEntityAction;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+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.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.openecomp.sdc.versioning.dao.types.SynchronizationState.OutOfSync;
+import static org.openecomp.sdc.versioning.dao.types.SynchronizationState.UpToDate;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
public class VersioningManagerImplTest {
+ @Mock
+ private VersionDao versionDaoMock;
+ @Mock
+ private VersionCalculator versionCalculatorMock;
+ @Mock
+ private ItemManager itemManagerMock;
+ @InjectMocks
+ private VersioningManagerImpl versioningManager;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testList() throws Exception {
+ String itemId = "itemId";
+
+ List<Version> returnedVersions = Stream.of(createVersion("1", null, null, false),
+ createVersion("2", null, null, false),
+ createVersion("3", null, null, false)).collect(Collectors.toList());
+ doReturn(returnedVersions).when(versionDaoMock).list(itemId);
+
+ List<Version> versions = versioningManager.list(itemId);
+ Assert.assertEquals(versions, returnedVersions);
+ }
+
+ @Test(expectedExceptions = Exception.class)
+ public void testGetNonExisting() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ doReturn(Optional.empty()).when(versionDaoMock).get(itemId, version);
+ doThrow(new Exception()).when(versionDaoMock).sync(itemId, version);
+
+ versioningManager.get(itemId, version);
+ }
+
+ @Test
+ public void testGetNonExistingForUser() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version requestedVersion = new Version(versionId);
+
+ Version returnedVersion = createVersion(versionId, Draft, UpToDate, false);
+ doReturn(Optional.empty()).doReturn(Optional.of(returnedVersion))
+ .when(versionDaoMock).get(itemId, requestedVersion);
+
+ Version version = versioningManager.get(itemId, requestedVersion);
+ Assert.assertEquals(version, returnedVersion);
+
+ verify(versionDaoMock, times(2)).get(itemId, requestedVersion);
+ verify(versionDaoMock).sync(itemId, requestedVersion);
+ }
+
+ @Test
+ public void testGetOutOfSyncCertified() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version requestedVersion = new Version(versionId);
+
+ Version returnedVersion = createVersion(versionId, Certified, UpToDate, false);
+ doReturn(Optional.of(createVersion(versionId, Certified, OutOfSync, false)))
+ .doReturn(Optional.of(returnedVersion))
+ .when(versionDaoMock).get(itemId, requestedVersion);
+
+ Version version = versioningManager.get(itemId, requestedVersion);
+ Assert.assertEquals(version, returnedVersion);
+
+ verify(versionDaoMock, times(2)).get(itemId, requestedVersion);
+ verify(versionDaoMock).forceSync(itemId, requestedVersion);
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version requestedVersion = new Version(versionId);
+
+ Version returnedVersion = createVersion(versionId, Draft, OutOfSync, true);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, requestedVersion);
+
+ Version version = versioningManager.get(itemId, requestedVersion);
+ Assert.assertEquals(version, returnedVersion);
+
+ verify(versionDaoMock).get(itemId, requestedVersion);
+ verify(versionDaoMock, never()).sync(any(), any());
+ verify(versionDaoMock, never()).forceSync(any(), any());
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ String itemId = "itemId";
+ Version requestedVersion = new Version();
+
+ String versionName = "versionName";
+ doReturn(versionName).when(versionCalculatorMock).calculate(null, VersionCreationMethod.major);
+
+ doReturn(Stream.of(createVersion("1", null, null, false),
+ createVersion("2", null, null, false),
+ createVersion("3", null, null, false)).collect(Collectors.toList()))
+ .when(versionDaoMock).list(itemId);
+
+ Version version =
+ versioningManager.create(itemId, requestedVersion, VersionCreationMethod.major);
+ Assert.assertNotNull(version);
+ Assert.assertEquals(version.getName(), versionName);
+
+ verify(versionDaoMock).create(itemId, requestedVersion);
+ verify(itemManagerMock).updateVersionStatus(itemId, Draft, null);
+ verify(versionDaoMock).publish(eq(itemId), eq(requestedVersion), anyString());
+ }
+
+ @Test
+ public void testCreateBasedOn() throws Exception {
+ String itemId = "itemId";
+ Version requestedVersion = new Version();
+ requestedVersion.setBaseId("baseVersionId");
+
+ Version baseVersion = createVersion(requestedVersion.getBaseId(), Certified, UpToDate, false);
+ // TODO: 12/13/2017 fix to eq(new Version("baseVersionId")) when version.equals will be fixed
+ doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(itemId), any(Version.class));
+
+ String versionName = "4.0";
+ doReturn(versionName)
+ .when(versionCalculatorMock).calculate(baseVersion.getName(), VersionCreationMethod.major);
+
+ doReturn(Stream.of(createVersion("1", null, null, false),
+ createVersion("2", null, null, false),
+ createVersion("3", null, null, false)).collect(Collectors.toList()))
+ .when(versionDaoMock).list(itemId);
+
+ Version version =
+ versioningManager.create(itemId, requestedVersion, VersionCreationMethod.major);
+ Assert.assertNotNull(version);
+ Assert.assertEquals(version.getName(), versionName);
+
+ verify(versionDaoMock).create(itemId, requestedVersion);
+ verify(itemManagerMock).updateVersionStatus(itemId, Draft, null);
+ verify(versionDaoMock).publish(eq(itemId), eq(requestedVersion), anyString());
+ }
+
+ @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp =
+ "Item itemId: create version failed, a version with the name 2.0 already exist")
+ public void testCreateWithExistingName() throws Exception {
+ String itemId = "itemId";
+ Version version = new Version();
+ version.setBaseId("baseVersionId");
+
+ Version baseVersion = createVersion(version.getBaseId(), Certified, UpToDate, false);
+ // TODO: 12/13/2017 fix to eq(new Version("baseVersionId")) when version.equals will be fixed
+ doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(itemId), any(Version.class));
+
+ String versionName = "2.0";
+ doReturn(versionName)
+ .when(versionCalculatorMock).calculate(baseVersion.getName(), VersionCreationMethod.major);
+
+ doReturn(Stream.of(createVersion("1", null, null, false),
+ createVersion("2", null, null, false),
+ createVersion("3", null, null, false)).collect(Collectors.toList()))
+ .when(versionDaoMock).list(itemId);
+
+ versioningManager.create(itemId, version, VersionCreationMethod.major);
+ }
+
+ @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp =
+ "Item itemId: submit version failed, version versionId is already Certified")
+ public void testSubmitCertified() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ Version returnedVersion = createVersion(versionId, Certified, UpToDate, false);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, version);
+
+ versioningManager.submit(itemId, version, "Submit message");
+ }
+
+ @Test
+ public void testSubmit() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ ArgumentCaptor<Version> versionArgumentCaptor = ArgumentCaptor.forClass(Version.class);
+
+ Version returnedVersion = createVersion(versionId, Draft, UpToDate, false);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, version);
+
+ String submitDescription = "Submit message";
+ versioningManager.submit(itemId, version, submitDescription);
+
+ verify(versionDaoMock).update(eq(itemId), versionArgumentCaptor.capture());
+ Assert.assertEquals(Certified, versionArgumentCaptor.getValue().getStatus());
+ verify(versionDaoMock).publish(itemId, version, submitDescription);
+ verify(itemManagerMock).updateVersionStatus(itemId, Certified, Draft);
+ }
+
+ @Test
+ public void testPublish() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+ String publishDescription = "Publish message";
+
+ versioningManager.publish(itemId, version, publishDescription);
+
+ verify(versionDaoMock).publish(itemId, version, publishDescription);
+ }
+
+ @Test
+ public void testSync() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ versioningManager.sync(itemId, version);
+
+ verify(versionDaoMock).sync(itemId, version);
+ }
+
+ @Test
+ public void testForceSync() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ versioningManager.forceSync(itemId, version);
+
+ verify(versionDaoMock).forceSync(itemId, version);
+ }
+
+ @Test
+ public void testRevert() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+ String revisionId = "revisionId";
+
+ versioningManager.revert(itemId, version, revisionId);
+
+ verify(versionDaoMock).revert(itemId, version, revisionId);
+ }
+
+ @Test
+ public void testListRevisions() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ List<Revision> returnedRevisions =
+ Stream.of(new Revision(), new Revision()).collect(Collectors.toList());
+ doReturn(returnedRevisions)
+ .when(versionDaoMock).listRevisions(itemId, version);
+
+ List<Revision> revisions = versioningManager.listRevisions(itemId, version);
+ Assert.assertEquals(revisions, returnedRevisions);
+ }
+
+ private Version createVersion(String id, VersionStatus status,
+ SynchronizationState syncState, boolean dirty) {
+ Version version = new Version(id);
+ version.setName(id + ".0");
+ version.setDescription(id + " desc");
+ version.setStatus(status);
+
+ VersionState state = new VersionState();
+ state.setSynchronizationState(syncState);
+ state.setDirty(dirty);
+ version.setState(state);
+ return version;
+ }
+
+/*
private static final String USR1 = "usr1";
private static final String USR2 = "usr2";
private static final String TYPE1 = "Type1";
-/* private static final String TYPE2 = "Type2";*/
+*/
+/* private static final String TYPE2 = "Type2";*//*
+
private static final String ID1 = "Id1";
+*/
/* private static final String ID2 = "Id2";
private static final String ID3 = "Id3";
private static final String TYPE1_TABLE_NAME = "vendor_license_model";
@@ -61,17 +348,20 @@ public class VersioningManagerImplTest {
private static final String TYPE1_VERSION_NAME = "version";
private static final String TYPE2_TABLE_NAME = "feature_group";
private static final String TYPE2_ID_NAME = "vlm_id";
- private static final String TYPE2_VERSION_NAME = "version";*/
+ private static final String TYPE2_VERSION_NAME = "version";*//*
+
private static final Version VERSION0 = new Version(0, 0);
private static final Version VERSION01 = new Version(0, 1);
private static final Version VERSION02 = new Version(0, 2);
private static final Version VERSION10 = new Version(1, 0);
private static final Version VERSION11 = new Version(1, 1);
- /* private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ */
+/* private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
private static UDTMapper<Version> versionMapper =
- noSqlDb.getMappingManager().udtMapper(Version.class);*/
+ noSqlDb.getMappingManager().udtMapper(Version.class);*//*
+
@Mock
private VersionInfoDao versionInfoDaoMock;
@Mock
@@ -87,7 +377,8 @@ public class VersioningManagerImplTest {
MockitoAnnotations.initMocks(this);
}
- /* @BeforeClass
+ */
+/* @BeforeClass
private void init() {
versionInfoDaoMock.delete(new VersionInfoEntity(TYPE1, ID1));
versionInfoDaoMock.delete(new VersionInfoEntity(TYPE1, ID2));
@@ -103,8 +394,10 @@ public class VersioningManagerImplTest {
new VersionableEntityMetadata(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME));
versioningManager.register(TYPE2,
new VersionableEntityMetadata(TYPE2_TABLE_NAME, TYPE2_ID_NAME, TYPE2_VERSION_NAME));
- }*/
+ }*//*
+
+*/
/* @Test
public void testRegister() throws Exception {
VersionableEntityMetadata entityMetadata =
@@ -116,7 +409,8 @@ public class VersioningManagerImplTest {
Set<VersionableEntityMetadata> type1Entities = versionableEntities.get(TYPE1);
Assert.assertNotNull(type1Entities);
Assert.assertTrue(type1Entities.contains(entityMetadata));
- }*/
+ }*//*
+
@Test(expectedExceptions = CoreException.class)
public void testCreateAlreadyExisting() {
@@ -129,8 +423,10 @@ public class VersioningManagerImplTest {
Version version = versioningManager.create(TYPE1, ID1, USR1);
Assert.assertEquals(version, VERSION01);
+*/
/* createVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
- version);*/
+ version);*//*
+
verify(versionInfoDaoMock).create(versionInfoEntityArg.capture());
VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue();
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, new Version(0, 0), VERSION01, USR1,
@@ -152,7 +448,7 @@ public class VersioningManagerImplTest {
@Test
public void testDelete() {
VersionInfoEntity versionInfoEntity = new VersionInfoEntity();
- versionInfoEntity.setStatus(VersionStatus.Available);
+ versionInfoEntity.setStatus(VersionStatus.Draft);
doReturn(versionInfoEntity).when(versionInfoDaoMock).get(anyObject());
versioningManager.delete(TYPE1, ID1, USR1);
@@ -171,13 +467,14 @@ public class VersioningManagerImplTest {
@Test
public void testUndoDelete() {
VersionInfoDeletedEntity versionInfoDeletedEntity = new VersionInfoDeletedEntity();
- versionInfoDeletedEntity.setStatus(VersionStatus.Available);
+ versionInfoDeletedEntity.setStatus(VersionStatus.Draft);
doReturn(versionInfoDeletedEntity).when(versionInfoDeletedDaoMock).get(anyObject());
versioningManager.undoDelete(TYPE1, ID1, USR1);
verify(versionInfoDeletedDaoMock).delete(versionInfoDeletedEntity);
verify(versionInfoDaoMock).create(versionInfoEntityArg.capture());
+*/
/*
VersionInfoDeletedEntity versionInfoDeletedEntity =
versionInfoDeletedDaoMock.get(new VersionInfoDeletedEntity(TYPE1, ID1));
@@ -190,7 +487,8 @@ public class VersioningManagerImplTest {
Assert.assertNull(versionInfoEntity);
versioningManager.undoDelete(TYPE1, ID1, USR1);
versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
- Assert.assertNotNull(versionInfoEntity);*/
+ Assert.assertNotNull(versionInfoEntity);*//*
+
}
@Test(expectedExceptions = CoreException.class)
@@ -216,7 +514,7 @@ public class VersioningManagerImplTest {
public void testCheckoutOnFinalized() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION10);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions,
VERSION10);
Version version = versioningManager.checkout(TYPE1, ID1, USR1);
@@ -225,18 +523,20 @@ public class VersioningManagerImplTest {
VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION10, VERSION11, USR1,
VersionStatus.Locked, viewableVersions, VERSION10);
+*/
/*
ResultSet results =
loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
VERSION11);
- Assert.assertTrue(results.iterator().hasNext());*/
+ Assert.assertTrue(results.iterator().hasNext());*//*
+
}
@Test
public void testCheckout() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
Version version = versioningManager.checkout(TYPE1, ID1, USR1);
@@ -248,10 +548,12 @@ public class VersioningManagerImplTest {
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, VERSION02, USR1,
VersionStatus.Locked, viewableVersions, null);
+*/
/* ResultSet results =
loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
VERSION02);
- Assert.assertTrue(results.iterator().hasNext());*/
+ Assert.assertTrue(results.iterator().hasNext());*//*
+
}
@Test(expectedExceptions = CoreException.class)
@@ -263,7 +565,7 @@ public class VersioningManagerImplTest {
public void testUndoCheckoutOnAvailable() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
versioningManager.undoCheckout(TYPE1, ID1, USR1);
@@ -273,7 +575,7 @@ public class VersioningManagerImplTest {
public void testUndoCheckouOnFinalized() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION10);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions,
VERSION10);
versioningManager.undoCheckout(TYPE1, ID1, USR2);
}
@@ -298,12 +600,14 @@ public class VersioningManagerImplTest {
VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null,
- VersionStatus.Available, viewableVersions, null);
+ VersionStatus.Draft, viewableVersions, null);
+*/
/* ResultSet results =
loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
VERSION02);
- Assert.assertFalse(results.iterator().hasNext());*/
+ Assert.assertFalse(results.iterator().hasNext());*//*
+
}
@Test(expectedExceptions = CoreException.class)
@@ -315,7 +619,7 @@ public class VersioningManagerImplTest {
public void testCheckinOnAvailable() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
versioningManager.checkin(TYPE1, ID1, USR1, "fail checkin");
@@ -326,7 +630,7 @@ public class VersioningManagerImplTest {
public void testCheckinOnFinalized() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION10);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions,
VERSION10);
versioningManager.checkin(TYPE1, ID1, USR1, "failed checkin");
@@ -354,7 +658,7 @@ public class VersioningManagerImplTest {
viewableVersions.add(VERSION01);
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null,
- VersionStatus.Available, viewableVersions, null);
+ VersionStatus.Draft, viewableVersions, null);
}
@Test(expectedExceptions = CoreException.class)
@@ -374,7 +678,7 @@ public class VersioningManagerImplTest {
public void testSubmitOnFinalized() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION10);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions,
VERSION10);
versioningManager.submit(TYPE1, ID1, USR2, "failed submit");
}
@@ -390,7 +694,7 @@ public class VersioningManagerImplTest {
viewableVersions.add(new Version(3, 0));
viewableVersions.add(new Version(3, 1));
viewableVersions.add(version32);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, version32, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, version32, null, viewableVersions,
new Version(3, 0));
Version version = versioningManager.submit(TYPE1, ID1, USR1, "submit msg");
@@ -403,12 +707,14 @@ public class VersioningManagerImplTest {
VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue();
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, version40, null, null,
- VersionStatus.Final, viewableVersions, version40);
+ VersionStatus.Certified, viewableVersions, version40);
+*/
/* ResultSet results =
loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
VERSION10);
- Assert.assertTrue(results.iterator().hasNext());*/
+ Assert.assertTrue(results.iterator().hasNext());*//*
+
}
@Test(expectedExceptions = CoreException.class)
@@ -420,12 +726,12 @@ public class VersioningManagerImplTest {
public void testGetVersionInfoForReadOnAvailable() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
VersionInfo versionInfo =
versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read);
- assertVersionInfo(versionInfo, VERSION01, VersionStatus.Available, null,
+ assertVersionInfo(versionInfo, VERSION01, VersionStatus.Draft, null,
viewableVersions, null);
}
@@ -433,7 +739,7 @@ public class VersioningManagerImplTest {
public void testGetVersionInfoForWriteOnAvailable() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write);
@@ -488,6 +794,7 @@ public class VersioningManagerImplTest {
assertVersionInfo(versionInfo, VERSION02, VersionStatus.Locked, USR1, viewableVersions, null);
}
+*/
/* private void createVersionableEntityRecord(String tableName, String idName, String versionName,
String id, Version version) {
noSqlDb.execute(
@@ -500,7 +807,8 @@ public class VersioningManagerImplTest {
return noSqlDb.execute(
String.format("select * from %s where %s=? and %s=?", tableName, idName, versionName), id,
versionMapper.toUDT(version));
- }*/
+ }*//*
+
private static void assretVersionInfoEntity(VersionInfoEntity actual, String entityType,
@@ -553,4 +861,5 @@ public class VersioningManagerImplTest {
doReturn(mock).when(versionInfoDaoMock).get(anyObject());
return mock;
}
+*/
}