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