Topology tree: extract AAITreeNodesEnricher out of AAIServiceTree
[vid.git] / vid-app-common / src / test / java / org / onap / vid / services / AAIServiceTreeTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.vid.services;
22
23 import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.junit.Assert.assertEquals;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28 import static org.onap.vid.services.AAITreeNodeBuilderTest.createExpectedVnfTreeNode;
29
30 import com.fasterxml.jackson.databind.JsonNode;
31 import com.google.common.util.concurrent.MoreExecutors;
32 import java.util.List;
33 import java.util.concurrent.ExecutorService;
34 import net.javacrumbs.jsonunit.core.Option;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 import org.onap.vid.aai.AaiClient;
39 import org.onap.vid.aai.util.AAITreeConverter;
40 import org.onap.vid.asdc.parser.ServiceModelInflator;
41 import org.onap.vid.model.ModelUtil;
42 import org.onap.vid.model.aaiTree.AAITreeNode;
43 import org.onap.vid.model.aaiTree.NodeType;
44 import org.onap.vid.mso.model.CloudConfiguration;
45 import org.onap.vid.testUtils.TestUtils;
46 import org.onap.vid.utils.Logging;
47 import org.onap.vid.utils.Unchecked;
48 import org.springframework.http.HttpMethod;
49 import org.testng.annotations.BeforeTest;
50 import org.testng.annotations.Test;
51
52 public class AAIServiceTreeTest {
53
54     @Mock
55     private VidService sdcService;
56     @Mock
57     private ServiceModelInflator serviceModelInflator;
58     @InjectMocks
59     private AAIServiceTree aaiServiceTree;
60
61     @BeforeTest
62     public void initMocks() {
63         MockitoAnnotations.initMocks(this);
64     }
65
66     @Test
67     public void whenBuildTreeForOneResource_resultAsExpected() {
68
69         AaiClient aaiClientMock = mock(AaiClient.class);
70         ExecutorService executorService = MoreExecutors.newDirectExecutorService();
71         AAIServiceTree aaiServiceTree = new AAIServiceTree(
72             new AAITreeNodeBuilder(aaiClientMock, new Logging()),
73             null,
74             new AAITreeConverter(new ModelUtil()), null,
75             executorService
76         );
77
78         String url = "anyUrl/vnf";
79
80         JsonNode mockedAaiGetVnfResponse = TestUtils.readJsonResourceFileAsObject("/getTopology/vnf.json", JsonNode.class);
81         when(aaiClientMock.typedAaiRest(Unchecked.toURI(url), JsonNode.class, null, HttpMethod.GET, false)).thenReturn(mockedAaiGetVnfResponse);
82
83         CloudConfiguration expectedCloudConfiguration = new CloudConfiguration("dyh3b", "c8035f5ee95d4c62bbc8074c044122b9", "irma-aic");
84         AAITreeNode expectedVnfNode = createExpectedVnfTreeNode(expectedCloudConfiguration);
85
86         List<AAITreeNode> aaiTreeNodes = aaiServiceTree.buildAAITreeForUniqueResource(url, NodeType.GENERIC_VNF);
87         assertEquals(1, aaiTreeNodes.size());
88         assertThat(aaiTreeNodes.get(0), jsonEquals(expectedVnfNode).when(Option.IGNORING_EXTRA_FIELDS).whenIgnoringPaths("relationshipList", "children[0].relationshipList"));
89     }
90 }