Update test for deleting communication service 40/103340/2
authorzm330 <zhangminyj@chinamobile.com>
Mon, 9 Mar 2020 08:46:06 +0000 (16:46 +0800)
committerZhang Min <zhangminyj@chinamobile.com>
Tue, 10 Mar 2020 06:02:47 +0000 (06:02 +0000)
Issue-ID: SO-2368

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

adapters/mso-nssmf-adapter/pom.xml
bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationService.groovy
bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteCommunicationServiceTest.groovy

index bad9c5a..3e9c2fe 100644 (file)
@@ -28,7 +28,7 @@
     <artifactId>adapters</artifactId>
     <version>1.6.0-SNAPSHOT</version>
   </parent>
- <groupId>org.onap.so.adapters</groupId>
 <groupId>org.onap.so.adapters</groupId>
   <artifactId>mso-nssmf-adapter</artifactId>
   <packaging>jar</packaging>
   <name>mso-nssmf-adapter</name>
index 71026f1..b121083 100644 (file)
@@ -214,7 +214,7 @@ class DeleteCommunicationService extends AbstractServiceTaskProcessor {
             requestBody.replaceAll("\\s+", "")
 
             String basicAuthValue =  UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
-            HttpClient httpClient = new HttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
+            HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
             httpClient.addAdditionalHeader("Authorization", basicAuthValue)
             httpClient.addAdditionalHeader("Accept", "application/json")
             Response httpResponse = httpClient.delete(requestBody)
index 29a976a..8c08e51 100644 (file)
@@ -25,14 +25,18 @@ import org.junit.Test
 import org.mockito.ArgumentCaptor
 import org.mockito.Captor
 import org.mockito.Mockito
+import org.onap.logging.filter.base.ONAPComponents
 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
 import org.onap.so.bpmn.core.WorkflowException
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
 import org.onap.so.client.aai.AAIObjectType
 import org.onap.so.client.aai.entities.AAIResultWrapper
 import org.onap.so.client.aai.entities.uri.AAIResourceUri
 import org.onap.so.client.aai.entities.uri.AAIUriFactory
 
 import javax.ws.rs.NotFoundException
+import javax.ws.rs.core.Response
 
 import static org.junit.Assert.assertEquals
 import static org.junit.Assert.assertNotNull
@@ -41,6 +45,9 @@ import static org.mockito.Mockito.*
 
 class DeleteCommunicationServiceTest extends MsoGroovyTest {
 
+    private HttpClientFactory httpClientFactoryMock
+    private HttpClient httpClientMock
+
     @Before
     void init() throws IOException {
         super.init("DeleteCommunicationServiceTest")
@@ -186,6 +193,47 @@ class DeleteCommunicationServiceTest extends MsoGroovyTest {
         assertNotNull(updateOperationStatus)
     }
 
+    @Test
+    void testSendRequest2NSMFWF(){
+        httpClientMock = mock(HttpClient.class)
+        httpClientFactoryMock = mock(HttpClientFactory.class)
+        String url ="http://so.onap:8080/onap/so/infra/e2eServiceInstances/v3/5G-777"
+        when(mockExecution.getVariable("serviceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
+        when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
+        when(mockExecution.getVariable("progress")).thenReturn("20")
+        when(mockExecution.getVariable("operationContent")).thenReturn("waiting nsmf service delete finished")
+        when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
+        when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://so.onap:8080/onap/so/infra")
+        when(mockExecution.getVariable("e2eSliceServiceInstanceId")).thenReturn("5G-777")
+        when(mockExecution.getVariable("e2eOperationId")).thenReturn("e151059a-d924-4629-845f-264db19e50b3")
+        when(httpClientFactoryMock.newJsonClient(new URL(url), ONAPComponents.SO)).thenReturn(httpClientMock)
+        DeleteCommunicationService obj = spy(DeleteCommunicationService.class)
+
+        Response responseMock = mock(Response.class)
+        when(responseMock.getStatus()).thenReturn(200)
+        when(responseMock.hasEntity()).thenReturn(true)
+        when(responseMock.getEntity()).thenReturn(getNSSMFResponse())
+        when(obj.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+        when(httpClientMock.delete(anyString())).thenReturn(responseMock)
+
+        obj.sendRequest2NSMFWF(mockExecution)
+        Mockito.verify(mockExecution,times(1)).setVariable(eq("updateOperationStatus"), captor.capture())
+        String updateOperationStatus= captor.getValue()
+        assertNotNull(updateOperationStatus)
+    }
+
+    private String getNSSMFResponse(){
+        String response = """{
+            "service":{        
+                "serviceId":"e151059a-d924-4629-845f-264db19e50b4",        
+                "operationId":"e151059a-d924-4629-845f-264db19e50b3"        
+            }
+        }"""
+        return response
+    }
+
+
+
 
     private String mockQueryCommunicationServiceReturn()
     {
@@ -257,8 +305,4 @@ class DeleteCommunicationServiceTest extends MsoGroovyTest {
         }"""
         return expect
     }
-
-
-
-
 }