2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.services;
23 import com.fasterxml.jackson.databind.JsonNode;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.onap.vid.aai.AaiClientInterface;
28 import org.onap.vid.model.aaiTree.AAITreeNode;
29 import org.onap.vid.utils.Unchecked;
30 import org.testng.Assert;
31 import org.testng.annotations.BeforeTest;
32 import org.testng.annotations.Test;
34 import java.io.IOException;
35 import java.util.HashMap;
36 import java.util.concurrent.ConcurrentLinkedQueue;
37 import java.util.concurrent.ConcurrentSkipListSet;
38 import java.util.concurrent.ThreadPoolExecutor;
39 import java.util.concurrent.atomic.AtomicInteger;
41 import static java.util.Comparator.comparing;
42 import static org.mockito.Mockito.when;
43 import static org.onap.vid.services.AAIServiceTree.AAI_TREE_PATHS;
45 public class AAITreeNodeBuilderTest {
47 AAITreeNodeBuilder aaiTreeNodeBuilder;
50 AaiClientInterface aaiClientMock;
53 ThreadPoolExecutor threadPoolMock;
57 public void initMocks() {
58 MockitoAnnotations.initMocks(this);
59 aaiTreeNodeBuilder = new AAITreeNodeBuilder(aaiClientMock);
63 public void buildNode_buildGroupNode_NodeIsAsExpected(){
64 ConcurrentSkipListSet<AAITreeNode> nodesAccumulator = new ConcurrentSkipListSet<>(comparing(AAITreeNode::getUniqueNodeKey));
65 ConcurrentLinkedQueue<String> visitedNodes = new ConcurrentLinkedQueue<>();
66 when(aaiClientMock.typedAaiGet(Unchecked.toURI("anyUrl"), JsonNode.class)).thenReturn(createGroupJson());
68 AAITreeNode groupNode = aaiTreeNodeBuilder.buildNode("instance-group",
74 AAI_TREE_PATHS).get(0);
76 AAITreeNode expectedGroupNode = createExpectedGroupNode();
77 assertNodeIsAsExpected(expectedGroupNode,groupNode);
80 private void assertNodeIsAsExpected(AAITreeNode expectedGroupNode, AAITreeNode groupNode) {
81 Assert.assertEquals(groupNode.getId(), expectedGroupNode.getId());
82 Assert.assertEquals(groupNode.getType(), expectedGroupNode.getType());
83 Assert.assertEquals(groupNode.getName(), expectedGroupNode.getName());
84 Assert.assertEquals(groupNode.getModelVersionId(), expectedGroupNode.getModelVersionId());
85 Assert.assertEquals(groupNode.getModelInvariantId(), expectedGroupNode.getModelInvariantId());
86 Assert.assertEquals(groupNode.getInMaint(), expectedGroupNode.getInMaint());
87 Assert.assertEquals(groupNode.getAdditionalProperties(), expectedGroupNode.getAdditionalProperties());
90 private AAITreeNode createExpectedGroupNode() {
91 AAITreeNode expectedNode = new AAITreeNode();
92 expectedNode.setId("c4fcf022-31a0-470a-b5b8-c18335b7af32");
93 expectedNode.setType("instance-group");
94 expectedNode.setName("Test vE-Flex");
95 expectedNode.setModelVersionId("Test vE-Flex");
96 expectedNode.setModelInvariantId("dd182d7d-6949-4b90-b3cc-5befe400742e");
97 expectedNode.setInMaint(false);
98 HashMap<String,Object> additionalProperties = new HashMap<>();
99 additionalProperties.put("inMaint","false");
100 additionalProperties.put("description","Test vE-Flex instance-group");
101 additionalProperties.put("instance-group-type","ha");
102 additionalProperties.put("instance-group-role","test-IG-role");
103 additionalProperties.put("resource-version","1533315433086");
104 additionalProperties.put("instance-group-function","vTSBC Customer Landing Network Collection");
105 expectedNode.setAdditionalProperties(additionalProperties);
111 private JsonNode createGroupJson() {
112 ObjectMapper objectMapper = new ObjectMapper();
113 JsonNode groupNode = null;
115 groupNode = objectMapper.readTree("" +
117 " \"id\": \"c4fcf022-31a0-470a-b5b8-c18335b7af32\"," +
118 " \"instance-group-role\": \"test-IG-role\"," +
119 " \"description\": \"Test vE-Flex instance-group\"," +
120 " \"instance-group-type\": \"ha\"," +
121 " \"resource-version\": \"1533315433086\"," +
122 " \"instance-group-name\": \"Test vE-Flex\"," +
123 " \"model-invariant-id\": \"dd182d7d-6949-4b90-b3cc-5befe400742e\"," +
124 " \"model-version-id\": \"Test vE-Flex\"," +
125 " \"inMaint\": \"false\"," +
126 " \"instance-group-function\": \"vTSBC Customer Landing Network Collection\"," +
127 " \"relationship-list\": {" +
128 " \"relationship\": [{" +
129 " \"related-to\": \"generic-vnf\"," +
130 " \"relationship-label\": \"org.onap.relationships.inventory.MemberOf\" ," +
131 " \"related-link\": \"/aai/v14/network/generic-vnfs/generic-vnf/8c54c369-2876-4423-9b33-80f783f29082\" ," +
132 " \"relationship-data\": [{" +
133 " \"relationship-key\": \"generic-vnf.vnf-id\"," +
134 " \"relationship-value\": \"8c54c369-2876-4423-9b33-80f783f29082\"" +
137 " \"related-to-property\": [{" +
138 " \"property-key\": \"generic-vnf.vnf-name\"," +
139 " \"property-value\": \"zrdm5bffad01\"" +
146 } catch (IOException e) {