diff options
author | Shashikanth VH <shashikanth.vh@huawei.com> | 2022-03-28 15:29:32 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-03-28 15:29:32 +0000 |
commit | d64070d39ee8608c514e6b1e45f1e1e25480c076 (patch) | |
tree | 646022a15c9b03496d22ea97907278537be8d506 /bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap | |
parent | 485b697439d1d9fbc567d226d91987ee551bc477 (diff) | |
parent | 843d057b61f5707f8f561ca2b2bcdfbb6aeabc4b (diff) |
Merge "Error during Deallocate Core NSSI Flow"
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap')
-rw-r--r-- | bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy | 105 |
1 files changed, 33 insertions, 72 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy index acace8c1c7..9ee9255499 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy @@ -20,31 +20,30 @@ package org.onap.so.bpmn.infrastructure.scripts -import com.fasterxml.jackson.databind.ObjectMapper import org.junit.Before import org.junit.Test import org.mockito.Mockito -import org.onap.aai.domain.yang.v19.* +import org.onap.aai.domain.yang.v19.AllottedResource +import org.onap.aai.domain.yang.v19.AllottedResources +import org.onap.aai.domain.yang.v19.ServiceInstance +import org.onap.aai.domain.yang.v19.SliceProfile import org.onap.aaiclient.client.aai.entities.AAIResultWrapper import org.onap.aaiclient.client.aai.entities.Relationships import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types -import org.onap.logging.filter.base.ONAPComponents import org.onap.so.bpmn.common.scripts.ExternalAPIUtil -import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory import org.onap.so.bpmn.common.scripts.MsoGroovyTest -import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.OofUtils import org.onap.so.client.HttpClient import org.onap.so.client.HttpClientFactory -import org.onap.so.serviceinstancebeans.RequestDetails import javax.ws.rs.core.Response import static org.junit.Assert.assertNotNull import static org.junit.Assert.assertTrue +import static org.mockito.ArgumentMatchers.any import static org.mockito.Mockito.* class DoDeallocateCoreNSSITest extends MsoGroovyTest { @@ -115,11 +114,6 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { String authHeaderResponse = "auth-header" - /* String authHeaderResponse = "{\n" + - " \"errorCode\": \"401\",\n" + - " \"errorMessage\": \"Bad request\"\n" + - "}" */ - when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse) AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) @@ -209,60 +203,32 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { currentNSSI.put("networkServiceInstance", networkServiceInstance) - when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088") - when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey") - when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth") + String externalAPIURL = "https://nbi.onap:8443/nbi/api/v4/serviceOrder" + when(mockExecution.getVariable("ExternalAPIURL")).thenReturn(externalAPIURL) DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class) when(spy.getAAIClient()).thenReturn(client) - GenericVnf genericVnf = new GenericVnf() - genericVnf.setServiceId("service-id") - genericVnf.setVnfName("vnf-name") - genericVnf.setModelInvariantId("model-invariant-id") - genericVnf.setModelCustomizationId("model-customization-id") - genericVnf.setVnfName("vnf-name") - genericVnf.setVnfId("vnf-id") - - - currentNSSI.put("constituteVnf", genericVnf) + String serviceOrderRequest = "" - String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), genericVnf.getVnfId()) + when(mockExecution.getVariable("serviceOrderRequest")).thenReturn(serviceOrderRequest) - RequestDetails requestDetails = new RequestDetails() - ObjectMapper mapper = new ObjectMapper() - String requestDetailsStr = mapper.writeValueAsString(requestDetails) - - when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr) - - MsoUtils msoUtilsMock = mock(MsoUtils.class) - String basicAuth = "basicAuth" - when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth) - - HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class) - when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock) Response responseMock = mock(Response.class) - HttpClient httpClientMock = mock(HttpClient.class) - - when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock) - - when(httpClientMock.delete(requestDetailsStr)).thenReturn(responseMock) + ExternalAPIUtil externalAPIUtil = mock(ExternalAPIUtil.class) + when(spy.getExternalAPIUtil()).thenReturn(externalAPIUtil) + when(externalAPIUtil.executeExternalAPIPostCall(mockExecution, externalAPIURL, serviceOrderRequest)).thenReturn(responseMock) when(responseMock.getStatus()).thenReturn(200) - when(responseMock.hasEntity()).thenReturn(true) - String macroOperationId = "request-id" - String requestSelfLink = "request-self-link" - String entity = "{\"requestReferences\":{\"requestId\": \"${macroOperationId}\",\"requestSelfLink\":\"${requestSelfLink}\"}}" + String id = UUID.randomUUID().toString() + String entity = "{\"id\":\"${id}\"}" when(responseMock.readEntity(String.class)).thenReturn(entity) spy.deleteServiceOrder(mockExecution) - Mockito.verify(mockExecution,times(1)).setVariable("macroOperationId", macroOperationId) - Mockito.verify(mockExecution,times(1)).setVariable("requestSelfLink", requestSelfLink) + verify(mockExecution,times(1)).setVariable("ServiceOrderId", id) - assertTrue(currentNSSI['requestSelfLink'].equals(requestSelfLink)) } @@ -436,49 +402,44 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { @Test void testDeleteServiceOrderProgressCompleted() { - executeDeleteServiceOrderProgress("COMPLETE") + executeDeleteServiceOrderProgress("COMPLETED") Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "completed") } void executeDeleteServiceOrderProgress(String state) { def currentNSSI = [:] + currentNSSI.put("nssiId","5G-999") - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - - String url = "http://nbi.onap:8088/api/v4/serviceOrder/NS-777" + ServiceInstance networkServiceInstance = new ServiceInstance() + networkServiceInstance.setServiceInstanceId("NS-777") + networkServiceInstance.setServiceRole("Network Service") - currentNSSI['requestSelfLink'] = url + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class) + currentNSSI.put("networkServiceInstance", networkServiceInstance) - /*ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class) - when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock) + String serviceOrder = UUID.randomUUID().toString() - ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class) + when(mockExecution.getVariable("ServiceOrderId")).thenReturn(serviceOrder) - when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock) */ + String externalAPIURL = "https://nbi.onap:8443/nbi/api/v4/serviceOrder" + when(mockExecution.getVariable("ExternalAPIURL")).thenReturn(externalAPIURL) - MsoUtils msoUtilsMock = mock(MsoUtils.class) - String basicAuth = "basicAuth" - when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth) + DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class) - HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class) - when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock) Response responseMock = mock(Response.class) - HttpClient httpClientMock = mock(HttpClient.class) + ExternalAPIUtil externalAPIUtil = mock(ExternalAPIUtil.class) + when(spy.getExternalAPIUtil()).thenReturn(externalAPIUtil) - - when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock) - - when(httpClientMock.get()).thenReturn(responseMock) -// when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock) + externalAPIURL += "/" + serviceOrder + when(externalAPIUtil.executeExternalAPIGetCall(mockExecution, externalAPIURL)).thenReturn(responseMock) when(responseMock.getStatus()).thenReturn(200) - when(responseMock.hasEntity()).thenReturn(true) - String entity = "{\"request\":{\"requestStatus\":{\"requestState\":\"${state}\"}},\"state\":\"ACCEPTED\"}" + String id = UUID.randomUUID().toString() + String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"state\":\"${state}\",\"service\":{\"id\":\"${id}\"}}]}" when(responseMock.readEntity(String.class)).thenReturn(entity) spy.getDeleteServiceOrderProgress(mockExecution) |