summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-04-13 11:21:15 +0100
committerMichael Morris <michael.morris@est.tech>2022-04-21 09:48:05 +0000
commit30ff812c65389f5ca4c91d9774d425e81ef62049 (patch)
treeb7d293c23621df6c1084b9ff7dbde9c7d7d888ac /openecomp-be/lib/openecomp-sdc-versioning-lib
parent225dabdf0812d1a3d9eb3a96740507744bb2b807 (diff)
Check if VLM is used before deleting
Checks if the VLM is in use by any VSP before allowing to delete it. Add unit tests for the delete method, considering the restriction. Applies minor refactors with related code. Change-Id: I4ff6ddf3959a4ca92ab68b29c8913fc6f0ebdb3c Issue-ID: SDC-3966 Signed-off-by: andre.schmid <andre.schmid@est.tech>
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/dao/impl/zusammen/ItemZusammenDaoImpl.java52
-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.java30
2 files changed, 48 insertions, 34 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
index 6ac18d9ff9..e2e7b1cc1e 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
@@ -21,9 +21,13 @@ package org.openecomp.sdc.versioning.dao.impl.zusammen;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.item.Info;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.core.zusammen.api.ZusammenUtil;
import org.openecomp.sdc.versioning.dao.ItemDao;
@@ -33,7 +37,7 @@ import org.openecomp.sdc.versioning.types.ItemStatus;
public class ItemZusammenDaoImpl implements ItemDao {
- private ZusammenAdaptor zusammenAdaptor;
+ private final ZusammenAdaptor zusammenAdaptor;
public ItemZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) {
this.zusammenAdaptor = zusammenAdaptor;
@@ -74,7 +78,7 @@ public class ItemZusammenDaoImpl implements ItemDao {
item.setId(zusammenItem.getId().getValue());
item.setName(zusammenItem.getInfo().getName());
item.setDescription(zusammenItem.getInfo().getDescription());
- zusammenItem.getInfo().getProperties().entrySet().forEach(property -> addPropertyToItem(property.getKey(), property.getValue(), item));
+ zusammenItem.getInfo().getProperties().forEach((key, value) -> addPropertyToItem(key, value, item));
item.setCreationTime(zusammenItem.getCreationTime());
item.setModificationTime(zusammenItem.getModificationTime());
if (item.getStatus() == null) {
@@ -85,17 +89,23 @@ public class ItemZusammenDaoImpl implements ItemDao {
}
private void addPropertyToItem(String propertyKey, Object propertyValue, Item item) {
- switch (propertyKey) {
- case InfoPropertyName.ITEM_TYPE:
+ final ItemInfoProperty itemInfoProperty = ItemInfoProperty.findByName(propertyKey).orElse(null);
+ if (itemInfoProperty == null) {
+ item.addProperty(propertyKey, propertyValue);
+ return;
+ }
+
+ switch (itemInfoProperty) {
+ case ITEM_TYPE:
item.setType((String) propertyValue);
break;
- case InfoPropertyName.ITEM_OWNER:
+ case ITEM_OWNER:
item.setOwner((String) propertyValue);
break;
- case InfoPropertyName.ITEM_STATUS:
+ case ITEM_STATUS:
item.setStatus(ItemStatus.valueOf((String) propertyValue));
break;
- case InfoPropertyName.ITEM_VERSIONS_STATUSES:
+ case ITEM_VERSIONS_STATUSES:
for (Map.Entry<String, Number> statusCounter : ((Map<String, Number>) propertyValue).entrySet()) {
item.getVersionStatusCounters().put(VersionStatus.valueOf(statusCounter.getKey()), statusCounter.getValue().intValue());
}
@@ -109,25 +119,29 @@ public class ItemZusammenDaoImpl implements ItemDao {
Info info = new Info();
info.setName(item.getName());
info.setDescription(item.getDescription());
- info.addProperty(InfoPropertyName.ITEM_TYPE, item.getType());
- info.addProperty(InfoPropertyName.ITEM_OWNER, item.getOwner());
+ info.addProperty(ItemInfoProperty.ITEM_TYPE.getName(), item.getType());
+ info.addProperty(ItemInfoProperty.ITEM_OWNER.getName(), item.getOwner());
if (item.getStatus() != null) {
- info.addProperty(InfoPropertyName.ITEM_STATUS, item.getStatus());
+ info.addProperty(ItemInfoProperty.ITEM_STATUS.getName(), item.getStatus());
}
- info.addProperty(InfoPropertyName.ITEM_VERSIONS_STATUSES, item.getVersionStatusCounters());
- item.getProperties().entrySet().forEach(property -> info.addProperty(property.getKey(), property.getValue()));
+ info.addProperty(ItemInfoProperty.ITEM_VERSIONS_STATUSES.getName(), item.getVersionStatusCounters());
+ item.getProperties().forEach(info::addProperty);
return info;
}
- private static final class InfoPropertyName {
+ @AllArgsConstructor
+ @Getter
+ public enum ItemInfoProperty {
+ ITEM_TYPE("item_type"),
+ ITEM_VERSIONS_STATUSES("item_versions_statuses"),
+ ITEM_OWNER("Owner"),
+ ITEM_STATUS("status");
- private static final String ITEM_TYPE = "item_type";
- private static final String ITEM_VERSIONS_STATUSES = "item_versions_statuses";
- private static final String ITEM_OWNER = "Owner";
- private static final String ITEM_STATUS = "status";
+ private final String name;
- private InfoPropertyName() {
- throw new IllegalStateException("Constants class");
+ public static Optional<ItemInfoProperty> findByName(final String name) {
+ return Arrays.stream(values()).filter(itemInfoProperty -> itemInfoProperty.getName().equals(name)).findFirst();
}
+
}
}
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
index a4584d6041..2749185213 100644
--- 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
@@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
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.ItemZusammenDaoImpl.ItemInfoProperty.ITEM_TYPE;
+import static org.openecomp.sdc.versioning.dao.impl.zusammen.ItemZusammenDaoImpl.ItemInfoProperty.ITEM_VERSIONS_STATUSES;
import static org.openecomp.sdc.versioning.dao.impl.zusammen.TestUtil.createZusammenContext;
import com.amdocs.zusammen.datatypes.Id;
@@ -49,8 +51,6 @@ import org.openecomp.sdc.versioning.types.ItemStatus;
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";
private static final String tenant = "dox";
@@ -69,7 +69,7 @@ public class ItemZusammenDaoImplTest {
@Test
public void testListWhenNone() throws Exception {
doReturn(new ArrayList<>()).when(zusammenAdaptorMock)
- .listItems(eq(createZusammenContext(USER)));
+ .listItems(createZusammenContext(USER));
Collection<Item> items = itemDao.list();
@@ -91,10 +91,10 @@ public class ItemZusammenDaoImplTest {
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)));
+ doReturn(returnedItems).when(zusammenAdaptorMock).listItems(createZusammenContext(USER));
Collection<Item> items = itemDao.list();
- assertEquals(items.size(), 3);
+ assertEquals(3, items.size());
Iterator<Item> itemIterator = items.iterator();
assertItemEquals(itemIterator.next(), returnedItems.get(0));
@@ -125,13 +125,13 @@ public class ItemZusammenDaoImplTest {
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())));
+ .getItem(createZusammenContext(USER), new Id(inputItem.getId()));
Item item = itemDao.get(inputItem);
Assert.assertNotNull(item);
assertItemEquals(item, toBeReturned);
- assertEquals(item.getStatus(), ItemStatus.ACTIVE);
+ assertEquals(ItemStatus.ACTIVE, item.getStatus());
}
@@ -153,8 +153,8 @@ public class ItemZusammenDaoImplTest {
Info capturedInfo = capturedZusammenInfo.getValue();
assertEquals(capturedInfo.getName(), inputItem.getName());
assertEquals(capturedInfo.getDescription(), inputItem.getDescription());
- assertEquals(capturedInfo.getProperty(ITEM_TYPE), inputItem.getType());
- assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES),
+ assertEquals(capturedInfo.getProperty(ITEM_TYPE.getName()), inputItem.getType());
+ assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES.getName()),
inputItem.getVersionStatusCounters());
assertEquals(item.getId(), itemId);
@@ -186,8 +186,8 @@ public class ItemZusammenDaoImplTest {
Info capturedInfo = capturedZusammenInfo.getValue();
assertEquals(capturedInfo.getName(), item.getName());
assertEquals(capturedInfo.getDescription(), item.getDescription());
- assertEquals(capturedInfo.getProperty(ITEM_TYPE), item.getType());
- assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES),
+ assertEquals(capturedInfo.getProperty(ITEM_TYPE.getName()), item.getType());
+ assertEquals(capturedInfo.getProperty(ITEM_VERSIONS_STATUSES.getName()),
item.getVersionStatusCounters());
}
@@ -201,8 +201,8 @@ public class ItemZusammenDaoImplTest {
Info info = new Info();
info.setName(name);
info.setDescription(description);
- info.addProperty(ITEM_TYPE, type);
- info.addProperty(ITEM_VERSIONS_STATUSES, versionStatusCounters);
+ info.addProperty(ITEM_TYPE.getName(), type);
+ info.addProperty(ITEM_VERSIONS_STATUSES.getName(), versionStatusCounters);
info.addProperty(APP_PROP_1, "app_prop1_value");
info.addProperty(APP_PROP_2, 8);
item.setInfo(info);
@@ -215,14 +215,14 @@ public class ItemZusammenDaoImplTest {
assertEquals(item.getId(), zusammenItem.getId().getValue());
assertEquals(item.getName(), zusammenItem.getInfo().getName());
assertEquals(item.getDescription(), zusammenItem.getInfo().getDescription());
- assertEquals(item.getType(), zusammenItem.getInfo().getProperty(ITEM_TYPE));
+ assertEquals(item.getType(), zusammenItem.getInfo().getProperty(ITEM_TYPE.getName()));
assertEquals(item.getProperties().get(APP_PROP_1),
zusammenItem.getInfo().getProperty(APP_PROP_1));
assertEquals(item.getProperties().get(APP_PROP_2),
zusammenItem.getInfo().getProperty(APP_PROP_2));
Map<String, Number> zusammenStatusesMap =
- zusammenItem.getInfo().getProperty(ITEM_VERSIONS_STATUSES);
+ zusammenItem.getInfo().getProperty(ITEM_VERSIONS_STATUSES.getName());
Map<VersionStatus, Integer> statusesMap = item.getVersionStatusCounters();
zusammenStatusesMap.entrySet()