9e1dac69e06c92cea4d113117c69d8e0e945d0c3
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / appc / tasks / AppcRunTasksITTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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 package org.onap.so.bpmn.infrastructure.appc.tasks;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.Mockito.doNothing;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.times;
26 import static org.mockito.Mockito.verify;
27
28 import java.util.HashMap;
29 import java.util.Optional;
30 import java.util.UUID;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mockito;
35 import org.onap.appc.client.lcm.model.Action;
36 import org.onap.so.bpmn.BaseTaskTest;
37 import org.onap.so.bpmn.common.BuildingBlockExecution;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
39 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
40 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
41 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
42 import org.springframework.beans.factory.annotation.Autowired;
43
44 public class AppcRunTasksITTest extends BaseTaskTest {
45         
46         @Autowired
47         private AppcRunTasks appcRunTasks;
48         
49         private GenericVnf genericVnf;
50         private RequestContext requestContext;
51         private String msoRequestId;
52
53         @Before
54         public void before() {
55                 genericVnf = setGenericVnf();
56                 msoRequestId = UUID.randomUUID().toString();
57                 requestContext = setRequestContext();
58                 requestContext.setMsoRequestId(msoRequestId);
59                 gBBInput.setRequestContext(requestContext);
60         }
61         
62         @Test 
63         public void preProcessActivityTest() throws Exception {
64                 appcRunTasks.preProcessActivity(execution);
65                 assertEquals(execution.getVariable("actionQuiesceTraffic"), Action.QuiesceTraffic);
66                 assertEquals(execution.getVariable("rollbackQuiesceTraffic"), false);           
67         }
68         
69         @Test
70         public void runAppcCommandTest() throws Exception {
71                 Action action = Action.QuiesceTraffic;
72                 ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
73                 controllerSelectionReference.setControllerName("testName");
74                 controllerSelectionReference.setActionCategory(action.toString());
75                 controllerSelectionReference.setVnfType("testVnfType");
76                 
77                 doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.QuiesceTraffic.toString());
78                 
79                 execution.setVariable("aicIdentity", "testAicIdentity");                
80                 
81                 String vnfId = genericVnf.getVnfId();
82                 genericVnf.setIpv4OamAddress("testOamIpAddress");
83                 String payload = "{\"testName\":\"testValue\",}";
84                 RequestParameters requestParameters = new RequestParameters();
85                 requestParameters.setPayload(payload);
86                 gBBInput.getRequestContext().setRequestParameters(requestParameters);
87                 
88                 String controllerType = "testName";
89                 HashMap<String, String> payloadInfo = new HashMap<String, String>();
90                 payloadInfo.put("vnfName", "testVnfName1");             
91                 payloadInfo.put("aicIdentity", "testAicIdentity");
92                 payloadInfo.put("vnfHostIpAddress", "testOamIpAddress");
93                 payloadInfo.put("vserverIdList", null);
94                 payloadInfo.put("vfModuleId", null);
95                 payloadInfo.put("identityUrl", null);
96                 payloadInfo.put("vmIdList", null);
97                 
98                 doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
99                 
100                 appcRunTasks.runAppcCommand(execution, action);
101                 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
102         }
103 }