Added creating WorkflowException in pnf-pnp 85/41185/3
authorbiniek <lukasz.biniek@nokia.com>
Thu, 5 Apr 2018 09:09:10 +0000 (11:09 +0200)
committerRob Daugherty <rd472p@att.com>
Fri, 6 Apr 2018 14:11:34 +0000 (14:11 +0000)
Change-Id: I3cd5932913e58983c85e63c84c5136d04b0489e8
Issue-ID: SO-506
Signed-off-by: biniek <lukasz.biniek@nokia.com>
bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java
bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java
bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java
bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java
bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java

index f4483f5..417bb46 100644 (file)
@@ -28,6 +28,7 @@ import java.io.IOException;
 import org.camunda.bpm.engine.delegate.BpmnError;
 import org.camunda.bpm.engine.delegate.DelegateExecution;
 import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
 import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection;
 import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiResponse;
 import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.CheckAaiForCorrelationIdImplementation;
@@ -58,21 +59,16 @@ public class CheckAaiForCorrelationIdDelegate implements JavaDelegate {
     public void execute(DelegateExecution execution) throws Exception {
         String correlationId = (String) execution.getVariable(CORRELATION_ID);
         if (correlationId == null) {
-            //todo: fix Execution -> DelegateExecution in ALL groovy scripts
-//            new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set");
-            throw new BpmnError("MSOWorkflowException");
+            new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set");
         }
 
         try {
             AaiResponse aaiResponse = implementation.check(correlationId, aaiConnection);
 
             execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, aaiResponse.getContainsInfoAboutPnf());
-            aaiResponse.getContainsInfoAboutIp().ifPresent(
-                    isIp -> execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, isIp)
-            );
+            execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, aaiResponse.getContainsInfoAboutIp());
         } catch (IOException e) {
-            //todo: log this
-            throw new BpmnError("MSOWorkflowException");
+            new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, e.getMessage());
         }
     }
 }
index 6b49908..0d64f2c 100644 (file)
@@ -23,6 +23,9 @@ package org.openecomp.mso.bpmn.infrastructure.pnf.delegate;
 @SuppressWarnings("ALL")
 public class ExecutionVariableNames {
 
+    private ExecutionVariableNames() {
+    }
+
     public final static String CORRELATION_ID = "correlationId";
     public final static String AAI_CONTAINS_INFO_ABOUT_PNF = "aaiContainsInfoAboutPnf";
     public final static String AAI_CONTAINS_INFO_ABOUT_IP = "aaiContainsInfoAboutIp";
index bbb7adc..5fb7a43 100644 (file)
@@ -24,28 +24,25 @@ import java.util.Optional;
 import javax.annotation.Nullable;
 import javax.validation.constraints.NotNull;
 
-public class AaiResponse {
+public enum AaiResponse {
+    NO_ENTRY(false, false),
+    ENTRY_NO_IP(true, false),
+    ENTRY_WITH_IP(true, true);
 
-    private Boolean containsInfoAboutPnf;
-    private Boolean containsInfoAboutIp;
-    private String ipAddress;
+    private boolean containsInfoAboutPnf;
+    private boolean containsInfoAboutIp;
 
-    public AaiResponse(@NotNull Boolean containsInfoAboutPnf, @Nullable Boolean containsInfoAboutIp,
-            @Nullable String ipAddress) {
+    AaiResponse(boolean containsInfoAboutPnf, boolean containsInfoAboutIp) {
         this.containsInfoAboutPnf = containsInfoAboutPnf;
         this.containsInfoAboutIp = containsInfoAboutIp;
-        this.ipAddress = ipAddress;
     }
 
-    public Boolean getContainsInfoAboutPnf() {
+    public boolean getContainsInfoAboutPnf() {
         return containsInfoAboutPnf;
     }
 
-    public Optional<Boolean> getContainsInfoAboutIp() {
-        return Optional.ofNullable(containsInfoAboutIp);
+    public boolean getContainsInfoAboutIp() {
+        return containsInfoAboutIp;
     }
 
-    public Optional<String> getIpAddress() {
-        return Optional.ofNullable(ipAddress);
-    }
 }
index 353a3bd..b982a69 100644 (file)
@@ -29,15 +29,14 @@ public class CheckAaiForCorrelationIdImplementation {
     public AaiResponse check(String correlationId, AaiConnection aaiConnection) throws IOException {
         Optional<Pnf> pnf = aaiConnection.getEntryFor(correlationId);
         if (!pnf.isPresent()) {
-            return new AaiResponse(false, null, null);
+            return AaiResponse.NO_ENTRY;
         }
 
-        Optional<String> ip = extractIp(pnf.get());
-        return ip.map(
-                s -> new AaiResponse(true, true, s)
-        ).orElseGet(
-                () -> new AaiResponse(true, false, null)
-        );
+        if(extractIp(pnf.get()).isPresent()) {
+            return AaiResponse.ENTRY_WITH_IP;
+        } else {
+            return AaiResponse.ENTRY_NO_IP;
+        }
     }
 
     private Optional<String> extractIp(Pnf pnf) {
index d98a395..75a7450 100644 (file)
 package org.openecomp.mso.bpmn.infrastructure.pnf.delegate;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.DEFAULT_IP;
 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY;
 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP;
 import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP;
@@ -38,6 +39,7 @@ import org.camunda.bpm.engine.delegate.DelegateExecution;
 import org.junit.Test;
 import org.junit.experimental.runners.Enclosed;
 import org.junit.runner.RunWith;
+import org.openecomp.mso.bpmn.core.WorkflowException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
@@ -60,8 +62,7 @@ public class CheckAaiForCorrelationIdDelegateTest {
             when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue");
             // when, then
             assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class);
-            // todo: uncomment line below after fixing Execution -> DelecateExecution in groovy scripts
-//        verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
+            verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
         }
 
         @Test
@@ -118,12 +119,14 @@ public class CheckAaiForCorrelationIdDelegateTest {
         private CheckAaiForCorrelationIdDelegate delegate;
 
         @Test
-        public void shouldThrowExceptionWhenSSADFDSADSFDS() throws Exception {
+        public void shouldThrowExceptionWhenIoExceptionOnConnectionToAai() throws Exception {
             // given
             DelegateExecution execution = mock(DelegateExecution.class);
             when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP);
+            when(execution.getVariable("testProcessKey")).thenReturn("testProcessKey");
             // when, then
             assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class);
+            verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class));
         }
     }
 }
\ No newline at end of file