diff options
author | aditya <ag282f@att.com> | 2017-10-23 23:43:59 -0500 |
---|---|---|
committer | aditya <ag282f@att.com> | 2017-10-26 15:00:59 -0500 |
commit | 559158d0731400894fd0fce10566328c6f39061d (patch) | |
tree | 1eeb76838ae3fe1d2a39d3de2dc5f88dc3f84de2 /src | |
parent | efd104965f09ccfedc9efb5692cbd7a0e04ef6ce (diff) |
Add unit test cases to increase sonar coverage
Add unit tests to test model loader, entity statistics and data provider
Issue-ID: AAI-429
Change-Id: I18142712d2c3cc5ee48d7c6689323016da57f726
Signed-off-by: Aditya Gajulapalli <ag282f@att.com>
Diffstat (limited to 'src')
5 files changed, 602 insertions, 0 deletions
diff --git a/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderTest.java b/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderTest.java new file mode 100644 index 0000000..3ef571e --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/config/oxm/OxmModelLoaderTest.java @@ -0,0 +1,50 @@ +/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.config.oxm;
+
+import static org.junit.Assert.assertNotEquals;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class OxmModelLoaderTest {
+
+ OxmModelLoader loader;
+
+ @Test
+ public void testLoadModel_ShouldSucceed() throws IOException {
+ String version = "v11";
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+
+ loader = Mockito.spy(new OxmModelLoader());
+ Mockito.when(loader.loadOxmFileName(version)).thenReturn(
+ System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/aai_oxm_" + version + ".xml");
+
+ loader.loadModel(version);
+
+ assertNotEquals(null, loader.getOxmModel());
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryAdapterTest.java b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryAdapterTest.java new file mode 100644 index 0000000..9f18ab2 --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/dal/aai/ActiveInventoryAdapterTest.java @@ -0,0 +1,102 @@ +/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.dal.aai;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.NoSuchElementException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;
+import org.onap.aai.sparky.dal.rest.RestClientBuilder;
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+
+public class ActiveInventoryAdapterTest {
+
+ OxmModelLoader oxmModelLoader;
+ ActiveInventoryAdapter adapter;
+
+ @Before
+ public void init() throws IOException, ElasticSearchOperationException {
+ String version = "v11";
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+ TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";
+ oxmModelLoader = Mockito.spy(new OxmModelLoader());
+ Mockito.when(oxmModelLoader.loadOxmFileName(version)).thenReturn(
+ System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/aai_oxm_" + version + ".xml");
+
+ adapter = new ActiveInventoryAdapter(new RestClientBuilder());
+ }
+
+ @Test
+ public void testQueryActiveInventoryWithRetries() {
+
+ adapter.queryActiveInventoryWithRetries("https://localhost:9517/model/aai/webapp/index.html", "response-type-1", 1);
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testGetSelfLinkForEntity_NullEntityType() throws Exception {
+
+ adapter.getSelfLinkForEntity(null, "key", "value");
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testGetSelfLinkForEntity_NullKeyName() throws Exception {
+
+ adapter.getSelfLinkForEntity("entity", null, "value");
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testGetSelfLinkForEntity_NullKeyValue() throws Exception {
+
+ adapter.getSelfLinkForEntity("entity", "key", null);
+ }
+
+ @Test
+ public void testGetSelfLinkForEntity_ServiceInstance() throws Exception {
+
+ adapter.getSelfLinkForEntity("service-instance", "key", "value");
+ }
+
+ @Test
+ public void testGetSelfLinkForEntity_NotServiceInstance() throws Exception {
+
+ adapter.getSelfLinkForEntity("service", "key", "value");
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testGetSelfLinkByEntityType_NullEntity() throws Exception {
+
+ adapter.getSelfLinksByEntityType(null);
+ }
+
+ @Test(expected=NoSuchElementException.class)
+ public void testGetSelfLinkByEntityType_NullEntityDescriptor() throws Exception {
+
+ adapter.getSelfLinksByEntityType("entity-1");
+ }
+
+}
diff --git a/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatisticsTest.java b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatisticsTest.java new file mode 100644 index 0000000..6e4cf8a --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/dal/elasticsearch/ElasticSearchEntityStatisticsTest.java @@ -0,0 +1,101 @@ +/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.dal.elasticsearch;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.dal.NetworkTransaction;
+import org.onap.aai.sparky.dal.rest.HttpMethod;
+import org.onap.aai.sparky.dal.rest.OperationResult;
+
+public class ElasticSearchEntityStatisticsTest {
+
+ @Test
+ public void testInitializeCountersFromOxmEntityDescriptors_NotNullDescriptors() {
+
+ ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader());
+ Map<String, OxmEntityDescriptor> descriptors = new HashMap<>();
+
+ OxmEntityDescriptor oxmEd = new OxmEntityDescriptor();
+ oxmEd.setEntityName("entity-1");
+ oxmEd.setGeoLatName("geoLatName-1");
+
+ descriptors.put("entity-1", oxmEd);
+
+ eses.initializeCountersFromOxmEntityDescriptors(descriptors);
+ eses.reset();
+ }
+
+ @Test
+ public void testInitializeCountersFromOxmEntityDescriptors_NullDescriptors() {
+
+ ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader());
+ Map<String, OxmEntityDescriptor> descriptors = null;
+ eses.initializeCountersFromOxmEntityDescriptors(descriptors);
+ }
+
+ @Test
+ public void testUpdateCounters() {
+
+ ElasticSearchEntityStatistics eses = new ElasticSearchEntityStatistics(new OxmModelLoader());
+ Map<String, OxmEntityDescriptor> descriptors = new HashMap<>();
+
+ OxmEntityDescriptor oxmEd = new OxmEntityDescriptor();
+ oxmEd.setEntityName("entity-1");
+ oxmEd.setGeoLatName("geoLatName-1");
+ descriptors.put("entity-1", oxmEd);
+
+ eses.initializeCountersFromOxmEntityDescriptors(descriptors);
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(200);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ eses.updateCounters(ntwTxn);
+
+ result.setResultCode(201);
+ NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ eses.updateCounters(ntwTxn1);
+
+ result.setResultCode(202);
+ NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ eses.updateCounters(ntwTxn2);
+ NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
+ eses.updateCounters(ntwTxn3);
+
+ result.setResultCode(101);
+ NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ eses.updateCounters(ntwTxn4);
+ NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
+ eses.updateCounters(ntwTxn5);
+
+ String statistics = eses.getStatisticsReport();
+ Assert.assertNotNull(statistics);
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/dal/rest/RestOperationalStatisticsTest.java b/src/test/java/org/onap/aai/sparky/dal/rest/RestOperationalStatisticsTest.java new file mode 100644 index 0000000..415cbe7 --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/dal/rest/RestOperationalStatisticsTest.java @@ -0,0 +1,210 @@ +/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.dal.rest;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sparky.dal.NetworkTransaction;
+
+public class RestOperationalStatisticsTest {
+
+ @Test
+ public void testUpdateCounters_Get() {
+ RestOperationalStatistics ros = new RestOperationalStatistics();
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(101);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ ros.updateCounters(ntwTxn1);
+
+ result.setResultCode(201);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ ros.updateCounters(ntwTxn2);
+
+ result.setResultCode(301);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ ros.updateCounters(ntwTxn3);
+
+ result.setResultCode(401);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ ros.updateCounters(ntwTxn4);
+
+ result.setResultCode(501);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ ros.updateCounters(ntwTxn5);
+
+ result.setResultCode(601);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.GET, "entity-1", result);
+ ros.updateCounters(ntwTxn6);
+
+ String statistics = ros.getStatisticsReport();
+ Assert.assertNotNull(statistics);
+ }
+
+ @Test
+ public void testUpdateCounters_Put() {
+ RestOperationalStatistics ros = new RestOperationalStatistics();
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(101);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ ros.updateCounters(ntwTxn1);
+
+ result.setResultCode(201);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ ros.updateCounters(ntwTxn2);
+
+ result.setResultCode(301);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ ros.updateCounters(ntwTxn3);
+
+ result.setResultCode(401);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ ros.updateCounters(ntwTxn4);
+
+ result.setResultCode(501);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ ros.updateCounters(ntwTxn5);
+
+ result.setResultCode(601);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.PUT, "entity-1", result);
+ ros.updateCounters(ntwTxn6);
+
+ String statistics = ros.getStatisticsReport();
+ Assert.assertNotNull(statistics);
+ }
+
+ @Test
+ public void testUpdateCounters_Post() {
+ RestOperationalStatistics ros = new RestOperationalStatistics();
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(101);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.POST, "entity-1", result);
+ ros.updateCounters(ntwTxn1);
+
+ result.setResultCode(201);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.POST, "entity-1", result);
+ ros.updateCounters(ntwTxn2);
+
+ result.setResultCode(301);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.POST, "entity-1", result);
+ ros.updateCounters(ntwTxn3);
+
+ result.setResultCode(401);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.POST, "entity-1", result);
+ ros.updateCounters(ntwTxn4);
+
+ result.setResultCode(501);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.POST, "entity-1", result);
+ ros.updateCounters(ntwTxn5);
+
+ result.setResultCode(601);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.POST, "entity-1", result);
+ ros.updateCounters(ntwTxn6);
+
+ String statistics = ros.getStatisticsReport();
+ Assert.assertNotNull(statistics);
+ }
+
+ @Test
+ public void testUpdateCounters_Delete() {
+ RestOperationalStatistics ros = new RestOperationalStatistics();
+
+ OperationResult result = new OperationResult();
+ result.setResultCode(101);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn1 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
+ ros.updateCounters(ntwTxn1);
+
+ result.setResultCode(201);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn2 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
+ ros.updateCounters(ntwTxn2);
+
+ result.setResultCode(301);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn3 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
+ ros.updateCounters(ntwTxn3);
+
+ result.setResultCode(401);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn4 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
+ ros.updateCounters(ntwTxn4);
+
+ result.setResultCode(501);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn5 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
+ ros.updateCounters(ntwTxn5);
+
+ result.setResultCode(601);
+ result.setResult("result-1");
+ result.setNumRequestRetries(1);
+ NetworkTransaction ntwTxn6 = new NetworkTransaction(HttpMethod.DELETE, "entity-1", result);
+ ros.updateCounters(ntwTxn6);
+
+ String statistics = ros.getStatisticsReport();
+ Assert.assertNotNull(statistics);
+ }
+}
diff --git a/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContextTest.java b/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContextTest.java new file mode 100644 index 0000000..08ce29d --- /dev/null +++ b/src/test/java/org/onap/aai/sparky/viewandinspect/services/VisualizationContextTest.java @@ -0,0 +1,139 @@ +/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.sparky.viewandinspect.services;
+
+import java.io.File;
+import java.io.IOException;
+import java.security.SecureRandom;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.ExecutorService;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
+import org.onap.aai.sparky.config.oxm.OxmModelLoader;
+import org.onap.aai.sparky.dal.aai.ActiveInventoryAdapter;
+import org.onap.aai.sparky.dal.aai.ActiveInventoryDataProvider;
+import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;
+import org.onap.aai.sparky.dal.rest.RestClientBuilder;
+import org.onap.aai.sparky.synchronizer.entity.SearchableEntity;
+import org.onap.aai.sparky.util.NodeUtils;
+import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
+import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
+import org.onap.aai.sparky.viewandinspect.entity.QueryParams;
+import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class VisualizationContextTest {
+
+ VisualizationContext context;
+ ActiveInventoryDataProvider dataProvider;
+ long contextId;
+ OxmModelLoader oxmModelLoader;
+ ExecutorService service;
+
+ @Before
+ public void init() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
+ TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";
+ TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/";
+ oxmModelLoader = Mockito.spy(OxmModelLoader.getInstance());
+ ActiveInventoryDataProvider dataProvider = new ActiveInventoryAdapter(new RestClientBuilder());
+ SecureRandom random = new SecureRandom();
+ long contextId = random.nextLong();
+ ExecutorService service = NodeUtils.createNamedExecutor("SLNC-WORKER",
+ 2, LoggerFactory.getInstance().getLogger(VisualizationContextTest.class));
+ context = new VisualizationContext(contextId, dataProvider, service, oxmModelLoader);
+ }
+
+ @Test
+ public void testExtractQueryParamsFromSelfLink_NullLink() {
+ List<String> queryParams = context.extractQueryParamsFromSelfLink(null);
+ Assert.assertEquals(queryParams.size(), 0);
+ }
+
+ @Test
+ public void testExtractQueryParamsFromSelfLink_NotNullLink() {
+ context.extractQueryParamsFromSelfLink("https://localhost:9517/model/aai/webapp/index.html");
+ }
+
+ @Test
+ public void testDecodeComplexAttributeGroup_NullAttributeGroup() {
+ ActiveInventoryNode ain = new ActiveInventoryNode();
+ ObjectNode node = JsonNodeFactory.instance.objectNode();
+ boolean retValue = context.decodeComplexAttributeGroup(ain, node);
+ Assert.assertFalse(retValue);
+ }
+
+ @Test
+ public void testDecodeComplexAttributeGroup_NotNullAttributeGroup() {
+ ActiveInventoryNode ain = new ActiveInventoryNode();
+ ObjectNode node1 = JsonNodeFactory.instance.objectNode();
+ ObjectNode node2 = JsonNodeFactory.instance.objectNode();
+ node1.set("model", node2);
+ ObjectNode modelNode = JsonNodeFactory.instance.objectNode();
+ node2.set("model-1", modelNode);
+ modelNode.set("firstValue", JsonNodeFactory.instance.objectNode());
+ modelNode.set("secondValue", JsonNodeFactory.instance.objectNode());
+ modelNode.set("thirdValue", JsonNodeFactory.instance.objectNode());
+ boolean retValue = context.decodeComplexAttributeGroup(ain, node1);
+ Assert.assertFalse(retValue);
+ }
+
+ @Test
+ public void testProcessSelfLinks() {
+ SearchableEntity entity = new SearchableEntity();
+ entity.setId("id-1");
+ entity.setEntityType("cloud-region");
+ entity.setEntityPrimaryKeyValue("cloud-region-1");
+ entity.setLink("https://localhost:9517/model/aai/webapp/index.html");
+ QueryParams params = new QueryParams();
+ params.setSearchTargetNodeId("id-1");
+ Map<String, ActiveInventoryNode> nodeMap = context.getNodeCache();
+ ActiveInventoryNode node = new ActiveInventoryNode();
+ node.setEntityType("cloud-region");
+ node.setNodeId("id-1");
+ node.setPrimaryKeyName("cloud-region-1");
+ node.setPrimaryKeyValue("cloud-region-1");
+ node.addQueryParam(
+ node.getEntityType() + "." + node.getPrimaryKeyName() + ":" + node.getPrimaryKeyValue());
+ node.setNodeDepth(0);
+ node.setRootNode(true);
+ node.setSelfLink(entity.getLink());
+ nodeMap.put("id-1", node);
+ node.setResolvedSelfLink(true);
+ context.processSelfLinks(entity, params);
+
+ }
+}
|