2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017 Amdocs
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 package org.onap.aai.sparky.viewandinspect.services;
\r
25 import java.io.File;
\r
26 import java.io.IOException;
\r
27 import java.security.SecureRandom;
\r
28 import java.util.List;
\r
29 import java.util.Map;
\r
30 import java.util.HashMap;
\r
31 import java.util.concurrent.ExecutorService;
\r
33 import org.junit.Assert;
\r
34 import org.junit.Before;
\r
35 import org.junit.Test;
\r
36 import org.mockito.InjectMocks;
\r
37 import org.mockito.Mockito;
\r
38 import org.mockito.MockitoAnnotations;
\r
39 import org.onap.aai.cl.eelf.LoggerFactory;
\r
40 import org.onap.aai.sparky.config.oxm.OxmEntityDescriptor;
\r
41 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
\r
42 import org.onap.aai.sparky.dal.aai.ActiveInventoryAdapter;
\r
43 import org.onap.aai.sparky.dal.aai.ActiveInventoryDataProvider;
\r
44 import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;
\r
45 import org.onap.aai.sparky.dal.rest.RestClientBuilder;
\r
46 import org.onap.aai.sparky.synchronizer.entity.SearchableEntity;
\r
47 import org.onap.aai.sparky.util.NodeUtils;
\r
48 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
\r
49 import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
\r
50 import org.onap.aai.sparky.viewandinspect.entity.QueryParams;
\r
51 import org.onap.aai.sparky.viewandinspect.enumeration.NodeProcessingState;
\r
53 import com.fasterxml.jackson.databind.JsonNode;
\r
54 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
\r
55 import com.fasterxml.jackson.databind.node.ObjectNode;
\r
57 public class VisualizationContextTest {
\r
59 VisualizationContext context;
\r
60 ActiveInventoryDataProvider dataProvider;
\r
62 OxmModelLoader oxmModelLoader;
\r
63 ExecutorService service;
\r
66 public void init() throws Exception {
\r
67 MockitoAnnotations.initMocks(this);
\r
68 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
\r
69 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION =
\r
70 System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/";
\r
71 TierSupportUiConstants.CONFIG_OXM_LOCATION =
\r
72 System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/";
\r
73 oxmModelLoader = Mockito.spy(OxmModelLoader.getInstance());
\r
74 ActiveInventoryDataProvider dataProvider = new ActiveInventoryAdapter(new RestClientBuilder());
\r
75 SecureRandom random = new SecureRandom();
\r
76 long contextId = random.nextLong();
\r
77 ExecutorService service = NodeUtils.createNamedExecutor("SLNC-WORKER", 2,
\r
78 LoggerFactory.getInstance().getLogger(VisualizationContextTest.class));
\r
79 context = new VisualizationContext(contextId, dataProvider, service, oxmModelLoader);
\r
83 public void testExtractQueryParamsFromSelfLink_NullLink() {
\r
84 List<String> queryParams = context.extractQueryParamsFromSelfLink(null);
\r
85 Assert.assertEquals(queryParams.size(), 0);
\r
89 public void testExtractQueryParamsFromSelfLink_NotNullLink() {
\r
90 context.extractQueryParamsFromSelfLink("https://localhost:9517/model/aai/webapp/index.html");
\r
94 public void testDecodeComplexAttributeGroup_NullAttributeGroup() {
\r
95 ActiveInventoryNode ain = new ActiveInventoryNode();
\r
96 ObjectNode node = JsonNodeFactory.instance.objectNode();
\r
97 boolean retValue = context.decodeComplexAttributeGroup(ain, node);
\r
98 Assert.assertFalse(retValue);
\r
102 public void testDecodeComplexAttributeGroup_NotNullAttributeGroup() {
\r
103 ActiveInventoryNode ain = new ActiveInventoryNode();
\r
104 ObjectNode node1 = JsonNodeFactory.instance.objectNode();
\r
105 ObjectNode node2 = JsonNodeFactory.instance.objectNode();
\r
106 node1.set("model", node2);
\r
107 ObjectNode modelNode = JsonNodeFactory.instance.objectNode();
\r
108 node2.set("model-1", modelNode);
\r
109 modelNode.set("firstValue", JsonNodeFactory.instance.objectNode());
\r
110 modelNode.set("secondValue", JsonNodeFactory.instance.objectNode());
\r
111 modelNode.set("thirdValue", JsonNodeFactory.instance.objectNode());
\r
112 boolean retValue = context.decodeComplexAttributeGroup(ain, node1);
\r
113 Assert.assertFalse(retValue);
\r
117 public void testProcessSelfLinks() {
\r
118 SearchableEntity entity = new SearchableEntity();
\r
119 entity.setId("id-1");
\r
120 entity.setEntityType("cloud-region");
\r
121 entity.setEntityPrimaryKeyValue("cloud-region-1");
\r
122 entity.setLink("https://localhost:9517/model/aai/webapp/index.html");
\r
123 QueryParams params = new QueryParams();
\r
124 params.setSearchTargetNodeId("id-1");
\r
125 Map<String, ActiveInventoryNode> nodeMap = context.getNodeCache();
\r
126 ActiveInventoryNode node = new ActiveInventoryNode();
\r
127 node.setEntityType("cloud-region");
\r
128 node.setNodeId("id-1");
\r
129 node.setPrimaryKeyName("cloud-region-1");
\r
130 node.setPrimaryKeyValue("cloud-region-1");
\r
131 node.addQueryParam(
\r
132 node.getEntityType() + "." + node.getPrimaryKeyName() + ":" + node.getPrimaryKeyValue());
\r
133 node.setNodeDepth(0);
\r
134 node.setRootNode(true);
\r
135 node.setSelfLink(entity.getLink());
\r
136 nodeMap.put("id-1", node);
\r
137 node.setResolvedSelfLink(true);
\r
138 context.processSelfLinks(entity, params);
\r