2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.appc.tasks;
25 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
26 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.junit.Assert.assertEquals;
29 import static org.mockito.ArgumentMatchers.eq;
30 import static org.mockito.Mockito.doReturn;
31 import static org.mockito.Mockito.when;
32 import java.nio.file.Files;
33 import java.nio.file.Paths;
34 import java.util.ArrayList;
35 import java.util.Optional;
36 import org.junit.Test;
37 import org.mockito.ArgumentMatchers;
38 import org.mockito.InjectMocks;
39 import org.onap.aai.domain.yang.Vserver;
40 import org.onap.appc.client.lcm.model.Action;
41 import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest;
42 import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf;
43 import org.onap.so.bpmn.BaseTaskTest;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
46 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
47 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
48 import org.onap.so.client.aai.entities.AAIResultWrapper;
49 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
50 import org.onap.so.client.policy.JettisonStyleMapperProvider;
51 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
52 import com.fasterxml.jackson.databind.ObjectMapper;
54 public class AppcOrchestratorPreProcessorTest extends BaseTaskTest {
56 private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/";
59 private AppcOrchestratorPreProcessor appcOrchestratorPreProcessor = new AppcOrchestratorPreProcessor();
61 private ObjectMapper mapper = new JettisonStyleMapperProvider().getMapper();
64 public void buildAppcTaskRequestTest() throws Exception {
65 final String expectedRequestJson =
66 new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "appcTaskRequest.json")));
67 ApplicationControllerTaskRequest expectedTaskRequest =
68 mapper.readValue(expectedRequestJson, ApplicationControllerTaskRequest.class);
69 execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "-TEST");
70 fillRequiredAppcExecutionFields();
71 GenericVnf genericVnf = getTestGenericVnf();
72 when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
73 mockReferenceResponse();
74 execution.getLookupMap().put(ResourceKey.VF_MODULE_ID, "VF-MODULE-ID-TEST");
75 VfModule vfModule = new VfModule();
76 vfModule.setVfModuleId("VF-MODULE-ID");
77 when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
78 appcOrchestratorPreProcessor.buildAppcTaskRequest(execution, "Lock");
79 ApplicationControllerTaskRequest actualTaskRequest = execution.getVariable("appcOrchestratorRequest");
80 assertThat(actualTaskRequest, sameBeanAs(expectedTaskRequest));
84 public void getVserversForAppcTest() throws Exception {
86 GenericVnf genericVnf = getTestGenericVnf();
88 final String aaiVnfJson =
89 new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnfWithVservers.json")));
90 final String aaiVserverJson =
91 new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverQueryResponse.json")));
92 AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiVnfJson);
93 ObjectMapper mapper = new ObjectMapper();
94 Vserver vserver = mapper.readValue(aaiVserverJson, Vserver.class);
95 doReturn(aaiResultWrapper).when(aaiVnfResources).queryVnfWrapperById(genericVnf);
96 doReturn(Optional.of(vserver)).when(aaiVnfResources).getVserver(ArgumentMatchers.any(AAIResourceUri.class));
97 appcOrchestratorPreProcessor.getVserversForAppc(execution, genericVnf);
98 ArrayList<String> vserverIdList = execution.getVariable("vserverIdList");
99 ArrayList<String> expectedVserverIdList = new ArrayList<String>();
100 expectedVserverIdList.add("1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5");
101 expectedVserverIdList.add("14551849-1e70-45cd-bc5d-a256d49548a2");
102 expectedVserverIdList.add("48bd7f11-408f-417c-b834-b41c1b98f7d7");
103 ArrayList<String> vmIdList = execution.getVariable("vmIdList");
104 ArrayList<String> expectedVmIdList = new ArrayList<String>();
105 expectedVmIdList.add("http://VSERVER-link.com");
106 expectedVmIdList.add("http://VSERVER-link.com");
107 expectedVmIdList.add("http://VSERVER-link.com");
108 assertEquals(vserverIdList, expectedVserverIdList);
109 assertEquals(vmIdList, expectedVmIdList);
113 public void addVmInfoToAppcTaskRequestTest() throws Exception {
114 ApplicationControllerTaskRequest appcTaskRequest = new ApplicationControllerTaskRequest();
115 ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf();
116 appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf);
117 execution.setVariable("appcOrchestratorRequest", appcTaskRequest);
118 ArrayList<String> vmIdList = new ArrayList<String>();
119 vmIdList.add("http://VSERVER-link.com");
120 vmIdList.add("http://VSERVER-link.com");
121 vmIdList.add("http://VSERVER-link.com");
122 execution.setVariable("vmIdList", vmIdList);
123 ArrayList<String> vserverIdList = new ArrayList<String>();
124 vserverIdList.add("1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5");
125 vserverIdList.add("14551849-1e70-45cd-bc5d-a256d49548a2");
126 vserverIdList.add("48bd7f11-408f-417c-b834-b41c1b98f7d7");
127 execution.setVariable("vserverIdList", vserverIdList);
128 execution.setVariable("vmIndex", 1);
129 appcOrchestratorPreProcessor.addVmInfoToAppcTaskRequest(execution);
130 Integer nextVmIndex = execution.getVariable("vmIndex");
131 assertThat(nextVmIndex == 2);
132 Integer vmIdListSize = execution.getVariable("vmIdListSize");
133 assertThat(vmIdListSize == 3);
134 appcTaskRequest = execution.getVariable("appcOrchestratorRequest");
135 assertEquals(appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm().getVserverId(),
136 "14551849-1e70-45cd-bc5d-a256d49548a2");
137 assertEquals(appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm().getVmId(),
138 "http://VSERVER-link.com");
141 private void mockReferenceResponse() {
142 ControllerSelectionReference reference = new ControllerSelectionReference();
143 reference.setControllerName("TEST-CONTROLLER-NAME");
144 when(catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(eq("TEST-VNF-TYPE"),
145 eq(Action.Lock.toString()))).thenReturn(reference);
148 private void fillRequiredAppcExecutionFields() {
149 RequestContext context = new RequestContext();
150 context.setMsoRequestId("TEST-MSO-ID");
151 execution.setVariable("aicIdentity", "AIC-TEST");
152 execution.setVariable("vmIdList", "VM-ID-LIST-TEST");
153 execution.setVariable("vserverIdList", "VSERVER-ID-LIST");
154 execution.setVariable("identityUrl", "IDENTITY-URL-TEST");
155 execution.getGeneralBuildingBlock().setRequestContext(context);
158 private GenericVnf getTestGenericVnf() {
159 GenericVnf genericVnf = new GenericVnf();
160 genericVnf.setVnfId("TEST-VNF-ID");
161 genericVnf.setVnfType("TEST-VNF-TYPE");
162 genericVnf.setVnfName("TEST-VNF-NAME");
163 genericVnf.setIpv4OamAddress("127.0.0.1");