From da366370647e6b72df4d8433bb52ec22a443d0ca Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Tue, 7 Jul 2020 11:46:43 -0400 Subject: move sdn clients to own package Began moving the sdn clients into one central isolated location Added test files, removed unused methods, fixed poms Fixed the client so that is doesnt have to import bpmn and can be built at top level Fixed bad merge that hapeened due to conflicts Added missing test files for sdno unit test Added maria db driver java client for spring test and jersey depend Issue-ID: SO-3034 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I4c0a6288623194c517dbc8fa6120d577b400ee01 --- .../GCTopologyOperationRequestMapperTest.java | 83 ++++ .../mapper/GeneralTopologyObjectMapperTest.java | 447 +++++++++++++++++++++ .../NetworkTopologyOperationRequestMapperTest.java | 234 +++++++++++ .../mapper/ServiceTopologyOperationMapperTest.java | 105 +++++ ...VfModuleTopologyOperationRequestMapperTest.java | 404 +++++++++++++++++++ .../VnfTopologyOperationRequestMapperTest.java | 154 +++++++ .../SDNCConfigurationResourcesTest.java | 2 +- .../orchestration/SDNCNetworkResourcesTest.java | 2 +- .../SDNCServiceInstanceResourcesTest.java | 2 +- .../orchestration/SDNCVfModuleResourcesTest.java | 4 +- .../client/orchestration/SDNCVnfResourcesTest.java | 2 +- .../so/client/sdn/common/SdnCommonTasksTest.java | 104 ----- .../java/org/onap/so/client/sdnc/SDNCClientIT.java | 79 ---- .../GCTopologyOperationRequestMapperTest.java | 158 -------- .../mapper/GeneralTopologyObjectMapperTest.java | 446 -------------------- .../NetworkTopologyOperationRequestMapperTest.java | 232 ----------- .../mapper/ServiceTopologyOperationMapperTest.java | 103 ----- ...VfModuleTopologyOperationRequestMapperTest.java | 402 ------------------ .../VnfTopologyOperationRequestMapperTest.java | 152 ------- .../so/client/sdno/SDNOHealthCheckClientTest.java | 94 ----- .../org/onap/so/client/sdno/SDNOValidatorIT.java | 124 ------ .../onap/so/client/sdno/SDNOValidatorImplTest.java | 56 --- 22 files changed, 1433 insertions(+), 1956 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/GCTopologyOperationRequestMapperTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/GeneralTopologyObjectMapperTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/ServiceTopologyOperationMapperTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapperTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java (limited to 'bpmn/so-bpmn-tasks/src/test/java/org') diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/GCTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/GCTopologyOperationRequestMapperTest.java new file mode 100644 index 0000000000..d4f1660986 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/GCTopologyOperationRequestMapperTest.java @@ -0,0 +1,83 @@ +/*- + * ============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.mapper; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdnc.northbound.client.model.GenericResourceApiGcTopologyOperationInformation; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.GCTopologyOperationRequestMapper; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.GeneralTopologyObjectMapper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class GCTopologyOperationRequestMapperTest extends TestDataSetup { + + + @Spy + private GeneralTopologyObjectMapper generalTopologyObjectMapper; + + @InjectMocks + private GCTopologyOperationRequestMapper genObjMapper = new GCTopologyOperationRequestMapper(); + + @Test + public void deactivateOrUnassignVnrReqMapperTest() throws URISyntaxException { + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("MsoRequestId"); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("ServiceInstanceId"); + Configuration Configuration = new Configuration(); + Configuration.setConfigurationId("ConfigurationId"); + Configuration.setConfigurationType("VLAN-NETWORK-RECEPTOR"); + GenericResourceApiGcTopologyOperationInformation genericInfo = + genObjMapper.deactivateOrUnassignVnrReqMapper(SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, + Configuration, "uuid", new URI("http://localhost")); + + Assert.assertNotNull(genericInfo); + Assert.assertNotNull(genericInfo.getRequestInformation()); + Assert.assertNotNull(genericInfo.getSdncRequestHeader()); + Assert.assertNotNull(genericInfo.getClass()); + Assert.assertNotNull(genericInfo.getServiceInformation()); + Assert.assertEquals("ConfigurationId", genericInfo.getConfigurationInformation().getConfigurationId()); + 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/bpmn/infrastructure/sdnc/mapper/GeneralTopologyObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/GeneralTopologyObjectMapperTest.java new file mode 100644 index 0000000000..92fc13b633 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/GeneralTopologyObjectMapperTest.java @@ -0,0 +1,447 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.mapper; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import java.util.HashMap; +import java.util.Map; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.InjectMocks; +import org.onap.sdnc.northbound.client.model.GenericResourceApiConfigurationinformationConfigurationInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiGcrequestinputGcRequestInput; +import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkinformationNetworkInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiParam; +import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam; +import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiSvcActionEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.GeneralTopologyObjectMapper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.client.exception.MapperException; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; + + +public class GeneralTopologyObjectMapperTest extends TestDataSetup { + @InjectMocks + private GeneralTopologyObjectMapper genObjMapper = new GeneralTopologyObjectMapper(); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Before + public void before() { + + } + + @After + public void after() { + + } + + @Test + public void testBuildServiceInformation() { + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); + modelInfoServiceInstance.setModelName("serviceModelName"); + modelInfoServiceInstance.setModelUuid("serviceModelUuid"); + modelInfoServiceInstance.setModelVersion("serviceModelVersion"); + + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + // prepare Customer object + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + ServiceSubscription serviceSubscription = new ServiceSubscription(); + serviceSubscription.setServiceType("productFamilyId"); + customer.setServiceSubscription(serviceSubscription); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + // + RequestContext requestContext = new RequestContext(); + Map userParams = new HashMap<>(); + userParams.put("key1", "value1"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + GenericResourceApiServiceinformationServiceInformation serviceInfo = + genObjMapper.buildServiceInformation(serviceInstance, requestContext, customer, true); + + assertEquals("serviceModelInvariantUuid", serviceInfo.getOnapModelInformation().getModelInvariantUuid()); + assertEquals("serviceModelName", serviceInfo.getOnapModelInformation().getModelName()); + assertEquals("serviceModelUuid", serviceInfo.getOnapModelInformation().getModelUuid()); + assertEquals("serviceModelVersion", serviceInfo.getOnapModelInformation().getModelVersion()); + assertNull(serviceInfo.getOnapModelInformation().getModelCustomizationUuid()); + assertEquals("serviceInstanceId", serviceInfo.getServiceInstanceId()); + assertEquals("serviceInstanceId", serviceInfo.getServiceId()); + assertEquals("globalCustomerId", serviceInfo.getGlobalCustomerId()); + assertEquals("productFamilyId", serviceInfo.getSubscriptionServiceType()); + } + + @Test + public void buildSdncRequestHeaderActivateTest() { + GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = + genObjMapper.buildSdncRequestHeader(SDNCSvcAction.ACTIVATE, "sdncReqId"); + + assertEquals(GenericResourceApiSvcActionEnumeration.ACTIVATE, requestHeader.getSvcAction()); + assertEquals("sdncReqId", requestHeader.getSvcRequestId()); + } + + @Test + public void buildSdncRequestHeaderAssignTest() { + GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = + genObjMapper.buildSdncRequestHeader(SDNCSvcAction.ASSIGN, "sdncReqId"); + + assertEquals(GenericResourceApiSvcActionEnumeration.ASSIGN, requestHeader.getSvcAction()); + assertEquals("sdncReqId", requestHeader.getSvcRequestId()); + } + + @Test + public void buildSdncRequestHeaderDeactivateTest() { + GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = + genObjMapper.buildSdncRequestHeader(SDNCSvcAction.DEACTIVATE, "sdncReqId"); + + assertEquals(GenericResourceApiSvcActionEnumeration.DEACTIVATE, requestHeader.getSvcAction()); + assertEquals("sdncReqId", requestHeader.getSvcRequestId()); + } + + @Test + public void buildSdncRequestHeaderDeleteTest() { + GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = + genObjMapper.buildSdncRequestHeader(SDNCSvcAction.DELETE, "sdncReqId"); + + assertEquals(GenericResourceApiSvcActionEnumeration.DELETE, requestHeader.getSvcAction()); + assertEquals("sdncReqId", requestHeader.getSvcRequestId()); + } + + @Test + public void buildSdncRequestHeaderChangeAssignTest() { + GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = + genObjMapper.buildSdncRequestHeader(SDNCSvcAction.CHANGE_ASSIGN, "sdncReqId"); + + assertEquals(GenericResourceApiSvcActionEnumeration.CHANGEASSIGN, requestHeader.getSvcAction()); + assertEquals("sdncReqId", requestHeader.getSvcRequestId()); + } + + @Test + public void buildConfigurationInformationTest_excludesOnapModelInfo() { + Configuration configuration = new Configuration(); + configuration.setConfigurationId("testConfigurationId"); + configuration.setConfigurationType("VNR"); + configuration.setConfigurationName("VNRCONF"); + GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = + genObjMapper.buildConfigurationInformation(configuration, false); + assertEquals(configuration.getConfigurationId(), configurationInformation.getConfigurationId()); + assertEquals(configuration.getConfigurationType(), configurationInformation.getConfigurationType()); + assertEquals(configuration.getConfigurationName(), configurationInformation.getConfigurationName()); + assertNull(configurationInformation.getOnapModelInformation()); + } + + @Test + public void buildConfigurationInformationTest_includesOnapModelInfo() { + Configuration configuration = new Configuration(); + configuration.setConfigurationId("testConfigurationId"); + configuration.setConfigurationType("VNR"); + configuration.setConfigurationName("VNRCONF"); + ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration(); + modelInfoConfiguration.setModelVersionId("modelVersionId"); + modelInfoConfiguration.setModelInvariantId("modelInvariantId"); + modelInfoConfiguration.setModelCustomizationId("modelCustomizationId"); + configuration.setModelInfoConfiguration(modelInfoConfiguration); + + GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = + genObjMapper.buildConfigurationInformation(configuration, true); + + assertEquals(configuration.getConfigurationId(), configurationInformation.getConfigurationId()); + assertEquals(configuration.getConfigurationType(), configurationInformation.getConfigurationType()); + assertEquals(configuration.getConfigurationName(), configurationInformation.getConfigurationName()); + assertNotNull(configurationInformation.getOnapModelInformation()); + assertEquals(configuration.getModelInfoConfiguration().getModelVersionId(), + configurationInformation.getOnapModelInformation().getModelUuid()); + assertEquals(configuration.getModelInfoConfiguration().getModelInvariantId(), + configurationInformation.getOnapModelInformation().getModelInvariantUuid()); + assertEquals(configuration.getModelInfoConfiguration().getModelCustomizationId(), + configurationInformation.getOnapModelInformation().getModelCustomizationUuid()); + + } + + @Test + public void buildGcRequestInformationTest() { + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("TestVnfId"); + GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = + genObjMapper.buildGcRequestInformation(vnf, null); + assertNotNull(gcRequestInput); + assertEquals(vnf.getVnfId(), gcRequestInput.getVnfId()); + assertNull(gcRequestInput.getInputParameters()); + } + + @Test + public void buildGcRequestInformationTest_withInputParams() { + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("TestVnfId"); + GenericResourceApiParam genericResourceApiParam = new GenericResourceApiParam(); + genericResourceApiParam.addParamItem(new GenericResourceApiParamParam()); + GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = + genObjMapper.buildGcRequestInformation(vnf, genericResourceApiParam); + assertNotNull(gcRequestInput); + assertEquals(vnf.getVnfId(), gcRequestInput.getVnfId()); + assertNotNull(gcRequestInput.getInputParameters()); + } + + @Test + public void buildVnfInformationTest_withNullData() { + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("TestVnfId"); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + GenericResourceApiVnfinformationVnfInformation gcRequestInput = + genObjMapper.buildVnfInformation(vnf, serviceInstance, true); + assertNotNull(gcRequestInput); + assertNull(vnf.getModelInfoGenericVnf()); + assertNull(gcRequestInput.getOnapModelInformation()); + assertEquals(vnf.getVnfId(), gcRequestInput.getVnfId()); + assertNotNull(gcRequestInput.getVnfId()); + } + + @Test + public void buildNetworkInformationTest() { + + L3Network network = new L3Network(); + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + modelInfoNetwork.setModelInvariantUUID("my-uuid"); + modelInfoNetwork.setModelName("my-model-name"); + modelInfoNetwork.setModelVersion("my-model-version"); + modelInfoNetwork.setModelUUID("my-model-uuid"); + modelInfoNetwork.setModelCustomizationUUID("my-customization-uuid"); + network.setModelInfoNetwork(modelInfoNetwork); + network.setNetworkId("my-network-id"); + network.setNetworkType("my-network-type"); + network.setNetworkTechnology("my-network-technology"); + + GenericResourceApiNetworkinformationNetworkInformation networkInformation = + new GenericResourceApiNetworkinformationNetworkInformation(); + GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = + new GenericResourceApiOnapmodelinformationOnapModelInformation(); + networkInformation.setNetworkId("my-network-id"); + networkInformation.setNetworkType("my-network-type"); + networkInformation.networkTechnology("my-network-technology"); + networkInformation.setFromPreload(null); + onapModelInformation.setModelInvariantUuid("my-uuid"); + onapModelInformation.setModelName("my-model-name"); + onapModelInformation.setModelVersion("my-model-version"); + onapModelInformation.setModelUuid("my-model-uuid"); + onapModelInformation.setModelCustomizationUuid("my-customization-uuid"); + networkInformation.setOnapModelInformation(onapModelInformation); + + assertThat(networkInformation, sameBeanAs(genObjMapper.buildNetworkInformation(network))); + + } + + @Test + public void buildNetworkInformationNoModelTest() { + + L3Network network = new L3Network(); + network.setNetworkId("my-network-id"); + network.setNetworkType("my-network-type"); + network.setNetworkTechnology("my-network-technology"); + + GenericResourceApiNetworkinformationNetworkInformation networkInformation = + new GenericResourceApiNetworkinformationNetworkInformation(); + networkInformation.setNetworkId("my-network-id"); + networkInformation.setNetworkType("my-network-type"); + networkInformation.networkTechnology("my-network-technology"); + networkInformation.setFromPreload(null); + + + assertThat(networkInformation, sameBeanAs(genObjMapper.buildNetworkInformation(network))); + + } + + + @Test + public void buildVfModuleInformationTest_withNoModelIsFromPreload() { + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("TestVfModuleId"); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("TestVnfId"); + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUsePreload(true); + requestContext.setRequestParameters(requestParameters); + GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; + try { + gcRequestInput = + genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, requestContext, false); + } catch (MapperException ex) { + + } + assertNotNull(gcRequestInput); + assertNull(vfModule.getModelInfoVfModule()); + assertNull(gcRequestInput.getOnapModelInformation()); + assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); + assertNotNull(gcRequestInput.getVfModuleId()); + assertTrue(gcRequestInput.getFromPreload()); + } + + @Test + public void buildVfModuleInformationTest_withNoModelIsNotFromPreload() { + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("TestVfModuleId"); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("TestVnfId"); + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUsePreload(false); + requestContext.setRequestParameters(requestParameters); + GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; + try { + gcRequestInput = + genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, requestContext, false); + } catch (MapperException ex) { + + } + assertNotNull(gcRequestInput); + assertNull(vfModule.getModelInfoVfModule()); + assertNull(gcRequestInput.getOnapModelInformation()); + assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); + assertNotNull(gcRequestInput.getVfModuleId()); + assertFalse(gcRequestInput.getFromPreload()); + } + + @Test + public void buildVfModuleInformationTest_withNoModelNoRequestContext() { + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("TestVfModuleId"); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("TestVnfId"); + GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; + try { + gcRequestInput = genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, null, false); + } catch (MapperException ex) { + + } + assertNotNull(gcRequestInput); + assertNull(vfModule.getModelInfoVfModule()); + assertNull(gcRequestInput.getOnapModelInformation()); + assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); + assertNotNull(gcRequestInput.getVfModuleId()); + assertTrue(gcRequestInput.getFromPreload()); + } + + @Test + public void buildVfModuleInformationTest_withNoModelNoRequestParameters() { + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("TestVfModuleId"); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("TestVnfId"); + RequestContext requestContext = new RequestContext(); + GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; + try { + gcRequestInput = + genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, requestContext, false); + } catch (MapperException ex) { + + } + assertNotNull(gcRequestInput); + assertNull(vfModule.getModelInfoVfModule()); + assertNull(gcRequestInput.getOnapModelInformation()); + assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); + assertNotNull(gcRequestInput.getVfModuleId()); + assertTrue(gcRequestInput.getFromPreload()); + } + + @Test + public void buildVfModuleInformationTest_withModel() { + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("TestVfModuleId"); + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelInvariantUUID("testModelInvariantUUID"); + modelInfoVfModule.setModelName("testModelName"); + modelInfoVfModule.setModelVersion("testModelVersion"); + modelInfoVfModule.setModelUUID("testModelUUID"); + modelInfoVfModule.setModelCustomizationUUID("testModelCustomizationUUID"); + vfModule.setModelInfoVfModule(modelInfoVfModule); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("TestVnfId"); + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUsePreload(true); + requestContext.setRequestParameters(requestParameters); + GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; + try { + gcRequestInput = + genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, requestContext, true); + } catch (MapperException ex) { + + } + assertNotNull(gcRequestInput); + assertNotNull(vfModule.getModelInfoVfModule()); + assertNotNull(gcRequestInput.getOnapModelInformation()); + assertEquals(modelInfoVfModule.getModelInvariantUUID(), + gcRequestInput.getOnapModelInformation().getModelInvariantUuid()); + assertEquals(modelInfoVfModule.getModelName(), gcRequestInput.getOnapModelInformation().getModelName()); + assertEquals(modelInfoVfModule.getModelVersion(), gcRequestInput.getOnapModelInformation().getModelVersion()); + assertEquals(modelInfoVfModule.getModelUUID(), gcRequestInput.getOnapModelInformation().getModelUuid()); + assertEquals(modelInfoVfModule.getModelCustomizationUUID(), + gcRequestInput.getOnapModelInformation().getModelCustomizationUuid()); + assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); + assertNotNull(gcRequestInput.getVfModuleId()); + assertTrue(gcRequestInput.getFromPreload()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java new file mode 100644 index 0000000000..0952a35ab0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java @@ -0,0 +1,234 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.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; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.GeneralTopologyObjectMapper; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.NetworkTopologyOperationRequestMapper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; +import org.onap.so.client.sdnc.beans.SDNCSvcOperation; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class NetworkTopologyOperationRequestMapperTest { + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + + private ServiceInstance serviceInstance; + private ServiceInstance serviceInstanceNoCollection; + private Customer customer; + private RequestContext requestContext; + private L3Network network; + private CloudRegion cloudRegion; + + @Spy + private GeneralTopologyObjectMapper generalTopologyObjectMapper; + + @InjectMocks + private NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper(); + + @Before + public void before() { + // prepare and set service instance + serviceInstance = new ServiceInstance(); + serviceInstanceNoCollection = new ServiceInstance(); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid"); + modelInfoServiceInstance.setModelName("modelName"); + modelInfoServiceInstance.setModelUuid("modelUuid"); + modelInfoServiceInstance.setModelVersion("modelVersion"); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + serviceInstanceNoCollection.setModelInfoServiceInstance(modelInfoServiceInstance); + // prepare Customer object + customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + // serviceInstance.setCustomer(customer); + // set Customer on service instance + ServiceSubscription serviceSubscription = new ServiceSubscription(); + serviceSubscription.setServiceType("productFamilyId"); + customer.setServiceSubscription(serviceSubscription); + + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + customer.getServiceSubscription().getServiceInstances().add(serviceInstanceNoCollection); + // + InstanceGroup networkInstanceGroup = new InstanceGroup(); + networkInstanceGroup.setId("networkInstanceGroupId"); + networkInstanceGroup.setInstanceGroupFunction("instanceGroupFunction"); + Collection networkCollection = new Collection(); + networkCollection.setInstanceGroup(networkInstanceGroup); + serviceInstance.setCollection(networkCollection); + // + requestContext = new RequestContext(); + Map userParams = new HashMap<>(); + userParams.put("key1", "value1"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + requestContext.setMsoRequestId("MsoRequestId"); + + network = new L3Network(); + network.setNetworkId("TEST_NETWORK_ID"); + network.setNetworkName("TEST_NETWORK_NAME"); + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + modelInfoNetwork.setModelInvariantUUID("modelInvariantUuid"); + modelInfoNetwork.setModelName("modelName"); + modelInfoNetwork.setModelVersion("modelVersion"); + modelInfoNetwork.setModelUUID("modelUuid"); + modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUUID"); + network.setModelInfoNetwork(modelInfoNetwork); + + cloudRegion = new CloudRegion(); + } + + @Test + public void createGenericResourceApiNetworkOperationInformationTest() throws Exception { + + GenericResourceApiNetworkOperationInformation networkSDNCrequest = + mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, + GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, + customer, requestContext, cloudRegion); + + ObjectMapper omapper = new ObjectMapper(); + GenericResourceApiNetworkOperationInformation reqMapper1 = + omapper.readValue(getJson("genericResourceApiNetworkOperationInformation.json"), + GenericResourceApiNetworkOperationInformation.class); + + 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 { + + GenericResourceApiNetworkOperationInformation networkSDNCrequest = + mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, + GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, + customer, requestContext, cloudRegion); + + assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); + assertEquals("modelCustomizationUUID", + networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid()); + } + + @Test + public void reqMapperNoCollectionTest() throws Exception { + GenericResourceApiNetworkOperationInformation networkSDNCrequest = + mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, + GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, + serviceInstanceNoCollection, customer, requestContext, cloudRegion); + + assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); + assertEquals("modelCustomizationUUID", + networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid()); + } + + @Test + public void createGenericResourceApiNetworkOperationInformation_UnassignTest() throws Exception { + + NetworkTopologyOperationRequestMapper mapperUnassign = mapper; + GenericResourceApiNetworkOperationInformation networkSDNCrequestUnassign = + mapperUnassign.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, + GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, + customer, requestContext, cloudRegion); + + ObjectMapper omapperUnassign = new ObjectMapper(); + GenericResourceApiNetworkOperationInformation reqMapperUnassign = + omapperUnassign.readValue(getJson("genericResourceApiNetworkOperationInformationUnAssign.json"), + GenericResourceApiNetworkOperationInformation.class); + + assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId") + .ignoring("requestInformation.requestId")); + assertEquals("MsoRequestId", networkSDNCrequestUnassign.getRequestInformation().getRequestId()); + + } + + @Test + public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception { + + // set network name NULL + network.setNetworkName(null); + GenericResourceApiNetworkOperationInformation networkSDNCrequest = + mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, + GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, + customer, requestContext, cloudRegion); + + ObjectMapper omapper = new ObjectMapper(); + GenericResourceApiNetworkOperationInformation reqMapper1 = + omapper.readValue(getJson("genericResourceApiNetworkOperationInformationNoNetworkName.json"), + GenericResourceApiNetworkOperationInformation.class); + + assertThat(reqMapper1, sameBeanAs(networkSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") + .ignoring("requestInformation.requestId")); + } + + /* + * Helper method to load JSON data + */ + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename))); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/ServiceTopologyOperationMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/ServiceTopologyOperationMapperTest.java new file mode 100644 index 0000000000..bd5c234e50 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/ServiceTopologyOperationMapperTest.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.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; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.GeneralTopologyObjectMapper; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.ServiceTopologyOperationMapper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; +import org.onap.so.client.sdnc.beans.SDNCSvcOperation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class ServiceTopologyOperationMapperTest { + + @Spy + private GeneralTopologyObjectMapper generalTopologyObjectMapper; + + @InjectMocks + private ServiceTopologyOperationMapper mapper = new ServiceTopologyOperationMapper(); + + @Test + public void reqMapperTest() throws Exception { + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid"); + modelInfoServiceInstance.setModelName("modelName"); + modelInfoServiceInstance.setModelUuid("modelUuid"); + modelInfoServiceInstance.setModelVersion("modelVersion"); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + + // prepare Customer object + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + + customer.setServiceSubscription(new ServiceSubscription()); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + // prepare RequestContext + RequestContext requestContext = new RequestContext(); + Map userParams = new HashMap<>(); + 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"))); + + ObjectMapper omapper = new ObjectMapper(); + GenericResourceApiOnapmodelinformationOnapModelInformation reqMapper1 = + omapper.readValue(jsonToCompare, 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/bpmn/infrastructure/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java new file mode 100644 index 0000000000..e064300ab7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java @@ -0,0 +1,404 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.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.net.URI; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.GeneralTopologyObjectMapper; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.VfModuleTopologyOperationRequestMapper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.client.exception.MapperException; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; +import org.onap.so.client.sdnc.beans.SDNCSvcOperation; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class VfModuleTopologyOperationRequestMapperTest { + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + private final static String ERRORMESSAGE = "VF Module model info is null for testVfModuleId"; + + @Spy + private GeneralTopologyObjectMapper generalTopologyObjectMapper; + + @InjectMocks + private VfModuleTopologyOperationRequestMapper mapper = new VfModuleTopologyOperationRequestMapper(); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void assignGenericResourceApiVfModuleInformationTest() throws Exception { + + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); + modelInfoServiceInstance.setModelName("serviceModelName"); + modelInfoServiceInstance.setModelUuid("serviceModelUuid"); + modelInfoServiceInstance.setModelVersion("serviceModelVersion"); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + // prepare Customer object + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + ServiceSubscription serviceSubscription = new ServiceSubscription(); + serviceSubscription.setServiceType("productFamilyId"); + customer.setServiceSubscription(serviceSubscription); + + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + // + RequestContext requestContext = new RequestContext(); + Map userParams = new HashMap<>(); + userParams.put("key1", "value1"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUsePreload(true); + requestContext.setRequestParameters(requestParameters); + requestContext.setMsoRequestId("MsoRequestId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("testVnfId"); + vnf.setVnfType("testVnfType"); + vnf.setVnfName("testVnfName"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); + modelInfoGenericVnf.setModelName("vnfModelName"); + modelInfoGenericVnf.setModelVersion("vnfModelVersion"); + modelInfoGenericVnf.setModelUuid("vnfModelUuid"); + modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("testVfModuleId"); + vfModule.setVfModuleName("testVfModuleName"); + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelInvariantUUID("vfModuleModelInvariantUuid"); + modelInfoVfModule.setModelName("vfModuleModelName"); + modelInfoVfModule.setModelVersion("vfModuleModelVersion"); + modelInfoVfModule.setModelUUID("vfModuleModelUuid"); + modelInfoVfModule.setModelCustomizationUUID("vfModuleModelCustomizationUuid"); + vfModule.setModelInfoVfModule(modelInfoVfModule); + HashMap cloudParams = new HashMap(); + cloudParams.put("key2", "value2"); + vfModule.setCloudParams(cloudParams); + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + volumeGroup.setVolumeGroupName("volumeGroupName"); + + CloudRegion cloudRegion = new CloudRegion(); + + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, volumeGroup, vnf, + serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); + + String jsonToCompare = new String(Files.readAllBytes( + Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleOperationInformationAssign.json"))); + + ObjectMapper omapper = new ObjectMapper(); + GenericResourceApiVfModuleOperationInformation reqMapper1 = + omapper.readValue(jsonToCompare, GenericResourceApiVfModuleOperationInformation.class); + + assertThat(vfModuleSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId") + .ignoring("requestInformation.requestId")); + assertEquals("MsoRequestId", vfModuleSDNCrequest.getRequestInformation().getRequestId()); + } + + @Test + public void unassignGenericResourceApiVfModuleInformationTest() 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(); + requestContext.setMsoRequestId("MsoRequestId"); + + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = + mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, + vnf, serviceInstance, null, null, requestContext, null, new URI("http://localhost:8080")); + + String jsonToCompare = new String(Files.readAllBytes( + Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleOperationInformationUnassign.json"))); + + ObjectMapper omapper = new ObjectMapper(); + GenericResourceApiVfModuleOperationInformation reqMapper1 = + omapper.readValue(jsonToCompare, GenericResourceApiVfModuleOperationInformation.class); + + assertThat(vfModuleSDNCrequest, sameBeanAs(reqMapper1).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, new URI("http://localhost:8080")); + + assertNotNull(vfModuleSDNCrequest.getRequestInformation().getRequestId()); + } + + @Test + public void reqMapperTest() throws Exception { + + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); + modelInfoServiceInstance.setModelName("serviceModelName"); + modelInfoServiceInstance.setModelUuid("serviceModelUuid"); + modelInfoServiceInstance.setModelVersion("serviceModelVersion"); + + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + // prepare Customer object + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + customer.setServiceSubscription(new ServiceSubscription()); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + // + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + HashMap userParams1 = new HashMap<>(); + userParams1.put("key1", "value1"); + List> userParams = new ArrayList<>(); + userParams.add(userParams1); + + requestParameters.setUserParams(userParams); + requestContext.setRequestParameters(requestParameters); + requestContext.setProductFamilyId("productFamilyId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("testVnfId"); + vnf.setVnfType("testVnfType"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); + modelInfoGenericVnf.setModelName("vnfModelName"); + modelInfoGenericVnf.setModelVersion("vnfModelVersion"); + modelInfoGenericVnf.setModelUuid("vnfModelUuid"); + modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("testVfModuleId"); + vfModule.setVfModuleName("testVfModuleName"); + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelInvariantUUID("vfModuleModelInvariantUuid"); + modelInfoVfModule.setModelName("vfModuleModelName"); + modelInfoVfModule.setModelVersion("vfModuleModelVersion"); + modelInfoVfModule.setModelUUID("vfModuleModelUuid"); + modelInfoVfModule.setModelCustomizationUUID("vfModuleModelCustomizationUuid"); + vfModule.setModelInfoVfModule(modelInfoVfModule); + + CloudRegion cloudRegion = new CloudRegion(); + + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, null, vnf, + serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); + + assertNull(vfModuleSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); + assertEquals("vnfModelCustomizationUuid", + vfModuleSDNCrequest.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); + assertEquals("vfModuleModelCustomizationUuid", + vfModuleSDNCrequest.getVfModuleInformation().getOnapModelInformation().getModelCustomizationUuid()); + } + + @Test + public void reqMapperNoModelInfoTest() throws Exception { + + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); + modelInfoServiceInstance.setModelName("serviceModelName"); + modelInfoServiceInstance.setModelUuid("serviceModelUuid"); + modelInfoServiceInstance.setModelVersion("serviceModelVersion"); + + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + // prepare Customer object + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + customer.setServiceSubscription(new ServiceSubscription()); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + // + RequestContext requestContext = new RequestContext(); + Map userParams = new HashMap(); + userParams.put("key1", "value1"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("testVnfId"); + vnf.setVnfType("testVnfType"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); + modelInfoGenericVnf.setModelName("vnfModelName"); + modelInfoGenericVnf.setModelVersion("vnfModelVersion"); + modelInfoGenericVnf.setModelUuid("vnfModelUuid"); + modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("testVfModuleId"); + vfModule.setVfModuleName("testVfModuleName"); + vfModule.setModelInfoVfModule(null); + + CloudRegion cloudRegion = new CloudRegion(); + + expectedException.expect(MapperException.class); + expectedException.expectMessage(ERRORMESSAGE); + + mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, null, vnf, + serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); + } + + @Test + public void reqMapperChangeAssignTest() throws Exception { + + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); + modelInfoServiceInstance.setModelName("serviceModelName"); + modelInfoServiceInstance.setModelUuid("serviceModelUuid"); + modelInfoServiceInstance.setModelVersion("serviceModelVersion"); + + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + // prepare Customer object + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + customer.setServiceSubscription(new ServiceSubscription()); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + // + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + HashMap userParams1 = new HashMap<>(); + userParams1.put("key1", "value1"); + List> userParams = new ArrayList<>(); + userParams.add(userParams1); + + requestParameters.setUserParams(userParams); + requestContext.setRequestParameters(requestParameters); + requestContext.setProductFamilyId("productFamilyId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("testVnfId"); + vnf.setVnfType("testVnfType"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); + modelInfoGenericVnf.setModelName("vnfModelName"); + modelInfoGenericVnf.setModelVersion("vnfModelVersion"); + modelInfoGenericVnf.setModelUuid("vnfModelUuid"); + modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("testVfModuleId"); + vfModule.setVfModuleName("testVfModuleName"); + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelInvariantUUID("vfModuleModelInvariantUuid"); + modelInfoVfModule.setModelName("vfModuleModelName"); + modelInfoVfModule.setModelVersion("vfModuleModelVersion"); + modelInfoVfModule.setModelUUID("vfModuleModelUuid"); + modelInfoVfModule.setModelCustomizationUUID("vfModuleModelCustomizationUuid"); + vfModule.setModelInfoVfModule(modelInfoVfModule); + + CloudRegion cloudRegion = new CloudRegion(); + + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN, vfModule, null, vnf, + serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); + + assertEquals("vnfModelCustomizationUuid", + vfModuleSDNCrequest.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); + assertEquals("vfModuleModelCustomizationUuid", + vfModuleSDNCrequest.getVfModuleInformation().getOnapModelInformation().getModelCustomizationUuid()); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java new file mode 100644 index 0000000000..a042289281 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java @@ -0,0 +1,154 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.mapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.GeneralTopologyObjectMapper; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.VnfTopologyOperationRequestMapper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.generalobjects.License; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; +import org.onap.so.client.sdnc.beans.SDNCSvcOperation; + +@RunWith(MockitoJUnitRunner.class) +public class VnfTopologyOperationRequestMapperTest { + + @Spy + private GeneralTopologyObjectMapper generalTopologyObjectMapper; + + @InjectMocks + private VnfTopologyOperationRequestMapper mapper = new VnfTopologyOperationRequestMapper(); + + @Test + public void reqMapperTest() throws Exception { + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid"); + modelInfoServiceInstance.setModelName("modelName"); + modelInfoServiceInstance.setModelUuid("modelUuid"); + modelInfoServiceInstance.setModelVersion("modelVersion"); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + + // prepare VNF + ModelInfoGenericVnf genericVnf = new ModelInfoGenericVnf(); + genericVnf.setModelInvariantUuid("vnfModelInvariantUUID"); + genericVnf.setModelVersion("vnfModelVersion"); + genericVnf.setModelName("vnfModelName"); + genericVnf.setModelUuid("vnfModelUUID"); + genericVnf.setModelCustomizationUuid("vnfModelCustomizationUUID"); + + ModelInfoInstanceGroup modelL3Network = new ModelInfoInstanceGroup(); + modelL3Network.setType("L3-NETWORK"); + + InstanceGroup instanceGroup1 = new InstanceGroup(); + instanceGroup1.setId("l3-network-ig-111"); + instanceGroup1.setModelInfoInstanceGroup(modelL3Network); + + InstanceGroup instanceGroup2 = new InstanceGroup(); + instanceGroup2.setId("l3-network-ig-222"); + instanceGroup2.setModelInfoInstanceGroup(modelL3Network); + + GenericVnf vnf = new GenericVnf(); + vnf.setModelInfoGenericVnf(genericVnf); + vnf.setVnfId("vnfId"); + vnf.setVnfType("vnfType"); + vnf.getInstanceGroups().add(instanceGroup1); + vnf.getInstanceGroups().add(instanceGroup2); + License license = new License(); + List entitlementPoolUuids = new ArrayList<>(); + entitlementPoolUuids.add("entitlementPoolUuid"); + List licenseKeyGroupUuids = new ArrayList<>(); + licenseKeyGroupUuids.add("licenseKeyGroupUuid"); + license.setEntitlementPoolUuids(entitlementPoolUuids); + license.setLicenseKeyGroupUuids(licenseKeyGroupUuids); + vnf.setLicense(license); + + // prepare Customer object + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + + ServiceSubscription serviceSubscription = new ServiceSubscription(); + serviceSubscription.setServiceType("productFamilyId"); + customer.setServiceSubscription(serviceSubscription); + + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + + // prepare RequestContext + RequestContext requestContext = new RequestContext(); + Map userParams = new HashMap<>(); + 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, new URI("http://localhost:8080")); + GenericResourceApiVnfOperationInformation vnfOpInformationNullReqContext = + mapper.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, + GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, + cloudRegion, null, true, new URI("http://localhost:8080")); + + assertNull(vnfOpInformation.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); + assertEquals("vnfModelCustomizationUUID", + vnfOpInformation.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); + assertEquals(2, vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().size()); + assertEquals("l3-network-ig-111", vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().get(0) + .getVnfNetworkInstanceGroupId()); + 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/orchestration/SDNCConfigurationResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java index 9049fe1965..3429a16f0b 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 @@ -35,6 +35,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdnc.northbound.client.model.GenericResourceApiGcTopologyOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.GCTopologyOperationRequestMapper; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -45,7 +46,6 @@ import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCSvcAction; -import org.onap.so.client.sdnc.mapper.GCTopologyOperationRequestMapper; @RunWith(MockitoJUnitRunner.Silent.class) public class SDNCConfigurationResourcesTest extends TestDataSetup { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCNetworkResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCNetworkResourcesTest.java index 327bae5749..f86a712e33 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCNetworkResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCNetworkResourcesTest.java @@ -32,6 +32,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.NetworkTopologyOperationRequestMapper; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; @@ -42,7 +43,6 @@ import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCSvcAction; import org.onap.so.client.sdnc.beans.SDNCSvcOperation; -import org.onap.so.client.sdnc.mapper.NetworkTopologyOperationRequestMapper; @RunWith(MockitoJUnitRunner.Silent.class) public class SDNCNetworkResourcesTest extends TestDataSetup { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCServiceInstanceResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCServiceInstanceResourcesTest.java index ad05ac0072..4282b0d158 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCServiceInstanceResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCServiceInstanceResourcesTest.java @@ -35,6 +35,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.ServiceTopologyOperationMapper; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; @@ -42,7 +43,6 @@ import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.beans.SDNCSvcAction; import org.onap.so.client.sdnc.beans.SDNCSvcOperation; -import org.onap.so.client.sdnc.mapper.ServiceTopologyOperationMapper; @RunWith(MockitoJUnitRunner.Silent.class) public class SDNCServiceInstanceResourcesTest extends TestDataSetup { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java index 14e993281a..813c2f7cd4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java @@ -33,6 +33,7 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.VfModuleTopologyOperationRequestMapper; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -43,8 +44,7 @@ import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.beans.SDNCSvcAction; -import org.onap.so.client.sdnc.beans.SDNCSvcOperation; -import org.onap.so.client.sdnc.mapper.VfModuleTopologyOperationRequestMapper;; +import org.onap.so.client.sdnc.beans.SDNCSvcOperation;; @RunWith(MockitoJUnitRunner.Silent.class) public class SDNCVfModuleResourcesTest extends TestDataSetup { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVnfResourcesTest.java index 0ccf056ddc..f9c380bc84 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVnfResourcesTest.java @@ -39,6 +39,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation; import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.sdnc.mapper.VnfTopologyOperationRequestMapper; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -49,7 +50,6 @@ import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCSvcAction; import org.onap.so.client.sdnc.beans.SDNCSvcOperation; -import org.onap.so.client.sdnc.mapper.VnfTopologyOperationRequestMapper; @RunWith(MockitoJUnitRunner.Silent.class) public class SDNCVnfResourcesTest extends TestDataSetup { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java deleted file mode 100644 index a8816e1b04..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ============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.client.sdn.common; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import java.util.LinkedHashMap; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.client.exception.BadResponseException; -import org.onap.so.client.exception.MapperException; -import org.onap.so.client.sdnc.SdnCommonTasks; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; - - -public class SdnCommonTasksTest { - - - SdnCommonTasks sdnCommonTasks = new SdnCommonTasks(); - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void buildJsonRequestTest() throws MapperException { - String jsonStr = sdnCommonTasks.buildJsonRequest(""); - Assert.assertNotNull(jsonStr); - } - - @Test - public void buildJsonRequestTestException() throws MapperException { - expectedException.expect(MapperException.class); - sdnCommonTasks.buildJsonRequest(new Object()); - } - - @Test - public void getHttpHeadersTest() { - HttpHeaders result = sdnCommonTasks.getHttpHeaders("auth", true); - - assertEquals("auth", result.getFirst("Authorization")); - assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Content-Type")); - assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Accept")); - } - - @Test - public void getHttpHeadersGetRequestTest() { - HttpHeaders result = sdnCommonTasks.getHttpHeaders("auth", false); - - assertEquals("auth", result.getFirst("Authorization")); - assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Accept")); - assertFalse(result.containsKey("Content-Type")); - } - - @Test - public void validateSDNResponseTest() throws BadResponseException { - String jsonResponse = "{\"output\":{\"response-code\":\"0\",\"response-message\":\"success\"}}"; - LinkedHashMap responseMap = new LinkedHashMap<>(); - LinkedHashMap output = new LinkedHashMap<>(); - output.put("response-code", "0"); - output.put("response-message", "success"); - responseMap.put("output", output); - assertEquals(jsonResponse, sdnCommonTasks.validateSDNResponse(responseMap)); - } - - @Test - public void validateSDNResponseTestException() throws BadResponseException { - expectedException.expect(BadResponseException.class); - LinkedHashMap responseMap = new LinkedHashMap(); - Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap)); - } - - @Test - public void validateSDNResponseTestRespCodeNot200() throws BadResponseException { - expectedException.expect(BadResponseException.class); - LinkedHashMap responseMap = new LinkedHashMap<>(); - LinkedHashMap output = new LinkedHashMap<>(); - output.put("response-code", "300"); - output.put("response-message", "Failed"); - responseMap.put("output", output); - sdnCommonTasks.validateSDNResponse(responseMap); - } - -} 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 deleted file mode 100644 index 0b338bde1d..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * ============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.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.urlEqualTo; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import org.junit.Test; -import org.onap.so.BaseIntegrationTest; -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; - -public class SDNCClientIT extends BaseIntegrationTest { - private final static String JSON_FILE_LOCATION = "src/test/resources/__files/"; - - @Test - public void getTest() throws BadResponseException, MapperException, IOException { - String responseJson = - new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json"))); - String queryLink = "/topologyQuery"; - - wireMockServer.stubFor(get(urlEqualTo(queryLink)).willReturn( - aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(responseJson))); - String response = SPY_sdncClient.get(queryLink); - JSONAssert.assertEquals(responseJson, response, false); - } - - @Test(expected = BadResponseException.class) - public void post404Test() throws BadResponseException, MapperException, IOException { - String responseJson = - new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut404Response.json"))); - - String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - - wireMockServer.stubFor(post(urlMatching(queryLink)).willReturn( - aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(responseJson))); - - SPY_sdncClient.post("", SDNCTopology.NETWORK); - } - - @Test - public void post200Test() throws BadResponseException, MapperException, IOException { - String responseJson = - new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut200Response.json"))); - - String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - - wireMockServer.stubFor(post(urlMatching(queryLink)).willReturn( - aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(responseJson))); - - String response = SPY_sdncClient.post("", SDNCTopology.NETWORK); - JSONAssert.assertEquals(responseJson, response, true); - } -} 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 deleted file mode 100644 index 0eb0304cdf..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * ============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.client.sdnc.mapper; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.sdnc.northbound.client.model.GenericResourceApiGcTopologyOperationInformation; -import org.onap.so.bpmn.common.data.TestDataSetup; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.client.sdnc.beans.SDNCSvcAction; - -@RunWith(MockitoJUnitRunner.Silent.class) -public class GCTopologyOperationRequestMapperTest extends TestDataSetup { - - - @Spy - private GeneralTopologyObjectMapper generalTopologyObjectMapper; - - @InjectMocks - private GCTopologyOperationRequestMapper genObjMapper = new GCTopologyOperationRequestMapper(); - - @Test - public void deactivateOrUnassignVnrReqMapperTest() throws URISyntaxException { - RequestContext requestContext = new RequestContext(); - requestContext.setMsoRequestId("MsoRequestId"); - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("ServiceInstanceId"); - Configuration Configuration = new Configuration(); - Configuration.setConfigurationId("ConfigurationId"); - Configuration.setConfigurationType("VLAN-NETWORK-RECEPTOR"); - GenericResourceApiGcTopologyOperationInformation genericInfo = - genObjMapper.deactivateOrUnassignVnrReqMapper(SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, - Configuration, "uuid", new URI("http://localhost")); - - Assert.assertNotNull(genericInfo); - Assert.assertNotNull(genericInfo.getRequestInformation()); - Assert.assertNotNull(genericInfo.getSdncRequestHeader()); - Assert.assertNotNull(genericInfo.getClass()); - Assert.assertNotNull(genericInfo.getServiceInformation()); - Assert.assertEquals("ConfigurationId", genericInfo.getConfigurationInformation().getConfigurationId()); - 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()); - } - - - - private VpnBondingLink getVpnBondingLink() { - VpnBondingLink vpnBondingLink = new VpnBondingLink(); - Configuration vrfConfiguration = getVRFConfiguration(); - vpnBondingLink.setVrfConfiguration(vrfConfiguration); - Configuration vnrConfiguration = getVNRConfiguration(); - vpnBondingLink.setVnrConfiguration(vnrConfiguration); - vpnBondingLink.setTransportServiceProxy(buildServiceProxy(buildServiceInstance(buildGenericVnf()))); - return vpnBondingLink; - } - - private RequestContext getRequestContext() { - RequestContext requestContext = new RequestContext(); - requestContext.setMsoRequestId("MsoRequestId"); - Map userParams = getUserParams(); - requestContext.setUserParams(userParams); - return requestContext; - } - - private Map getUserParams() { - Map userParams = new HashMap<>(); - userParams.put("lppCustomerId", "lppCustomerId"); - return userParams; - } - - private ServiceProxy buildServiceProxy(ServiceInstance serviceInstance) { - ServiceProxy serviceProxy = new ServiceProxy(); - serviceProxy.setServiceInstance(serviceInstance); - return serviceProxy; - } - - private Configuration getVRFConfiguration() { - Configuration vrfConfiguration = new Configuration(); - vrfConfiguration.setConfigurationId("ConfigurationId"); - vrfConfiguration.setConfigurationName("ConfigurationName"); - vrfConfiguration.setConfigurationSubType("ConfigurationSubType"); - vrfConfiguration.setConfigurationType("VRF-ENTRY"); - return vrfConfiguration; - } - - public Configuration getVNRConfiguration() { - Configuration vnrConfiguration = new Configuration(); - vnrConfiguration.setConfigurationId("ConfigurationId"); - vnrConfiguration.setConfigurationName("ConfigurationName"); - vnrConfiguration.setConfigurationSubType("ConfigurationSubType"); - vnrConfiguration.setConfigurationType("VNRConfiguration"); - L3Network l3Network = getL3Network(); - vnrConfiguration.setNetwork(l3Network); - return vnrConfiguration; - } - - public L3Network getL3Network() { - L3Network l3Network = new L3Network(); - l3Network.setNetworkId("l3NetworkId"); - Subnet ipv4subnet = getSubnet("ipv4CidrMask", "ipv4NetworkStartAddress", "IPV4"); - Subnet ipv6subnet = getSubnet("ipv6CidrMask", "ipv6NetworkStartAddress", "IPV6"); - l3Network.getSubnets().add(ipv4subnet); - l3Network.getSubnets().add(ipv6subnet); - return l3Network; - } - - private Subnet getSubnet(String ipv4CidrMask, String ipv4NetworkStartAddress, String ipv4) { - Subnet ipv4subnet = new Subnet(); - ipv4subnet.setCidrMask(ipv4CidrMask); - ipv4subnet.setNetworkStartAddress(ipv4NetworkStartAddress); - ipv4subnet.setIpVersion(ipv4); - return ipv4subnet; - } - - private ServiceInstance buildServiceInstance(GenericVnf vnf) { - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("ServiceInstanceId"); - List vnfs = serviceInstance.getVnfs(); - vnfs.add(vnf); - return serviceInstance; - } -} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapperTest.java deleted file mode 100644 index 88a291e68b..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapperTest.java +++ /dev/null @@ -1,446 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.client.sdnc.mapper; - -import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import java.util.HashMap; -import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.InjectMocks; -import org.onap.sdnc.northbound.client.model.GenericResourceApiConfigurationinformationConfigurationInformation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiGcrequestinputGcRequestInput; -import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkinformationNetworkInformation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiParam; -import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam; -import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader; -import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiSvcActionEnumeration; -import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation; -import org.onap.so.bpmn.common.data.TestDataSetup; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; -import org.onap.so.client.exception.MapperException; -import org.onap.so.client.sdnc.beans.SDNCSvcAction; - - -public class GeneralTopologyObjectMapperTest extends TestDataSetup { - @InjectMocks - private GeneralTopologyObjectMapper genObjMapper = new GeneralTopologyObjectMapper(); - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void before() { - - } - - @After - public void after() { - - } - - @Test - public void testBuildServiceInformation() { - // prepare and set service instance - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); - modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); - modelInfoServiceInstance.setModelName("serviceModelName"); - modelInfoServiceInstance.setModelUuid("serviceModelUuid"); - modelInfoServiceInstance.setModelVersion("serviceModelVersion"); - - serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - // prepare Customer object - Customer customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - ServiceSubscription serviceSubscription = new ServiceSubscription(); - serviceSubscription.setServiceType("productFamilyId"); - customer.setServiceSubscription(serviceSubscription); - // set Customer on service instance - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - // - RequestContext requestContext = new RequestContext(); - Map userParams = new HashMap<>(); - userParams.put("key1", "value1"); - requestContext.setUserParams(userParams); - requestContext.setProductFamilyId("productFamilyId"); - - GenericResourceApiServiceinformationServiceInformation serviceInfo = - genObjMapper.buildServiceInformation(serviceInstance, requestContext, customer, true); - - assertEquals("serviceModelInvariantUuid", serviceInfo.getOnapModelInformation().getModelInvariantUuid()); - assertEquals("serviceModelName", serviceInfo.getOnapModelInformation().getModelName()); - assertEquals("serviceModelUuid", serviceInfo.getOnapModelInformation().getModelUuid()); - assertEquals("serviceModelVersion", serviceInfo.getOnapModelInformation().getModelVersion()); - assertNull(serviceInfo.getOnapModelInformation().getModelCustomizationUuid()); - assertEquals("serviceInstanceId", serviceInfo.getServiceInstanceId()); - assertEquals("serviceInstanceId", serviceInfo.getServiceId()); - assertEquals("globalCustomerId", serviceInfo.getGlobalCustomerId()); - assertEquals("productFamilyId", serviceInfo.getSubscriptionServiceType()); - } - - @Test - public void buildSdncRequestHeaderActivateTest() { - GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = - genObjMapper.buildSdncRequestHeader(SDNCSvcAction.ACTIVATE, "sdncReqId"); - - assertEquals(GenericResourceApiSvcActionEnumeration.ACTIVATE, requestHeader.getSvcAction()); - assertEquals("sdncReqId", requestHeader.getSvcRequestId()); - } - - @Test - public void buildSdncRequestHeaderAssignTest() { - GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = - genObjMapper.buildSdncRequestHeader(SDNCSvcAction.ASSIGN, "sdncReqId"); - - assertEquals(GenericResourceApiSvcActionEnumeration.ASSIGN, requestHeader.getSvcAction()); - assertEquals("sdncReqId", requestHeader.getSvcRequestId()); - } - - @Test - public void buildSdncRequestHeaderDeactivateTest() { - GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = - genObjMapper.buildSdncRequestHeader(SDNCSvcAction.DEACTIVATE, "sdncReqId"); - - assertEquals(GenericResourceApiSvcActionEnumeration.DEACTIVATE, requestHeader.getSvcAction()); - assertEquals("sdncReqId", requestHeader.getSvcRequestId()); - } - - @Test - public void buildSdncRequestHeaderDeleteTest() { - GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = - genObjMapper.buildSdncRequestHeader(SDNCSvcAction.DELETE, "sdncReqId"); - - assertEquals(GenericResourceApiSvcActionEnumeration.DELETE, requestHeader.getSvcAction()); - assertEquals("sdncReqId", requestHeader.getSvcRequestId()); - } - - @Test - public void buildSdncRequestHeaderChangeAssignTest() { - GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = - genObjMapper.buildSdncRequestHeader(SDNCSvcAction.CHANGE_ASSIGN, "sdncReqId"); - - assertEquals(GenericResourceApiSvcActionEnumeration.CHANGEASSIGN, requestHeader.getSvcAction()); - assertEquals("sdncReqId", requestHeader.getSvcRequestId()); - } - - @Test - public void buildConfigurationInformationTest_excludesOnapModelInfo() { - Configuration configuration = new Configuration(); - configuration.setConfigurationId("testConfigurationId"); - configuration.setConfigurationType("VNR"); - configuration.setConfigurationName("VNRCONF"); - GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = - genObjMapper.buildConfigurationInformation(configuration, false); - assertEquals(configuration.getConfigurationId(), configurationInformation.getConfigurationId()); - assertEquals(configuration.getConfigurationType(), configurationInformation.getConfigurationType()); - assertEquals(configuration.getConfigurationName(), configurationInformation.getConfigurationName()); - assertNull(configurationInformation.getOnapModelInformation()); - } - - @Test - public void buildConfigurationInformationTest_includesOnapModelInfo() { - Configuration configuration = new Configuration(); - configuration.setConfigurationId("testConfigurationId"); - configuration.setConfigurationType("VNR"); - configuration.setConfigurationName("VNRCONF"); - ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration(); - modelInfoConfiguration.setModelVersionId("modelVersionId"); - modelInfoConfiguration.setModelInvariantId("modelInvariantId"); - modelInfoConfiguration.setModelCustomizationId("modelCustomizationId"); - configuration.setModelInfoConfiguration(modelInfoConfiguration); - - GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = - genObjMapper.buildConfigurationInformation(configuration, true); - - assertEquals(configuration.getConfigurationId(), configurationInformation.getConfigurationId()); - assertEquals(configuration.getConfigurationType(), configurationInformation.getConfigurationType()); - assertEquals(configuration.getConfigurationName(), configurationInformation.getConfigurationName()); - assertNotNull(configurationInformation.getOnapModelInformation()); - assertEquals(configuration.getModelInfoConfiguration().getModelVersionId(), - configurationInformation.getOnapModelInformation().getModelUuid()); - assertEquals(configuration.getModelInfoConfiguration().getModelInvariantId(), - configurationInformation.getOnapModelInformation().getModelInvariantUuid()); - assertEquals(configuration.getModelInfoConfiguration().getModelCustomizationId(), - configurationInformation.getOnapModelInformation().getModelCustomizationUuid()); - - } - - @Test - public void buildGcRequestInformationTest() { - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("TestVnfId"); - GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = - genObjMapper.buildGcRequestInformation(vnf, null); - assertNotNull(gcRequestInput); - assertEquals(vnf.getVnfId(), gcRequestInput.getVnfId()); - assertNull(gcRequestInput.getInputParameters()); - } - - @Test - public void buildGcRequestInformationTest_withInputParams() { - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("TestVnfId"); - GenericResourceApiParam genericResourceApiParam = new GenericResourceApiParam(); - genericResourceApiParam.addParamItem(new GenericResourceApiParamParam()); - GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = - genObjMapper.buildGcRequestInformation(vnf, genericResourceApiParam); - assertNotNull(gcRequestInput); - assertEquals(vnf.getVnfId(), gcRequestInput.getVnfId()); - assertNotNull(gcRequestInput.getInputParameters()); - } - - @Test - public void buildVnfInformationTest_withNullData() { - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("TestVnfId"); - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - GenericResourceApiVnfinformationVnfInformation gcRequestInput = - genObjMapper.buildVnfInformation(vnf, serviceInstance, true); - assertNotNull(gcRequestInput); - assertNull(vnf.getModelInfoGenericVnf()); - assertNull(gcRequestInput.getOnapModelInformation()); - assertEquals(vnf.getVnfId(), gcRequestInput.getVnfId()); - assertNotNull(gcRequestInput.getVnfId()); - } - - @Test - public void buildNetworkInformationTest() { - - L3Network network = new L3Network(); - ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); - modelInfoNetwork.setModelInvariantUUID("my-uuid"); - modelInfoNetwork.setModelName("my-model-name"); - modelInfoNetwork.setModelVersion("my-model-version"); - modelInfoNetwork.setModelUUID("my-model-uuid"); - modelInfoNetwork.setModelCustomizationUUID("my-customization-uuid"); - network.setModelInfoNetwork(modelInfoNetwork); - network.setNetworkId("my-network-id"); - network.setNetworkType("my-network-type"); - network.setNetworkTechnology("my-network-technology"); - - GenericResourceApiNetworkinformationNetworkInformation networkInformation = - new GenericResourceApiNetworkinformationNetworkInformation(); - GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = - new GenericResourceApiOnapmodelinformationOnapModelInformation(); - networkInformation.setNetworkId("my-network-id"); - networkInformation.setNetworkType("my-network-type"); - networkInformation.networkTechnology("my-network-technology"); - networkInformation.setFromPreload(null); - onapModelInformation.setModelInvariantUuid("my-uuid"); - onapModelInformation.setModelName("my-model-name"); - onapModelInformation.setModelVersion("my-model-version"); - onapModelInformation.setModelUuid("my-model-uuid"); - onapModelInformation.setModelCustomizationUuid("my-customization-uuid"); - networkInformation.setOnapModelInformation(onapModelInformation); - - assertThat(networkInformation, sameBeanAs(genObjMapper.buildNetworkInformation(network))); - - } - - @Test - public void buildNetworkInformationNoModelTest() { - - L3Network network = new L3Network(); - network.setNetworkId("my-network-id"); - network.setNetworkType("my-network-type"); - network.setNetworkTechnology("my-network-technology"); - - GenericResourceApiNetworkinformationNetworkInformation networkInformation = - new GenericResourceApiNetworkinformationNetworkInformation(); - networkInformation.setNetworkId("my-network-id"); - networkInformation.setNetworkType("my-network-type"); - networkInformation.networkTechnology("my-network-technology"); - networkInformation.setFromPreload(null); - - - assertThat(networkInformation, sameBeanAs(genObjMapper.buildNetworkInformation(network))); - - } - - - @Test - public void buildVfModuleInformationTest_withNoModelIsFromPreload() { - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("TestVfModuleId"); - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId("TestVnfId"); - RequestContext requestContext = new RequestContext(); - RequestParameters requestParameters = new RequestParameters(); - requestParameters.setUsePreload(true); - requestContext.setRequestParameters(requestParameters); - GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; - try { - gcRequestInput = - genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, requestContext, false); - } catch (MapperException ex) { - - } - assertNotNull(gcRequestInput); - assertNull(vfModule.getModelInfoVfModule()); - assertNull(gcRequestInput.getOnapModelInformation()); - assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); - assertNotNull(gcRequestInput.getVfModuleId()); - assertTrue(gcRequestInput.getFromPreload()); - } - - @Test - public void buildVfModuleInformationTest_withNoModelIsNotFromPreload() { - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("TestVfModuleId"); - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId("TestVnfId"); - RequestContext requestContext = new RequestContext(); - RequestParameters requestParameters = new RequestParameters(); - requestParameters.setUsePreload(false); - requestContext.setRequestParameters(requestParameters); - GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; - try { - gcRequestInput = - genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, requestContext, false); - } catch (MapperException ex) { - - } - assertNotNull(gcRequestInput); - assertNull(vfModule.getModelInfoVfModule()); - assertNull(gcRequestInput.getOnapModelInformation()); - assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); - assertNotNull(gcRequestInput.getVfModuleId()); - assertFalse(gcRequestInput.getFromPreload()); - } - - @Test - public void buildVfModuleInformationTest_withNoModelNoRequestContext() { - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("TestVfModuleId"); - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId("TestVnfId"); - GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; - try { - gcRequestInput = genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, null, false); - } catch (MapperException ex) { - - } - assertNotNull(gcRequestInput); - assertNull(vfModule.getModelInfoVfModule()); - assertNull(gcRequestInput.getOnapModelInformation()); - assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); - assertNotNull(gcRequestInput.getVfModuleId()); - assertTrue(gcRequestInput.getFromPreload()); - } - - @Test - public void buildVfModuleInformationTest_withNoModelNoRequestParameters() { - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("TestVfModuleId"); - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId("TestVnfId"); - RequestContext requestContext = new RequestContext(); - GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; - try { - gcRequestInput = - genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, requestContext, false); - } catch (MapperException ex) { - - } - assertNotNull(gcRequestInput); - assertNull(vfModule.getModelInfoVfModule()); - assertNull(gcRequestInput.getOnapModelInformation()); - assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); - assertNotNull(gcRequestInput.getVfModuleId()); - assertTrue(gcRequestInput.getFromPreload()); - } - - @Test - public void buildVfModuleInformationTest_withModel() { - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("TestVfModuleId"); - ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); - modelInfoVfModule.setModelInvariantUUID("testModelInvariantUUID"); - modelInfoVfModule.setModelName("testModelName"); - modelInfoVfModule.setModelVersion("testModelVersion"); - modelInfoVfModule.setModelUUID("testModelUUID"); - modelInfoVfModule.setModelCustomizationUUID("testModelCustomizationUUID"); - vfModule.setModelInfoVfModule(modelInfoVfModule); - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId("TestVnfId"); - RequestContext requestContext = new RequestContext(); - RequestParameters requestParameters = new RequestParameters(); - requestParameters.setUsePreload(true); - requestContext.setRequestParameters(requestParameters); - GenericResourceApiVfmoduleinformationVfModuleInformation gcRequestInput = null; - try { - gcRequestInput = - genObjMapper.buildVfModuleInformation(vfModule, genericVnf, serviceInstance, requestContext, true); - } catch (MapperException ex) { - - } - assertNotNull(gcRequestInput); - assertNotNull(vfModule.getModelInfoVfModule()); - assertNotNull(gcRequestInput.getOnapModelInformation()); - assertEquals(modelInfoVfModule.getModelInvariantUUID(), - gcRequestInput.getOnapModelInformation().getModelInvariantUuid()); - assertEquals(modelInfoVfModule.getModelName(), gcRequestInput.getOnapModelInformation().getModelName()); - assertEquals(modelInfoVfModule.getModelVersion(), gcRequestInput.getOnapModelInformation().getModelVersion()); - assertEquals(modelInfoVfModule.getModelUUID(), gcRequestInput.getOnapModelInformation().getModelUuid()); - assertEquals(modelInfoVfModule.getModelCustomizationUUID(), - gcRequestInput.getOnapModelInformation().getModelCustomizationUuid()); - assertEquals(vfModule.getVfModuleId(), gcRequestInput.getVfModuleId()); - assertNotNull(gcRequestInput.getVfModuleId()); - assertTrue(gcRequestInput.getFromPreload()); - } -} 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 deleted file mode 100644 index 76e915781f..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java +++ /dev/null @@ -1,232 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.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; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; -import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; -import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; -import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; -import org.onap.so.client.sdnc.beans.SDNCSvcAction; -import org.onap.so.client.sdnc.beans.SDNCSvcOperation; -import com.fasterxml.jackson.databind.ObjectMapper; - -@RunWith(MockitoJUnitRunner.class) -public class NetworkTopologyOperationRequestMapperTest { - - private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; - - private ServiceInstance serviceInstance; - private ServiceInstance serviceInstanceNoCollection; - private Customer customer; - private RequestContext requestContext; - private L3Network network; - private CloudRegion cloudRegion; - - @Spy - private GeneralTopologyObjectMapper generalTopologyObjectMapper; - - @InjectMocks - private NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper(); - - @Before - public void before() { - // prepare and set service instance - serviceInstance = new ServiceInstance(); - serviceInstanceNoCollection = new ServiceInstance(); - ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); - modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid"); - modelInfoServiceInstance.setModelName("modelName"); - modelInfoServiceInstance.setModelUuid("modelUuid"); - modelInfoServiceInstance.setModelVersion("modelVersion"); - serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - serviceInstanceNoCollection.setModelInfoServiceInstance(modelInfoServiceInstance); - // prepare Customer object - customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - // serviceInstance.setCustomer(customer); - // set Customer on service instance - ServiceSubscription serviceSubscription = new ServiceSubscription(); - serviceSubscription.setServiceType("productFamilyId"); - customer.setServiceSubscription(serviceSubscription); - - // set Customer on service instance - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - customer.getServiceSubscription().getServiceInstances().add(serviceInstanceNoCollection); - // - InstanceGroup networkInstanceGroup = new InstanceGroup(); - networkInstanceGroup.setId("networkInstanceGroupId"); - networkInstanceGroup.setInstanceGroupFunction("instanceGroupFunction"); - Collection networkCollection = new Collection(); - networkCollection.setInstanceGroup(networkInstanceGroup); - serviceInstance.setCollection(networkCollection); - // - requestContext = new RequestContext(); - Map userParams = new HashMap<>(); - userParams.put("key1", "value1"); - requestContext.setUserParams(userParams); - requestContext.setProductFamilyId("productFamilyId"); - requestContext.setMsoRequestId("MsoRequestId"); - - network = new L3Network(); - network.setNetworkId("TEST_NETWORK_ID"); - network.setNetworkName("TEST_NETWORK_NAME"); - ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); - modelInfoNetwork.setModelInvariantUUID("modelInvariantUuid"); - modelInfoNetwork.setModelName("modelName"); - modelInfoNetwork.setModelVersion("modelVersion"); - modelInfoNetwork.setModelUUID("modelUuid"); - modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUUID"); - network.setModelInfoNetwork(modelInfoNetwork); - - cloudRegion = new CloudRegion(); - } - - @Test - public void createGenericResourceApiNetworkOperationInformationTest() throws Exception { - - GenericResourceApiNetworkOperationInformation networkSDNCrequest = - mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, - GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, - customer, requestContext, cloudRegion); - - ObjectMapper omapper = new ObjectMapper(); - GenericResourceApiNetworkOperationInformation reqMapper1 = - omapper.readValue(getJson("genericResourceApiNetworkOperationInformation.json"), - GenericResourceApiNetworkOperationInformation.class); - - 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 { - - GenericResourceApiNetworkOperationInformation networkSDNCrequest = - mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, - GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, - customer, requestContext, cloudRegion); - - assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); - assertEquals("modelCustomizationUUID", - networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid()); - } - - @Test - public void reqMapperNoCollectionTest() throws Exception { - GenericResourceApiNetworkOperationInformation networkSDNCrequest = - mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, - GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, - serviceInstanceNoCollection, customer, requestContext, cloudRegion); - - assertNull(networkSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); - assertEquals("modelCustomizationUUID", - networkSDNCrequest.getNetworkInformation().getOnapModelInformation().getModelCustomizationUuid()); - } - - @Test - public void createGenericResourceApiNetworkOperationInformation_UnassignTest() throws Exception { - - NetworkTopologyOperationRequestMapper mapperUnassign = mapper; - GenericResourceApiNetworkOperationInformation networkSDNCrequestUnassign = - mapperUnassign.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, - GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, - customer, requestContext, cloudRegion); - - ObjectMapper omapperUnassign = new ObjectMapper(); - GenericResourceApiNetworkOperationInformation reqMapperUnassign = - omapperUnassign.readValue(getJson("genericResourceApiNetworkOperationInformationUnAssign.json"), - GenericResourceApiNetworkOperationInformation.class); - - assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId") - .ignoring("requestInformation.requestId")); - assertEquals("MsoRequestId", networkSDNCrequestUnassign.getRequestInformation().getRequestId()); - - } - - @Test - public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception { - - // set network name NULL - network.setNetworkName(null); - GenericResourceApiNetworkOperationInformation networkSDNCrequest = - mapper.reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, - GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, - customer, requestContext, cloudRegion); - - ObjectMapper omapper = new ObjectMapper(); - GenericResourceApiNetworkOperationInformation reqMapper1 = - omapper.readValue(getJson("genericResourceApiNetworkOperationInformationNoNetworkName.json"), - GenericResourceApiNetworkOperationInformation.class); - - assertThat(reqMapper1, sameBeanAs(networkSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") - .ignoring("requestInformation.requestId")); - } - - /* - * Helper method to load JSON data - */ - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename))); - } - -} 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 deleted file mode 100644 index f4006ab5d5..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.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; -import java.util.HashMap; -import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; -import org.onap.so.client.sdnc.beans.SDNCSvcAction; -import org.onap.so.client.sdnc.beans.SDNCSvcOperation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation; -import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; -import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; -import com.fasterxml.jackson.databind.ObjectMapper; - -@RunWith(MockitoJUnitRunner.class) -public class ServiceTopologyOperationMapperTest { - - @Spy - private GeneralTopologyObjectMapper generalTopologyObjectMapper; - - @InjectMocks - private ServiceTopologyOperationMapper mapper = new ServiceTopologyOperationMapper(); - - @Test - public void reqMapperTest() throws Exception { - // prepare and set service instance - ServiceInstance serviceInstance = new ServiceInstance(); - ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); - modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid"); - modelInfoServiceInstance.setModelName("modelName"); - modelInfoServiceInstance.setModelUuid("modelUuid"); - modelInfoServiceInstance.setModelVersion("modelVersion"); - serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - - // prepare Customer object - Customer customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - - customer.setServiceSubscription(new ServiceSubscription()); - // set Customer on service instance - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - - // prepare RequestContext - RequestContext requestContext = new RequestContext(); - Map userParams = new HashMap<>(); - 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"))); - - ObjectMapper omapper = new ObjectMapper(); - GenericResourceApiOnapmodelinformationOnapModelInformation reqMapper1 = - omapper.readValue(jsonToCompare, 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 deleted file mode 100644 index 2fd684e0f0..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java +++ /dev/null @@ -1,402 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.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.net.URI; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; -import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; -import org.onap.so.client.exception.MapperException; -import org.onap.so.client.sdnc.beans.SDNCSvcAction; -import org.onap.so.client.sdnc.beans.SDNCSvcOperation; -import com.fasterxml.jackson.databind.ObjectMapper; - -@RunWith(MockitoJUnitRunner.class) -public class VfModuleTopologyOperationRequestMapperTest { - - private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; - private final static String ERRORMESSAGE = "VF Module model info is null for testVfModuleId"; - - @Spy - private GeneralTopologyObjectMapper generalTopologyObjectMapper; - - @InjectMocks - private VfModuleTopologyOperationRequestMapper mapper = new VfModuleTopologyOperationRequestMapper(); - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void assignGenericResourceApiVfModuleInformationTest() throws Exception { - - // prepare and set service instance - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); - modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); - modelInfoServiceInstance.setModelName("serviceModelName"); - modelInfoServiceInstance.setModelUuid("serviceModelUuid"); - modelInfoServiceInstance.setModelVersion("serviceModelVersion"); - serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - // prepare Customer object - Customer customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - ServiceSubscription serviceSubscription = new ServiceSubscription(); - serviceSubscription.setServiceType("productFamilyId"); - customer.setServiceSubscription(serviceSubscription); - - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - // - RequestContext requestContext = new RequestContext(); - Map userParams = new HashMap<>(); - userParams.put("key1", "value1"); - requestContext.setUserParams(userParams); - requestContext.setProductFamilyId("productFamilyId"); - RequestParameters requestParameters = new RequestParameters(); - requestParameters.setUsePreload(true); - requestContext.setRequestParameters(requestParameters); - requestContext.setMsoRequestId("MsoRequestId"); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("testVnfId"); - vnf.setVnfType("testVnfType"); - vnf.setVnfName("testVnfName"); - ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); - modelInfoGenericVnf.setModelName("vnfModelName"); - modelInfoGenericVnf.setModelVersion("vnfModelVersion"); - modelInfoGenericVnf.setModelUuid("vnfModelUuid"); - modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); - vnf.setModelInfoGenericVnf(modelInfoGenericVnf); - - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("testVfModuleId"); - vfModule.setVfModuleName("testVfModuleName"); - ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); - modelInfoVfModule.setModelInvariantUUID("vfModuleModelInvariantUuid"); - modelInfoVfModule.setModelName("vfModuleModelName"); - modelInfoVfModule.setModelVersion("vfModuleModelVersion"); - modelInfoVfModule.setModelUUID("vfModuleModelUuid"); - modelInfoVfModule.setModelCustomizationUUID("vfModuleModelCustomizationUuid"); - vfModule.setModelInfoVfModule(modelInfoVfModule); - HashMap cloudParams = new HashMap(); - cloudParams.put("key2", "value2"); - vfModule.setCloudParams(cloudParams); - - VolumeGroup volumeGroup = new VolumeGroup(); - volumeGroup.setVolumeGroupId("volumeGroupId"); - volumeGroup.setVolumeGroupName("volumeGroupName"); - - CloudRegion cloudRegion = new CloudRegion(); - - GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( - SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, volumeGroup, vnf, - serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); - - String jsonToCompare = new String(Files.readAllBytes( - Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleOperationInformationAssign.json"))); - - ObjectMapper omapper = new ObjectMapper(); - GenericResourceApiVfModuleOperationInformation reqMapper1 = - omapper.readValue(jsonToCompare, GenericResourceApiVfModuleOperationInformation.class); - - assertThat(vfModuleSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId") - .ignoring("requestInformation.requestId")); - assertEquals("MsoRequestId", vfModuleSDNCrequest.getRequestInformation().getRequestId()); - } - - @Test - public void unassignGenericResourceApiVfModuleInformationTest() 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(); - requestContext.setMsoRequestId("MsoRequestId"); - - GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = - mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, - vnf, serviceInstance, null, null, requestContext, null, new URI("http://localhost:8080")); - - String jsonToCompare = new String(Files.readAllBytes( - Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleOperationInformationUnassign.json"))); - - ObjectMapper omapper = new ObjectMapper(); - GenericResourceApiVfModuleOperationInformation reqMapper1 = - omapper.readValue(jsonToCompare, GenericResourceApiVfModuleOperationInformation.class); - - assertThat(vfModuleSDNCrequest, sameBeanAs(reqMapper1).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, new URI("http://localhost:8080")); - - assertNotNull(vfModuleSDNCrequest.getRequestInformation().getRequestId()); - } - - @Test - public void reqMapperTest() throws Exception { - - // prepare and set service instance - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); - modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); - modelInfoServiceInstance.setModelName("serviceModelName"); - modelInfoServiceInstance.setModelUuid("serviceModelUuid"); - modelInfoServiceInstance.setModelVersion("serviceModelVersion"); - - serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - // prepare Customer object - Customer customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - customer.setServiceSubscription(new ServiceSubscription()); - // set Customer on service instance - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - // - RequestContext requestContext = new RequestContext(); - RequestParameters requestParameters = new RequestParameters(); - HashMap userParams1 = new HashMap<>(); - userParams1.put("key1", "value1"); - List> userParams = new ArrayList<>(); - userParams.add(userParams1); - - requestParameters.setUserParams(userParams); - requestContext.setRequestParameters(requestParameters); - requestContext.setProductFamilyId("productFamilyId"); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("testVnfId"); - vnf.setVnfType("testVnfType"); - ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); - modelInfoGenericVnf.setModelName("vnfModelName"); - modelInfoGenericVnf.setModelVersion("vnfModelVersion"); - modelInfoGenericVnf.setModelUuid("vnfModelUuid"); - modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); - vnf.setModelInfoGenericVnf(modelInfoGenericVnf); - - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("testVfModuleId"); - vfModule.setVfModuleName("testVfModuleName"); - ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); - modelInfoVfModule.setModelInvariantUUID("vfModuleModelInvariantUuid"); - modelInfoVfModule.setModelName("vfModuleModelName"); - modelInfoVfModule.setModelVersion("vfModuleModelVersion"); - modelInfoVfModule.setModelUUID("vfModuleModelUuid"); - modelInfoVfModule.setModelCustomizationUUID("vfModuleModelCustomizationUuid"); - vfModule.setModelInfoVfModule(modelInfoVfModule); - - CloudRegion cloudRegion = new CloudRegion(); - - GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( - SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, null, vnf, - serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); - - assertNull(vfModuleSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); - assertEquals("vnfModelCustomizationUuid", - vfModuleSDNCrequest.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); - assertEquals("vfModuleModelCustomizationUuid", - vfModuleSDNCrequest.getVfModuleInformation().getOnapModelInformation().getModelCustomizationUuid()); - } - - @Test - public void reqMapperNoModelInfoTest() throws Exception { - - // prepare and set service instance - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); - modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); - modelInfoServiceInstance.setModelName("serviceModelName"); - modelInfoServiceInstance.setModelUuid("serviceModelUuid"); - modelInfoServiceInstance.setModelVersion("serviceModelVersion"); - - serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - // prepare Customer object - Customer customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - customer.setServiceSubscription(new ServiceSubscription()); - // set Customer on service instance - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - // - RequestContext requestContext = new RequestContext(); - Map userParams = new HashMap(); - userParams.put("key1", "value1"); - requestContext.setUserParams(userParams); - requestContext.setProductFamilyId("productFamilyId"); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("testVnfId"); - vnf.setVnfType("testVnfType"); - ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); - modelInfoGenericVnf.setModelName("vnfModelName"); - modelInfoGenericVnf.setModelVersion("vnfModelVersion"); - modelInfoGenericVnf.setModelUuid("vnfModelUuid"); - modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); - vnf.setModelInfoGenericVnf(modelInfoGenericVnf); - - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("testVfModuleId"); - vfModule.setVfModuleName("testVfModuleName"); - vfModule.setModelInfoVfModule(null); - - CloudRegion cloudRegion = new CloudRegion(); - - expectedException.expect(MapperException.class); - expectedException.expectMessage(ERRORMESSAGE); - - mapper.reqMapper(SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, null, vnf, - serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); - } - - @Test - public void reqMapperChangeAssignTest() throws Exception { - - // prepare and set service instance - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); - modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); - modelInfoServiceInstance.setModelName("serviceModelName"); - modelInfoServiceInstance.setModelUuid("serviceModelUuid"); - modelInfoServiceInstance.setModelVersion("serviceModelVersion"); - - serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - // prepare Customer object - Customer customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - customer.setServiceSubscription(new ServiceSubscription()); - // set Customer on service instance - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - // - RequestContext requestContext = new RequestContext(); - RequestParameters requestParameters = new RequestParameters(); - HashMap userParams1 = new HashMap<>(); - userParams1.put("key1", "value1"); - List> userParams = new ArrayList<>(); - userParams.add(userParams1); - - requestParameters.setUserParams(userParams); - requestContext.setRequestParameters(requestParameters); - requestContext.setProductFamilyId("productFamilyId"); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("testVnfId"); - vnf.setVnfType("testVnfType"); - ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); - modelInfoGenericVnf.setModelName("vnfModelName"); - modelInfoGenericVnf.setModelVersion("vnfModelVersion"); - modelInfoGenericVnf.setModelUuid("vnfModelUuid"); - modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); - vnf.setModelInfoGenericVnf(modelInfoGenericVnf); - - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("testVfModuleId"); - vfModule.setVfModuleName("testVfModuleName"); - ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); - modelInfoVfModule.setModelInvariantUUID("vfModuleModelInvariantUuid"); - modelInfoVfModule.setModelName("vfModuleModelName"); - modelInfoVfModule.setModelVersion("vfModuleModelVersion"); - modelInfoVfModule.setModelUUID("vfModuleModelUuid"); - modelInfoVfModule.setModelCustomizationUUID("vfModuleModelCustomizationUuid"); - vfModule.setModelInfoVfModule(modelInfoVfModule); - - CloudRegion cloudRegion = new CloudRegion(); - - GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( - SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN, vfModule, null, vnf, - serviceInstance, customer, cloudRegion, requestContext, null, new URI("http://localhost:8080")); - - assertEquals("vnfModelCustomizationUuid", - vfModuleSDNCrequest.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); - assertEquals("vfModuleModelCustomizationUuid", - vfModuleSDNCrequest.getVfModuleInformation().getOnapModelInformation().getModelCustomizationUuid()); - } - -} 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 deleted file mode 100644 index 00836176f0..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.client.sdnc.mapper; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; -import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation; -import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; -import org.onap.so.bpmn.servicedecomposition.generalobjects.License; -import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; -import org.onap.so.client.sdnc.beans.SDNCSvcAction; -import org.onap.so.client.sdnc.beans.SDNCSvcOperation; - -@RunWith(MockitoJUnitRunner.class) -public class VnfTopologyOperationRequestMapperTest { - - @Spy - private GeneralTopologyObjectMapper generalTopologyObjectMapper; - - @InjectMocks - private VnfTopologyOperationRequestMapper mapper = new VnfTopologyOperationRequestMapper(); - - @Test - public void reqMapperTest() throws Exception { - // prepare and set service instance - ServiceInstance serviceInstance = new ServiceInstance(); - ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); - modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid"); - modelInfoServiceInstance.setModelName("modelName"); - modelInfoServiceInstance.setModelUuid("modelUuid"); - modelInfoServiceInstance.setModelVersion("modelVersion"); - serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); - - // prepare VNF - ModelInfoGenericVnf genericVnf = new ModelInfoGenericVnf(); - genericVnf.setModelInvariantUuid("vnfModelInvariantUUID"); - genericVnf.setModelVersion("vnfModelVersion"); - genericVnf.setModelName("vnfModelName"); - genericVnf.setModelUuid("vnfModelUUID"); - genericVnf.setModelCustomizationUuid("vnfModelCustomizationUUID"); - - ModelInfoInstanceGroup modelL3Network = new ModelInfoInstanceGroup(); - modelL3Network.setType("L3-NETWORK"); - - InstanceGroup instanceGroup1 = new InstanceGroup(); - instanceGroup1.setId("l3-network-ig-111"); - instanceGroup1.setModelInfoInstanceGroup(modelL3Network); - - InstanceGroup instanceGroup2 = new InstanceGroup(); - instanceGroup2.setId("l3-network-ig-222"); - instanceGroup2.setModelInfoInstanceGroup(modelL3Network); - - GenericVnf vnf = new GenericVnf(); - vnf.setModelInfoGenericVnf(genericVnf); - vnf.setVnfId("vnfId"); - vnf.setVnfType("vnfType"); - vnf.getInstanceGroups().add(instanceGroup1); - vnf.getInstanceGroups().add(instanceGroup2); - License license = new License(); - List entitlementPoolUuids = new ArrayList<>(); - entitlementPoolUuids.add("entitlementPoolUuid"); - List licenseKeyGroupUuids = new ArrayList<>(); - licenseKeyGroupUuids.add("licenseKeyGroupUuid"); - license.setEntitlementPoolUuids(entitlementPoolUuids); - license.setLicenseKeyGroupUuids(licenseKeyGroupUuids); - vnf.setLicense(license); - - // prepare Customer object - Customer customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - - ServiceSubscription serviceSubscription = new ServiceSubscription(); - serviceSubscription.setServiceType("productFamilyId"); - customer.setServiceSubscription(serviceSubscription); - - // set Customer on service instance - customer.getServiceSubscription().getServiceInstances().add(serviceInstance); - - - // prepare RequestContext - RequestContext requestContext = new RequestContext(); - Map userParams = new HashMap<>(); - 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, new URI("http://localhost:8080")); - GenericResourceApiVnfOperationInformation vnfOpInformationNullReqContext = - mapper.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, - GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, - cloudRegion, null, true, new URI("http://localhost:8080")); - - assertNull(vnfOpInformation.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); - assertEquals("vnfModelCustomizationUUID", - vnfOpInformation.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); - assertEquals(2, vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().size()); - assertEquals("l3-network-ig-111", vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().get(0) - .getVnfNetworkInstanceGroupId()); - 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/sdno/SDNOHealthCheckClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java deleted file mode 100644 index 750e578558..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.client.sdno; - -import static org.junit.Assert.assertEquals; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Optional; -import org.junit.Test; -import org.onap.so.client.sdno.beans.SDNO; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class SDNOHealthCheckClientTest { - - - - private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/health-check/"; - private static final String userId = "test-user"; - private static final Optional clliCode = Optional.of("test-clli"); - private static final String requestId = "test-request-id"; - private static final String configurationId = "test-configuration-id"; - private static final String interfaceId = "test-interface-id"; - - @Test - public void verfyLPortMirrorPreCheckRequest() throws IOException { - String content = this.getJson("custom-lport-mirror-pre-check-request.json"); - ObjectMapper mapper = new ObjectMapper(); - SDNO expected = mapper.readValue(content, SDNO.class); - SDNOHealthCheckClient client = new SDNOHealthCheckClient(); - String actual = - client.buildLPortMirrorCheckPreRequest(userId, requestId, clliCode, configurationId, interfaceId); - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - } - - @Test - public void verfyLPortMirrorPostCheckRequest() throws IOException { - String content = this.getJson("custom-lport-mirror-post-check-request.json"); - ObjectMapper mapper = new ObjectMapper(); - SDNO expected = mapper.readValue(content, SDNO.class); - SDNOHealthCheckClient client = new SDNOHealthCheckClient(); - String actual = - client.buildLPortMirrorCheckPostRequest(userId, requestId, clliCode, configurationId, interfaceId); - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - } - - - @Test - public void verifyPortMirrorPostCheckRequest() throws IOException { - String content = this.getJson("custom-port-mirror-post-check-request.json"); - ObjectMapper mapper = new ObjectMapper(); - SDNO expected = mapper.readValue(content, SDNO.class); - SDNOHealthCheckClient client = new SDNOHealthCheckClient(); - String actual = client.buildPortMirrorPostCheckRequest(userId, requestId, clliCode, configurationId); - - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - - } - - @Test - public void verifyPortMirrorPreCheckRequest() throws IOException { - String content = this.getJson("custom-port-mirror-pre-check-request.json"); - ObjectMapper mapper = new ObjectMapper(); - SDNO expected = mapper.readValue(content, SDNO.class); - SDNOHealthCheckClient client = new SDNOHealthCheckClient(); - String actual = client.buildPortMirrorPreCheckRequest(userId, requestId, clliCode, configurationId); - - assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); - - } - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); - } - -} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java deleted file mode 100644 index b91f83c1b7..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.client.sdno; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.UUID; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.so.BaseIntegrationTest; -import org.onap.so.client.dmaap.Consumer; -import org.onap.so.client.dmaap.exceptions.DMaaPConsumerFailure; -import org.onap.so.client.exceptions.SDNOException; -import org.onap.so.client.sdno.beans.SDNO; -import org.onap.so.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer; -import com.fasterxml.jackson.databind.ObjectMapper; - - - -public class SDNOValidatorIT extends BaseIntegrationTest { - - - @Mock - private Consumer mrConsumer; - private SDNOHealthCheckDmaapConsumer dmaapConsumer; - private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/"; - private final String uuid = "xyz123"; - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUpTests() { - MockitoAnnotations.initMocks(this); - - } - - @Test - public void success() throws IOException, Exception { - dmaapConsumer = spy(new SDNOHealthCheckDmaapConsumer()); - when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer); - when(mrConsumer.fetch()) - .thenReturn(Arrays.asList(new String[] {getJson("response.json"), getJson("output-success.json")})); - - SDNOValidatorImpl validator = new SDNOValidatorImpl(); - SDNOValidatorImpl spy = spy(validator); - when(dmaapConsumer.getRequestId()).thenReturn("xyz123"); - doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class)); - boolean result = spy.pollForResponse("xyz123"); - assertEquals("result is true", result, true); - } - - @Test - public void failure() throws IOException, Exception { - dmaapConsumer = spy(new SDNOHealthCheckDmaapConsumer()); - - when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer); - when(mrConsumer.fetch()) - .thenReturn(Arrays.asList(new String[] {getJson("response.json"), getJson("output-failure.json")})); - - SDNOValidatorImpl validator = new SDNOValidatorImpl(); - SDNOValidatorImpl spy = spy(validator); - when(dmaapConsumer.getRequestId()).thenReturn("xyz123"); - doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class)); - thrown.expect(SDNOException.class); - thrown.expectMessage(containsString("my error message")); - boolean result = spy.pollForResponse("xyz123"); - - } - - @Ignore - @Test - public void run() throws Exception { - SDNOValidatorImpl validator = new SDNOValidatorImpl(); - UUID uuid = UUID.randomUUID(); - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("test"); - vnf.setIpv4OamAddress("1.2.3.4"); - vnf.setNfRole("VPE"); - SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid"); - ObjectMapper mapper = new ObjectMapper(); - String json = mapper.writeValueAsString(request); - validator.submitRequest(json); - thrown.expect(DMaaPConsumerFailure.class); - boolean result = validator.pollForResponse(uuid.toString()); - System.out.println(json); - - } - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); - } -} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java deleted file mode 100644 index c2278c26f9..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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.client.sdno; - -import static org.junit.Assert.assertEquals; -import java.util.UUID; -import org.junit.Test; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.so.client.sdno.beans.RequestHealthDiagnostic; -import org.onap.so.client.sdno.beans.SDNO; - -public class SDNOValidatorImplTest { - - @Test - public void buildRequestDiagnosticTest() throws Exception { - SDNOValidatorImpl validator = new SDNOValidatorImpl(); - UUID uuid = UUID.randomUUID(); - GenericVnf vnf = new GenericVnf(); - vnf.setVnfName("VNFNAME"); - vnf.setVnfId("test"); - vnf.setIpv4OamAddress("1.2.3.4"); - vnf.setNfRole("VPE"); - SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid"); - assertEquals(request.getNodeType(), "VPE"); - assertEquals(request.getOperation(), "health-diagnostic"); - - RequestHealthDiagnostic innerRequest = request.getBody().getInput().getRequestHealthDiagnostic(); - assertEquals(innerRequest.getRequestClientName(), "MSO"); - assertEquals(innerRequest.getRequestNodeName(), "VNFNAME"); - assertEquals(innerRequest.getRequestNodeUuid(), "test"); - assertEquals(innerRequest.getRequestNodeType(), "VPE"); - assertEquals(innerRequest.getRequestNodeIp(), "1.2.3.4"); - assertEquals(innerRequest.getRequestUserId(), "mechid"); - assertEquals(innerRequest.getRequestId(), uuid.toString()); - assertEquals(innerRequest.getHealthDiagnosticCode(), "default"); - - } -} -- cgit 1.2.3-korg