2  * ============LICENSE_START======================================================= 
\r 
   4  * ================================================================================ 
\r 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 
\r 
   6  * ================================================================================ 
\r 
   7  * Licensed under the Apache License, Version 2.0 (the "License"); 
\r 
   8  * you may not use this file except in compliance with the License. 
\r 
   9  * You may obtain a copy of the License at 
\r 
  11  *      http://www.apache.org/licenses/LICENSE-2.0 
\r 
  13  * Unless required by applicable law or agreed to in writing, software 
\r 
  14  * distributed under the License is distributed on an "AS IS" BASIS, 
\r 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
\r 
  16  * See the License for the specific language governing permissions and 
\r 
  17  * limitations under the License. 
\r 
  18  * ============LICENSE_END========================================================= 
\r 
  21 package org.openecomp.mso.bpmn.common;
\r 
  23 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithPriority;
\r 
  24 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetVfModuleId;
\r 
  25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutVfModuleIdNoResponse;
\r 
  27 import java.io.IOException;
\r 
  28 import java.util.HashMap;
\r 
  29 import java.util.Map;
\r 
  30 import java.util.UUID;
\r 
  32 import org.camunda.bpm.engine.test.Deployment;
\r 
  33 import org.junit.Assert;
\r 
  34 import org.junit.Test;
\r 
  35 import org.openecomp.mso.bpmn.mock.FileUtil;
\r 
  38  * Unit tests for CreateAAIVfModuleVolumeGroup.bpmn.
\r 
  40 public class CreateAAIVfModuleVolumeGroupTest extends WorkflowTest {
\r 
  43          * Test the happy path through the flow.
\r 
  46         @Deployment(resources = {
\r 
  47                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"
\r 
  49         public void happyPath() throws IOException {
\r 
  53                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); 
\r 
  54                 MockGetGenericVnfByIdWithPriority("skask", "lukewarm", 200, "VfModularity/VfModule-lukewarm.xml", 2);
\r 
  55                 MockPutVfModuleIdNoResponse("skask", "PCRF", "lukewarm");
\r 
  57                 String businessKey = UUID.randomUUID().toString();
\r 
  58                 Map<String, Object> variables = new HashMap<String, Object>();
\r 
  59                 variables.put("mso-request-id", "999-99-9999");
\r 
  60                 variables.put("isDebugLogEnabled","true");
\r 
  61                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
\r 
  62                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
\r 
  64                 Assert.assertTrue(isProcessEnded(businessKey));
\r 
  65                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");
\r 
  66                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");
\r 
  67                 System.out.println("Subflow response code: " + responseCode);
\r 
  68                 System.out.println("Subflow response: " + response);
\r 
  69                 Assert.assertEquals(200, responseCode.intValue());
\r 
  75          * Test the case where the GET to AAI returns a 404.
\r 
  78         @Deployment(resources = {
\r 
  79                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"
\r 
  81         public void badGet() throws IOException {
\r 
  85                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); 
\r 
  86                 MockGetVfModuleId("skask", ".*", "VfModularity/VfModule-supercool.xml", 404);
\r 
  88                 String businessKey = UUID.randomUUID().toString();
\r 
  89                 Map<String, Object> variables = new HashMap<String, Object>();
\r 
  90                 variables.put("mso-request-id", "999-99-9999");
\r 
  91                 variables.put("isDebugLogEnabled","true");
\r 
  92                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
\r 
  93                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
\r 
  95                 Assert.assertTrue(isProcessEnded(businessKey));
\r 
  96                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponse");
\r 
  97                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_getVfModuleResponseCode");
\r 
  98                 System.out.println("Subflow response code: " + responseCode);
\r 
  99                 System.out.println("Subflow response: " + response);
\r 
 100                 Assert.assertEquals(404, responseCode.intValue());
\r 
 106          * Test the case where the GET to AAI is successful, but he subsequent PUT returns 404.
\r 
 109         @Deployment(resources = {
\r 
 110                         "subprocess/CreateAAIVfModuleVolumeGroup.bpmn"
\r 
 112         public void badPatch() throws IOException {
\r 
 116                 String updateAAIVfModuleRequest = FileUtil.readResourceFile("__files/VfModularity/CreateAAIVfModuleVolumeGroupRequest.xml"); 
\r 
 117                 MockGetVfModuleId("skask", "lukewarm", "VfModularity/VfModule-lukewarm.xml", 200);
\r 
 119                 String businessKey = UUID.randomUUID().toString();
\r 
 120                 Map<String, Object> variables = new HashMap<String, Object>();
\r 
 121                 variables.put("mso-request-id", "999-99-9999");
\r 
 122                 variables.put("isDebugLogEnabled","true");
\r 
 123                 variables.put("CreateAAIVfModuleVolumeGroupRequest", updateAAIVfModuleRequest);
\r 
 124                 invokeSubProcess("CreateAAIVfModuleVolumeGroup", businessKey, variables);
\r 
 126                 Assert.assertTrue(isProcessEnded(businessKey));
\r 
 127                 String response = (String) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponse");
\r 
 128                 Integer responseCode = (Integer) getVariableFromHistory(businessKey, "CAAIVfModVG_updateVfModuleResponseCode");
\r 
 129                 System.out.println("Subflow response code: " + responseCode);
\r 
 130                 System.out.println("Subflow response: " + response);
\r 
 131                 Assert.assertEquals(404, responseCode.intValue());
\r