exception handling 34/88334/3
authoreeginux <henry.xie@est.tech>
Thu, 23 May 2019 09:51:36 +0000 (10:51 +0100)
committereeginux <henry.xie@est.tech>
Thu, 23 May 2019 11:22:54 +0000 (12:22 +0100)
Update the appc client jar version
Throw exception for non success cds call
Fix CreateVcpeResCustServiceSimplifiedTest IT

Issue-ID: SO-1857 SO-1779
Change-Id: Ifee080600051c92fd964a92d16efb67e4ab05d5d
Signed-off-by: eeginux <henry.xie@est.tech>
bpmn/MSOCommonBPMN/pom.xml
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java
bpmn/pom.xml
bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ConfigurePnfResource.bpmn
bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/CreateVcpeResCustServiceSimplifiedTest.java

index 20be69c..e233e6a 100644 (file)
     <dependency>
       <groupId>org.onap.appc.client</groupId>
       <artifactId>client-lib</artifactId>
-      <version>1.5.0-SNAPSHOT</version>
+      <version>${appc.client.version}</version>
       <exclusions>
         <exclusion>
           <groupId>org.mockito</groupId>
     <dependency>
       <groupId>org.onap.appc.client</groupId>
       <artifactId>client-kit</artifactId>
-      <version>1.5.0-SNAPSHOT</version>
+      <version>${appc.client.version}</version>
       <exclusions>
         <exclusion>
           <groupId>org.mockito</groupId>
index 6bfa675..5498b5b 100644 (file)
@@ -34,6 +34,7 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOu
 import org.onap.so.client.PreconditionFailedException;
 import org.onap.so.client.RestPropertiesLoader;
 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
+import org.onap.so.client.exception.BadResponseException;
 import org.onap.so.client.exception.ExceptionBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,6 +59,12 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener {
     private static final String FAILED = "Failed";
     private static final String PROCESSING = "Processing";
 
+    /**
+     * indicate exception thrown.
+     */
+    private static final String EXCEPTION = "Exception";
+
+
     private final AtomicReference<String> cdsResponse = new AtomicReference<>();
 
     @Autowired
@@ -132,7 +139,15 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener {
             }
 
             if (cdsResponse != null) {
-                execution.setVariable("CDSStatus", cdsResponse.get());
+                String cdsResponseStatus = cdsResponse.get();
+                execution.setVariable("CDSStatus", cdsResponseStatus);
+
+                /**
+                 * throw CDS failed exception.
+                 */
+                if (cdsResponseStatus != SUCCESS) {
+                    throw new BadResponseException("CDS call failed with status: " + cdsResponseStatus);
+                }
             }
 
         } catch (Exception ex) {
@@ -177,6 +192,7 @@ public class AbstractCDSProcessingBBUtils implements CDSProcessingListener {
     public void onError(Throwable t) {
         Status status = Status.fromThrowable(t);
         logger.error("Failed processing blueprint {}", status, t);
+        cdsResponse.set(EXCEPTION);
     }
 
 }
index c4aad4b..fd070bb 100644 (file)
@@ -25,6 +25,7 @@
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <sdnc.northbound.version>1.5.1</sdnc.northbound.version>
+    <appc.client.version>1.6.0-SNAPSHOT</appc.client.version>
   </properties>
 
   <modules>
index f489a27..9a1a7ed 100644 (file)
@@ -30,7 +30,7 @@
       <bpmn:incoming>SequenceFlow_17llfxw</bpmn:incoming>
       <bpmn:outgoing>SequenceFlow_0p0aqtx</bpmn:outgoing>
     </bpmn:callActivity>
-    <bpmn:exclusiveGateway id="ExclusiveGateway_0vtv1wi">
+    <bpmn:exclusiveGateway id="ExclusiveGateway_0vtv1wi" default="SequenceFlow_1w4p9f7">
       <bpmn:incoming>SequenceFlow_0p0aqtx</bpmn:incoming>
       <bpmn:outgoing>SequenceFlow_1owbpsy</bpmn:outgoing>
       <bpmn:outgoing>SequenceFlow_1w4p9f7</bpmn:outgoing>
@@ -49,7 +49,7 @@
       <bpmn:incoming>SequenceFlow_0jfgn7n</bpmn:incoming>
       <bpmn:outgoing>SequenceFlow_08voj55</bpmn:outgoing>
     </bpmn:callActivity>
-    <bpmn:exclusiveGateway id="ExclusiveGateway_01jwwmc">
+    <bpmn:exclusiveGateway id="ExclusiveGateway_01jwwmc" default="SequenceFlow_0d24h26">
       <bpmn:incoming>SequenceFlow_08voj55</bpmn:incoming>
       <bpmn:outgoing>SequenceFlow_1n080up</bpmn:outgoing>
       <bpmn:outgoing>SequenceFlow_0d24h26</bpmn:outgoing>
index f51ea00..35f8f45 100644 (file)
@@ -33,10 +33,8 @@ import com.google.protobuf.Struct;
 import java.io.IOException;
 import java.util.List;
 import java.util.UUID;
-import org.camunda.bpm.engine.runtime.Execution;
 import org.camunda.bpm.engine.runtime.ProcessInstance;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers;
 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
@@ -52,12 +50,13 @@ import org.springframework.beans.factory.annotation.Autowired;
 /**
  * Basic Integration test for createVcpeResCustService_Simplified.bpmn workflow.
  */
-@Ignore
 public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
 
-    private static final long WORKFLOW_WAIT_TIME = 1000L;
     private Logger logger = LoggerFactory.getLogger(getClass());
 
+    private static final long WORKFLOW_WAIT_TIME = 1000L;
+    private static final int DMAAP_DELAY_TIME_MS = 2000;
+
     private static final String TEST_PROCESSINSTANCE_KEY = "CreateVcpeResCustService_simplified";
 
     private String testBusinessKey;
@@ -113,17 +112,9 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
 
         ProcessInstance pi =
                 runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, variables);
