Merge "Removing so-monitoring module"
[so.git] / so-etsi-nfvo / so-etsi-nfvo-ns-lcm / so-etsi-nfvo-ns-lcm-bpmn-flows / src / test / java / org / onap / so / etsi / nfvo / ns / workflow / engine / tasks / MonitorInstantiateSol003AdapterNodeTaskTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks;
21
22 import static com.github.tomakehurst.wiremock.client.WireMock.get;
23 import static com.github.tomakehurst.wiremock.client.WireMock.ok;
24 import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
25 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.UUID;
32 import org.camunda.bpm.engine.history.HistoricProcessInstance;
33 import org.camunda.bpm.engine.history.HistoricVariableInstance;
34 import org.camunda.bpm.engine.runtime.ProcessInstance;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest;
38 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants;
39 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks.MonitorInstantiateSol003AdapterNodeTask;
40
41 /**
42  * @author Waqas Ikram (waqas.ikram@est.tech)
43  *
44  */
45 public class MonitorInstantiateSol003AdapterNodeTaskTest extends BaseTest {
46
47     private static final String RANDOWM_GENERIC_VNF_ID = UUID.randomUUID().toString();
48     private static final String MONITOR_SOL003_ADAPTER_CREATE_NODE_STATUS_WORKFLOW =
49             "MonitorSol003AdapterCreateNodeStatus";
50
51     @Before
52     public void before() {
53         wireMockServer.resetAll();
54     }
55
56     @Test
57     public void testMonitorSol003AdapterCreateNodeStatus_SuccessfullCase() throws InterruptedException {
58
59         final String modelEndpoint = "/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + UUID_REGEX;
60
61         wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok())
62                 .willReturn(okJson("{\"orchestration-status\": \"Created\"}")));
63
64
65         final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_CREATE_NODE_STATUS_WORKFLOW,
66                 RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, RANDOWM_GENERIC_VNF_ID));
67
68         assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId()));
69
70         final HistoricProcessInstance historicProcessInstance =
71                 getHistoricProcessInstance(processInstance.getProcessInstanceId());
72         assertNotNull(historicProcessInstance);
73
74         assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState());
75
76         final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(),
77                 MonitorInstantiateSol003AdapterNodeTask.CREATE_VNF_NODE_STATUS);
78
79         assertNotNull(nsResponseVariable);
80         assertTrue((boolean) nsResponseVariable.getValue());
81
82     }
83
84     private Map<String, Object> getVariables(final String jobId, final String vnfId) {
85         final Map<String, Object> variables = new HashMap<>();
86         variables.put(CamundaVariableNameConstants.JOB_ID_PARAM_NAME, jobId);
87         variables.put(CamundaVariableNameConstants.NF_INST_ID_PARAM_NAME, vnfId);
88
89         return variables;
90     }
91
92
93 }