aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-dao/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-dao/src')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/TagData.java51
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java56
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java17
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/TagDataTest.java9
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEventTest.java24
-rw-r--r--catalog-dao/src/test/resources/fixtures/ListCapabilityDataDefinition2.json17
6 files changed, 121 insertions, 53 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/TagData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/TagData.java
index 43b52e2a54..949aa83c14 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/TagData.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/TagData.java
@@ -20,6 +20,10 @@
package org.openecomp.sdc.be.resources.data;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -27,6 +31,10 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import java.util.HashMap;
import java.util.Map;
+@Getter
+@Setter
+@EqualsAndHashCode
+@ToString
public class TagData extends GraphNode {
private String name;
@@ -56,49 +64,6 @@ public class TagData extends GraphNode {
return map;
}
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- return "Tag [Name=" + name + "]";
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- TagData other = (TagData) obj;
- if (name == null) {
- if (other.getClass() != null) {
- return false;
- }
- } else if (!name.equals(other.getName())) {
- return false;
- }
- return true;
- }
-
@Override
public String getUniqueIdKey() {
return GraphPropertiesDictionary.NAME.getProperty();
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java
index 0cb045aaad..ea562b1f3e 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java
@@ -21,13 +21,17 @@
package org.openecomp.sdc.be.dao.utils;
import com.google.common.collect.ImmutableMap;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
import java.util.*;
import java.util.function.Function;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.openecomp.sdc.be.dao.utils.MapUtil.mergeMaps;
public class MapUtilTest {
@@ -64,14 +68,54 @@ public class MapUtilTest {
}
@Test
public void testGet() throws Exception {
- Map<String, ? extends Object> map = null;
+ Map<String, ? extends Object> mapWildcard = null;
String path = "";
Object result;
- // default test
- result = MapUtil.get(map, path);
- path = "\\mock\\mock";
- result = MapUtil.get(map, path);
+ result = MapUtil.get(mapWildcard, path);
+ assertNull(result);
+
+ path = "mock1.mock2";
+
+ Map<String, Object> map = new HashMap<>();
+ map.put("mock1", "test");
+ mapWildcard = map;
+ result = MapUtil.get(mapWildcard, path);
+ assertNull(result);
+
+ Map<String, Integer> subMap = new HashMap<>();
+ subMap.put("mock2", 1);
+ Map<String, ? extends Object> subMapWildcard = subMap;
+ map.put("mock1", subMapWildcard);
+ mapWildcard = map;
+ result = MapUtil.get(mapWildcard, path);
+ assertEquals(1, result);
+ }
+
+ @Test
+ public void testFlattenMapValues() throws Exception {
+ assertNotNull(MapUtil.flattenMapValues(null));
+
+ Map<String, List<String>> map = new HashMap<>();
+ List<String> list1 = new LinkedList<>();
+ list1.add("test1");
+ List<String> list2 = new LinkedList<>();
+ list2.add("test2");
+ map.put("key1", list1);
+ map.put("key2", list2);
+ List<String> result = MapUtil.flattenMapValues(map);
+ assertEquals(2, result.size());
+ assertEquals("test1", result.get(0));
+ assertEquals("test2", result.get(1));
+ }
+
+ @Test
+ public void testStreamOfNullable() throws Exception {
+ assertEquals(0, MapUtil.streamOfNullable(null).count());
+
+ Collection collectionTest = new LinkedList<String>();
+ collectionTest.add("test");
+ assertEquals(1, MapUtil.streamOfNullable(collectionTest).count());
}
@Test
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java
index 21a728053c..09e751580f 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java
@@ -37,12 +37,16 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.openecomp.sdc.be.utils.FixtureHelpers.fixture;
import static org.openecomp.sdc.be.utils.JsonTester.testJsonMap;
public class JsonParserUtilsTests {
private static final String FIXTURE_PATH = "fixtures/ListCapabilityDataDefinition.json";
+ private static final String FIXTURE_PATH2 = "fixtures/ListCapabilityDataDefinition2.json";
@Test
public void testToMap() {
@@ -54,6 +58,19 @@ public class JsonParserUtilsTests {
}
@Test
+ public void testToList() {
+ assertNull(JsonParserUtils.toList(null, ListCapabilityDataDefinition.class));
+ String json = fixture(FIXTURE_PATH2);
+ List<ListCapabilityDataDefinition> actual = JsonParserUtils.toList(json,
+ ListCapabilityDataDefinition.class);
+ assertEquals(1, actual.size());
+ CapabilityDataDefinition expectedDef = buildListCapabilityDataDefinition().getListToscaDataDefinition().get(0);
+ CapabilityDataDefinition actualDef = actual.get(0).getListToscaDataDefinition().get(0);
+ assertEquals(1, actual.get(0).getListToscaDataDefinition().size());
+ assertEquals(expectedDef, actualDef);
+ }
+
+ @Test
public void testJacksonFasterXml() {
ObjectMapper mapper = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/TagDataTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/TagDataTest.java
index c1729d0f3d..919b7c7663 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/TagDataTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/TagDataTest.java
@@ -20,13 +20,15 @@
package org.openecomp.sdc.be.resources.data;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
public class TagDataTest {
private TagData createTestSubject() {
@@ -90,6 +92,7 @@ public class TagDataTest {
result = testSubject.hashCode();
}
+
@Test
public void testEquals() throws Exception {
TagData testSubject;
@@ -100,7 +103,7 @@ public class TagDataTest {
testSubject = createTestSubject();
obj = null;
result = testSubject.equals(obj);
- Assert.assertEquals(false, result);
+ assertEquals(false, result);
}
@Test
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEventTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEventTest.java
index f0557aaee5..7a94b4da27 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEventTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEventTest.java
@@ -20,7 +20,14 @@
package org.openecomp.sdc.be.resources.data.auditing;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class AuditingGenericEventTest {
@@ -29,6 +36,21 @@ public class AuditingGenericEventTest {
}
@Test
+ public void testTimestamp() throws Exception {
+ AuditingGenericEvent testSubject = createTestSubject();
+ testSubject.setTimestamp("timestamp");
+ assertEquals("timestamp", testSubject.getTimestamp());
+ }
+
+ @Test
+ public void testFields() throws Exception {
+ AuditingGenericEvent testSubject = createTestSubject();
+ Map<String, Object> map = new HashMap<>();
+ testSubject.setFields(map);
+ assertNotNull(testSubject.getFields());
+ }
+
+ @Test
public void testGetRequestId() throws Exception {
AuditingGenericEvent testSubject;
String result;
diff --git a/catalog-dao/src/test/resources/fixtures/ListCapabilityDataDefinition2.json b/catalog-dao/src/test/resources/fixtures/ListCapabilityDataDefinition2.json
new file mode 100644
index 0000000000..81485110d0
--- /dev/null
+++ b/catalog-dao/src/test/resources/fixtures/ListCapabilityDataDefinition2.json
@@ -0,0 +1,17 @@
+[[
+ {
+ "name": "forwarder",
+ "type": "org.openecomp.capabilities.Forwarder",
+ "uniqueId": "capability.deb142fd-95eb-48f7-99ae-81ab09466b1e.forwarder",
+ "ownerId": "deb142fd-95eb-48f7-99ae-81ab09466b1e",
+ "capabilitySources": [
+ "org.openecomp.resource.cp.nodes.network.Port",
+ "org.openecomp.resource.cp.v2.extCP",
+ "org.openecomp.resource.cp.v2.extContrailCP"
+ ],
+ "minOccurrences": "1",
+ "leftOccurrences": "UNBOUNDED",
+ "maxOccurrences": "UNBOUNDED",
+ "empty": false
+ }
+]]