Add test for scritp util 36/103336/2
authorzm330 <zhangminyj@chinamobile.com>
Mon, 9 Mar 2020 05:58:06 +0000 (13:58 +0800)
committerZhang Min <zhangminyj@chinamobile.com>
Tue, 10 Mar 2020 05:12:00 +0000 (05:12 +0000)
Issue-ID: SO-2368

Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Change-Id: I1102a6ca9ba4d22b2ab58b45111e401ac67ac2e7

bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy
bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtilTest.groovy [new file with mode: 0644]
bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteSliceServiceTest.groovy

index ce474fa..b35042e 100644 (file)
@@ -49,8 +49,8 @@ class RequestDBUtil {
             String operationType = operationStatus.getOperation()
             String result = operationStatus.getResult()
             String progress = operationStatus.getProgress()
-            String operationContent = operationStatus.getOperationContent()
-            String reason = operationStatus.getReason()
+            String operationContent = operationStatus.getOperationContent()?: ""
+            String reason = operationStatus.getReason()?: ""
 
             String payload =
                     """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtilTest.groovy
new file mode 100644 (file)
index 0000000..6b63bbe
--- /dev/null
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2019, CMCC Technologies Co., Ltd.
+ #
+ # 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.impl.persistence.entity.ExecutionEntity
+import org.junit.Before
+import org.junit.Test
+import org.mockito.ArgumentCaptor
+import org.mockito.Captor
+import org.mockito.Mockito
+import org.onap.so.db.request.beans.OperationStatus
+
+import static org.junit.Assert.assertNotNull
+import static org.mockito.ArgumentMatchers.eq
+import static org.mockito.Mockito.times
+import static org.mockito.Mockito.when
+
+class RequestDBUtilTest extends MsoGroovyTest {
+
+    @Before
+    void init() throws IOException {
+        super.init("DoDeleteSliceServiceTest")
+    }
+
+    @Captor
+    static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
+
+    @Test
+    void prepareUpdateOperationStatus(){
+        when(mockExecution.getVariable("mso.adapters.openecomp.db.endpoint")).thenReturn("http://sdc-wfd-be:8080")
+        OperationStatus operationStatus = new OperationStatus()
+        operationStatus.setServiceId("testServiceId")
+        operationStatus.setOperationId("testOperationId")
+        operationStatus.setUserId("testUserId")
+        operationStatus.setOperation("testOpertation")
+        operationStatus.setResult("testResult")
+        operationStatus.setProgress("testProgress")
+        operationStatus.setOperationContent("testOperationContent")
+        operationStatus.setReason("testReason")
+
+        RequestDBUtil requestDBUtil = new RequestDBUtil()
+        requestDBUtil.prepareUpdateOperationStatus(mockExecution, operationStatus)
+
+        Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
+        String updateOperationStatus = captor.getAllValues()
+        assertNotNull(updateOperationStatus)
+    }
+
+    @Test
+    void testGetOperationStatus(){
+        when(mockExecution.getVariable("mso.adapters.openecomp.db.endpoint")).thenReturn("http://sdc-wfd-be:8080")
+
+        RequestDBUtil requestDBUtil = new RequestDBUtil()
+        requestDBUtil.getOperationStatus(mockExecution, "testServiceId","testOperationId")
+
+        Mockito.verify(mockExecution,times(1)).setVariable(eq("getOperationStatus"), captor.capture())
+        String getOperationStatus = captor.getAllValues()
+        assertNotNull(getOperationStatus)
+
+    }
+}
index 099fc6f..8a18376 100644 (file)
@@ -1,3 +1,22 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2019, CMCC Technologies Co., Ltd.
+ #
+ # 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.infrastructure.scripts
 
 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity