Add junit for MSOCommonBPMN 51/58751/1
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Thu, 2 Aug 2018 14:54:44 +0000 (16:54 +0200)
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Thu, 2 Aug 2018 15:07:43 +0000 (17:07 +0200)
Change-Id: I665f35bd6385ceec2d5aeff9a1d8af359bccd97a
Issue-ID: SO-784
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AppCClient.groovy
bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy
bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AppCClientTest.groovy [new file with mode: 0644]
bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcessTest.groovy
bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/MsoGroovyTest.groovy

index bb1de36..5cbbe0a 100644 (file)
 
 package org.onap.so.bpmn.common.scripts
 
-import org.onap.so.bpmn.core.UrnPropertiesReader
-
-import java.util.HashMap;
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.hibernate.event.internal.AbstractLockUpgradeEventListener
 import org.onap.so.bpmn.core.json.JsonUtils
-import org.onap.so.client.appc.ApplicationControllerOrchestrator
-import org.onap.so.client.appc.ApplicationControllerOrchestratorException
 import org.onap.appc.client.lcm.model.Action
-import org.onap.appc.client.lcm.model.Status
-import org.onap.so.bpmn.appc.payload.PayloadClient
 import org.onap.so.client.appc.ApplicationControllerAction;
-import groovy.transform.TypeChecked;
-import java.util.UUID;
 import org.onap.so.logger.MessageEnum
 import org.onap.so.logger.MsoLogger
 
@@ -113,7 +103,7 @@ public class AppCClient extends AbstractServiceTaskProcessor{
                                payload =  Optional.of(pay)
                        }
                        if(action.equals(Action.HealthCheck)){
-                               String healthCheckIndex = execution.getVariable('healthCheckIndex')
+                               Integer healthCheckIndex = (Integer) execution.getVariable('healthCheckIndex')
                                execution.setVariable('workStep', action.toString() + healthCheckIndex)
                                execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
                        }
index 9c4c73f..ff5dabf 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.onap.so.bpmn.common.scripts
 
-import org.apache.commons.lang3.*
 import org.camunda.bpm.engine.delegate.BpmnError
 import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.onap.so.logger.MessageEnum
@@ -170,8 +169,6 @@ public class CompleteMsoProcess extends AbstractServiceTaskProcessor {
                        msoLogger.debug("Exception Occured During PreProcessRequest: " + e);
                        exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in " + method)
                }
-
-//             msoLogger.trace("Completed CompleteMsoProcess preProcessRequest Method ");
        }
 
        public void setUpdateDBstatustoSuccessPayload (DelegateExecution execution){
@@ -303,8 +300,6 @@ public class CompleteMsoProcess extends AbstractServiceTaskProcessor {
                                        msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
                                        exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Internal Error - Occured in" + method)
                                }
-               //              msoLogger.trace("Completed CompleteMsoProcess PostProcessRequest Method ");
-
        }
 
 
diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AppCClientTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/AppCClientTest.groovy
new file mode 100644 (file)
index 0000000..bb56787
--- /dev/null
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.common.scripts
+
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.junit.Test
+import org.onap.appc.client.lcm.model.Action
+
+import static org.mockito.Mockito.*
+
+class AppCClientTest extends MsoGroovyTest {
+
+    @Test
+    void runAppcCommand_healtCheck_indexIncremented() {
+        DelegateExecution delegateExecutionMock = mock(DelegateExecution.class)
+        mockGettingExecutionVariables(delegateExecutionMock)
+
+        new AppCClient().runAppcCommand(delegateExecutionMock)
+
+        verifySettingExecutionVariables(delegateExecutionMock)
+    }
+
+    private mockGettingExecutionVariables(DelegateExecution delegateExecutionMock) {
+        when(delegateExecutionMock.getVariable("isDebugLogEnabled")).thenReturn('true')
+        when(delegateExecutionMock.getVariable("action")).thenReturn(Action.HealthCheck)
+        when(delegateExecutionMock.getVariable("vnfId")).thenReturn("vnfIdTest")
+        when(delegateExecutionMock.getVariable("msoRequestId")).thenReturn("msoRequestIdTest")
+        when(delegateExecutionMock.getVariable("vnfName")).thenReturn("vnfNameTest")
+        when(delegateExecutionMock.getVariable("aicIdentity")).thenReturn("aicIdentityTest")
+        when(delegateExecutionMock.getVariable("vnfHostIpAddress")).thenReturn("vnfHostIpAddressTest")
+        when(delegateExecutionMock.getVariable("vmIdList")).thenReturn("vmIdListTest")
+        when(delegateExecutionMock.getVariable("identityUrl")).thenReturn("identityUrlTest")
+        when(delegateExecutionMock.getVariable("vfModuleId")).thenReturn("vfModuleIdTest")
+        when(delegateExecutionMock.getVariable("healthCheckIndex")).thenReturn(1)
+    }
+
+    private verifySettingExecutionVariables(DelegateExecution delegateExecutionMock) {
+        verify(delegateExecutionMock).setVariable("rollbackVnfStop", false)
+        verify(delegateExecutionMock).setVariable("rollbackVnfLock", false)
+        verify(delegateExecutionMock).setVariable("rollbackQuiesceTraffic", false)
+        verify(delegateExecutionMock).setVariable("workStep", Action.HealthCheck.toString())
+        verify(delegateExecutionMock).setVariable("workStep", Action.HealthCheck.toString() + 1)
+        verify(delegateExecutionMock).setVariable("healthCheckIndex", 2)
+    }
+}
index 9aa8425..8ac8f25 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.so.bpmn.common.scripts
 
 import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
 import org.junit.Before
 import org.junit.Test
@@ -140,11 +141,6 @@ class CompleteMsoProcessTest {
    <sdncadapterworkflow:out>BPEL BPEL-NAME FAILED</sdncadapterworkflow:out>
 </sdncadapterworkflow:MsoCompletionResponse>"""
 
-/*
-       private String msoCompletionResponse = """<sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
-   <sdncadapterworkflow:out>BPEL BPEL-NAME FAILED</sdncadapterworkflow:out>
-</sdncadapterworkflow:MsoCompletionResponse>"""
-*/
        @Test
     void testBuildDataError() {
                // given
@@ -167,4 +163,20 @@ class CompleteMsoProcessTest {
                assertThat capturedException.errorCode isEqualTo 500
                assertThat capturedException.errorMessage isEqualTo message
     }
+
+       @Test
+       void postProcessResponse_successful() {
+               DelegateExecution mockExecution = mock(DelegateExecution.class)
+               when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
+               when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("mso-bpel-test")
+               new CompleteMsoProcess().postProcessResponse(mockExecution)
+
+               String expectedResponse = "<sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow=\"http://ecomp.com/mso/workflow/schema/v1\">\n" +
+                               "  <sdncadapterworkflow:out>BPEL mso-bpel-test completed</sdncadapterworkflow:out>\n" +
+                               "</sdncadapterworkflow:MsoCompletionResponse>"
+
+               verify(mockExecution).setVariable("WorkflowResponse", expectedResponse)
+               verify(mockExecution).setVariable("CompleteMsoProcessResponse", expectedResponse)
+               verify(mockExecution).setVariable("CMSO_ResponseCode", "200")
+       }
 }
\ No newline at end of file
index cd95a3a..01e37f0 100644 (file)
@@ -22,13 +22,9 @@ package org.onap.so.bpmn.common.scripts
 
 import static org.mockito.Mockito.*
 
-import org.mockito.MockitoAnnotations
-import org.mockito.runners.MockitoJUnitRunner
-import org.mockito.internal.debugging.MockitoDebuggerImpl
 import org.camunda.bpm.engine.ProcessEngineServices
 import org.camunda.bpm.engine.RepositoryService
 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
-import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl
 import org.camunda.bpm.engine.repository.ProcessDefinition
 
 abstract class MsoGroovyTest {