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 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;
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;
52 public class AAIServiceTreeTest {
55 private VidService sdcService;
57 private ServiceModelInflator serviceModelInflator;
59 private AAIServiceTree aaiServiceTree;
62 public void initMocks() {
63 MockitoAnnotations.initMocks(this);
67 public void whenBuildTreeForOneResource_resultAsExpected() {
69 AaiClient aaiClientMock = mock(AaiClient.class);
70 ExecutorService executorService = MoreExecutors.newDirectExecutorService();
71 AAIServiceTree aaiServiceTree = new AAIServiceTree(
72 new AAITreeNodeBuilder(aaiClientMock, new Logging()),
74 new AAITreeConverter(new ModelUtil()), null,
78 String url = "anyUrl/vnf";
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);
83 CloudConfiguration expectedCloudConfiguration = new CloudConfiguration("dyh3b", "c8035f5ee95d4c62bbc8074c044122b9", "irma-aic");
84 AAITreeNode expectedVnfNode = createExpectedVnfTreeNode(expectedCloudConfiguration);
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"));