aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2018-01-01 13:07:47 +0200
committertalig <talig@amdocs.com>2018-01-01 13:07:47 +0200
commit664c11581c7ea5d36e36af1fe7b26e14271e77fe (patch)
treee0e519697d5105c8ef57406c548f1444e9bf476c /openecomp-be/lib/openecomp-sdc-versioning-lib
parent16f5d02fee065f1bbafe056e22627d996dcf2e6a (diff)
Fix sonar issues + tests in versioning lib
Change-Id: Ib49288fe49be1e848b9615e548689cdbe0df4fee Issue-ID: SDC-779 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java20
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java110
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java170
4 files changed, 154 insertions, 148 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
index 3e85a53ac2..e46037373f 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
@@ -13,7 +13,7 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
public class ItemManagerImpl implements ItemManager {
- public static final String CREATE_ITEM = "Create_Item";
+ private static final String CREATE_ITEM = "Create_Item";
private ItemDao itemDao;
private PermissionsServices permissionsServices;
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
index 7f983477cf..347d328193 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
@@ -75,8 +75,9 @@ import java.util.stream.Collectors;
public class VersioningManagerImpl implements VersioningManager {
private static final Logger LOGGER = LoggerFactory.getLogger(VersioningManagerImpl.class);
private static final Version INITIAL_ACTIVE_VERSION = new Version(0, 0);
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
- private static Map<String, Set<VersionableEntityMetadata>> versionableEntities = new HashMap<>();
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+ private static final Map<String, Set<VersionableEntityMetadata>> VERSIONABLE_ENTITIES =
+ new HashMap<>();
private final VersionInfoDao versionInfoDao;
private final VersionInfoDeletedDao versionInfoDeletedDao;
@@ -129,7 +130,7 @@ public class VersioningManagerImpl implements VersioningManager {
VersionableEntityAction action, String user) {
- mdcDataDebugMessage.debugEntryMessage("entity Id", entityId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("entity Id", entityId);
Version activeVersion;
@@ -180,7 +181,7 @@ public class VersioningManagerImpl implements VersioningManager {
}
}
- mdcDataDebugMessage.debugExitMessage("entity Id", entityId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("entity Id", entityId);
return versionInfo;
}
@@ -198,7 +199,7 @@ public class VersioningManagerImpl implements VersioningManager {
@Override
public void register(String entityType, VersionableEntityMetadata entityMetadata) {
Set<VersionableEntityMetadata> entitiesMetadata =
- versionableEntities.computeIfAbsent(entityType, k -> new HashSet<>());
+ VERSIONABLE_ENTITIES.computeIfAbsent(entityType, k -> new HashSet<>());
entitiesMetadata.add(entityMetadata);
}
@@ -518,7 +519,7 @@ public class VersioningManagerImpl implements VersioningManager {
versionDao.create(itemId, version);
itemManager.updateVersionStatus(itemId, VersionStatus.Draft, null);
- publish(itemId, version, String.format("Initial version: %s ", version.getName()));
+ publish(itemId, version, String.format("Create version: %s", version.getName()));
return version;
}
@@ -597,7 +598,6 @@ public class VersioningManagerImpl implements VersioningManager {
@Override
public List<Revision> listRevisions(String itemId, Version version) {
return versionDao.listRevisions(itemId, version);
-
}
private void markAsCheckedOut(VersionInfoEntity versionInfoEntity, String checkingOutUser) {
@@ -683,7 +683,7 @@ public class VersioningManagerImpl implements VersioningManager {
private void initVersionOnEntity(String entityType, String entityId, Version baseVersion,
Version newVersion) {
- Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
if (entityMetadatas != null) {
for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
@@ -694,7 +694,7 @@ public class VersioningManagerImpl implements VersioningManager {
private void deleteVersionFromEntity(String entityType, String entityId,
Version versionToDelete, Version backToVersion) {
- Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
if (entityMetadatas != null) {
for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
@@ -704,7 +704,7 @@ public class VersioningManagerImpl implements VersioningManager {
}
private void closeVersionOnEntity(String entityType, String entityId, Version versionToClose) {
- Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
if (entityMetadatas != null) {
for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
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
index afffd47943..6ac2ab30d5 100644
--- 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
@@ -9,11 +9,11 @@ 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.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -21,9 +21,17 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
public class ItemManagerImplTest {
+ private static final String USER = "user1";
+ private static final String ITEM_ID = "item1";
+ private static final String ITEM_NAME = "item 1 name";
+ private static final String ITEM_TYPE_A = "A";
+ private static final String ITEM_TYPE_B = "B";
@Mock
private ItemDao itemDao;
@Mock
@@ -40,116 +48,128 @@ public class ItemManagerImplTest {
@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())));
+ List<Item> returnedItems = Stream.of(createItem(ITEM_ID, ITEM_NAME, ITEM_TYPE_A),
+ createItem("item2", "item2 name", ITEM_TYPE_B),
+ createItem("item3", "item3 name", ITEM_TYPE_B),
+ createItem("item4", "item4 name", ITEM_TYPE_A)).collect(Collectors.toList());
+ doReturn(returnedItems).when(itemDao).list();
+
+ Collection<Item> items = itemManager.list(item -> ITEM_TYPE_B.equals(item.getType()));
+
+ assertEquals(items.size(), 2);
+ assertTrue(
+ items.stream().anyMatch(item -> returnedItems.get(1).getName().equals(item.getName())));
+ assertTrue(
+ items.stream().anyMatch(item -> returnedItems.get(2).getName().equals(item.getName())));
}
@Test
public void testGetNotExisting() throws Exception {
- Item item = itemManager.get("item1");
- Assert.assertNull(item);
+ Item item = itemManager.get(ITEM_ID);
+ assertNull(item);
}
@Test
public void testGet() throws Exception {
- Item toBeReturned = new Item();
- toBeReturned.setId("itemId");
+ Item toBeReturned = createItem(ITEM_ID, ITEM_NAME, ITEM_TYPE_A);
doReturn(toBeReturned).when(itemDao).get(any(Item.class));
- Item item = itemManager.get("itemId");
- Assert.assertEquals(item.getId(), "itemId");
+ Item item = itemManager.get(ITEM_ID);
+
+ assertItemEquals(item, toBeReturned);
}
@Test
public void testCreate() throws Exception {
- SessionContextProviderFactory.getInstance().createInterface().create("user1");
+ SessionContextProviderFactory.getInstance().createInterface().create(USER);
+
+ Item returnedItem = createItem(ITEM_ID, ITEM_NAME, ITEM_TYPE_A);
+ doReturn(returnedItem).when(itemDao).create(any(Item.class));
- Item toBeReturned = new Item();
- toBeReturned.setId("itemId");
- doReturn(toBeReturned).when(itemDao).create(any(Item.class));
+ Item inputItem = createItem(null, returnedItem.getName(), returnedItem.getType());
+ Item item = itemManager.create(inputItem);
- Item item = itemManager.create(createItem("item1", "A"));
- Assert.assertEquals(item.getId(), "itemId");
+ assertItemEquals(item, returnedItem);
+ verify(permissionsServices).execute(ITEM_ID, USER, "Create_Item");
+ verify(subscriptionService).subscribe(USER, ITEM_ID);
}
@Test
public void testUpdateNotExistingVersionStatus() throws Exception {
- itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Certified, VersionStatus.Draft);
+
verify(itemDao, never()).update(any(Item.class));
}
@Test
public void testUpdateVersionStatusWhenNone() throws Exception {
Item item = new Item();
- item.setId("itemId");
+ item.setId(ITEM_ID);
doReturn(item).when(itemDao).get(any(Item.class));
- itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Certified, VersionStatus.Draft);
+
verify(itemDao).update(item);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 1);
- Assert.assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 1);
+ assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
}
@Test
public void testUpdateVersionStatusAddFirst() throws Exception {
Item item = new Item();
- item.setId("itemId");
+ item.setId(ITEM_ID);
doReturn(item).when(itemDao).get(any(Item.class));
- itemManager.updateVersionStatus("itemId", VersionStatus.Draft, null);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Draft, null);
verify(itemDao).update(item);
- Assert.assertEquals(item.getVersionStatusCounters().size(), 1);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 1);
+ assertEquals(item.getVersionStatusCounters().size(), 1);
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 1);
}
@Test
public void testUpdateVersionStatus() throws Exception {
Item item = new Item();
- item.setId("itemId");
+ item.setId(ITEM_ID);
item.getVersionStatusCounters().put(VersionStatus.Certified, 2);
item.getVersionStatusCounters().put(VersionStatus.Draft, 3);
doReturn(item).when(itemDao).get(any(Item.class));
- itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Certified, VersionStatus.Draft);
verify(itemDao).update(item);
- Assert.assertEquals(item.getVersionStatusCounters().size(), 2);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 2);
+ assertEquals(item.getVersionStatusCounters().size(), 2);
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 2);
}
@Test
public void testUpdateVersionStatusRemoveLast() throws Exception {
Item item = new Item();
- item.setId("itemId");
+ item.setId(ITEM_ID);
item.getVersionStatusCounters().put(VersionStatus.Certified, 2);
item.getVersionStatusCounters().put(VersionStatus.Draft, 1);
doReturn(item).when(itemDao).get(any(Item.class));
- itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ itemManager.updateVersionStatus(ITEM_ID, VersionStatus.Certified, VersionStatus.Draft);
verify(itemDao).update(item);
- Assert.assertEquals(item.getVersionStatusCounters().size(), 1);
- Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
- Assert.assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
+ assertEquals(item.getVersionStatusCounters().size(), 1);
+ assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
+ assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
}
- private Item createItem(String name, String type) {
+ private Item createItem(String id, String name, String type) {
Item item = new Item();
- item.setId(name);
+ item.setId(id);
item.setName(name);
item.setType(type);
return item;
}
+ private void assertItemEquals(Item actual, Item expected) {
+ assertEquals(actual.getId(), expected.getId());
+ assertEquals(actual.getName(), expected.getName());
+ assertEquals(actual.getType(), expected.getType());
+ }
} \ 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 2d1109abe6..4f8c682c5e 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
@@ -39,13 +39,13 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
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;
@@ -58,6 +58,9 @@ import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
public class VersioningManagerImplTest {
+ private static final String ITEM_ID = "itemId";
+ private static final String VERSION_ID = "versionId";
+
@Mock
private VersionDao versionDaoMock;
@Mock
@@ -73,85 +76,83 @@ public class VersioningManagerImplTest {
}
@Test
- public void testList() throws Exception {
- String itemId = "itemId";
+ public void testListWhenNone() throws Exception {
+ doReturn(new ArrayList<>()).when(versionDaoMock).list(ITEM_ID);
+ List<Version> versions = versioningManager.list(ITEM_ID);
+
+ Assert.assertTrue(versions.isEmpty());
+ }
+
+ @Test
+ public void testList() throws Exception {
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);
+ doReturn(returnedVersions).when(versionDaoMock).list(ITEM_ID);
- List<Version> versions = versioningManager.list(itemId);
+ List<Version> versions = versioningManager.list(ITEM_ID);
Assert.assertEquals(versions, returnedVersions);
}
@Test(expectedExceptions = Exception.class)
public void testGetNonExisting() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
- doReturn(Optional.empty()).when(versionDaoMock).get(itemId, version);
- doThrow(new Exception()).when(versionDaoMock).sync(itemId, version);
+ doReturn(Optional.empty()).when(versionDaoMock).get(ITEM_ID, version);
+ doThrow(new Exception()).when(versionDaoMock).sync(ITEM_ID, version);
- versioningManager.get(itemId, version);
+ versioningManager.get(ITEM_ID, version);
}
@Test
public void testGetNonExistingForUser() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version requestedVersion = new Version(versionId);
+ Version requestedVersion = new Version(VERSION_ID);
- Version returnedVersion = createVersion(versionId, Draft, UpToDate, false);
+ Version returnedVersion = createVersion(VERSION_ID, Draft, UpToDate, false);
doReturn(Optional.empty()).doReturn(Optional.of(returnedVersion))
- .when(versionDaoMock).get(itemId, requestedVersion);
+ .when(versionDaoMock).get(ITEM_ID, requestedVersion);
- Version version = versioningManager.get(itemId, requestedVersion);
+ Version version = versioningManager.get(ITEM_ID, requestedVersion);
Assert.assertEquals(version, returnedVersion);
- verify(versionDaoMock, times(2)).get(itemId, requestedVersion);
- verify(versionDaoMock).sync(itemId, requestedVersion);
+ verify(versionDaoMock, times(2)).get(ITEM_ID, requestedVersion);
+ verify(versionDaoMock).sync(ITEM_ID, requestedVersion);
}
@Test
public void testGetOutOfSyncCertified() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version requestedVersion = new Version(versionId);
+ Version requestedVersion = new Version(VERSION_ID);
- Version returnedVersion = createVersion(versionId, Certified, UpToDate, false);
- doReturn(Optional.of(createVersion(versionId, Certified, OutOfSync, false)))
+ Version returnedVersion = createVersion(VERSION_ID, Certified, UpToDate, false);
+ doReturn(Optional.of(createVersion(VERSION_ID, Certified, OutOfSync, false)))
.doReturn(Optional.of(returnedVersion))
- .when(versionDaoMock).get(itemId, requestedVersion);
+ .when(versionDaoMock).get(ITEM_ID, requestedVersion);
- Version version = versioningManager.get(itemId, requestedVersion);
+ Version version = versioningManager.get(ITEM_ID, requestedVersion);
Assert.assertEquals(version, returnedVersion);
- verify(versionDaoMock, times(2)).get(itemId, requestedVersion);
- verify(versionDaoMock).forceSync(itemId, requestedVersion);
+ verify(versionDaoMock, times(2)).get(ITEM_ID, requestedVersion);
+ verify(versionDaoMock).forceSync(ITEM_ID, requestedVersion);
}
@Test
public void testGet() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version requestedVersion = new Version(versionId);
+ Version requestedVersion = new Version(VERSION_ID);
- Version returnedVersion = createVersion(versionId, Draft, OutOfSync, true);
- doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, requestedVersion);
+ Version returnedVersion = createVersion(VERSION_ID, Draft, OutOfSync, true);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(ITEM_ID, requestedVersion);
- Version version = versioningManager.get(itemId, requestedVersion);
+ Version version = versioningManager.get(ITEM_ID, requestedVersion);
Assert.assertEquals(version, returnedVersion);
- verify(versionDaoMock).get(itemId, requestedVersion);
+ verify(versionDaoMock).get(ITEM_ID, 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";
@@ -160,27 +161,27 @@ public class VersioningManagerImplTest {
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);
+ .when(versionDaoMock).list(ITEM_ID);
Version version =
- versioningManager.create(itemId, requestedVersion, VersionCreationMethod.major);
+ versioningManager.create(ITEM_ID, 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());
+ verify(versionDaoMock).create(ITEM_ID, requestedVersion);
+ verify(itemManagerMock).updateVersionStatus(ITEM_ID, Draft, null);
+ verify(versionDaoMock)
+ .publish(eq(ITEM_ID), eq(requestedVersion), eq("Create version: versionName"));
}
@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));
+ doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(ITEM_ID), any(Version.class));
String versionName = "4.0";
doReturn(versionName)
@@ -189,28 +190,27 @@ public class VersioningManagerImplTest {
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);
+ .when(versionDaoMock).list(ITEM_ID);
Version version =
- versioningManager.create(itemId, requestedVersion, VersionCreationMethod.major);
+ versioningManager.create(ITEM_ID, 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());
+ verify(versionDaoMock).create(ITEM_ID, requestedVersion);
+ verify(itemManagerMock).updateVersionStatus(ITEM_ID, Draft, null);
+ verify(versionDaoMock).publish(eq(ITEM_ID), eq(requestedVersion), eq("Create version: 4.0"));
}
@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));
+ doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(ITEM_ID), any(Version.class));
String versionName = "2.0";
doReturn(versionName)
@@ -219,102 +219,88 @@ public class VersioningManagerImplTest {
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);
+ .when(versionDaoMock).list(ITEM_ID);
- versioningManager.create(itemId, version, VersionCreationMethod.major);
+ versioningManager.create(ITEM_ID, 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 version = new Version(VERSION_ID);
- Version returnedVersion = createVersion(versionId, Certified, UpToDate, false);
- doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, version);
+ Version returnedVersion = createVersion(VERSION_ID, Certified, UpToDate, false);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(ITEM_ID, version);
- versioningManager.submit(itemId, version, "Submit message");
+ versioningManager.submit(ITEM_ID, version, "Submit message");
}
@Test
public void testSubmit() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
ArgumentCaptor<Version> versionArgumentCaptor = ArgumentCaptor.forClass(Version.class);
- Version returnedVersion = createVersion(versionId, Draft, UpToDate, false);
- doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, version);
+ Version returnedVersion = createVersion(VERSION_ID, Draft, UpToDate, false);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(ITEM_ID, version);
String submitDescription = "Submit message";
- versioningManager.submit(itemId, version, submitDescription);
+ versioningManager.submit(ITEM_ID, version, submitDescription);
- verify(versionDaoMock).update(eq(itemId), versionArgumentCaptor.capture());
+ verify(versionDaoMock).update(eq(ITEM_ID), versionArgumentCaptor.capture());
Assert.assertEquals(Certified, versionArgumentCaptor.getValue().getStatus());
- verify(versionDaoMock).publish(itemId, version, submitDescription);
- verify(itemManagerMock).updateVersionStatus(itemId, Certified, Draft);
+ verify(versionDaoMock).publish(ITEM_ID, version, submitDescription);
+ verify(itemManagerMock).updateVersionStatus(ITEM_ID, Certified, Draft);
}
@Test
public void testPublish() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
String publishDescription = "Publish message";
- versioningManager.publish(itemId, version, publishDescription);
+ versioningManager.publish(ITEM_ID, version, publishDescription);
- verify(versionDaoMock).publish(itemId, version, publishDescription);
+ verify(versionDaoMock).publish(ITEM_ID, version, publishDescription);
}
@Test
public void testSync() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
- versioningManager.sync(itemId, version);
+ versioningManager.sync(ITEM_ID, version);
- verify(versionDaoMock).sync(itemId, version);
+ verify(versionDaoMock).sync(ITEM_ID, version);
}
@Test
public void testForceSync() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
- versioningManager.forceSync(itemId, version);
+ versioningManager.forceSync(ITEM_ID, version);
- verify(versionDaoMock).forceSync(itemId, version);
+ verify(versionDaoMock).forceSync(ITEM_ID, version);
}
@Test
public void testRevert() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
String revisionId = "revisionId";
- versioningManager.revert(itemId, version, revisionId);
+ versioningManager.revert(ITEM_ID, version, revisionId);
- verify(versionDaoMock).revert(itemId, version, revisionId);
+ verify(versionDaoMock).revert(ITEM_ID, version, revisionId);
}
@Test
public void testListRevisions() throws Exception {
- String itemId = "itemId";
- String versionId = "versionId";
- Version version = new Version(versionId);
+ Version version = new Version(VERSION_ID);
List<Revision> returnedRevisions =
Stream.of(new Revision(), new Revision()).collect(Collectors.toList());
doReturn(returnedRevisions)
- .when(versionDaoMock).listRevisions(itemId, version);
+ .when(versionDaoMock).listRevisions(ITEM_ID, version);
- List<Revision> revisions = versioningManager.listRevisions(itemId, version);
+ List<Revision> revisions = versioningManager.listRevisions(ITEM_ID, version);
Assert.assertEquals(revisions, returnedRevisions);
}