2  * ============LICENSE_START=======================================================
 
   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
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  21 package org.onap.so.bpmn.infrastructure.bpmn.subprocess;
 
  23 import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
 
  24 import static org.mockito.ArgumentMatchers.any;
 
  25 import static org.mockito.Mockito.doThrow;
 
  26 import org.camunda.bpm.engine.delegate.BpmnError;
 
  27 import org.camunda.bpm.engine.runtime.ProcessInstance;
 
  28 import org.junit.Test;
 
  29 import org.onap.so.bpmn.BaseBPMNTest;
 
  30 import org.onap.so.bpmn.common.BuildingBlockExecution;
 
  32 public class CreateVfModuleBBTest extends BaseBPMNTest {
 
  34     public void sunnyDayCreateVfModule_Test() throws InterruptedException {
 
  35         mockSubprocess("VnfAdapter", "Mocked VnfAdapter", "GenericStub");
 
  36         ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
 
  37         assertThat(pi).isNotNull();
 
  38         assertThat(pi).isStarted().hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf", "QueryVfModule",
 
  39                 "CreateVfModule", "VnfAdapter", "CreateNetworkPolicies", "UpdateVnfIpv4OamAddress",
 
  40                 "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn",
 
  41                 "UpdateVfModuleHeatStackId", "UpdateVfModuleStatus", "CreateVfModuleBB_End");
 
  42         assertThat(pi).isEnded();
 
  46     public void rainyDayCreateVfModuleSDNCQueryVnfError_Test() throws Exception {
 
  47         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(sdncQueryTasks)
 
  48                 .queryVnf(any(BuildingBlockExecution.class));
 
  49         ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
 
  50         assertThat(pi).isNotNull();
 
  51         assertThat(pi).isStarted().hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf").hasNotPassed("QueryVfModule",
 
  52                 "CreateVfModule", "VnfAdapter", "CreateNetworkPolicies", "UpdateVnfIpv4OamAddress",
 
  53                 "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn",
 
  54                 "UpdateVfModuleHeatStackId", "UpdateVfModuleStatus", "CreateVfModuleBB_End");
 
  55         assertThat(pi).isEnded();
 
  59     public void rainyDayCreateVfModuleSDNCQueryVnfModuleError_Test() throws Exception {
 
  60         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(sdncQueryTasks)
 
  61                 .queryVfModule(any(BuildingBlockExecution.class));
 
  62         ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
 
  63         assertThat(pi).isNotNull();
 
  64         assertThat(pi).isStarted().hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf", "QueryVfModule").hasNotPassed(
 
  65                 "CreateVfModule", "VnfAdapter", "CreateNetworkPolicies", "UpdateVnfIpv4OamAddress",
 
  66                 "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn",
 
  67                 "UpdateVfModuleHeatStackId", "UpdateVfModuleStatus", "CreateVfModuleBB_End");
 
  68         assertThat(pi).isEnded();
 
  72     public void rainyDayCreateVfModuleVnfAdapterCreateError_Test() throws Exception {
 
  73         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(vnfAdapterCreateTasks)
 
  74                 .createVfModule(any(BuildingBlockExecution.class));
 
  75         ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
 
  76         assertThat(pi).isNotNull();
 
  77         assertThat(pi).isStarted()
 
  78                 .hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf", "QueryVfModule", "CreateVfModule")
 
  79                 .hasNotPassed("VnfAdapter", "CreateNetworkPolicies", "UpdateVnfIpv4OamAddress",
 
  80                         "UpdateVnfManagementV6Address", "UpdateVfModuleContrailServiceInstanceFqdn",
 
  81                         "UpdateVfModuleHeatStackId", "UpdateVfModuleStatus", "CreateVfModuleBB_End");
 
  82         assertThat(pi).isEnded();
 
  86     public void rainyDayCreateVfModuleUpdateVfModuleHeatStackIdError_Test() throws Exception {
 
  87         mockSubprocess("VnfAdapter", "Mocked VnfAdapter", "GenericStub");
 
  89         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(aaiUpdateTasks)
 
  90                 .updateHeatStackIdVfModule(any(BuildingBlockExecution.class));
 
  91         ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
 
  92         assertThat(pi).isNotNull();
 
  93         assertThat(pi).isStarted()
 
  94                 .hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf", "QueryVfModule", "CreateVfModule", "VnfAdapter",
 
  95                         "CreateNetworkPolicies", "UpdateVnfIpv4OamAddress", "UpdateVnfManagementV6Address",
 
  96                         "UpdateVfModuleContrailServiceInstanceFqdn", "UpdateVfModuleHeatStackId")
 
  97                 .hasNotPassed("UpdateVfModuleStatus", "CreateVfModuleBB_End");
 
  98         assertThat(pi).isEnded();
 
 103     public void rainyDayCreateVfModuleUpdateVfModuleStatusError_Test() throws Exception {
 
 104         mockSubprocess("VnfAdapter", "Mocked VnfAdapter", "GenericStub");
 
 105         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(aaiUpdateTasks)
 
 106                 .updateOrchestrationStatusCreatedVfModule(any(BuildingBlockExecution.class));
 
 107         ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateVfModuleBB", variables);
 
 108         assertThat(pi).isNotNull();
 
 109         assertThat(pi).isStarted()
 
 110                 .hasPassedInOrder("CreateVfModuleBB_Start", "QueryVnf", "QueryVfModule", "CreateVfModule", "VnfAdapter",
 
 111                         "CreateNetworkPolicies", "UpdateVnfIpv4OamAddress", "UpdateVnfManagementV6Address",
 
 112                         "UpdateVfModuleContrailServiceInstanceFqdn", "UpdateVfModuleHeatStackId",
 
 113                         "UpdateVfModuleStatus")
 
 114                 .hasNotPassed("CreateVfModuleBB_End");
 
 115         assertThat(pi).isEnded();