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
 
   9  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  17  * SPDX-License-Identifier: Apache-2.0
 
  18  * ============LICENSE_END=========================================================
 
  20 package org.onap.so.etsi.nfvo.ns.workflow.engine.tasks;
 
  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;
 
  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;
 
  42  * @author Waqas Ikram (waqas.ikram@est.tech)
 
  45 public class MonitorInstantiateSol003AdapterNodeTaskTest extends BaseTest {
 
  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";
 
  52     public void before() {
 
  53         wireMockServer.resetAll();
 
  57     public void testMonitorSol003AdapterCreateNodeStatus_SuccessfullCase() throws InterruptedException {
 
  59         final String modelEndpoint = "/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + UUID_REGEX;
 
  61         wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok())
 
  62                 .willReturn(okJson("{\"orchestration-status\": \"Created\"}")));
 
  65         final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_CREATE_NODE_STATUS_WORKFLOW,
 
  66                 RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, RANDOWM_GENERIC_VNF_ID));
 
  68         assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId()));
 
  70         final HistoricProcessInstance historicProcessInstance =
 
  71                 getHistoricProcessInstance(processInstance.getProcessInstanceId());
 
  72         assertNotNull(historicProcessInstance);
 
  74         assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState());
 
  76         final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(),
 
  77                 MonitorInstantiateSol003AdapterNodeTask.CREATE_VNF_NODE_STATUS);
 
  79         assertNotNull(nsResponseVariable);
 
  80         assertTrue((boolean) nsResponseVariable.getValue());
 
  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);