diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
27 files changed, 518 insertions, 147 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/AllIntegrationTestSuites.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/AllIntegrationTestSuites.java new file mode 100644 index 0000000000..8a57d5d43a --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/AllIntegrationTestSuites.java @@ -0,0 +1,12 @@ +package org.onap.so; + +import org.junit.runner.RunWith; + +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses({"**/SniroHomingV2IT.class"}) +public class AllIntegrationTestSuites{ + +} 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 4bf6f0e185..6500e3a850 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 @@ -22,13 +22,16 @@ package org.onap.so; import java.io.IOException; import java.io.InputStream; +import org.junit.Before; import org.junit.runner.RunWith; import org.onap.so.bpmn.buildingblock.SniroHomingV2; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.client.appc.ApplicationControllerAction; 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.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; @@ -37,29 +40,40 @@ 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; + @RunWith(SpringRunner.class) @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") @ContextConfiguration @AutoConfigureWireMock(port = 0) public abstract class BaseIntegrationTest extends TestDataSetup { - + + @Value("${wiremock.server.port}") + protected String wireMockPort; + @SpyBean protected SDNCClient SPY_sdncClient; - + @SpyBean protected SDNOHealthCheckResources MOCK_sdnoHealthCheckResources; - @MockBean + @SpyBean protected SniroHomingV2 sniroHoming; - + + @SpyBean + protected SniroClient sniroClient; + @MockBean protected ApplicationControllerAction appCClient; - - + @MockBean protected CatalogDbClient catalogDbClient; - + + @Before + public void baseTestBefore() { + WireMock.reset(); + } public String readResourceFile(String fileName) { InputStream stream; try { @@ -73,7 +87,7 @@ public abstract class BaseIntegrationTest extends TestDataSetup { stream.close(); return ""; } - } catch (IOException e) { + } catch (IOException e) { return ""; } } @@ -85,7 +99,7 @@ public abstract class BaseIntegrationTest extends TestDataSetup { throw new IOException("Can't access resource '" + resourceName + "'"); } return stream; - } + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/IntegrationTestSuite.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/IntegrationTestSuite.java new file mode 100644 index 0000000000..ab999a9889 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/IntegrationTestSuite.java @@ -0,0 +1,12 @@ +package org.onap.so; + +import org.junit.runner.RunWith; + +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses({"**/*IT.class"}) +public class IntegrationTestSuite { + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/UnitTestSuite.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/UnitTestSuite.java new file mode 100644 index 0000000000..5ac9f229f6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/UnitTestSuite.java @@ -0,0 +1,13 @@ +package org.onap.so; + + +import org.junit.runner.RunWith; + +import com.googlecode.junittoolbox.SuiteClasses; +import com.googlecode.junittoolbox.WildcardPatternSuite; + +@RunWith(WildcardPatternSuite.class) +@SuiteClasses({"**/*Test.class"}) +public class UnitTestSuite { + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index 09ca0e543e..95201d555d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -7,9 +7,9 @@ * 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. @@ -23,6 +23,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.buildingblock.SniroHomingV2; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; @@ -51,89 +52,92 @@ import org.onap.so.client.orchestration.SDNCVnfResources; import org.onap.so.client.orchestration.VnfAdapterVfModuleResources; import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources; import org.onap.so.client.sdnc.SDNCClient; +import org.onap.so.client.sniro.SniroClient; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.client.RequestsDbClient; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; @RunWith(MockitoJUnitRunner.Silent.class) public abstract class BaseTaskTest extends TestDataSetup { @Mock protected AAIVolumeGroupResources aaiVolumeGroupResources; - + @Mock protected AAIServiceInstanceResources aaiServiceInstanceResources; - + @Mock protected AAIVnfResources aaiVnfResources; - + @Mock protected AAIVfModuleResources aaiVfModuleResources; - + @Mock protected AAIVpnBindingResources aaiVpnBindingResources; - + @Mock protected AAINetworkResources aaiNetworkResources; - + @Mock protected AAICollectionResources aaiCollectionResources; - + @Mock protected NetworkAdapterResources networkAdapterResources; - + @Mock protected VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources; - + @Mock protected VnfAdapterVfModuleResources vnfAdapterVfModuleResources; - + @Mock protected SDNCVnfResources sdncVnfResources; - + @Mock protected SDNCNetworkResources sdncNetworkResources; - + @Mock protected SDNCVfModuleResources sdncVfModuleResources; - + @Mock protected SDNCServiceInstanceResources sdncServiceInstanceResources; - + @Mock protected AssignNetworkBBUtils assignNetworkBBUtils; - + @Mock protected NetworkAdapterObjectMapper networkAdapterObjectMapper; - + @Mock protected AAIInstanceGroupResources aaiInstanceGroupResources; - + @Mock protected ApplicationControllerAction appCClient; - + @Mock protected CatalogDbClient catalogDbClient; - + @Mock protected RequestsDbClient requestsDbClient; - + @Mock protected BBInputSetupUtils bbSetupUtils; - + @Mock protected BBInputSetup bbInputSetup; @Mock protected AAIConfigurationResources aaiConfigurationResources; - + @Mock protected AAIObjectMapper MOCK_aaiObjectMapper; @Mock protected InjectionHelper MOCK_injectionHelper; - + @Mock - protected AAIResourcesClient MOCK_aaiResourcesClient; + protected AAIResourcesClient MOCK_aaiResourcesClient; @Mock protected ExtractPojosForBB extractPojosForBB; @@ -141,4 +145,5 @@ public abstract class BaseTaskTest extends TestDataSetup { @Mock protected ExceptionBuilder exceptionUtil; + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java index 1901a08f28..c96c38dab1 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java @@ -478,6 +478,8 @@ public class TestDataSetup{ modelInfoGenericVnf.setModelInvariantUuid("testModelInvariantUUID" + genericVnfCounter); modelInfoGenericVnf.setModelVersion("testModelVersion" + genericVnfCounter); modelInfoGenericVnf.setModelUuid("testModelUUID" + genericVnfCounter); + modelInfoGenericVnf.setModelInstanceName("testInstanceName" + genericVnfCounter); + genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); License license = new License(); @@ -652,6 +654,7 @@ public class TestDataSetup{ modelInfo.setModelName("testProxyModelName" + uniqueIdentifier); modelInfo.setModelUuid("testProxyModelUuid" + uniqueIdentifier); modelInfo.setModelVersion("testProxyModelVersion" + uniqueIdentifier); + modelInfo.setModelInstanceName("testProxyInstanceName" + uniqueIdentifier); serviceProxy.setModelInfoServiceProxy(modelInfo); @@ -663,10 +666,11 @@ public class TestDataSetup{ ar.setId("testAllottedResourceId" + uniqueIdentifier); ModelInfoAllottedResource modelInfo = new ModelInfoAllottedResource(); - modelInfo.setModelInvariantUuid("testProxyModelInvariantUuid" + uniqueIdentifier); - modelInfo.setModelName("testProxyModelName" + uniqueIdentifier); - modelInfo.setModelUuid("testProxyModelUuid" + uniqueIdentifier); - modelInfo.setModelVersion("testProxyModelVersion" + uniqueIdentifier); + modelInfo.setModelInvariantUuid("testAllottedModelInvariantUuid" + uniqueIdentifier); + modelInfo.setModelName("testAllottedModelName" + uniqueIdentifier); + modelInfo.setModelUuid("testAllottedModelUuid" + uniqueIdentifier); + modelInfo.setModelVersion("testAllottedModelVersion" + uniqueIdentifier); + modelInfo.setModelInstanceName("testAllottedModelInstanceName" + uniqueIdentifier); ar.setModelInfoAllottedResource(modelInfo); @@ -688,7 +692,7 @@ public class TestDataSetup{ serviceInstance.setConfigurations(configurations); return config; } - + public Subnet buildSubnet() { Subnet subnet = new Subnet(); subnet.setSubnetId("testSubnetId"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index 52a64f4863..bf66283b17 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -35,6 +35,7 @@ import static org.mockito.Mockito.when; import java.util.HashMap; import org.camunda.bpm.engine.delegate.BpmnError; +import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksITTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java index 942553b1dc..9cf1a1cdc9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksITTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksIT.java @@ -39,7 +39,7 @@ import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; import org.onap.so.db.catalog.beans.ControllerSelectionReference; import org.springframework.beans.factory.annotation.Autowired; -public class AppcRunTasksITTest extends BaseIntegrationTest { +public class AppcRunTasksIT extends BaseIntegrationTest { @Autowired private AppcRunTasks appcRunTasks; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java index 73e7215fc6..f0bb6a369c 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2Test.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java @@ -58,8 +58,7 @@ import org.onap.so.BaseIntegrationTest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -@Ignore -public class SniroHomingV2Test extends BaseIntegrationTest{ +public class SniroHomingV2IT extends BaseIntegrationTest{ private ServiceInstance serviceInstance; @@ -72,7 +71,7 @@ public class SniroHomingV2Test extends BaseIntegrationTest{ String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}"; -/** + @Before public void before() { serviceInstance = setServiceInstance(); @@ -493,5 +492,5 @@ public class SniroHomingV2Test extends BaseIntegrationTest{ verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class)); } -**/ + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java index 4ba6339f0a..4c5c50ebbf 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java @@ -40,6 +40,7 @@ import org.mockito.InjectMocks; 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.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.client.exception.BBObjectNotFoundException; @@ -51,15 +52,19 @@ public class SDNCQueryTasksTest extends BaseTaskTest{ @Rule public ExpectedException expectedException = ExpectedException.none(); + private ServiceInstance serviceInstance; private GenericVnf genericVnf; private VfModule vfModule; @Before public void before() throws BBObjectNotFoundException { + serviceInstance = setServiceInstance(); genericVnf = setGenericVnf(); vfModule = setVfModule(); doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf); when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java new file mode 100644 index 0000000000..a6efbd5989 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.sdnc.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; + +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.exception.MapperException; +import org.onap.so.client.sdnc.SDNCClient; +import org.onap.so.client.sdnc.beans.SDNCRequest; +import org.onap.so.client.sdnc.endpoint.SDNCTopology; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class SDNCRequestTasksTest extends SDNCRequestTasks{ + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @InjectMocks + SDNCRequestTasks sndcRequestTasks = new SDNCRequestTasks(); + + @Mock + SDNCClient sdncClient; + + @Spy + private ExceptionBuilder exceptionBuilder; + + protected DelegateExecution delegateExecution; + + + @Before + public void setup(){ + delegateExecution = new DelegateExecutionFake(); + delegateExecution.setVariable("SDNCRequest", createSDNCRequest()); + } + + @Test + public void createCorrelationVariables_Test(){ + sndcRequestTasks.createCorrelationVariables(delegateExecution); + assertEquals("correlationValue",delegateExecution.getVariable("correlationName_CORRELATOR")); + } + + @Test + public void callSDNC_Final_Test() throws MapperException, BadResponseException, IOException{ + final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientPut200Response.json"))); + doReturn(sdncResponse).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION); + sndcRequestTasks.callSDNC(delegateExecution); + assertEquals(true,delegateExecution.getVariable("isSDNCCompleted")); + } + + @Test + public void callSDNC_Not_Final_Test() throws MapperException, BadResponseException, IOException{ + final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json"))); + doReturn(sdncResponse).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION); + sndcRequestTasks.callSDNC(delegateExecution); + assertEquals(false,delegateExecution.getVariable("isSDNCCompleted")); + } + + @Test + public void callSDNC_Error_Test() throws MapperException, BadResponseException{ + doThrow(MapperException.class).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION); + doReturn("processKey").when(exceptionBuilder).getProcessKey(delegateExecution); + expectedException.expect(BpmnError.class); + sndcRequestTasks.callSDNC(delegateExecution); + } + + @Test + public void convertIndicatorToBoolean_True_Test() throws MapperException, BadResponseException{ + boolean testValue = sndcRequestTasks.convertIndicatorToBoolean("Y"); + assertEquals(true,testValue); + } + + @Test + public void convertIndicatorToBoolean_False_Test() throws MapperException, BadResponseException{ + boolean testValue = sndcRequestTasks.convertIndicatorToBoolean("N"); + assertEquals(false,testValue); + } + + @Test + public void HandleTimeout_Test() throws MapperException, BadResponseException{ + doReturn("processKey").when(exceptionBuilder).getProcessKey(delegateExecution); + expectedException.expect(BpmnError.class); + sndcRequestTasks.handleTimeOutException(delegateExecution); + } + + + @Test + public void HandleSyncError_Test() throws MapperException, BadResponseException{ + delegateExecution.setVariable("SDNCSyncError", "Error in SDNC Request"); + doReturn("processKey").when(exceptionBuilder).getProcessKey(delegateExecution); + expectedException.expect(BpmnError.class); + sndcRequestTasks.handleSyncError(delegateExecution); + } + + @Test + public void processCallBack_Final_Test() throws MapperException, BadResponseException, IOException{ + final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_ASYNC_Request.json"))); + delegateExecution.setVariable("correlationName_MESSAGE", sdncResponse); + sndcRequestTasks.processCallback(delegateExecution); + assertEquals(true,delegateExecution.getVariable(IS_CALLBACK_COMPLETED)); + } + + public SDNCRequest createSDNCRequest(){ + SDNCRequest request = new SDNCRequest(); + request.setCorrelationName("correlationName"); + request.setCorrelationValue("correlationValue"); + request.setTopology(SDNCTopology.CONFIGURATION); + ObjectMapper mapper = new ObjectMapper(); + try { + GenericResourceApiServiceOperationInformation sdncReq = + mapper.readValue(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_Client_Request.json")), GenericResourceApiServiceOperationInformation.class); + request.setSDNCPayload(sdncReq); + } catch (JsonParseException e) { + + } catch (JsonMappingException e) { + + } catch (IOException e) { + + } + + return request; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java index 8a2230feb5..b0a80ebc72 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -25,27 +25,23 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; -import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; -import org.onap.so.db.request.beans.InfraActiveRequests; -import org.springframework.beans.factory.annotation.Autowired; public class WorkflowActionBBTasksTest extends BaseTaskTest { @@ -53,6 +49,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { protected WorkflowAction workflowAction; @InjectMocks + @Spy protected WorkflowActionBBTasks workflowActionBBTasks; private DelegateExecution execution; @@ -88,32 +85,6 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { } @Test - public void getUpdatedRequestTest() throws Exception{ - List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); - ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); - BuildingBlock bb1 = new BuildingBlock(); - bb1.setBpmnFlowName("CreateNetworkBB"); - flowsToExecute.add(ebb1); - ebb1.setBuildingBlock(bb1); - ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); - BuildingBlock bb2 = new BuildingBlock(); - bb2.setBpmnFlowName("ActivateNetworkBB"); - flowsToExecute.add(ebb2); - ebb2.setBuildingBlock(bb2); - String requestId = "requestId"; - execution.setVariable("mso-request-id", requestId); - execution.setVariable("flowsToExecute", flowsToExecute); - int currentSequence = 2; - String expectedStatusMessage = "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1)."; - Long expectedLong = new Long(52); - InfraActiveRequests mockedRequest = new InfraActiveRequests(); - when(requestsDbClient.getInfraActiveRequestbyRequestId(requestId)).thenReturn(mockedRequest); - InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence); - assertEquals(expectedStatusMessage, actual.getStatusMessage()); - assertEquals(expectedLong, actual.getProgress()); - } - - @Test public void select2BBTest() throws Exception{ String gAction = "Delete-Network-Collection"; execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); @@ -146,17 +117,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { } @Test - public void setupFalloutHandlerTest(){ - execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); - execution.setVariable("serviceInstanceId", "123"); - execution.setVariable("WorkflowActionErrorMessage", "Error in WorkFlowAction"); - execution.setVariable("requestAction", "createInstance"); - workflowActionBBTasks.setupFalloutHandler(execution); - assertEquals(execution.getVariable("falloutRequest"),"<aetgt:FalloutHandlerRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"xmlns:ns=\"http://org.onap/so/request/types/v1\"xmlns:wfsch=\"http://org.onap/so/workflow/schema/v1\"><request-info xmlns=\"http://org.onap/so/infra/vnf-request/v1\"><request-id>00f704ca-c5e5-4f95-a72c-6889db7b0688</request-id><action>createInstance</action><source>VID</source></request-info><aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>Error in WorkFlowAction</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException></aetgt:FalloutHandlerRequest>"); - } - - @Test public void rollbackExecutionPathTest(){ + execution.setVariable("handlingCode", "Rollback"); execution.setVariable("isRollback", false); List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); @@ -177,7 +139,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB"); @@ -188,6 +151,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { @Test public void rollbackExecutionPathUnfinishedFlowTest(){ + execution.setVariable("handlingCode", "Rollback"); execution.setVariable("isRollback", false); List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); @@ -208,7 +172,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 2); - + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); @@ -219,6 +184,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { @Test public void rollbackExecutionTest(){ + execution.setVariable("handlingCode", "Rollback"); execution.setVariable("isRollback", false); List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); @@ -244,7 +210,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); @@ -254,7 +221,44 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { } @Test + public void rollbackExecutionRollbackToAssignedTest(){ + execution.setVariable("isRollback", false); + execution.setVariable("handlingCode", "RollbackToAssigned"); + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); + BuildingBlock bb1 = new BuildingBlock(); + bb1.setBpmnFlowName("AssignServiceInstanceBB"); + ebb1.setBuildingBlock(bb1); + flowsToExecute.add(ebb1); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("CreateNetworkCollectionBB"); + ebb2.setBuildingBlock(bb2); + flowsToExecute.add(ebb2); + ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock(); + BuildingBlock bb3 = new BuildingBlock(); + bb3.setBpmnFlowName("AssignNetworkBB"); + ebb3.setBuildingBlock(bb3); + flowsToExecute.add(ebb3); + ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock(); + BuildingBlock bb4 = new BuildingBlock(); + bb4.setBpmnFlowName("CreateNetworkBB"); + ebb4.setBuildingBlock(bb4); + flowsToExecute.add(ebb4); + + execution.setVariable("flowsToExecute", flowsToExecute); + execution.setVariable("gCurrentSequence", 3); + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + + workflowActionBBTasks.rollbackExecutionPath(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkCollectionBB"); + assertEquals(0,execution.getVariable("gCurrentSequence")); + } + + @Test public void checkRetryStatusTest(){ + doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); execution.setVariable("handlingCode","Retry"); execution.setVariable("retryCount", 1); execution.setVariable("gCurrentSequence",1); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksUpdateReqDbTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksUpdateReqDbTest.java new file mode 100644 index 0000000000..1e2558b580 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksUpdateReqDbTest.java @@ -0,0 +1,74 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.db.request.beans.InfraActiveRequests; + +public class WorkflowActionBBTasksUpdateReqDbTest extends BaseTaskTest{ + + protected WorkflowAction workflowAction = new WorkflowAction(); + + @Spy + @InjectMocks + protected WorkflowActionBBTasks workflowActionBBTasks; + + private DelegateExecution execution; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance(); + servInstance.setServiceInstanceId("TEST"); + when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), any())).thenReturn(servInstance); + workflowAction.setBbInputSetupUtils(bbSetupUtils); + workflowAction.setBbInputSetup(bbInputSetup); + } + + @Test + public void getUpdatedRequestTest() throws Exception{ + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); + BuildingBlock bb1 = new BuildingBlock(); + bb1.setBpmnFlowName("CreateNetworkBB"); + flowsToExecute.add(ebb1); + ebb1.setBuildingBlock(bb1); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("ActivateNetworkBB"); + flowsToExecute.add(ebb2); + ebb2.setBuildingBlock(bb2); + String requestId = "requestId"; + execution.setVariable("mso-request-id", requestId); + execution.setVariable("flowsToExecute", flowsToExecute); + int currentSequence = 2; + String expectedStatusMessage = "Execution of CreateNetworkBB has completed successfully, next invoking ActivateNetworkBB (Execution Path progress: BBs completed = 1; BBs remaining = 1)."; + Long expectedLong = new Long(52); + InfraActiveRequests mockedRequest = new InfraActiveRequests(); + doReturn(mockedRequest).when(requestsDbClient).getInfraActiveRequestbyRequestId(isA(String.class)); + InfraActiveRequests actual = workflowActionBBTasks.getUpdatedRequest(execution, currentSequence); + assertEquals(expectedStatusMessage, actual.getStatusMessage()); + assertEquals(expectedLong, actual.getProgress()); + } +} 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 9ca49788ae..a2880ce07f 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 @@ -25,11 +25,13 @@ 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 org.junit.BeforeClass; import org.junit.Test; +import org.onap.so.BaseIntegrationTest; import org.onap.so.adapters.nwrest.CreateNetworkError; import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; @@ -44,12 +46,11 @@ import org.onap.so.adapters.nwrest.RollbackNetworkResponse; import org.onap.so.adapters.nwrest.UpdateNetworkError; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; -import org.onap.so.BaseIntegrationTest; +import org.onap.so.client.policy.JettisonStyleMapperProvider; import org.onap.so.openstack.beans.NetworkRollback; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import static com.github.tomakehurst.wiremock.client.WireMock.*; public class NetworkAdapterClientIT extends BaseIntegrationTest{ @@ -58,7 +59,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ private static final String REST_ENDPOINT = "/networks/rest/v1/networks"; private NetworkAdapterClientImpl client = new NetworkAdapterClientImpl(); - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = new JettisonStyleMapperProvider().getMapper(); @BeforeClass public static void setUp() { 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 0f9e11f354..3387920d40 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 @@ -31,6 +31,7 @@ import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.so.BaseIntegrationTest; import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; import org.onap.so.adapters.vnfrest.CreateVfModuleResponse; import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; @@ -42,7 +43,8 @@ import org.onap.so.adapters.vnfrest.UpdateVfModuleRequest; import org.onap.so.adapters.vnfrest.UpdateVfModuleResponse; import org.onap.so.adapters.vnfrest.VfModuleExceptionResponse; import org.onap.so.adapters.vnfrest.VfModuleRollback; -import org.onap.so.BaseIntegrationTest; +import org.onap.so.client.policy.JettisonStyleMapperProvider; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -54,7 +56,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ private static final String REST_ENDPOINT = "/services/rest/v1/vnfs"; private VnfAdapterClientImpl client = new VnfAdapterClientImpl(); - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = new JettisonStyleMapperProvider().getMapper(); @BeforeClass public static void setUp() { 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 149417d89b..0b33b1d187 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 @@ -20,20 +20,21 @@ package org.onap.so.client.oof; -import com.fasterxml.jackson.core.JsonProcessingException; +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; +import org.onap.so.BaseIntegrationTest; import org.onap.so.client.exception.BadResponseException; -import org.onap.so.client.oof.OofClient; import org.onap.so.client.oof.beans.OofRequest; import org.springframework.beans.factory.annotation.Autowired; -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 com.fasterxml.jackson.core.JsonProcessingException; -public class OofClientTestIT { +public class OofClientTestIT extends BaseIntegrationTest { @Autowired private OofClient client; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java index 8bb46d80d7..4d90a3fcc9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java @@ -27,11 +27,15 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import java.net.URI; +import java.net.URISyntaxException; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.common.data.TestDataSetup; @@ -68,49 +72,34 @@ public class SDNCConfigurationResourcesTest extends TestDataSetup{ @Before public void setUp(){ - customer = buildCustomer(); - requestContext = buildRequestContext(); - serviceInstance = buildServiceInstance(); - - vpnBondingLink = buildVpnBondingLink(); - + vpnBondingLink = buildVpnBondingLink(); vnf = vpnBondingLink.getInfrastructureServiceProxy().getServiceInstance().getVnfs().get(0); } @Test - public void activateVnrConfigurationTest() throws BadResponseException, MapperException { - - doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); - String response = sdncConfigurationResources.activateVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf); - verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + public void activateVnrConfigurationTest() throws BadResponseException, MapperException, URISyntaxException { + GenericResourceApiGcTopologyOperationInformation response = sdncConfigurationResources.activateVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf,"uuid",new URI("http://localhost")); assertNotNull(response); } @Test - public void assignVnrConfigurationTest() throws BadResponseException, MapperException { - - doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); - String response = sdncConfigurationResources.assignVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf); - verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + public void assignVnrConfigurationTest() throws BadResponseException, MapperException, URISyntaxException { + GenericResourceApiGcTopologyOperationInformation response = sdncConfigurationResources.assignVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf,"uuid",new URI("http://localhost")); assertNotNull(response); } @Test - public void unAssignVnrConfigurationTest() throws BadResponseException, MapperException { - doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); - String response = sdncConfigurationResources.unAssignVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration()); - verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + public void unAssignVnrConfigurationTest() throws BadResponseException, MapperException , URISyntaxException{ + GenericResourceApiGcTopologyOperationInformation response = sdncConfigurationResources.unAssignVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration(),"uuid",new URI("http://localhost")); assertNotNull(response); } @Test - public void deactivateVnrConfigurationTest() throws BadResponseException, MapperException { - doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); - String response = sdncConfigurationResources.deactivateVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration()); - verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + public void deactivateVnrConfigurationTest() throws BadResponseException, MapperException , URISyntaxException{ + GenericResourceApiGcTopologyOperationInformation response = sdncConfigurationResources.deactivateVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration(),"uuid",new URI("http://localhost")); assertNotNull(response); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java index 66ec514039..cc1c5c5329 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java @@ -23,37 +23,30 @@ 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; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import org.junit.Rule; import org.junit.Test; import org.onap.so.BaseIntegrationTest; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.endpoint.SDNCTopology; import org.skyscreamer.jsonassert.JSONAssert; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class SDNCClientTest extends BaseIntegrationTest { +public class SDNCClientIT extends BaseIntegrationTest { private final static String JSON_FILE_LOCATION = "src/test/resources/__files/"; - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8446)); - @Test public void getTest() throws BadResponseException, MapperException, IOException { String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json"))); String queryLink = "/topologyQuery"; - wireMockRule.stubFor(get(urlEqualTo(queryLink)) + stubFor(get(urlEqualTo(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); String response = SPY_sdncClient.get(queryLink); @@ -66,7 +59,7 @@ public class SDNCClientTest extends BaseIntegrationTest { String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - wireMockRule.stubFor(post(urlMatching(queryLink)) + stubFor(post(urlMatching(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); @@ -79,7 +72,7 @@ public class SDNCClientTest extends BaseIntegrationTest { String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - wireMockRule.stubFor(post(urlMatching(queryLink)) + 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 7c5e9ccf26..f01eeaeae8 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 @@ -20,6 +20,8 @@ package org.onap.so.client.sdnc.mapper; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.List; @@ -44,7 +46,7 @@ public class GCTopologyOperationRequestMapperTest extends TestDataSetup{ private GCTopologyOperationRequestMapper genObjMapper = new GCTopologyOperationRequestMapper(); @Test - public void deactivateOrUnassignVnrReqMapperTest() { + public void deactivateOrUnassignVnrReqMapperTest() throws URISyntaxException { RequestContext requestContext = new RequestContext(); requestContext.setMsoRequestId("MsoRequestId"); ServiceInstance serviceInstance = new ServiceInstance(); @@ -52,10 +54,15 @@ public class GCTopologyOperationRequestMapperTest extends TestDataSetup{ Configuration Configuration = new Configuration(); Configuration.setConfigurationId("ConfigurationId"); GenericResourceApiGcTopologyOperationInformation genericInfo = genObjMapper.deactivateOrUnassignVnrReqMapper - (SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, Configuration); + (SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, Configuration,"uuid",new URI("http://localhost")); Assert.assertNotNull(genericInfo); - Assert.assertNotNull(genericInfo.getSdncRequestHeader().getSvcRequestId()); + Assert.assertNotNull(genericInfo.getRequestInformation()); + Assert.assertNotNull(genericInfo.getSdncRequestHeader()); + Assert.assertNotNull(genericInfo.getClass()); + Assert.assertNotNull(genericInfo.getServiceInformation()); + Assert.assertEquals("uuid",genericInfo.getSdncRequestHeader().getSvcRequestId()); + Assert.assertEquals("http://localhost",genericInfo.getSdncRequestHeader().getSvcNotificationUrl()); } 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 e5eb6bce54..3387e9ddef 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,18 +22,20 @@ 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; +import org.onap.so.BaseIntegrationTest; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.sniro.beans.SniroConductorRequest; import org.onap.so.client.sniro.beans.SniroManagerRequest; import org.springframework.beans.factory.annotation.Autowired; import com.fasterxml.jackson.core.JsonProcessingException; -import static com.github.tomakehurst.wiremock.client.WireMock.*; -public class SniroClientTestIT{ +public class SniroClientTestIT extends BaseIntegrationTest { @Autowired private SniroClient client; diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json index ba7ab9e3b8..55aa2ef58c 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1Vpn.json @@ -2,5 +2,5 @@ "requestInfo" : {"sourceId":"mso","requestType":"create","requestId":"testRequestId","callbackUrl":"http://localhost:28080/mso/WorkflowMesssage/SNIROResponse/testRequestId","transactionId":"testRequestId","timeout":1800}, "serviceInfo" : {"modelInfo":{"modelName":"testModelName1","modelVersionId":"testModelUUID1","modelVersion":"testModelVersion1","modelInvariantId":"testModelInvariantUUID1"},"serviceInstanceId":"testServiceInstanceId1","serviceName":"testServiceType1"}, "placementInfo" : {"subscriberInfo":{"subscriberName":"testCustomerName","globalSubscriberId":"testCustomerId"},"placementDemands":[{"resourceModelInfo":{"modelName":"testProxyModelName1","modelVersionId":"testProxyModelUuid1","modelVersion":"testProxyModelVersion1","modelInvariantId":"testProxyModelInvariantUuid1"},"resourceModuleName":"testProxyInstanceName1","serviceResourceId":"testProxyId1"},{"resourceModelInfo":{"modelName":"testProxyModelName2","modelVersionId":"testProxyModelUuid2","modelVersion":"testProxyModelVersion2","modelInvariantId":"testProxyModelInvariantUuid2"},"requiredCandidates":[{"candidateType":{"name":"vnfId"},"candidates":["testVnfId"]}],"resourceModuleName":"testProxyInstanceName2","serviceResourceId":"testProxyId2"}],"requestParameters":{"aLaCarte":false,"subscriptionServiceType":"iptollfree"}}, - "licenseInfo" : [] + "licenseInfo" : {"licenseDemands":[]} }
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json new file mode 100644 index 0000000000..6977224ffa --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3AR.json @@ -0,0 +1,6 @@ +{ + "requestInfo" : {"sourceId":"mso","requestType":"create","requestId":"testRequestId","callbackUrl":"http://localhost:28080/mso/WorkflowMesssage/SNIROResponse/testRequestId","transactionId":"testRequestId","timeout":1800}, + "serviceInfo" : {"modelInfo":{"modelName":"testModelName1","modelVersionId":"testModelUUID1","modelVersion":"testModelVersion1","modelInvariantId":"testModelInvariantUUID1"},"serviceInstanceId":"testServiceInstanceId1","serviceName":"testServiceType1"}, + "placementInfo" : {"subscriberInfo":{"subscriberName":"testCustomerName","globalSubscriberId":"testCustomerId"},"placementDemands":[{"resourceModelInfo":{"modelName":"testAllottedModelName1","modelVersionId":"testAllottedModelUuid1","modelVersion":"testAllottedModelVersion1","modelInvariantId":"testAllottedModelInvariantUuid1"},"resourceModuleName":"testAllottedModelInstanceName1","serviceResourceId":"testAllottedResourceId1"},{"resourceModelInfo":{"modelName":"testAllottedModelName2","modelVersionId":"testAllottedModelUuid2","modelVersion":"testAllottedModelVersion2","modelInvariantId":"testAllottedModelInvariantUuid2"},"resourceModuleName":"testAllottedModelInstanceName2","serviceResourceId":"testAllottedResourceId2"},{"resourceModelInfo":{"modelName":"testAllottedModelName3","modelVersionId":"testAllottedModelUuid3","modelVersion":"testAllottedModelVersion3","modelInvariantId":"testAllottedModelInvariantUuid3"},"resourceModuleName":"testAllottedModelInstanceName3","serviceResourceId":"testAllottedResourceId3"}],"requestParameters":{"aLaCarte":false,"subscriptionServiceType":"iptollfree"}}, + "licenseInfo" : {"licenseDemands":[]} +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json index c5d0ffe38d..c72831b79f 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest3Vpn.json @@ -2,5 +2,5 @@ "requestInfo" : {"sourceId":"mso","requestType":"create","requestId":"testRequestId","callbackUrl":"http://localhost:28080/mso/WorkflowMesssage/SNIROResponse/testRequestId","transactionId":"testRequestId","timeout":1800}, "serviceInfo" : {"modelInfo":{"modelName":"testModelName1","modelVersionId":"testModelUUID1","modelVersion":"testModelVersion1","modelInvariantId":"testModelInvariantUUID1"},"serviceInstanceId":"testServiceInstanceId1","serviceName":"testServiceType1"}, "placementInfo" : {"subscriberInfo":{"subscriberName":"testCustomerName","globalSubscriberId":"testCustomerId"},"placementDemands":[{"resourceModelInfo":{"modelName":"testProxyModelName1","modelVersionId":"testProxyModelUuid1","modelVersion":"testProxyModelVersion1","modelInvariantId":"testProxyModelInvariantUuid1"},"resourceModuleName":"testProxyInstanceName1","serviceResourceId":"testProxyId1"},{"resourceModelInfo":{"modelName":"testProxyModelName2","modelVersionId":"testProxyModelUuid2","modelVersion":"testProxyModelVersion2","modelInvariantId":"testProxyModelInvariantUuid2"},"requiredCandidates":[{"candidateType":{"name":"vnfId"},"candidates":["testVnfId"]}],"resourceModuleName":"testProxyInstanceName2","serviceResourceId":"testProxyId2"},{"resourceModelInfo":{"modelName":"testProxyModelName1","modelVersionId":"testProxyModelUuid1","modelVersion":"testProxyModelVersion1","modelInvariantId":"testProxyModelInvariantUuid1"},"resourceModuleName":"testProxyInstanceName1","serviceResourceId":"testProxyId1"},{"resourceModelInfo":{"modelName":"testProxyModelName2","modelVersionId":"testProxyModelUuid2","modelVersion":"testProxyModelVersion2","modelInvariantId":"testProxyModelInvariantUuid2"},"requiredCandidates":[{"candidateType":{"name":"vnfId"},"candidates":["testVnfId"]}],"resourceModuleName":"testProxyInstanceName2","serviceResourceId":"testProxyId2"},{"resourceModelInfo":{"modelName":"testProxyModelName1","modelVersionId":"testProxyModelUuid1","modelVersion":"testProxyModelVersion1","modelInvariantId":"testProxyModelInvariantUuid1"},"resourceModuleName":"testProxyInstanceName1","serviceResourceId":"testProxyId1"},{"resourceModelInfo":{"modelName":"testProxyModelName2","modelVersionId":"testProxyModelUuid2","modelVersion":"testProxyModelVersion2","modelInvariantId":"testProxyModelInvariantUuid2"},"requiredCandidates":[{"candidateType":{"name":"vnfId"},"candidates":["testVnfId"]}],"resourceModuleName":"testProxyInstanceName2","serviceResourceId":"testProxyId2"}],"requestParameters":{"aLaCarte":false,"subscriptionServiceType":"iptollfree"}}, - "licenseInfo" : [] + "licenseInfo" : {"licenseDemands":[]} }
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json new file mode 100644 index 0000000000..deb4de0219 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json @@ -0,0 +1,15 @@ +{ + "output": { + "svc-request-id": "5d24d40e-4c77-4c06-94a3-6d168c47a57c", + "network-response-information": { + "instance-id": "4063e0aa-af13-4872-8473-b40c94f9316b", + "object-path": "restconf/config/GENERIC-RESOURCE-API:services/service/2c9c7996-75a7-4f92-becc-9e13e8bd288a/service-data/networks/network/4063e0aa-af13-4872-8473-b40c94f9316b/network-data/network-topology/" + }, + "response-code": "200", + "service-response-information": { + "instance-id": "2c9c7996-75a7-4f92-becc-9e13e8bd288a" + }, + "response-message": "", + "ack-final-indicator": "N" + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_ASYNC_Request.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_ASYNC_Request.json new file mode 100644 index 0000000000..c1ea682068 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_ASYNC_Request.json @@ -0,0 +1,15 @@ +{ + "input": { + "svc-request-id": "5d24d40e-4c77-4c06-94a3-6d168c47a57c", + "network-response-information": { + "instance-id": "4063e0aa-af13-4872-8473-b40c94f9316b", + "object-path": "restconf/config/GENERIC-RESOURCE-API:services/service/2c9c7996-75a7-4f92-becc-9e13e8bd288a/service-data/networks/network/4063e0aa-af13-4872-8473-b40c94f9316b/network-data/network-topology/" + }, + "response-code": "200", + "service-response-information": { + "instance-id": "2c9c7996-75a7-4f92-becc-9e13e8bd288a" + }, + "response-message": "", + "ack-final-indicator": "Y" + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Client_Request.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Client_Request.json new file mode 100644 index 0000000000..f60767b85e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNC_Client_Request.json @@ -0,0 +1,28 @@ +: { + "input": { + "request-information": { + "request-action": "CreateServiceInstance", + "source": "MSO", + "request-id": "5a09ab96-032b-41cd-ad81-4fb9ec5fade7" + }, + "sdnc-request-header": { + "svc-request-id": "5a09ab96-032b-41cd-ad81-4fb9ec5fade7", + "svc-action": "assign" + }, + "service-information": { + "onap-model-information": { + "model-name": "Vf zrdm5bpxmc02092017-Service", + "model-version": "1.0", + "model-uuid": "bad955c3-29b2-4a27-932e-28e942cc6480", + "model-invariant-uuid": "b16a9398-ffa3-4041-b78c-2956b8ad9c7b" + }, + "subscription-service-type": "Robot_Test_Service_Type", + "service-id": "48121c5e-dde0-42a6-a78a-89556ff355d0", + "global-customer-id": "Robot_Test_Subscriber_ID", + "service-instance-id": "48121c5e-dde0-42a6-a78a-89556ff355d0" + }, + "service-request-input": { + "service-instance-name": "Robot_SI_For_VolumeGroup" + } + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml index 69d2e18e7a..4ecdc721f0 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml +++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml @@ -160,7 +160,7 @@ policy: environment: TEST sdnc: auth: Basic YWRtaW46YWRtaW4= - host: http://localhost:8446 + host: http://localhost:${wiremock.server.port} path: /restconf/operations/GENERIC-RESOURCE-API sniro: conductor: @@ -180,8 +180,7 @@ sniro: oof: timeout: PT30M host: http://localhost:${wiremock.server.port} - uri.v1: /api/oof/v1/placement - uri.v2: /api/oof/v2/placement + uri: /api/oof/v1/placement headers.auth: Basic dGVzdDp0ZXN0cHdk spring: datasource: |