-        assertThat(pi).isNotNull();
-
-        Thread.sleep(WORKFLOW_WAIT_TIME);
-
-        Execution execution = runtimeService.createExecutionQuery().processInstanceBusinessKey(testBusinessKey)
-                .messageEventSubscriptionName("WorkflowMessage").singleResult();
-
-        assertThat(execution).isNotNull();
 
         int waitCount = 10;
-        while (!pi.isEnded() && waitCount >= 0) {
+        while (!isProcessInstanceEnded() && waitCount >= 0) {
             Thread.sleep(WORKFLOW_WAIT_TIME);
             waitCount--;
         }
@@ -145,6 +136,11 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
         }
     }
 
+    private boolean isProcessInstanceEnded() {
+        return runtimeService.createProcessInstanceQuery().processDefinitionKey(TEST_PROCESSINSTANCE_KEY)
+                .singleResult() == null;
+    }
+
     private void checkConfigAssign(ExecutionServiceInput executionServiceInput) {
 
         logger.info("Checking the configAssign request");
@@ -154,26 +150,26 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
          * the fields of actionIdentifiers should match the one in the
          * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
          */
-        assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
-        assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
-        assertThat(actionIdentifiers.getActionName()).matches("config-assign");
-        assertThat(actionIdentifiers.getMode()).matches("sync");
+        assertThat(actionIdentifiers.getBlueprintName()).isEqualTo("test_configuration_restconf");
+        assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo("1.0.0");
+        assertThat(actionIdentifiers.getActionName()).isEqualTo("config-assign");
+        assertThat(actionIdentifiers.getMode()).isEqualTo("sync");
 
         CommonHeader commonHeader = executionServiceInput.getCommonHeader();
-        assertThat(commonHeader.getOriginatorId()).matches("SO");
-        assertThat(commonHeader.getRequestId()).matches(msoRequestId);
+        assertThat(commonHeader.getOriginatorId()).isEqualTo("SO");
+        assertThat(commonHeader.getRequestId()).isEqualTo(msoRequestId);
 
         Struct payload = executionServiceInput.getPayload();
         Struct requeststruct = payload.getFieldsOrThrow("config-assign-request").getStructValue();
 
-        assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
+        assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo("PNFDemo");
         Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-assign-properties").getStructValue();
 
-        assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
+        assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo("PNFDemo");
         assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
-                .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
+                .isEqualTo("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
         assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
-                .matches("68dc9a92-214c-11e7-93ae-92361f002680");
+                .isEqualTo("68dc9a92-214c-11e7-93ae-92361f002680");
     }
 
     private void checkConfigDeploy(ExecutionServiceInput executionServiceInput) {
@@ -185,32 +181,32 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
          * the fields of actionIdentifiers should match the one in the
          * response/createVcpeResCustServiceSimplifiedTest_catalogdb.json.
          */
-        assertThat(actionIdentifiers.getBlueprintName()).matches("test_configuration_restconf");
-        assertThat(actionIdentifiers.getBlueprintVersion()).matches("1.0.0");
-        assertThat(actionIdentifiers.getActionName()).matches("config-deploy");
-        assertThat(actionIdentifiers.getMode()).matches("async");
+        assertThat(actionIdentifiers.getBlueprintName()).isEqualTo("test_configuration_restconf");
+        assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo("1.0.0");
+        assertThat(actionIdentifiers.getActionName()).isEqualTo("config-deploy");
+        assertThat(actionIdentifiers.getMode()).isEqualTo("async");
 
         CommonHeader commonHeader = executionServiceInput.getCommonHeader();
-        assertThat(commonHeader.getOriginatorId()).matches("SO");
-        assertThat(commonHeader.getRequestId()).matches(msoRequestId);
+        assertThat(commonHeader.getOriginatorId()).isEqualTo("SO");
+        assertThat(commonHeader.getRequestId()).isEqualTo(msoRequestId);
 
         Struct payload = executionServiceInput.getPayload();
         Struct requeststruct = payload.getFieldsOrThrow("config-deploy-request").getStructValue();
 
-        assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).matches("PNFDemo");
+        assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo("PNFDemo");
         Struct propertiesStruct = requeststruct.getFieldsOrThrow("config-deploy-properties").getStructValue();
 
-        assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).matches("PNFDemo");
+        assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo("PNFDemo");
         assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue())
-                .matches("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
+                .isEqualTo("f2daaac6-5017-4e1e-96c8-6a27dfbe1421");
         assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue())
-                .matches("68dc9a92-214c-11e7-93ae-92361f002680");
+                .isEqualTo("68dc9a92-214c-11e7-93ae-92361f002680");
 
         /**
          * IP addresses match the OAM ip addresses from AAI.
          */
-        assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).matches("1.1.1.1");
-        assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).matches("::/128");
+        assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv4-address").getStringValue()).isEqualTo("1.1.1.1");
+        assertThat(propertiesStruct.getFieldsOrThrow("pnf-ipv6-address").getStringValue()).isEqualTo("::/128");
     }
 
     /**
@@ -223,8 +219,8 @@ public class CreateVcpeResCustServiceSimplifiedTest extends BaseBPMNTest {
         /**
          * Get the events from PNF topic
          */
-        wireMockServer
-                .stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*")).willReturn(okJson(pnfResponse)));
+        wireMockServer.stubFor(get(urlPathMatching("/events/pnfReady/consumerGroup.*"))
+                .willReturn(okJson(pnfResponse).withFixedDelay(DMAAP_DELAY_TIME_MS)));
     }
 
     private void mockAai() {