Add unit tests to increase sonar coverage 15/27315/1
authoraditya <ag282f@att.com>
Wed, 3 Jan 2018 23:25:58 +0000 (17:25 -0600)
committeraditya <ag282f@att.com>
Wed, 3 Jan 2018 23:25:58 +0000 (17:25 -0600)
Add unit tests to entity, exception, search and util packages

Issue-ID: AAI-499

Change-Id: I8e2ca9055f97ac2db16c256d4d4ae417a158e66c
Signed-off-by: Aditya Gajulapalli <ag282f@att.com>
src/test/java/org/onap/aai/datarouter/entity/AaiEventEntityTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/datarouter/exception/DataRouterExceptionTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/datarouter/policy/EntityEventPolicyConfigTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/datarouter/search/filters/config/FiltersConfigTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/datarouter/util/CrossEntityReferenceTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/datarouter/util/DataRouterPropertiesTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/datarouter/util/NodeUtilsTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/datarouter/util/RouterServiceUtilTest.java [new file with mode: 0644]

diff --git a/src/test/java/org/onap/aai/datarouter/entity/AaiEventEntityTest.java b/src/test/java/org/onap/aai/datarouter/entity/AaiEventEntityTest.java
new file mode 100644 (file)
index 0000000..413fd74
--- /dev/null
@@ -0,0 +1,166 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.datarouter.entity;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.onap.aai.datarouter.util.CrossEntityReference;\r
+\r
+import java.io.IOException;\r
+import java.security.NoSuchAlgorithmException;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+public class AaiEventEntityTest {\r
+\r
+    @Test\r
+    public void testAddCrossEntityReferenceValue(){\r
+        AaiEventEntity eventEntity = new AaiEventEntity();\r
+        Assert.assertTrue(eventEntity.crossEntityReferenceCollection.size()==0);\r
+        eventEntity.addCrossEntityReferenceValue("reference-1");\r
+        Assert.assertTrue(eventEntity.crossEntityReferenceCollection.size()==1);\r
+    }\r
+\r
+    @Test\r
+    public void testOtherMethods(){\r
+        AaiEventEntity eventEntity = new AaiEventEntity();\r
+        eventEntity.setEntityType("type-1");\r
+        Assert.assertEquals(eventEntity.getEntityType(), "type-1");\r
+\r
+        eventEntity.setSearchTagCollection(new ArrayList<String>());\r
+        Assert.assertTrue(eventEntity.getSearchTagCollection().size()==0);\r
+\r
+        eventEntity.setSearchTags("tag-1");\r
+        Assert.assertEquals(eventEntity.getSearchTags(), "tag-1");\r
+\r
+        eventEntity.setSearchTagIDs("tagid-1");\r
+        Assert.assertEquals(eventEntity.getSearchTagIDs(), "tagid-1");\r
+\r
+        eventEntity.setId("id-1");\r
+        Assert.assertEquals(eventEntity.getId(), "id-1");\r
+\r
+        eventEntity.setSearchTagIdCollection(new ArrayList<String>());\r
+        Assert.assertTrue(eventEntity.getSearchTagIdCollection().size()==0);\r
+\r
+        eventEntity.setLastmodTimestamp("2017-28-12");\r
+        Assert.assertEquals(eventEntity.getLastmodTimestamp(), "2017-28-12");\r
+\r
+        eventEntity.setLink("link-1");\r
+        Assert.assertEquals(eventEntity.getLink(), "link-1");\r
+\r
+        eventEntity.setCrossReferenceEntityValues("cross-entity");\r
+        Assert.assertEquals(eventEntity.getCrossReferenceEntityValues(), "cross-entity");\r
+\r
+        Assert.assertNotNull(eventEntity.toString());\r
+    }\r
+\r
+    @Test\r
+    public void testAggregationEntity(){\r
+        AggregationEntity entity = new AggregationEntity();\r
+        entity.setLastmodTimestamp("2017-28-12");\r
+        Assert.assertEquals(entity.getLastmodTimestamp(), "2017-28-12");\r
+\r
+        entity.addAttributeKeyValuePair("key1", "value1");\r
+\r
+        Map<String, Object> entityMap = new HashMap<String, Object>();\r
+        entityMap.put("relationship", "relationship-value");\r
+        entityMap.put("relationship-list", new ArrayList<String>());\r
+        entity.copyAttributeKeyValuePair(entityMap);\r
+\r
+        Assert.assertTrue(entity.attributes.containsKey("relationship"));\r
+        Assert.assertFalse(entity.attributes.containsKey("relationship-list"));\r
+\r
+        entity.setId("id-1");\r
+        entity.setLink("link-1");\r
+        Assert.assertNotNull(entity.toString());\r
+    }\r
+\r
+    @Test\r
+    public void testOxmEntityDescriptor(){\r
+        OxmEntityDescriptor descriptor = new OxmEntityDescriptor();\r
+        descriptor.setEntityName("entity-1");\r
+        Assert.assertEquals(descriptor.getEntityName(), "entity-1");\r
+\r
+        descriptor.setPrimaryKeyAttributeName(new ArrayList<String>());\r
+        Assert.assertTrue(descriptor.getPrimaryKeyAttributeName().size()==0);\r
+\r
+        Assert.assertFalse(descriptor.hasSearchableAttributes());\r
+\r
+        List<String> searchableAttr = new ArrayList<String>();\r
+        searchableAttr.add("search");\r
+        descriptor.setSearchableAttributes(searchableAttr);\r
+        Assert.assertTrue(descriptor.getSearchableAttributes().size()==1);\r
+\r
+        Assert.assertTrue(descriptor.hasSearchableAttributes());\r
+\r
+        CrossEntityReference ref = new CrossEntityReference();\r
+        descriptor.setCrossEntityReference(ref);\r
+        Assert.assertEquals(descriptor.getCrossEntityReference(), ref);\r
+\r
+        descriptor.setSuggestableEntity(true);\r
+        Assert.assertTrue(descriptor.isSuggestableEntity());\r
+\r
+        Assert.assertNotNull(descriptor.toString());\r
+    }\r
+\r
+    @Test\r
+    public void testPolicyResponse(){\r
+        PolicyResponse response = new PolicyResponse(PolicyResponse.ResponseType.SUCCESS, "response-data");\r
+\r
+        Assert.assertEquals(response.getResponseType(), PolicyResponse.ResponseType.SUCCESS);\r
+        Assert.assertEquals(response.getResponseData(), "response-data");\r
+\r
+        response.setHttpResponseCode(200);\r
+        Assert.assertTrue(response.getHttpResponseCode() == 200);\r
+\r
+        Assert.assertNotNull(response.toString());\r
+    }\r
+\r
+    @Test\r
+    public void testTopographicalEntity() throws NoSuchAlgorithmException, IOException {\r
+        TopographicalEntity entity = new TopographicalEntity();\r
+        String retStr = entity.generateUniqueShaDigest("entity", "name-1", "value-1");\r
+        Assert.assertNotNull(retStr);\r
+\r
+        entity.setEntityType("type-1");\r
+        Assert.assertEquals(entity.getEntityType(),"type-1");\r
+        entity.setEntityPrimaryKeyName("key-1");\r
+        Assert.assertEquals(entity.getEntityPrimaryKeyName(), "key-1");\r
+        entity.setEntityPrimaryKeyValue("value-1");\r
+        Assert.assertEquals(entity.getEntityPrimaryKeyValue(),"value-1");\r
+        entity.setLatitude("37.0902");\r
+        Assert.assertEquals(entity.getLatitude(),"37.0902");\r
+        entity.setLongitude("95.7129");\r
+        Assert.assertEquals(entity.getLongitude(),"95.7129");\r
+        entity.setId("id-1");\r
+        Assert.assertEquals(entity.getId(),"id-1");\r
+        entity.setSelfLink("link-1");\r
+        Assert.assertEquals(entity.getSelfLink(),"link-1");\r
+\r
+        Assert.assertNotNull(TopographicalEntity.getSerialversionuid());\r
+        Assert.assertNotNull(entity.getAsJson());\r
+        Assert.assertNotNull(entity.toString());\r
+    }\r
+}\r
diff --git a/src/test/java/org/onap/aai/datarouter/exception/DataRouterExceptionTest.java b/src/test/java/org/onap/aai/datarouter/exception/DataRouterExceptionTest.java
new file mode 100644 (file)
index 0000000..ecf845c
--- /dev/null
@@ -0,0 +1,51 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.datarouter.exception;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import javax.ws.rs.core.Response;\r
+\r
+public class DataRouterExceptionTest {\r
+\r
+    @Test\r
+    public void testDataRouterError(){\r
+        DataRouterError error1 = DataRouterError.DL_PARSE_100;\r
+        Assert.assertEquals("DL-100", error1.getId());\r
+        Assert.assertNotNull(error1.getMessage());\r
+        Assert.assertEquals(Response.Status.BAD_REQUEST, error1.getHttpStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testBaseDataRouterException(){\r
+        BaseDataRouterException exp1 = new BaseDataRouterException("id-1");\r
+        Assert.assertEquals(exp1.getId(), "id-1");\r
+\r
+        BaseDataRouterException exp2 = new BaseDataRouterException("id-1", "test-error");\r
+        Assert.assertEquals(exp2.getId(), "id-1");\r
+\r
+        BaseDataRouterException exp3 = new BaseDataRouterException("id-1", "test-error", new Throwable());\r
+        Assert.assertEquals(exp3.getId(), "id-1");\r
+    }\r
+}\r
diff --git a/src/test/java/org/onap/aai/datarouter/policy/EntityEventPolicyConfigTest.java b/src/test/java/org/onap/aai/datarouter/policy/EntityEventPolicyConfigTest.java
new file mode 100644 (file)
index 0000000..7324071
--- /dev/null
@@ -0,0 +1,69 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.datarouter.policy;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+public class EntityEventPolicyConfigTest {\r
+\r
+    @Test\r
+    public void testAllMethods() {\r
+        EntityEventPolicyConfig eConfig = new EntityEventPolicyConfig();\r
+        eConfig.setSourceDomain("source-domain");\r
+        Assert.assertEquals(eConfig.getSourceDomain(),"source-domain");\r
+\r
+        eConfig.setSearchBaseUrl("http://base-url");\r
+        Assert.assertEquals(eConfig.getSearchBaseUrl(),"http://base-url");\r
+\r
+        eConfig.setSearchEndpoint("end-point");\r
+        Assert.assertEquals(eConfig.getSearchEndpoint(),"end-point");\r
+\r
+        eConfig.setSearchEndpointDocuments("end-document");\r
+        Assert.assertEquals(eConfig.getSearchEndpointDocuments(),"end-document");\r
+\r
+        eConfig.setSearchEntitySearchIndex("search-index");\r
+        Assert.assertEquals(eConfig.getSearchEntitySearchIndex(),"search-index");\r
+\r
+        eConfig.setSearchTopographySearchIndex("topography");\r
+        Assert.assertEquals(eConfig.getSearchTopographySearchIndex(),"topography");\r
+\r
+        eConfig.setSearchEntityAutoSuggestIndex("auto-suggest");\r
+        Assert.assertEquals(eConfig.getSearchEntityAutoSuggestIndex(),"auto-suggest");\r
+\r
+        eConfig.setSearchCertName("cert-name");\r
+        Assert.assertEquals(eConfig.getSearchCertName(),"cert-name");\r
+\r
+        eConfig.setSearchKeystore("key-store");\r
+        Assert.assertEquals(eConfig.getSearchKeystore(),"key-store");\r
+\r
+        eConfig.setSearchKeystorePwd("key-store-pass");\r
+        Assert.assertEquals(eConfig.getSearchKeystorePwd(),"key-store-pass");\r
+\r
+        eConfig.setSearchAggregationVnfIndex("vnf-index");\r
+        Assert.assertEquals(eConfig.getSearchAggregationVnfIndex(),"vnf-index");\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/src/test/java/org/onap/aai/datarouter/search/filters/config/FiltersConfigTest.java b/src/test/java/org/onap/aai/datarouter/search/filters/config/FiltersConfigTest.java
new file mode 100644 (file)
index 0000000..073e306
--- /dev/null
@@ -0,0 +1,80 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.datarouter.search.filters.config;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+public class FiltersConfigTest {\r
+\r
+    @Test\r
+    public void testUiFiltersConfig_AllMethods(){\r
+\r
+        UiFilterDataSourceConfig dsConfig = getDataSourceConfig();\r
+        UiFilterConfig filterConfig = getFilterConfig(dsConfig);\r
+\r
+        List<UiFilterConfig> filters = new ArrayList<UiFilterConfig>();\r
+        filters.add(filterConfig);\r
+        UiFiltersConfig config1 = new UiFiltersConfig(filters);\r
+        Assert.assertNotNull(config1);\r
+        UiFiltersConfig config2 = new UiFiltersConfig();\r
+        config2.setFilters(filters);\r
+        Assert.assertTrue(config2.getFilters().size()==1);\r
+        Assert.assertNotNull(config2.toString());\r
+    }\r
+\r
+    private UiFilterConfig getFilterConfig(UiFilterDataSourceConfig dsConfig) {\r
+        UiFilterConfig filterConfig = new UiFilterConfig("id-1", "name-1",\r
+                "display-1", "dataType-1", dsConfig);\r
+        filterConfig.setFilterId("id-1");\r
+        Assert.assertEquals("id-1", filterConfig.getFilterId());\r
+        filterConfig.setFilterName("name-1");\r
+        Assert.assertEquals("name-1", filterConfig.getFilterName());\r
+        filterConfig.setDisplayName("display-1");\r
+        Assert.assertEquals("display-1", filterConfig.getDisplayName());\r
+        filterConfig.setDataType("dataType-1");\r
+        Assert.assertEquals("dataType-1", filterConfig.getDataType());\r
+        filterConfig.setDataSource(dsConfig);\r
+        Assert.assertEquals(dsConfig, filterConfig.getDataSource());\r
+        Assert.assertNotNull(filterConfig.toString());\r
+        return filterConfig;\r
+    }\r
+\r
+    private UiFilterDataSourceConfig getDataSourceConfig() {\r
+        UiFilterDataSourceConfig dsConfig = new UiFilterDataSourceConfig("index-1", "doctype-1",\r
+                "field-1", "path-1");\r
+        dsConfig.setIndexName("index-1");\r
+        Assert.assertEquals("index-1", dsConfig.getIndexName());\r
+        dsConfig.setDocType("doctype-1");\r
+        Assert.assertEquals("doctype-1", dsConfig.getDocType());\r
+        dsConfig.setFieldName("field-1");\r
+        Assert.assertEquals("field-1", dsConfig.getFieldName());\r
+        dsConfig.setPathToField("path-1");\r
+        Assert.assertEquals("path-1", dsConfig.getPathToField());\r
+        Assert.assertNotNull(dsConfig.toString());\r
+        return dsConfig;\r
+    }\r
+}\r
diff --git a/src/test/java/org/onap/aai/datarouter/util/CrossEntityReferenceTest.java b/src/test/java/org/onap/aai/datarouter/util/CrossEntityReferenceTest.java
new file mode 100644 (file)
index 0000000..79a3141
--- /dev/null
@@ -0,0 +1,51 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.datarouter.util;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+public class CrossEntityReferenceTest {\r
+\r
+    @Test\r
+    public void testCrossEntityReference() {\r
+\r
+        CrossEntityReference reference = new CrossEntityReference();\r
+\r
+        reference.setTargetEntityType("entity-type");\r
+        Assert.assertEquals(reference.getTargetEntityType(),"entity-type");\r
+\r
+        reference.setAttributeNames(new ArrayList<String>());\r
+        Assert.assertTrue(reference.getAttributeNames().size()==0);\r
+\r
+        reference.addAttributeName("attribute");\r
+        Assert.assertEquals(reference.getAttributeNames().get(0),"attribute");\r
+    }\r
+\r
+\r
+}
\ No newline at end of file
diff --git a/src/test/java/org/onap/aai/datarouter/util/DataRouterPropertiesTest.java b/src/test/java/org/onap/aai/datarouter/util/DataRouterPropertiesTest.java
new file mode 100644 (file)
index 0000000..84616d4
--- /dev/null
@@ -0,0 +1,35 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.datarouter.util;\r
+\r
+import org.junit.Test;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+public class DataRouterPropertiesTest {\r
+\r
+    @Test\r
+    public void testGet(){\r
+        DataRouterProperties.get("key");\r
+    }\r
+}
\ No newline at end of file
diff --git a/src/test/java/org/onap/aai/datarouter/util/NodeUtilsTest.java b/src/test/java/org/onap/aai/datarouter/util/NodeUtilsTest.java
new file mode 100644 (file)
index 0000000..19af9eb
--- /dev/null
@@ -0,0 +1,100 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.datarouter.util;\r
+\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.fasterxml.jackson.databind.node.ObjectNode;\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+public class NodeUtilsTest {\r
+\r
+    @Test\r
+    public void testGenerateUniqueShaDigest_NullParam(){\r
+        NodeUtils utils = new NodeUtils();\r
+        String keys=null;\r
+        String hashdId = NodeUtils.generateUniqueShaDigest();\r
+        Assert.assertNull(hashdId);\r
+    }\r
+\r
+    @Test\r
+    public void testExtractFieldValueFromObject_NullNode_ExpectNullString(){\r
+        JsonNode node = null;\r
+        String valueNode = NodeUtils.extractFieldValueFromObject(node, "field-1");\r
+        Assert.assertNull(valueNode);\r
+    }\r
+\r
+    @Test\r
+    public void testExtractFieldValueFromObject_NotNullNode_ExpectNotNullString() throws IOException {\r
+        String jsonStr = "{\"key\":\"value\"}";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        JsonNode node = mapper.readTree(jsonStr);\r
+        String valueNode = NodeUtils.extractFieldValueFromObject(node, "key");\r
+        Assert.assertEquals(valueNode, "value");\r
+    }\r
+\r
+    @Test\r
+    public void testConvertJsonStrToJsonNode_NullJsonStr() throws IOException {\r
+        String jsonStr = null;\r
+        JsonNode jsonNode = NodeUtils.convertJsonStrToJsonNode(jsonStr);\r
+        Assert.assertNull(jsonNode);\r
+    }\r
+\r
+    @Test\r
+    public void testExtractObjectsByKey() throws IOException {\r
+        String jsonStr = "{\n" +\r
+                "  \"id\"   : 1,\n" +\r
+                "  \"name\" : {\n" +\r
+                "    \"first\" : \"user\",\n" +\r
+                "    \"last\" : \"name\"\n" +\r
+                "  },\n" +\r
+                "  \"contact\" : [\n" +\r
+                "    { \"type\" : \"phone/home\", \"ref\" : \"111-111-1234\"},\n" +\r
+                "    { \"type\" : \"phone/work\", \"ref\" : \"222-222-2222\"}\n" +\r
+                "  ]\n" +\r
+                "}";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        JsonNode node = mapper.readTree(jsonStr);\r
+        List arrList = new ArrayList();\r
+        NodeUtils.extractObjectsByKey(node, "name", arrList);\r
+    }\r
+\r
+    @Test\r
+    public void testConvertObjectToJson() throws IOException {\r
+        String jsonStr = "{\"key\":\"value\"}";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        Object node = mapper.readTree(jsonStr);\r
+        String retNode1 = NodeUtils.convertObjectToJson(node, false);\r
+        Assert.assertNotNull(retNode1);\r
+        String retNode2 = NodeUtils.convertObjectToJson(node, true);\r
+        Assert.assertNotNull(retNode2);\r
+    }\r
+}
\ No newline at end of file
diff --git a/src/test/java/org/onap/aai/datarouter/util/RouterServiceUtilTest.java b/src/test/java/org/onap/aai/datarouter/util/RouterServiceUtilTest.java
new file mode 100644 (file)
index 0000000..a49427e
--- /dev/null
@@ -0,0 +1,143 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.datarouter.util;\r
+\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import javax.json.Json;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+public class RouterServiceUtilTest {\r
+\r
+    @Test\r
+    public void testParseJsonPayloadIntoMap(){\r
+        String jsonStr = "{\"key1\":\"value1\", \"key2\":\"value2\", \"key3\":\"value3\"}";\r
+        Map<String, String> retMap = RouterServiceUtil.parseJsonPayloadIntoMap(jsonStr);\r
+        Assert.assertNotNull(retMap);\r
+        Assert.assertEquals(retMap.get("key1"), "value1");\r
+    }\r
+\r
+    @Test\r
+    public void testGetNodeFieldAsText() throws IOException {\r
+        String jsonStr = "{\"key\":\"value\"}";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        JsonNode node = mapper.readTree(jsonStr);\r
+        String field = RouterServiceUtil.getNodeFieldAsText(node, "key");\r
+    }\r
+\r
+    @Test\r
+    public void testConcatArray_NullList(){\r
+        List<String> strList = null;\r
+        String result = RouterServiceUtil.concatArray(strList);\r
+        Assert.assertTrue(result.isEmpty());\r
+    }\r
+\r
+    /*Method in RouterServiceUtil is wrong. It should be corrected\r
+    @Test\r
+    public void testConcatArray_NotNullList(){\r
+        List<String> strList = new ArrayList<String>();\r
+        strList.add("str1");\r
+        strList.add("str2");\r
+        strList.add("str3");\r
+        String result = RouterServiceUtil.concatArray(strList);\r
+        Assert.assertEquals(result, "str1 str2 str3");\r
+    }*/\r
+\r
+    @Test\r
+    public void testConcatArray_NullArray(){\r
+        String[] values = new String[]{};\r
+        //String[] values = new String[]{"value1", "value2", "value3"};\r
+        String result = RouterServiceUtil.concatArray(values);\r
+        Assert.assertTrue(result.isEmpty());\r
+    }\r
+\r
+    @Test\r
+    public void testConcatArray_NotNullArray(){\r
+        String[] values = new String[]{"value1", "value2", "value3"};\r
+        String result = RouterServiceUtil.concatArray(values);\r
+        Assert.assertEquals(result, "value1.value2.value3");\r
+    }\r
+\r
+    @Test\r
+    public void testRecursivelyLookupJsonPayload_JsonArray() throws IOException {\r
+        String jsonStr = "[{\"key1\":\"value1\"}, {\"key2\":\"value2\"}]";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        JsonNode node = mapper.readTree(jsonStr);\r
+        String result = RouterServiceUtil.recursivelyLookupJsonPayload(node, "key1");\r
+        Assert.assertEquals(result, "value1");\r
+    }\r
+\r
+    @Test\r
+    public void testExtractObjectsByKey() throws IOException {\r
+        String jsonStr = "[{\"key1\":\"value1\"}, {\"key2\":\"value2\"}]";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        JsonNode node = mapper.readTree(jsonStr);\r
+        List<JsonNode> nodeList = new ArrayList<JsonNode>();\r
+        RouterServiceUtil.extractObjectsByKey(node, "key1", nodeList);\r
+        Assert.assertTrue(nodeList.size() == 1);\r
+    }\r
+\r
+    @Test\r
+    public void testConvertArrayIntoList() throws IOException {\r
+        String jsonStr = "[{\"key1\":\"value1\"}, {\"key2\":\"value2\"}]";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        JsonNode node = mapper.readTree(jsonStr);\r
+        List<JsonNode> nodeList = new ArrayList<JsonNode>();\r
+        RouterServiceUtil.convertArrayIntoList(node, nodeList);\r
+        Assert.assertTrue(nodeList.size() == 2);\r
+    }\r
+\r
+    @Test\r
+    public void testExtractFieldValueFromObject() throws IOException {\r
+        String jsonStr = "{\"key1\":\"value1\"}";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        JsonNode node = mapper.readTree(jsonStr);\r
+        List<String> attrList = new ArrayList<String>();\r
+        attrList.add("key1");\r
+        List<String> valueList = new ArrayList<String>();\r
+        RouterServiceUtil.extractFieldValuesFromObject(node,attrList,valueList);\r
+        Assert.assertTrue(valueList.size()==1);\r
+        Assert.assertTrue(valueList.get(0).equals("value1"));\r
+    }\r
+\r
+    @Test\r
+    public void testObjToJson() throws IOException {\r
+        String jsonStr = "{\"key1\":\"value1\"}";\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        Object node = mapper.readTree(jsonStr);\r
+        String retJson = RouterServiceUtil.objToJson(node);\r
+        Assert.assertNotNull("localhost/aai/data-router/");\r
+    }\r
+\r
+    @Test\r
+    public void testConcatSubUri(){\r
+        String finalSubUri = RouterServiceUtil.concatSubUri("localhost/","aai/","data-router");\r
+        Assert.assertEquals(finalSubUri, "localhost/aai/data-router/");\r
+    }\r
+}\r