summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2017-12-26 09:22:12 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-26 10:50:04 +0000
commit6cec2fdd8c296655122dc25294840d777de59614 (patch)
tree5869deece3d7deeb50948341acbb19c9d1c41f04 /openecomp-be/lib/openecomp-sdc-versioning-lib
parentfe4aff78dd7efe4feb092ba8025077ba1b419905 (diff)
Add Item Manager and Dao impl unit tests
Change-Id: I30df90a7ca543195d286f322e8bfa52ffabca849 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-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java3
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java215
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java35
3 files changed, 250 insertions, 3 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java
index 329ac52133..2a95c05f49 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java
@@ -3,6 +3,7 @@ package org.openecomp.sdc.versioning.types;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import java.util.Date;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
@@ -12,7 +13,7 @@ public class Item {
private String name;
private String description;
private Map<String, Object> properties = new HashMap<>();
- private Map<VersionStatus, Integer> versionStatusCounters = new HashMap<>();
+ private Map<VersionStatus, Integer> versionStatusCounters = new EnumMap<>(VersionStatus.class);
private Date creationTime;
private Date modificationTime;
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java
new file mode 100644
index 0000000000..b2a27de2c1
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImplTest.java
@@ -0,0 +1,215 @@
+package org.openecomp.sdc.versioning.dao.impl.zusammen;
+
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.item.Info;
+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.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.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.mockito.Matchers.eq;
+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 ItemZusammenDaoImplTest {
+
+ private static final String USER = "user1";
+ private static final String ITEM_TYPE = "item_type";
+ private static final String ITEM_VERSIONS_STATUSES = "item_versions_statuses";
+ private static final String APP_PROP_1 = "app_prop1";
+ private static final String APP_PROP_2 = "app_prop2";
+
+ @Mock
+ private ZusammenAdaptor zusammenAdaptorMock;
+ @InjectMocks
+ private ItemZusammenDaoImpl itemDao;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ SessionContextProviderFactory.getInstance().createInterface().create(USER);
+ }
+
+ @Test
+ public void testListWhenNone() throws Exception {
+ doReturn(new ArrayList<>()).when(zusammenAdaptorMock)
+ .listItems(eq(createZusammenContext(USER)));
+
+ Collection<Item> items = itemDao.list();
+
+ Assert.assertTrue(items.isEmpty());
+ }
+
+ @Test
+ public void testList() throws Exception {
+ Map<String, Number> vlm1versionStatuses = new HashMap<>();
+ vlm1versionStatuses.put(VersionStatus.Draft.name(), 1);
+
+ Map<String, Number> vsp2versionStatuses = new HashMap<>();
+ vsp2versionStatuses.put(VersionStatus.Draft.name(), 3);
+ vsp2versionStatuses.put(VersionStatus.Certified.name(), 2);
+
+
+ List<com.amdocs.zusammen.datatypes.item.Item> returnedItems = Stream.of(
+ createItem("1", "vsp1", "vsp 1", "vsp", new Date(), new Date(), new HashMap<>()),
+ createItem("2", "vlm1", "vlm 1", "vlm", new Date(), new Date(), vlm1versionStatuses),
+ createItem("3", "vsp2", "vsp 2", "vsp", new Date(), new Date(), vsp2versionStatuses))
+ .collect(Collectors.toList());
+ doReturn(returnedItems).when(zusammenAdaptorMock).listItems(eq(createZusammenContext(USER)));
+
+ Collection<Item> items = itemDao.list();
+ Assert.assertEquals(items.size(), 3);
+
+ Iterator<Item> itemIterator = items.iterator();
+ assertItemEquals(itemIterator.next(), returnedItems.get(0));
+ assertItemEquals(itemIterator.next(), returnedItems.get(1));
+ assertItemEquals(itemIterator.next(), returnedItems.get(2));
+ }
+
+ @Test
+ public void testGetNonExisting() throws Exception {
+ Item requestedItem = new Item();
+ requestedItem.setId("1");
+
+ Item item = itemDao.get(requestedItem);
+
+ Assert.assertNull(item);
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ Item inputItem = new Item();
+ inputItem.setId("1");
+
+ Map<String, Number> versionStatuses = new HashMap<>();
+ versionStatuses.put(VersionStatus.Draft.name(), 3);
+ versionStatuses.put(VersionStatus.Certified.name(), 2);
+
+ com.amdocs.zusammen.datatypes.item.Item toBeReturned =
+ createItem("1", "vsp1", "vsp 1", "vsp", new Date(System.currentTimeMillis() - 100),
+ new Date(), versionStatuses);
+ doReturn(toBeReturned).when(zusammenAdaptorMock)
+ .getItem(eq(createZusammenContext(USER)), eq(new Id(inputItem.getId())));
+
+ Item item = itemDao.get(inputItem);
+
+ Assert.assertNotNull(item);
+ assertItemEquals(item, toBeReturned);
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ Item inputItem = new Item();
+ inputItem.setName("vsp1");
+ inputItem.setDescription("VSP 1");
+ inputItem.setType("vsp");
+
+ ArgumentCaptor<Info> capturedZusammenInfo = ArgumentCaptor.forClass(Info.class);
+
+ String itemId = "1";
+ doReturn(new Id(itemId)).when(zusammenAdaptorMock)
+ .createItem(eq(createZusammenContext(USER)), capturedZusammenInfo.capture());
+
+ Item item = itemDao.create(inputItem);
+
+ Info capturedInfo = capturedZusammenInfo.getValue();
+ Assert.assertEquals(capturedInfo.getName(), inputItem.getName());
+ Assert.assertEquals(capturedInfo.getDescription(), inputItem.getDescription());
+ Assert.assertEquals(capturedInfo.getProperty(ITEM_TYPE), inputItem.getType());
+ Assert.assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES),
+ inputItem.getVersionStatusCounters());
+
+ Assert.assertEquals(item.getId(), itemId);
+ Assert.assertEquals(item.getName(), inputItem.getName());
+ Assert.assertEquals(item.getDescription(), inputItem.getDescription());
+ Assert.assertEquals(item.getType(), inputItem.getType());
+ Assert.assertEquals(item.getVersionStatusCounters(), inputItem.getVersionStatusCounters());
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ Item item = new Item();
+ item.setId("1");
+ item.setName("vsp1");
+ item.setDescription("VSP 1");
+ item.setType("vsp");
+ item.addVersionStatus(VersionStatus.Draft);
+ item.addVersionStatus(VersionStatus.Draft);
+ item.addVersionStatus(VersionStatus.Certified);
+
+ ArgumentCaptor<Info> capturedZusammenInfo = ArgumentCaptor.forClass(Info.class);
+
+ itemDao.update(item);
+
+ verify(zusammenAdaptorMock)
+ .updateItem(eq(createZusammenContext(USER)), eq(new Id(item.getId())),
+ capturedZusammenInfo.capture());
+
+ Info capturedInfo = capturedZusammenInfo.getValue();
+ Assert.assertEquals(capturedInfo.getName(), item.getName());
+ Assert.assertEquals(capturedInfo.getDescription(), item.getDescription());
+ Assert.assertEquals(capturedInfo.getProperty(ITEM_TYPE), item.getType());
+ Assert.assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES),
+ item.getVersionStatusCounters());
+ }
+
+ private com.amdocs.zusammen.datatypes.item.Item createItem(String id, String name,
+ String description, String type,
+ Date creationTime,
+ Date modificationTime,
+ Map<String, Number> versionStatusCounters) {
+ com.amdocs.zusammen.datatypes.item.Item item = new com.amdocs.zusammen.datatypes.item.Item();
+ item.setId(new Id(id));
+ Info info = new Info();
+ info.setName(name);
+ info.setDescription(description);
+ info.addProperty(ITEM_TYPE, type);
+ info.addProperty(ITEM_VERSIONS_STATUSES, versionStatusCounters);
+ info.addProperty(APP_PROP_1, "app_prop1_value");
+ info.addProperty(APP_PROP_2, 8);
+ item.setInfo(info);
+ item.setCreationTime(creationTime);
+ item.setModificationTime(modificationTime);
+ return item;
+ }
+
+ private void assertItemEquals(Item item, com.amdocs.zusammen.datatypes.item.Item zusammenItem) {
+ Assert.assertEquals(item.getId(), zusammenItem.getId().getValue());
+ Assert.assertEquals(item.getName(), zusammenItem.getInfo().getName());
+ Assert.assertEquals(item.getDescription(), zusammenItem.getInfo().getDescription());
+ Assert.assertEquals(item.getType(), zusammenItem.getInfo().getProperty(ITEM_TYPE));
+ Assert.assertEquals(item.getProperties().get(APP_PROP_1),
+ zusammenItem.getInfo().getProperty(APP_PROP_1));
+ Assert.assertEquals(item.getProperties().get(APP_PROP_2),
+ zusammenItem.getInfo().getProperty(APP_PROP_2));
+
+ Map<String, Number> zusammenStatusesMap =
+ zusammenItem.getInfo().getProperty(ITEM_VERSIONS_STATUSES);
+ Map<VersionStatus, Integer> statusesMap = item.getVersionStatusCounters();
+
+ zusammenStatusesMap.entrySet().forEach(entry -> Assert
+ .assertEquals(statusesMap.get(VersionStatus.valueOf(entry.getKey())), entry.getValue()));
+
+ Assert.assertEquals(item.getCreationTime(), zusammenItem.getCreationTime());
+ Assert.assertEquals(item.getModificationTime(), zusammenItem.getModificationTime());
+ }
+
+} \ 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
index 755bfb4442..afffd47943 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
@@ -100,17 +100,48 @@ public class ItemManagerImplTest {
}
@Test
+ public void testUpdateVersionStatusAddFirst() throws Exception {
+ Item item = new Item();
+ item.setId("itemId");
+ doReturn(item).when(itemDao).get(any(Item.class));
+
+ itemManager.updateVersionStatus("itemId", VersionStatus.Draft, null);
+
+ verify(itemDao).update(item);
+ Assert.assertEquals(item.getVersionStatusCounters().size(), 1);
+ Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 1);
+ }
+
+ @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);
+ item.getVersionStatusCounters().put(VersionStatus.Draft, 3);
doReturn(item).when(itemDao).get(any(Item.class));
itemManager.updateVersionStatus("itemId", 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(), 4);
+ Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 2);
+ }
+
+ @Test
+ public void testUpdateVersionStatusRemoveLast() throws Exception {
+ Item item = new Item();
+ item.setId("itemId");
+ 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);
+
+ 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));
}
private Item createItem(String name, String type) {