diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java')
18 files changed, 502 insertions, 225 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java index 6500e3a850..aefe4c64bf 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java @@ -31,6 +31,7 @@ import org.onap.so.client.orchestration.SDNOHealthCheckResources; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sniro.SniroClient; import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -40,7 +41,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.WireMockServer; @RunWith(SpringRunner.class) @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -69,10 +70,13 @@ public abstract class BaseIntegrationTest extends TestDataSetup { @MockBean protected CatalogDbClient catalogDbClient; + + @Autowired + protected WireMockServer wireMockServer; @Before public void baseTestBefore() { - WireMock.reset(); + wireMockServer.resetAll(); } public String readResourceFile(String fileName) { InputStream stream; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTaskTest.java new file mode 100644 index 0000000000..5c76018ced --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTaskTest.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.UUID; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import com.google.common.base.Optional; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * + */ +public class EtsiVnfDeleteTaskTest extends BaseTaskTest { + + private static final String MODEL_INSTANCE_NAME = "MODEL_INSTANCE_NAME"; + + private static final String VNF_ID = UUID.randomUUID().toString(); + + private static final String VNF_NAME = "VNF_NAME"; + + private static final String JOB_ID = UUID.randomUUID().toString(); + + @Mock + private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider; + + @Mock + private GeneralBuildingBlock buildingBlock; + + @Mock + private RequestContext requestContext; + + private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); + + @Test + public void testInvokeVnfmAdapter() throws Exception { + final EtsiVnfDeleteTask objUnderTest = getEtsiVnfDeleteTask(); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + when(mockedVnfmAdapterServiceProvider.invokeDeleteRequest(eq(VNF_ID))).thenReturn(getDeleteVnfResponse()); + objUnderTest.invokeVnfmAdapter(stubbedxecution); + assertNotNull(stubbedxecution.getVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME)); + } + + @Test + public void testInvokeVnfmAdapterException() throws Exception { + final EtsiVnfDeleteTask objUnderTest = getEtsiVnfDeleteTask(); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + when(mockedVnfmAdapterServiceProvider.invokeDeleteRequest(eq(VNF_ID))).thenReturn(Optional.absent()); + objUnderTest.invokeVnfmAdapter(stubbedxecution); + assertNull(stubbedxecution.getVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME)); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1212), + any(Exception.class)); + } + + private Optional<DeleteVnfResponse> getDeleteVnfResponse() { + final DeleteVnfResponse response = new DeleteVnfResponse(); + response.setJobId(JOB_ID); + return Optional.of(response); + } + + private GenericVnf getGenericVnf() { + final GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(VNF_ID); + genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); + genericVnf.setVnfName(VNF_NAME); + return genericVnf; + } + + private ModelInfoGenericVnf getModelInfoGenericVnf() { + final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); + return modelInfoGenericVnf; + } + + private EtsiVnfDeleteTask getEtsiVnfDeleteTask() { + return new EtsiVnfDeleteTask(exceptionUtil, extractPojosForBB, mockedVnfmAdapterServiceProvider); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/StubbedBuildingBlockExecution.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/StubbedBuildingBlockExecution.java new file mode 100644 index 0000000000..260585d208 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/StubbedBuildingBlockExecution.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * + */ +public class StubbedBuildingBlockExecution implements BuildingBlockExecution { + + private static final String CLOUD_OWNER = "CLOUD_OWNER"; + private static final String LCP_CLOUD_REGIONID = "RegionOnce"; + private static final String TENANT_ID = UUID.randomUUID().toString(); + private final Map<String, Serializable> execution = new HashMap<>(); + private final GeneralBuildingBlock generalBuildingBlock; + + StubbedBuildingBlockExecution() { + generalBuildingBlock = getGeneralBuildingBlockValue(); + } + + @Override + public GeneralBuildingBlock getGeneralBuildingBlock() { + return generalBuildingBlock; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T getVariable(final String key) { + return (T) execution.get(key); + } + + @Override + public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { + return null; + } + + @Override + public void setVariable(final String key, final Serializable value) { + execution.put(key, value); + } + + @Override + public Map<ResourceKey, String> getLookupMap() { + return Collections.emptyMap(); + } + + @Override + public String getFlowToBeCalled() { + return null; + } + + public static String getTenantId() { + return TENANT_ID; + } + + private GeneralBuildingBlock getGeneralBuildingBlockValue() { + final GeneralBuildingBlock buildingBlock = new GeneralBuildingBlock(); + buildingBlock.setCloudRegion(getCloudRegion()); + return buildingBlock; + } + + private CloudRegion getCloudRegion() { + final CloudRegion cloudRegion = new CloudRegion(); + cloudRegion.setCloudOwner(CLOUD_OWNER); + cloudRegion.setLcpCloudRegionId(LCP_CLOUD_REGIONID); + cloudRegion.setTenantId(TENANT_ID); + return cloudRegion; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskTest.java index 20abe6ece1..22c4c15079 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskTest.java @@ -30,28 +30,19 @@ import static org.mockito.Mockito.when; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_VNF_REQUEST_PARAM_NAME; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_VNF_RESPONSE_PARAM_NAME; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT_PARAMETER; - -import java.io.Serializable; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; import java.util.UUID; - import org.junit.Test; import org.mockito.Mock; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter; -import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; import org.onap.vnfmadapter.v1.model.Tenant; - import com.google.common.base.Optional; @@ -60,191 +51,131 @@ import com.google.common.base.Optional; */ public class VnfmAdapterCreateVnfTaskTest extends BaseTaskTest { - private static final String MODEL_INSTANCE_NAME = "MODEL_INSTANCE_NAME"; - - private static final String CLOUD_OWNER = "CLOUD_OWNER"; - - private static final String LCP_CLOUD_REGIONID = "RegionOnce"; - - private static final String TENANT_ID = UUID.randomUUID().toString(); - - private static final String VNF_ID = UUID.randomUUID().toString(); - - private static final String VNF_NAME = "VNF_NAME"; - - private static final String JOB_ID = UUID.randomUUID().toString(); - - @Mock - private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider; - - private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); - - @Test - public void testBuildCreateVnfRequest_withValidValues_storesRequestInExecution() throws Exception { - - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - stubbedxecution.setVariable(INPUT_PARAMETER, - new InputParameter(Collections.emptyMap(), Collections.emptyList())); - - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); - objUnderTest.buildCreateVnfRequest(stubbedxecution); - - final CreateVnfRequest actual = stubbedxecution.getVariable(CREATE_VNF_REQUEST_PARAM_NAME); - assertNotNull(actual); - assertEquals(VNF_NAME + "." + MODEL_INSTANCE_NAME, actual.getName()); - - final Tenant actualTenant = actual.getTenant(); - assertEquals(CLOUD_OWNER, actualTenant.getCloudOwner()); - assertEquals(LCP_CLOUD_REGIONID, actualTenant.getRegionName()); - assertEquals(TENANT_ID, actualTenant.getTenantId()); - - } + private static final String MODEL_INSTANCE_NAME = "MODEL_INSTANCE_NAME"; - @Test - public void testBuildCreateVnfRequest_extractPojosForBBThrowsException_exceptionBuilderCalled() throws Exception { + private static final String CLOUD_OWNER = "CLOUD_OWNER"; - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + private static final String LCP_CLOUD_REGIONID = "RegionOnce"; - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class); + private static final String VNF_ID = UUID.randomUUID().toString(); - objUnderTest.buildCreateVnfRequest(stubbedxecution); + private static final String VNF_NAME = "VNF_NAME"; - final CreateVnfRequest actual = stubbedxecution.getVariable(CREATE_VNF_REQUEST_PARAM_NAME); + private static final String JOB_ID = UUID.randomUUID().toString(); - assertNull(actual); - verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1200), - any(Exception.class)); + @Mock + private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider; - } + private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); - @Test - public void testInvokeVnfmAdapter_validValues_storesResponseInExecution() throws Exception { + @Test + public void testBuildCreateVnfRequest_withValidValues_storesRequestInExecution() throws Exception { - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + stubbedxecution.setVariable(INPUT_PARAMETER, new InputParameter(Collections.emptyMap(), Collections.emptyList())); - stubbedxecution.setVariable(CREATE_VNF_REQUEST_PARAM_NAME, new CreateVnfRequest()); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + objUnderTest.buildCreateVnfRequest(stubbedxecution); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); - when(mockedVnfmAdapterServiceProvider.invokeCreateInstantiationRequest(eq(VNF_ID), any(CreateVnfRequest.class))) - .thenReturn(getCreateVnfResponse()); + final CreateVnfRequest actual = stubbedxecution.getVariable(CREATE_VNF_REQUEST_PARAM_NAME); + assertNotNull(actual); + assertEquals(VNF_NAME + "." + MODEL_INSTANCE_NAME, actual.getName()); - objUnderTest.invokeVnfmAdapter(stubbedxecution); + final Tenant actualTenant = actual.getTenant(); + assertEquals(CLOUD_OWNER, actualTenant.getCloudOwner()); + assertEquals(LCP_CLOUD_REGIONID, actualTenant.getRegionName()); + assertEquals(StubbedBuildingBlockExecution.getTenantId(), actualTenant.getTenantId()); - assertNotNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); - } + } - @Test - public void testInvokeVnfmAdapter_invalidValues_storesResponseInExecution() throws Exception { + @Test + public void testBuildCreateVnfRequest_extractPojosForBBThrowsException_exceptionBuilderCalled() throws Exception { - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - stubbedxecution.setVariable(CREATE_VNF_REQUEST_PARAM_NAME, new CreateVnfRequest()); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); - when(mockedVnfmAdapterServiceProvider.invokeCreateInstantiationRequest(eq(VNF_ID), any(CreateVnfRequest.class))) - .thenReturn(Optional.absent()); + objUnderTest.buildCreateVnfRequest(stubbedxecution); - objUnderTest.invokeVnfmAdapter(stubbedxecution); + final CreateVnfRequest actual = stubbedxecution.getVariable(CREATE_VNF_REQUEST_PARAM_NAME); - assertNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); - verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1202), - any(Exception.class)); - } + assertNull(actual); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1200), + any(Exception.class)); + } - @Test - public void testInvokeVnfmAdapter_extractPojosForBBThrowsException_exceptionBuilderCalled() throws Exception { + @Test + public void testInvokeVnfmAdapter_validValues_storesResponseInExecution() throws Exception { - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class); + stubbedxecution.setVariable(CREATE_VNF_REQUEST_PARAM_NAME, new CreateVnfRequest()); - objUnderTest.invokeVnfmAdapter(stubbedxecution); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + when(mockedVnfmAdapterServiceProvider.invokeCreateInstantiationRequest(eq(VNF_ID), any(CreateVnfRequest.class))) + .thenReturn(getCreateVnfResponse()); - assertNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); - verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1202), - any(Exception.class)); + objUnderTest.invokeVnfmAdapter(stubbedxecution); - } + assertNotNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); + } - private Optional<CreateVnfResponse> getCreateVnfResponse() { - final CreateVnfResponse response = new CreateVnfResponse(); - response.setJobId(JOB_ID); - return Optional.of(response); - } + @Test + public void testInvokeVnfmAdapter_invalidValues_storesResponseInExecution() throws Exception { - private GenericVnf getGenericVnf() { - final GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId(VNF_ID); - genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); - genericVnf.setVnfName(VNF_NAME); - return genericVnf; - } + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - private ModelInfoGenericVnf getModelInfoGenericVnf() { - final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); - return modelInfoGenericVnf; - } + stubbedxecution.setVariable(CREATE_VNF_REQUEST_PARAM_NAME, new CreateVnfRequest()); - private VnfmAdapterCreateVnfTask getEtsiVnfInstantiateTask() { - return new VnfmAdapterCreateVnfTask(exceptionUtil, extractPojosForBB, mockedVnfmAdapterServiceProvider); - } + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + when(mockedVnfmAdapterServiceProvider.invokeCreateInstantiationRequest(eq(VNF_ID), any(CreateVnfRequest.class))) + .thenReturn(Optional.absent()); - private class StubbedBuildingBlockExecution implements BuildingBlockExecution { + objUnderTest.invokeVnfmAdapter(stubbedxecution); - private final Map<String, Serializable> execution = new HashMap<>(); - private final GeneralBuildingBlock generalBuildingBlock; + assertNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1202), + any(Exception.class)); + } - StubbedBuildingBlockExecution() { - generalBuildingBlock = getGeneralBuildingBlockValue(); - } - @Override - public GeneralBuildingBlock getGeneralBuildingBlock() { - return generalBuildingBlock; - } + @Test + public void testInvokeVnfmAdapter_extractPojosForBBThrowsException_exceptionBuilderCalled() throws Exception { - @SuppressWarnings("unchecked") - @Override - public <T> T getVariable(final String key) { - return (T) execution.get(key); - } + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - @Override - public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { - return null; - } + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class); - @Override - public void setVariable(final String key, final Serializable value) { - execution.put(key, value); - } + objUnderTest.invokeVnfmAdapter(stubbedxecution); - @Override - public Map<ResourceKey, String> getLookupMap() { - return Collections.emptyMap(); - } + assertNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1202), + any(Exception.class)); - @Override - public String getFlowToBeCalled() { - return null; - } + } - private GeneralBuildingBlock getGeneralBuildingBlockValue() { - final GeneralBuildingBlock buildingBlock = new GeneralBuildingBlock(); - buildingBlock.setCloudRegion(getCloudRegion()); - return buildingBlock; - } + private Optional<CreateVnfResponse> getCreateVnfResponse() { + final CreateVnfResponse response = new CreateVnfResponse(); + response.setJobId(JOB_ID); + return Optional.of(response); + } - private CloudRegion getCloudRegion() { - final CloudRegion cloudRegion = new CloudRegion(); - cloudRegion.setCloudOwner(CLOUD_OWNER); - cloudRegion.setLcpCloudRegionId(LCP_CLOUD_REGIONID); - cloudRegion.setTenantId(TENANT_ID); - return cloudRegion; - } + private GenericVnf getGenericVnf() { + final GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(VNF_ID); + genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); + genericVnf.setVnfName(VNF_NAME); + return genericVnf; + } - } + private ModelInfoGenericVnf getModelInfoGenericVnf() { + final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); + return modelInfoGenericVnf; + } + private VnfmAdapterCreateVnfTask getEtsiVnfInstantiateTask() { + return new VnfmAdapterCreateVnfTask(exceptionUtil, extractPojosForBB, mockedVnfmAdapterServiceProvider); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImplTest.java index 0f443916c4..79894d513d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImplTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImplTest.java @@ -28,23 +28,18 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.DUMMY_GENERIC_VND_ID; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.getVnfmBasicHttpConfigProvider; - import java.util.UUID; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmAdapterServiceProvider; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmAdapterServiceProviderImpl; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmAdapterUrlProvider; import org.onap.so.rest.exceptions.RestProcessingException; import org.onap.so.rest.service.HttpRestServiceProvider; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; - import com.google.common.base.Optional; @@ -66,6 +61,9 @@ public class VnfmAdapterServiceProviderImplTest { @Mock private ResponseEntity<CreateVnfResponse> mockedResponseEntity; + @Mock + private ResponseEntity<DeleteVnfResponse> deleteVnfResponse; + @Test public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusAcceptedWithBody_validResponse() { @@ -120,6 +118,67 @@ public class VnfmAdapterServiceProviderImplTest { } + @Test + public void testInvokeDeleteRequest() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenReturn(deleteVnfResponse); + when(deleteVnfResponse.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + when(deleteVnfResponse.hasBody()).thenReturn(true); + final DeleteVnfResponse response = getDeleteVnfResponse(DUMMY_JOB_ID); + when(deleteVnfResponse.getBody()).thenReturn(response); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertTrue(actual.isPresent()); + } + + @Test + public void testInvokeDeleteRequestNotAccepted() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenReturn(deleteVnfResponse); + when(deleteVnfResponse.getStatusCode()).thenReturn(HttpStatus.BAD_GATEWAY); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testInvokeDeleteRequestNoBody() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenReturn(deleteVnfResponse); + when(deleteVnfResponse.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + when(deleteVnfResponse.hasBody()).thenReturn(false); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testInvokeDeleteRequestNoJobId() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenReturn(deleteVnfResponse); + when(deleteVnfResponse.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + when(deleteVnfResponse.hasBody()).thenReturn(true); + final DeleteVnfResponse response = getDeleteVnfResponse(""); + when(deleteVnfResponse.getBody()).thenReturn(response); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testInvokeDeleteRequestException() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenThrow(RestProcessingException.class); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertFalse(actual.isPresent()); + } + private void assertWithJobId(final String jobId) { when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), @@ -160,6 +219,12 @@ public class VnfmAdapterServiceProviderImplTest { return response; } + private DeleteVnfResponse getDeleteVnfResponse(final String jobId) { + final DeleteVnfResponse response = new DeleteVnfResponse(); + response.setJobId(jobId); + return response; + } + private VnfmAdapterUrlProvider getVnfmAdapterUrlProvider() { return new VnfmAdapterUrlProvider(getVnfmBasicHttpConfigProvider()); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java index c4129a3b96..b50cd69f73 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java @@ -22,7 +22,6 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -41,6 +40,7 @@ import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.onap.so.BaseIntegrationTest; import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -53,7 +53,7 @@ import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate; import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.sniro.beans.SniroManagerRequest; -import org.onap.so.BaseIntegrationTest; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -117,7 +117,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{ beforeVpnBondingLink("1"); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -138,7 +138,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ beforeVpnBondingLink("2"); beforeVpnBondingLink("3"); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -157,7 +157,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException{ beforeAllottedResource(); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -176,7 +176,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException{ beforeVnf(); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -193,7 +193,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ beforeAllottedResource(); beforeVnf(); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -482,7 +482,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ beforeAllottedResource(); mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java index 1bcc464fa0..fe9e1c1608 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java @@ -21,15 +21,17 @@ package org.onap.so.client.adapter.network; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; + import javax.ws.rs.core.Response; + import org.junit.BeforeClass; import org.junit.Test; import org.onap.so.BaseIntegrationTest; @@ -74,7 +76,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ CreateNetworkResponse mockResponse = new CreateNetworkResponse(); mockResponse.setNetworkCreated(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT)) + wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -89,7 +91,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ CreateNetworkError mockResponse = new CreateNetworkError(); mockResponse.setMessage("Error in create network"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT)) + wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -104,7 +106,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ DeleteNetworkResponse mockResponse = new DeleteNetworkResponse(); mockResponse.setNetworkDeleted(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -119,7 +121,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ DeleteNetworkError mockResponse = new DeleteNetworkError(); mockResponse.setMessage("Error in delete network"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -136,7 +138,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ RollbackNetworkResponse mockResponse = new RollbackNetworkResponse(); mockResponse.setNetworkRolledBack(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -154,7 +156,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ RollbackNetworkError mockResponse = new RollbackNetworkError(); mockResponse.setMessage("Error in rollback network"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -166,7 +168,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ QueryNetworkResponse mockResponse = new QueryNetworkResponse(); mockResponse.setNetworkExists(true); - stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) + wireMockServer.stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) .withQueryParam("tenantId", equalTo(TESTING_ID)) .withQueryParam("networkStackId", equalTo("networkStackId")).withQueryParam("skipAAI", equalTo("true")) .withQueryParam("msoRequest.requestId", equalTo("testRequestId")) @@ -184,7 +186,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ QueryNetworkError mockResponse = new QueryNetworkError(); mockResponse.setMessage("Error in query network"); - stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) + wireMockServer.stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) .withQueryParam("tenantId", equalTo(TESTING_ID)) .withQueryParam("networkStackId", equalTo("networkStackId")).withQueryParam("skipAAI", equalTo("true")) .withQueryParam("msoRequest.requestId", equalTo("testRequestId")) @@ -204,7 +206,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ UpdateNetworkResponse mockResponse = new UpdateNetworkResponse(); mockResponse.setNetworkId("test1"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -220,7 +222,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ UpdateNetworkResponse mockResponse = new UpdateNetworkResponse(); mockResponse.setNetworkId("test1"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -236,7 +238,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ UpdateNetworkError mockResponse = new UpdateNetworkError(); mockResponse.setMessage("Error in update network"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java index 3387920d40..90e99eb0ad 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java @@ -21,11 +21,11 @@ package org.onap.so.client.adapter.vnf; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; @@ -70,7 +70,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ CreateVfModuleResponse mockResponse = new CreateVfModuleResponse(); mockResponse.setVfModuleCreated(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) + wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -85,7 +85,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in create Vf module"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) + wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -101,8 +101,8 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ RollbackVfModuleResponse mockResponse = new RollbackVfModuleResponse(); mockResponse.setVfModuleRolledback(true); - stubFor( - post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) + wireMockServer.stubFor( + delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -119,8 +119,8 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in rollback Vf module"); - stubFor( - post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) + wireMockServer.stubFor( + delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -134,7 +134,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ DeleteVfModuleResponse mockResponse = new DeleteVfModuleResponse(); mockResponse.setVfModuleDeleted(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -149,7 +149,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in delete Vf module"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -164,7 +164,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ UpdateVfModuleResponse mockResponse = new UpdateVfModuleResponse(); mockResponse.setVfModuleId("test1"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -180,7 +180,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in update Vf module"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -192,7 +192,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ QueryVfModuleResponse mockResponse = new QueryVfModuleResponse(); mockResponse.setVnfId(AAI_VNF_ID); mockResponse.setVfModuleId(AAI_VF_MODULE_ID); - stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .withQueryParam("cloudSiteId", equalTo(TESTING_ID)) .withQueryParam("tenantId", equalTo(TESTING_ID)) .withQueryParam("vfModuleName", equalTo("someName")) @@ -210,7 +210,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ public void queryVfModuleTestThrowException() throws JsonProcessingException, VnfAdapterClientException { VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in update Vf module"); - stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .withQueryParam("cloudSiteId", equalTo(TESTING_ID)) .withQueryParam("tenantId", equalTo(TESTING_ID)) .withQueryParam("vfModuleName", equalTo("someName")) diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java index 40b6498034..4a006f8b66 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java @@ -44,8 +44,6 @@ import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse; import org.onap.so.client.adapter.rest.AdapterRestClient; import org.onap.so.BaseIntegrationTest; - -@RunWith(MockitoJUnitRunner.Silent.class) public class VnfVolumeAdapterClientIT extends BaseIntegrationTest{ private static final String TESTING_ID = "___TESTING___"; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java index d6f8c70aa1..4bae5b40e4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java @@ -23,7 +23,6 @@ package org.onap.so.client.namingservice; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertTrue; @@ -55,7 +54,7 @@ public class NamingClientTest extends BaseIntegrationTest{ @Test public void assignNameGenRequest() throws BadResponseException, IOException{ - stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + wireMockServer.stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("NamingClient/AssignResponse.json") .withStatus(HttpStatus.SC_ACCEPTED))); @@ -66,7 +65,7 @@ public class NamingClientTest extends BaseIntegrationTest{ } @Test public void assignNameGenRequestError() throws BadResponseException, IOException{ - stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + wireMockServer.stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("NamingClient/ErrorResponse.json") .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); @@ -78,7 +77,7 @@ public class NamingClientTest extends BaseIntegrationTest{ } @Test public void unassignNameGenRequest() throws BadResponseException, IOException{ - stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + wireMockServer.stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("NamingClient/UnassignResponse.json") .withStatus(HttpStatus.SC_ACCEPTED))); @@ -88,7 +87,7 @@ public class NamingClientTest extends BaseIntegrationTest{ } @Test public void unassignNameGenRequestError() throws BadResponseException, IOException{ - stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + wireMockServer.stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("NamingClient/ErrorResponse.json") .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java index 0b33b1d187..05ba512c9d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java @@ -22,7 +22,6 @@ package org.onap.so.client.oof; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import org.junit.Test; @@ -44,7 +43,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_success() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -56,7 +55,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testAsyncResponse_success() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -68,7 +67,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -84,7 +83,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -98,7 +97,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -112,7 +111,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException { String mockResponse = "{ }"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java index 9117b8ea64..70f196db8c 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java @@ -23,7 +23,6 @@ package org.onap.so.client.sdnc; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; @@ -46,7 +45,7 @@ public class SDNCClientIT extends BaseIntegrationTest { String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json"))); String queryLink = "/topologyQuery"; - stubFor(get(urlEqualTo(queryLink)) + wireMockServer.stubFor(get(urlEqualTo(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); String response = SPY_sdncClient.get(queryLink); @@ -59,7 +58,7 @@ public class SDNCClientIT extends BaseIntegrationTest { String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - stubFor(post(urlMatching(queryLink)) + wireMockServer.stubFor(post(urlMatching(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); @@ -72,7 +71,7 @@ public class SDNCClientIT extends BaseIntegrationTest { String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - stubFor(post(urlMatching(queryLink)) + wireMockServer.stubFor(post(urlMatching(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java index 0ca80c75f7..302bb551c3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java @@ -75,6 +75,7 @@ public class GCTopologyOperationRequestMapperTest extends TestDataSetup { Assert.assertEquals("VLAN-NETWORK-RECEPTOR", genericInfo.getConfigurationInformation().getConfigurationType()); Assert.assertEquals("uuid",genericInfo.getSdncRequestHeader().getSvcRequestId()); Assert.assertEquals("http://localhost",genericInfo.getSdncRequestHeader().getSvcNotificationUrl()); + Assert.assertEquals("MsoRequestId",genericInfo.getRequestInformation().getRequestId()); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java index 6a14f8b567..1bfa78ad6d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java @@ -23,6 +23,7 @@ package org.onap.so.client.sdnc.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.io.IOException; @@ -109,6 +110,7 @@ public class NetworkTopologyOperationRequestMapperTest { userParams.put("key1", "value1"); requestContext.setUserParams(userParams); requestContext.setProductFamilyId("productFamilyId"); + requestContext.setMsoRequestId("MsoRequestId"); network = new L3Network(); network.setNetworkId("TEST_NETWORK_ID"); @@ -138,8 +140,24 @@ public class NetworkTopologyOperationRequestMapperTest { assertThat(networkSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); + assertEquals("MsoRequestId", networkSDNCrequest.getRequestInformation().getRequestId()); } + + @Test + public void createGenericResourceApiNetworkOperationInformationReqContextNullTest() throws Exception { + RequestContext rc = new RequestContext(); + rc.setMsoRequestId(null); + GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer, + rc, cloudRegion); + assertNotNull(networkSDNCrequest.getRequestInformation().getRequestId()); + GenericResourceApiNetworkOperationInformation networkSDNCrequest2 = mapper.reqMapper( + SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer, + null, cloudRegion); + assertNotNull(networkSDNCrequest2.getRequestInformation().getRequestId()); + } + @Test public void reqMapperTest() throws Exception { @@ -175,7 +193,8 @@ public class NetworkTopologyOperationRequestMapperTest { assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); - + assertEquals("MsoRequestId", networkSDNCrequestUnassign.getRequestInformation().getRequestId()); + } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java index 0bf06a0bb0..1919ef437b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java @@ -22,6 +22,8 @@ package org.onap.so.client.sdnc.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.nio.file.Files; import java.nio.file.Paths; @@ -80,10 +82,14 @@ public class ServiceTopologyOperationMapperTest { userParams.put("key1", "value1"); requestContext.setUserParams(userParams); requestContext.setProductFamilyId("productFamilyId"); + requestContext.setMsoRequestId("MsoRequestId"); GenericResourceApiServiceOperationInformation serviceOpInformation = mapper.reqMapper( SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, requestContext); + GenericResourceApiServiceOperationInformation serviceOpInformationNullReqContext = mapper.reqMapper( + SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, + null); String jsonToCompare = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/BuildingBlocks/genericResourceApiEcompModelInformation.json"))); @@ -92,5 +98,7 @@ public class ServiceTopologyOperationMapperTest { GenericResourceApiOnapmodelinformationOnapModelInformation.class); assertThat(reqMapper1, sameBeanAs(serviceOpInformation.getServiceInformation().getOnapModelInformation())); + assertEquals("MsoRequestId", serviceOpInformation.getRequestInformation().getRequestId()); + assertNotNull(serviceOpInformationNullReqContext.getRequestInformation().getRequestId()); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java index 282f23caa7..7fce8c48c8 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java @@ -23,6 +23,7 @@ package org.onap.so.client.sdnc.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.nio.file.Files; @@ -102,6 +103,7 @@ public class VfModuleTopologyOperationRequestMapperTest { RequestParameters requestParameters = new RequestParameters(); requestParameters.setUsePreload(true); requestContext.setRequestParameters(requestParameters); + requestContext.setMsoRequestId("MsoRequestId"); GenericVnf vnf = new GenericVnf(); vnf.setVnfId("testVnfId"); @@ -148,6 +150,7 @@ public class VfModuleTopologyOperationRequestMapperTest { assertThat(reqMapper1, sameBeanAs(vfModuleSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); + assertEquals("MsoRequestId", vfModuleSDNCrequest.getRequestInformation().getRequestId()); } @Test @@ -168,10 +171,13 @@ public class VfModuleTopologyOperationRequestMapperTest { VfModule vfModule = new VfModule(); vfModule.setVfModuleId("testVfModuleId"); vfModule.setVfModuleName("testVfModuleName"); + + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("MsoRequestId"); GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, - null, null, null); + null, requestContext, null); String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleOperationInformationUnassign.json"))); @@ -182,6 +188,35 @@ public class VfModuleTopologyOperationRequestMapperTest { assertThat(reqMapper1, sameBeanAs(vfModuleSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); + assertEquals("MsoRequestId", vfModuleSDNCrequest.getRequestInformation().getRequestId()); + } + + @Test + public void unassignGenericResourceApiVfModuleInformationNullMsoReqIdTest() throws Exception { + + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + + // prepare and set vnf instance + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("testVnfId"); + vnf.setVnfType("testVnfType"); + + // prepare and set vf module instance + + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("testVfModuleId"); + vfModule.setVfModuleName("testVfModuleName"); + + RequestContext requestContext = new RequestContext(); + + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, + null, requestContext, null); + + assertNotNull(vfModuleSDNCrequest.getRequestInformation().getRequestId()); } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java index 229a8cf601..64b532fd07 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java @@ -21,6 +21,7 @@ package org.onap.so.client.sdnc.mapper; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.util.ArrayList; @@ -122,12 +123,16 @@ public class VnfTopologyOperationRequestMapperTest { userParams.put("key1", "value1"); requestContext.setUserParams(userParams); requestContext.setProductFamilyId("productFamilyId"); + requestContext.setMsoRequestId("MsoRequestId"); CloudRegion cloudRegion = new CloudRegion(); GenericResourceApiVnfOperationInformation vnfOpInformation = mapper.reqMapper( SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, cloudRegion, requestContext,true); + GenericResourceApiVnfOperationInformation vnfOpInformationNullReqContext = mapper.reqMapper( + SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, + cloudRegion, null,true); assertNull(vnfOpInformation.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); assertEquals("vnfModelCustomizationUUID", vnfOpInformation.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); @@ -136,5 +141,7 @@ public class VnfTopologyOperationRequestMapperTest { assertEquals("l3-network-ig-222", vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().get(1).getVnfNetworkInstanceGroupId()); assertEquals("entitlementPoolUuid", vnfOpInformation.getVnfRequestInput().getVnfInputParameters().getParam().get(1).getValue()); assertEquals("licenseKeyGroupUuid", vnfOpInformation.getVnfRequestInput().getVnfInputParameters().getParam().get(2).getValue()); + assertEquals("MsoRequestId", vnfOpInformation.getRequestInformation().getRequestId()); + assertNotNull(vnfOpInformationNullReqContext.getRequestInformation().getRequestId()); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java index 3387e9ddef..722180f54b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java @@ -22,7 +22,6 @@ package org.onap.so.client.sniro; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import org.junit.Test; @@ -45,7 +44,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_success() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -58,7 +57,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -74,7 +73,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -88,7 +87,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -102,7 +101,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException { String mockResponse = "{ }"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -115,7 +114,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_success() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -127,7 +126,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -139,7 +138,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -152,7 +151,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"status\": \"failure\", \"message\": null}"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -165,7 +164,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException { String mockResponse = "{ }"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); |