diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java/org/onap')
70 files changed, 12857 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseTest.java new file mode 100644 index 0000000000..e527b587b7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseTest.java @@ -0,0 +1,44 @@ +/*- + * ============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; + +import org.junit.runner.RunWith; +import org.onap.so.bpmn.buildingblock.SniroHomingV2; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.client.orchestration.SDNOHealthCheckResources; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +@ContextConfiguration +public abstract class BaseTest extends TestDataSetup { + + @SpyBean + protected SDNOHealthCheckResources MOCK_sdnoHealthCheckResources; + + @MockBean + protected SniroHomingV2 sniroHoming; +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java new file mode 100644 index 0000000000..a29df9cbcf --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java @@ -0,0 +1,64 @@ +/*- + * ============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; +import ch.vorburger.exec.ManagedProcessException; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; +import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import javax.sql.DataSource; + +@Configuration +@Profile({"test"}) +public class EmbeddedMariaDbConfig { + + @Bean + MariaDB4jSpringService mariaDB4jSpringService() { + MariaDB4jSpringService service = new MariaDB4jSpringService(); + + + service.getConfiguration().addArg("--lower_case_table_names=1"); + return service; + } + + @Bean + DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService, + @Value("${mariaDB4j.databaseName}") String databaseName, + @Value("${spring.datasource.username}") String datasourceUsername, + @Value("${spring.datasource.password}") String datasourcePassword, + @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException { + //Create our database with default root user and no password + mariaDB4jSpringService.getDB().createDB(databaseName); + + DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration(); + + return DataSourceBuilder + .create() + .username(datasourceUsername) + .password(datasourcePassword) + .url(config.getURL(databaseName)) + .driverClassName(datasourceDriver) + .build(); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/FileUtil.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/FileUtil.java new file mode 100644 index 0000000000..e35fe0db9f --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/FileUtil.java @@ -0,0 +1,81 @@ +/*- + * ============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; + +import java.io.IOException; +import java.io.InputStream; +import org.onap.so.logger.MsoLogger; + +/** + * + * File utility class.<br/> + * <p> + * </p> + * + * @author + * @version ONAP Sep 15, 2017 + */ +public class FileUtil { + + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, FileUtil.class); + + /** + * Read the specified resource file and return the contents as a String. + * + * @param fileName Name of the resource file + * @return the contents of the resource file as a String + * @throws IOException if there is a problem reading the file + */ + public static String readResourceFile(String fileName) { + InputStream stream; + try { + stream = getResourceAsStream(fileName); + byte[] bytes; + bytes = new byte[stream.available()]; + if(stream.read(bytes) > 0) { + stream.close(); + return new String(bytes); + } else { + stream.close(); + return ""; + } + } catch (IOException e) { + LOGGER.debug("Exception:", e); + return ""; + } + } + + /** + * Get an InputStream for the resource specified. + * + * @param resourceName Name of resource for which to get InputStream. + * @return an InputStream for the resource specified. + * @throws IOException If we can't get the InputStream for whatever reason. + */ + private static InputStream getResourceAsStream(String resourceName) throws IOException { + InputStream stream = + FileUtil.class.getClassLoader().getResourceAsStream(resourceName); + if (stream == null) { + throw new IOException("Can't access resource '" + resourceName + "'"); + } + return stream; + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/TestApplication.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/TestApplication.java new file mode 100644 index 0000000000..6401d5516d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/TestApplication.java @@ -0,0 +1,54 @@ +package org.onap.so; +/*- + * ============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========================================================= + */ + + + +import java.io.IOException; + +import javax.annotation.PreDestroy; + +import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication; +import org.onap.so.bpmn.common.DefaultToShortClassNameBeanNameGenerator; +import org.onap.so.db.request.data.repository.InfraActiveRequestsRepositoryImpl; +import org.onap.so.requestsdb.RequestsDBHelper; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.Profile; + +@SpringBootApplication +@Profile("test") +@EnableProcessApplication("MSO CommonBPMN Test Application") +@ComponentScan(basePackages = {"org.onap.so"}, nameGenerator = DefaultToShortClassNameBeanNameGenerator.class, excludeFilters = { + @Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class), + @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = RequestsDBHelper.class), + @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = InfraActiveRequestsRepositoryImpl.class) }) +public class TestApplication { + public static void main(String... args) { + SpringApplication.run(TestApplication.class, args); + System.getProperties().setProperty("mso.db", "MARIADB"); + System.getProperties().setProperty("server.name", "Springboot"); + + + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java new file mode 100644 index 0000000000..501e64f4d4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -0,0 +1,119 @@ +/*- + * ============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; + +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.onap.so.TestApplication; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; +import org.onap.so.client.orchestration.AAICollectionResources; +import org.onap.so.client.orchestration.AAIInstanceGroupResources; +import org.onap.so.client.orchestration.AAINetworkResources; +import org.onap.so.client.orchestration.AAIServiceInstanceResources; +import org.onap.so.client.orchestration.AAIVfModuleResources; +import org.onap.so.client.orchestration.AAIVnfResources; +import org.onap.so.client.orchestration.AAIVolumeGroupResources; +import org.onap.so.client.orchestration.AAIVpnBindingResources; +import org.onap.so.client.orchestration.NetworkAdapterResources; +import org.onap.so.client.orchestration.SDNCNetworkResources; +import org.onap.so.client.orchestration.SDNCServiceInstanceResources; +import org.onap.so.client.orchestration.SDNCVfModuleResources; +import org.onap.so.client.orchestration.SDNCVnfResources; +import org.onap.so.client.orchestration.VnfAdapterVfModuleResources; +import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources; +import org.onap.so.client.sdnc.SDNCClient; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public abstract class BaseTaskTest extends TestDataSetup { + @MockBean + protected AAIVolumeGroupResources aaiVolumeGroupResources; + + @MockBean + protected AAIServiceInstanceResources aaiServiceInstanceResources; + + @MockBean + protected AAIVnfResources aaiVnfResources; + + @MockBean + protected AAIVfModuleResources aaiVfModuleResources; + + @MockBean + protected AAIVpnBindingResources aaiVpnBindingResources; + + @MockBean + protected AAINetworkResources aaiNetworkResources; + + @MockBean + protected AAICollectionResources aaiCollectionResources; + + @MockBean + protected NetworkAdapterResources networkAdapterResources; + + @MockBean + protected VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources; + + @MockBean + protected VnfAdapterVfModuleResources vnfAdapterVfModuleResources; + + @MockBean + protected SDNCVnfResources sdncVnfResources; + + @MockBean + protected SDNCNetworkResources sdncNetworkResources; + + @MockBean + protected SDNCVfModuleResources sdncVfModuleResources; + + @MockBean + protected SDNCServiceInstanceResources sdncServiceInstanceResources; + + @MockBean + protected AssignNetworkBBUtils assignNetworkBBUtils; + + @MockBean + protected NetworkAdapterObjectMapper networkAdapterObjectMapper; + + @MockBean + protected AAIInstanceGroupResources aaiInstanceGroupResources; + + @MockBean + protected CatalogDbClient catalogDbClient; + + @Mock + protected BBInputSetupUtils bbSetupUtils; + + @Mock + protected BBInputSetup bbInputSetup; + + @SpyBean + protected SDNCClient SPY_sdncClient; +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java new file mode 100644 index 0000000000..946c5dfe80 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java @@ -0,0 +1,139 @@ +/*- + * ============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.common.aai.tasks; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.infrastructure.aai.tasks.AAIFlagTasks; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.AAIVnfResources; +import org.springframework.beans.factory.annotation.Autowired; + +@RunWith(MockitoJUnitRunner.class) +public class AAIFlagTasksTest extends TestDataSetup { + + @InjectMocks + private AAIFlagTasks aaiFlagTasks = new AAIFlagTasks(); + + @Mock + private AAIVnfResources aaiVnfResources; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + + @Mock + private ExtractPojosForBB extractPojosForBB; + + @Mock + private ExceptionBuilder exceptionUtil; + + private GenericVnf genericVnf; + + @Before + public void before() throws BBObjectNotFoundException { + genericVnf = setGenericVnf(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + when(extractPojosForBB.extractByKey(any(),any(), any())).thenReturn(genericVnf); + } + + @Test + public void checkVnfInMaintTestTrue() throws Exception { + doThrow(new BpmnError("VNF is in maintenance in A&AI")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class)); + doReturn(true).when(aaiVnfResources).checkInMaintFlag(isA(String.class)); + try { + aaiFlagTasks.checkVnfInMaintFlag(execution); + } catch (Exception e) { + verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class)); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), eq("VNF is in maintenance in A&AI")); + } + } + + @Test + public void checkVnfInMaintTestFalse() throws Exception { + doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class)); + aaiFlagTasks.checkVnfInMaintFlag(execution); + verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), any(int.class), any(String.class)); + } + + @Test + public void checkVnfInMaintFlagExceptionTest() { + + doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + doThrow(Exception.class).when(aaiVnfResources).checkInMaintFlag(isA(String.class)); + try { + aaiFlagTasks.checkVnfInMaintFlag(execution); + } catch (Exception e) { + verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class)); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + } + + } + + @Test + public void modifyVnfInMaintFlagTest() throws Exception { + doNothing().when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class)); + aaiFlagTasks.modifyVnfInMaintFlag(execution, true); + verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf); + } + + @Test + public void modifyVnfInMaintFlagExceptionTest() { + + doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class)); + try { + aaiFlagTasks.modifyVnfInMaintFlag(execution, true); + } catch (Exception e) { + verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class)); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java new file mode 100644 index 0000000000..a20b68b147 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java @@ -0,0 +1,665 @@ +/*- + * ============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.common.data; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.assertj.core.util.Arrays; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.impl.pvm.runtime.ExecutionImpl; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.ExpectedException; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; +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.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; +import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Project; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy; +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.bbobjects.VpnBinding; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoAllottedResource; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceProxy; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.BBObjectNotFoundException; + +public class TestDataSetup{ + private int collectionCounter; + private int configurationCounter; + private int customerCounter; + private int genericVnfCounter; + private int instanceGroupCounter; + private int l3NetworkCounter; + private int owningEntityCounter; + private int pnfCounter; + private int projectCounter; + private int serviceInstanceCounter; + private int serviceProxyCounter; + private int serviceSubscriptionCounter; + private int vfModuleCounter; + private int volumeGroupCounter; + private int vpnBindingCounter; + private int vpnBondingLinkCounter; + + protected BuildingBlockExecution execution; + + protected GeneralBuildingBlock gBBInput; + + protected HashMap<ResourceKey, String> lookupKeyMap; + + protected ExtractPojosForBB extractPojosForBB = new ExtractPojosForBB(); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + protected DelegateExecution delegateExecution; + + @Before + public void buildingBlockTestDataSetupBefore() { + collectionCounter = 0; + configurationCounter = 0; + customerCounter = 0; + genericVnfCounter = 0; + instanceGroupCounter = 0; + l3NetworkCounter = 0; + owningEntityCounter = 0; + pnfCounter = 0; + projectCounter = 0; + serviceInstanceCounter = 0; + serviceProxyCounter = 0; + serviceSubscriptionCounter = 0; + vfModuleCounter = 0; + volumeGroupCounter = 0; + vpnBindingCounter = 0; + vpnBondingLinkCounter = 0; + + execution = new DelegateExecutionImpl(new ExecutionImpl()); + execution.setVariable("testProcessKey", "testProcessKeyValue"); + + gBBInput = new GeneralBuildingBlock(); + execution.setVariable("gBBInput", gBBInput); + + lookupKeyMap = new HashMap<ResourceKey, String>(); + execution.setVariable("lookupKeyMap", lookupKeyMap); + + ExecutionImpl mockExecutionImpl = mock(ExecutionImpl.class); + doReturn("test").when(mockExecutionImpl).getProcessInstanceId(); + + ExecutionImpl executionImpl = new ExecutionImpl(); + executionImpl.setProcessInstance(mockExecutionImpl); + + delegateExecution = (DelegateExecution) executionImpl; + delegateExecution.setVariable("testProcessKey", "testProcessKeyValue"); + } + + public Map<String, String> buildUserInput() { + Map<String, String> userInput = new HashMap<>(); + userInput.put("testUserInputKey", "testUserInputValue"); + + return userInput; + } + + public Map<String, String> setUserInput() { + Map<String, String> userInput = buildUserInput(); + + gBBInput.setUserInput(userInput); + + return userInput; + } + + public RequestContext buildRequestContext() { + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId(UUID.randomUUID().toString()); + requestContext.setProductFamilyId("testProductFamilyId"); + requestContext.setRequestorId("testRequestorId"); + + requestContext.setUserParams(new HashMap<>()); + + Map<String,Object> dataMap = new HashMap<>(); + dataMap.put("vpnId","testVpnId"); + dataMap.put("vpnRegion","testVpnRegion"); + dataMap.put("vpnRt","testVpnRt"); + dataMap.put("vpnName","vpnName"); + dataMap.put("vpnRegion", Arrays.asList(new String[] {"USA", "EMEA", "APAC"})); + + HashMap<String,Object> userParams = new HashMap<>(); + userParams.put("vpnData",dataMap); + + List<Map<String,Object>> userParamsList = new ArrayList<>(); + userParamsList.add(userParams); + + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(userParamsList); + requestContext.setRequestParameters(requestParameters); + + return requestContext; + } + + public RequestContext setRequestContext() { + RequestContext requestContext = buildRequestContext(); + + gBBInput.setRequestContext(requestContext); + + return requestContext; + } + + public CloudRegion buildCloudRegion() { + CloudRegion cloudRegion = new CloudRegion(); + cloudRegion.setLcpCloudRegionId("testLcpCloudRegionId"); + cloudRegion.setTenantId("testTenantId"); + cloudRegion.setCloudOwner("testCloudOwner"); + + return cloudRegion; + } + + public CloudRegion setCloudRegion() { + CloudRegion cloudRegion = buildCloudRegion(); + + gBBInput.setCloudRegion(cloudRegion); + + return cloudRegion; + } + + public OrchestrationContext buildOrchestrationContext() { + OrchestrationContext orchestrationContext = new OrchestrationContext(); + + return orchestrationContext; + } + + public OrchestrationContext setOrchestrationContext() { + OrchestrationContext orchestrationContext = buildOrchestrationContext(); + + gBBInput.setOrchContext(orchestrationContext); + + return orchestrationContext; + } + + public Collection buildCollection() { + collectionCounter++; + + Collection collection = new Collection(); + collection.setId("testId" + collectionCounter); + collection.setInstanceGroup(buildInstanceGroup()); + + return collection; + } + + public Configuration buildConfiguration() { + configurationCounter++; + + Configuration configuration = new Configuration(); + configuration.setConfigurationId("testConfigurationId" + configurationCounter); + configuration.setConfigurationName("testConfigurationName" + configurationCounter); + + ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration(); + modelInfoConfiguration.setModelVersionId("testModelVersionId" + configurationCounter); + modelInfoConfiguration.setModelInvariantId("testModelInvariantId" + configurationCounter); + modelInfoConfiguration.setModelCustomizationId("testModelCustomizationId" + configurationCounter); + + configuration.setModelInfoConfiguration(modelInfoConfiguration); + + return configuration; + } + + public OwningEntity buildOwningEntity() { + owningEntityCounter++; + + OwningEntity owningEntity = new OwningEntity(); + owningEntity.setOwningEntityId("testOwningEntityId" + owningEntityCounter); + owningEntity.setOwningEntityName("testOwningEntityName" + owningEntityCounter); + + return owningEntity; + } + + public Project buildProject() { + projectCounter++; + + Project project = new Project(); + project.setProjectName("testProjectName" + projectCounter); + + return project; + } + + public ServiceSubscription buildServiceSubscription() { + serviceSubscriptionCounter++; + + ServiceSubscription serviceSubscription = new ServiceSubscription(); + serviceSubscription.setTempUbSubAccountId("testTempUbSubAccountId" + serviceSubscriptionCounter); + serviceSubscription.setServiceType("testServiceType" + serviceSubscriptionCounter); + + return serviceSubscription; + } + + public Customer buildCustomer() { + customerCounter++; + + Customer customer = new Customer(); + customer.setGlobalCustomerId("testGlobalCustomerId" + customerCounter); + customer.setSubscriberType("testSubscriberType" + customerCounter); + + customer.setServiceSubscription(buildServiceSubscription()); + + return customer; + } + + public ServiceInstance buildServiceInstance() { + serviceInstanceCounter++; + + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("testServiceInstanceId" + serviceInstanceCounter); + serviceInstance.setServiceInstanceName("testServiceInstanceName" + serviceInstanceCounter); + + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("testModelInvariantUUID" + serviceInstanceCounter); + modelInfoServiceInstance.setModelUuid("testModelUUID" + serviceInstanceCounter); + modelInfoServiceInstance.setModelVersion("testModelVersion" + serviceInstanceCounter); + modelInfoServiceInstance.setModelName("testModelName" + serviceInstanceCounter); + modelInfoServiceInstance.setServiceType("testServiceType" + serviceInstanceCounter); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + + serviceInstance.setProject(buildProject()); + + serviceInstance.setOwningEntity(buildOwningEntity()); + + serviceInstance.setCollection(buildCollection()); + + serviceInstance.getConfigurations().add(buildConfiguration()); + + return serviceInstance; + } + + public ServiceInstance setServiceInstance() { + ServiceInstance serviceInstance = buildServiceInstance(); + + if(gBBInput.getCustomer() == null) { + gBBInput.setCustomer(buildCustomer()); + } + gBBInput.getCustomer().getServiceSubscription().getServiceInstances().add(serviceInstance); + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstance.getServiceInstanceId()); + + return serviceInstance; + } + + public Customer setCustomer() { + if(gBBInput.getCustomer() != null) return gBBInput.getCustomer(); + Customer customer = new Customer(); + customer.setGlobalCustomerId("testGlobalCustomerId"); + customer.setSubscriberType("testSubscriberType"); + + customer.setServiceSubscription(buildServiceSubscription()); + + gBBInput.setCustomer(customer); + + return customer; + } + + public Collection setCollection() { + Collection collection = new Collection(); + collection.setId("testId"); + + ServiceInstance serviceInstance = null; + + try { + serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + } catch(BBObjectNotFoundException e) { + serviceInstance = setServiceInstance(); + } + + serviceInstance.setCollection(collection); + + return collection; + } + + public InstanceGroup setInstanceGroup() { + InstanceGroup instanceGroup = new InstanceGroup(); + instanceGroup.setId("testId"); + instanceGroup.setInstanceGroupFunction("testInstanceGroupFunction"); + + Collection collection = null; + + try { + ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + collection = serviceInstance.getCollection(); + + if (collection == null) { + collection = setCollection(); + } + } catch(BBObjectNotFoundException e) { + collection = setCollection(); + } + + collection.setInstanceGroup(instanceGroup); + + return instanceGroup; + } + + public VpnBinding buildVpnBinding() { + vpnBindingCounter++; + + VpnBinding vpnBinding = new VpnBinding(); + vpnBinding.setVpnId("testVpnId" + vpnBindingCounter); + vpnBinding.setVpnName("testVpnName" + vpnBindingCounter); + vpnBinding.setCustomerVpnId("testCustomerVpnId" + vpnBindingCounter); + + return vpnBinding; + } + + public VpnBinding setVpnBinding() { + VpnBinding vpnBinding = buildVpnBinding(); + + Customer customer = gBBInput.getCustomer(); + + if(customer == null){ + customer = buildCustomer(); + } + + customer.getVpnBindings().add(vpnBinding); + lookupKeyMap.put(ResourceKey.VPN_ID, vpnBinding.getVpnId()); + + return vpnBinding; + } + + public InstanceGroup buildInstanceGroup() { + instanceGroupCounter++; + + InstanceGroup instanceGroup = new InstanceGroup(); + instanceGroup.setId("testId" + instanceGroupCounter); + instanceGroup.setInstanceGroupFunction("testInstanceGroupFunction" + instanceGroupCounter); + + return instanceGroup; + } + + public L3Network buildL3Network() { + l3NetworkCounter++; + + L3Network network = new L3Network(); + network.setNetworkId("testNetworkId" + l3NetworkCounter); + network.setNetworkName("testNetworkName" + l3NetworkCounter); + network.setNetworkType("testNetworkType" + l3NetworkCounter); + + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + modelInfoNetwork.setModelInvariantUUID("testModelInvariantUUID" + l3NetworkCounter); + modelInfoNetwork.setModelName("testModelName" + l3NetworkCounter); + modelInfoNetwork.setModelVersion("testModelVersion" + l3NetworkCounter); + modelInfoNetwork.setModelUUID("testModelUUID" + l3NetworkCounter); + network.setModelInfoNetwork(modelInfoNetwork); + + return network; + } + + public L3Network setL3Network() { + L3Network network = buildL3Network(); + + ServiceInstance serviceInstance = null; + + try { + serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + } catch(BBObjectNotFoundException e) { + serviceInstance = setServiceInstance(); + } + + serviceInstance.getNetworks().add(network); + lookupKeyMap.put(ResourceKey.NETWORK_ID, network.getNetworkId()); + + return network; + } + + public GenericVnf buildGenericVnf() { + genericVnfCounter++; + + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("testVnfId" + genericVnfCounter); + genericVnf.setVnfName("testVnfName" + genericVnfCounter); + genericVnf.setVnfType("testVnfType" + genericVnfCounter); + + Platform platform = new Platform(); + platform.setPlatformName("testPlatformName"); + genericVnf.setPlatform(platform); + + LineOfBusiness lob = new LineOfBusiness(); + lob.setLineOfBusinessName("testLineOfBusinessName"); + genericVnf.setLineOfBusiness(lob); + + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelName("testModelName" + genericVnfCounter); + modelInfoGenericVnf.setModelCustomizationUuid("testModelCustomizationUUID" + genericVnfCounter); + modelInfoGenericVnf.setModelInvariantUuid("testModelInvariantUUID" + genericVnfCounter); + modelInfoGenericVnf.setModelVersion("testModelVersion" + genericVnfCounter); + modelInfoGenericVnf.setModelUuid("testModelUUID" + genericVnfCounter); + genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + return genericVnf; + } + + public GenericVnf setGenericVnf() { + GenericVnf genericVnf = buildGenericVnf(); + + ServiceInstance serviceInstance = null; + + try { + serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + } catch(BBObjectNotFoundException e) { + serviceInstance = setServiceInstance(); + } + + serviceInstance.getVnfs().add(genericVnf); + lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, genericVnf.getVnfId()); + + return genericVnf; + } + + public VfModule buildVfModule() { + vfModuleCounter++; + + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("testVfModuleId" + vfModuleCounter); + vfModule.setVfModuleName("testVfModuleName" + vfModuleCounter); + + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelInvariantUUID("testModelInvariantUUID" + vfModuleCounter); + modelInfoVfModule.setModelVersion("testModelVersion" + vfModuleCounter); + modelInfoVfModule.setModelUUID("testModelUUID" + vfModuleCounter); + modelInfoVfModule.setModelName("testModelName" + vfModuleCounter); + modelInfoVfModule.setModelCustomizationUUID("testModelCustomizationUUID" + vfModuleCounter); + vfModule.setModelInfoVfModule(modelInfoVfModule); + + return vfModule; + } + + public VfModule setVfModule() { + VfModule vfModule = buildVfModule(); + + GenericVnf genericVnf = null; + + try { + genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + } catch(BBObjectNotFoundException e) { + genericVnf = setGenericVnf(); + } + + genericVnf.getVfModules().add(vfModule); + lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModule.getVfModuleId()); + + return vfModule; + } + + public VolumeGroup buildVolumeGroup() { + volumeGroupCounter++; + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("testVolumeGroupId" + volumeGroupCounter); + volumeGroup.setVolumeGroupName("testVolumeGroupName" + volumeGroupCounter); + volumeGroup.setHeatStackId("testHeatStackId" + volumeGroupCounter); + + return volumeGroup; + } + + public VolumeGroup setVolumeGroup() { + VolumeGroup volumeGroup = buildVolumeGroup(); + + GenericVnf genericVnf = null; + + try { + genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + } catch(BBObjectNotFoundException e) { + genericVnf = setGenericVnf(); + } + + genericVnf.getVolumeGroups().add(volumeGroup); + lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, volumeGroup.getVolumeGroupId()); + + return volumeGroup; + } + + public Pnf buildPnf() { + pnfCounter++; + + Pnf pnf = new Pnf(); + pnf.setPnfId("testPnfId" + pnfCounter); + pnf.setPnfName("testPnfName" + pnfCounter); + + return pnf; + } + + public ServiceProxy buildServiceProxy() { + serviceProxyCounter++; + + ServiceProxy serviceProxy = new ServiceProxy(); + serviceProxy.setServiceInstance(buildServiceInstance()); + serviceProxy.getServiceInstance().getVnfs().add(buildGenericVnf()); + + Pnf primaryPnf = buildPnf(); + primaryPnf.setRole("Primary"); + serviceProxy.getServiceInstance().getPnfs().add(primaryPnf); + + Pnf secondaryPnf = buildPnf(); + secondaryPnf.setRole("Secondary"); + serviceProxy.getServiceInstance().getPnfs().add(secondaryPnf); + + return serviceProxy; + } + + public VpnBondingLink buildVpnBondingLink() { + vpnBondingLinkCounter++; + + VpnBondingLink vpnBondingLink = new VpnBondingLink(); + vpnBondingLink.setVpnBondingLinkId("testVpnBondingLinkId" + vpnBondingLinkCounter); + + Configuration vnrConfiguration = buildConfiguration(); + vnrConfiguration.setNetwork(buildL3Network()); + vpnBondingLink.setVnrConfiguration(vnrConfiguration); + + vpnBondingLink.setVrfConfiguration(buildConfiguration()); + + vpnBondingLink.setInfrastructureServiceProxy(buildServiceProxy()); + + vpnBondingLink.setTransportServiceProxy(buildServiceProxy()); + + return vpnBondingLink; + } + + public VpnBondingLink setVpnBondingLink() { + VpnBondingLink vpnBondingLink = buildVpnBondingLink(); + + ServiceInstance serviceInstance = null; + + try { + serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + } catch(BBObjectNotFoundException e) { + serviceInstance = setServiceInstance(); + } + + serviceInstance.getVpnBondingLinks().add(vpnBondingLink); + lookupKeyMap.put(ResourceKey.VPN_BONDING_LINK_ID, vpnBondingLink.getVpnBondingLinkId()); + + + return vpnBondingLink; + } + + public Customer setAvpnCustomer() { + Customer customer = buildCustomer(); + + gBBInput.setCustomer(customer); + + return customer; + } + + public ServiceProxy setServiceProxy(String uniqueIdentifier, String type) { + ServiceProxy serviceProxy = new ServiceProxy(); + serviceProxy.setId("testProxyId" + uniqueIdentifier); + serviceProxy.setType(type); + + ModelInfoServiceProxy modelInfo = new ModelInfoServiceProxy(); + modelInfo.setModelInvariantUuid("testProxyModelInvariantUuid" + uniqueIdentifier); + modelInfo.setModelName("testProxyModelName" + uniqueIdentifier); + modelInfo.setModelUuid("testProxyModelUuid" + uniqueIdentifier); + modelInfo.setModelVersion("testProxyModelVersion" + uniqueIdentifier); + + serviceProxy.setModelInfoServiceProxy(modelInfo); + + return serviceProxy; + } + + public AllottedResource setAllottedResource(String uniqueIdentifier) { + AllottedResource ar = new AllottedResource(); + ar.setId("testAllottedResourceId" + uniqueIdentifier); + + ModelInfoAllottedResource modelInfo = new ModelInfoAllottedResource(); + modelInfo.setModelInvariantUuid("testProxyModelInvariantUuid" + uniqueIdentifier); + modelInfo.setModelName("testProxyModelName" + uniqueIdentifier); + modelInfo.setModelUuid("testProxyModelUuid" + uniqueIdentifier); + modelInfo.setModelVersion("testProxyModelVersion" + uniqueIdentifier); + + ar.setModelInfoAllottedResource(modelInfo); + + return ar; + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java new file mode 100644 index 0000000000..51a7f1ab04 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java @@ -0,0 +1,387 @@ +/*- + * ============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.aai.tasks; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.bpmn.BaseTaskTest; +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.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.springframework.beans.factory.annotation.Autowired; + +public class AAICreateTasksTest extends BaseTaskTest{ + @Autowired + private AAICreateTasks aaiCreateTasks; + + private ServiceInstance serviceInstance; + private L3Network network; + private GenericVnf genericVnf; + private VolumeGroup volumeGroup; + private CloudRegion cloudRegion; + private VfModule vfModule; + private Customer customer; + + @Rule + public final ExpectedException exception = ExpectedException.none(); + + @Before + public void before() { + customer = setCustomer(); + serviceInstance = setServiceInstance(); + network = setL3Network(); + genericVnf = setGenericVnf(); + volumeGroup = setVolumeGroup(); + cloudRegion = setCloudRegion(); + vfModule = setVfModule(); + + } + + @Test + public void createServiceInstanceTest() throws Exception { + doNothing().when(aaiServiceInstanceResources).createServiceInstance(serviceInstance, customer); + aaiCreateTasks.createServiceInstance(execution); + verify(aaiServiceInstanceResources, times(1)).createServiceInstance(serviceInstance, customer); + } + + @Test + public void createServiceInstanceExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "notfound"); + doThrow(Exception.class).when(aaiServiceInstanceResources).createServiceInstance(serviceInstance, customer); + aaiCreateTasks.createServiceInstance(execution); + } + + @Test + public void createVolumeGroupTest() throws Exception { + volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + doNothing().when(aaiVolumeGroupResources).createVolumeGroup(volumeGroup, cloudRegion); + doNothing().when(aaiVolumeGroupResources).connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion); + + aaiCreateTasks.createVolumeGroup(execution); + + verify(aaiVolumeGroupResources, times(1)).createVolumeGroup(volumeGroup, cloudRegion); + verify(aaiVolumeGroupResources, times(1)).connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion); + verify(aaiVolumeGroupResources, times(1)).connectVolumeGroupToTenant(volumeGroup, cloudRegion); + } + + @Test + public void createVolumeGroupExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + doThrow(Exception.class).when(aaiVolumeGroupResources).createVolumeGroup(volumeGroup, cloudRegion); + + aaiCreateTasks.createVolumeGroup(execution); + } + + @Test + public void createProjectTest() throws Exception { + doNothing().when(aaiServiceInstanceResources).createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); + aaiCreateTasks.createProject(execution); + verify(aaiServiceInstanceResources, times(1)).createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); + } + + @Test + public void createPlatformTest() throws Exception { + doNothing().when(aaiVnfResources).createPlatformandConnectVnf(genericVnf.getPlatform(), genericVnf); + aaiCreateTasks.createPlatform(execution); + verify(aaiVnfResources, times(1)).createPlatformandConnectVnf(genericVnf.getPlatform(), genericVnf); + } + + @Test + public void createLineOfBusinessTest() throws Exception { + doNothing().when(aaiVnfResources).createLineOfBusinessandConnectVnf(genericVnf.getLineOfBusiness(), genericVnf); + aaiCreateTasks.createLineOfBusiness(execution); + verify(aaiVnfResources, times(1)).createLineOfBusinessandConnectVnf(genericVnf.getLineOfBusiness(), genericVnf); + } + + @Test + public void createProjectExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "notfound"); + doThrow(Exception.class).when(aaiServiceInstanceResources).createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); + aaiCreateTasks.createProject(execution); + } + + @Test + public void createProjectNullProjectNameTest() throws Exception { + serviceInstance.getProject().setProjectName(null); + doNothing().when(aaiServiceInstanceResources).createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); + aaiCreateTasks.createProject(execution); + verify(aaiServiceInstanceResources, times(0)).createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); + } + + @Test + public void createProjectEmptyProjectNameTest() throws Exception { + serviceInstance.getProject().setProjectName(""); + doNothing().when(aaiServiceInstanceResources).createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); + aaiCreateTasks.createProject(execution); + verify(aaiServiceInstanceResources, times(0)).createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); + } + + @Test + public void createOwningEntityTest() throws Exception { + doReturn(true).when(aaiServiceInstanceResources).existsOwningEntity(serviceInstance.getOwningEntity()); + doNothing().when(aaiServiceInstanceResources).connectOwningEntityandServiceInstance(serviceInstance.getOwningEntity(),serviceInstance); + aaiCreateTasks.createOwningEntity(execution); + verify(aaiServiceInstanceResources, times(1)).existsOwningEntity(serviceInstance.getOwningEntity()); + verify(aaiServiceInstanceResources, times(1)).connectOwningEntityandServiceInstance(serviceInstance.getOwningEntity(), serviceInstance); + } + + @Test + public void createOwningEntityNotExistsOwningEntityTest() throws Exception { + doReturn(false).when(aaiServiceInstanceResources).existsOwningEntity(serviceInstance.getOwningEntity()); + doNothing().when(aaiServiceInstanceResources).createOwningEntityandConnectServiceInstance(serviceInstance.getOwningEntity(),serviceInstance); + aaiCreateTasks.createOwningEntity(execution); + verify(aaiServiceInstanceResources, times(1)).existsOwningEntity(serviceInstance.getOwningEntity()); + verify(aaiServiceInstanceResources, times(1)).createOwningEntityandConnectServiceInstance(serviceInstance.getOwningEntity(), serviceInstance); + } + + @Test + public void createOwningEntityNullOwningEntityIdTest() throws Exception { + expectedException.expect(BpmnError.class); + + serviceInstance.getOwningEntity().setOwningEntityId(null); + + aaiCreateTasks.createOwningEntity(execution); + } + + @Test + public void createOwningEntityEmptyOwningEntityIdTest() throws Exception { + expectedException.expect(BpmnError.class); + + serviceInstance.getOwningEntity().setOwningEntityId(""); + + aaiCreateTasks.createOwningEntity(execution); + } + + @Test + public void createOwningEntityNullOwningEntityNameTest() throws Exception { + expectedException.expect(BpmnError.class); + + serviceInstance.getOwningEntity().setOwningEntityName(null); + + doReturn(false).when(aaiServiceInstanceResources).existsOwningEntity(serviceInstance.getOwningEntity()); + + aaiCreateTasks.createOwningEntity(execution); + } + + @Test + public void createOwningEntityEmptyOwningEntityNameTest() throws Exception { + expectedException.expect(BpmnError.class); + + serviceInstance.getOwningEntity().setOwningEntityName(""); + + doReturn(false).when(aaiServiceInstanceResources).existsOwningEntity(serviceInstance.getOwningEntity()); + + aaiCreateTasks.createOwningEntity(execution); + } + + @Test + public void createOwningEntityExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doReturn(true).when(aaiServiceInstanceResources).existsOwningEntity(serviceInstance.getOwningEntity()); + + doThrow(Exception.class).when(aaiServiceInstanceResources).connectOwningEntityandServiceInstance(serviceInstance.getOwningEntity(), serviceInstance); + + aaiCreateTasks.createOwningEntity(execution); + } + + @Test + public void createVnfTest() throws Exception { + doNothing().when(aaiVnfResources).createVnfandConnectServiceInstance(genericVnf, serviceInstance); + aaiCreateTasks.createVnf(execution); + verify(aaiVnfResources, times(1)).createVnfandConnectServiceInstance(genericVnf, serviceInstance); + } + + @Test + public void createVnfExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "notfound"); + doNothing().when(aaiVnfResources).createVnfandConnectServiceInstance(genericVnf, serviceInstance); + aaiCreateTasks.createVnf(execution); + verify(aaiVnfResources, times(1)).createVnfandConnectServiceInstance(genericVnf, serviceInstance); + } + + + @Test + public void createVfModuleTest() throws Exception { + doNothing().when(aaiVfModuleResources).createVfModule(vfModule, genericVnf); + aaiCreateTasks.createVfModule(execution); + verify(aaiVfModuleResources, times(1)).createVfModule(vfModule, genericVnf); + } + + @Test + public void createServiceSubscriptionTest(){ + doNothing().when(aaiServiceInstanceResources).createServiceSubscription(customer); + aaiCreateTasks.createServiceSubscription(execution); + verify(aaiServiceInstanceResources, times(1)).createServiceSubscription(customer); + } + + @Test + public void createServiceSubscriptionTestExceptionHandling(){ + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiServiceInstanceResources).createServiceSubscription(customer); + aaiCreateTasks.createServiceSubscription(execution); + } + + @Test + public void createServiceSubscriptionTestCustomerIsNull(){ + expectedException.expect(BpmnError.class); + gBBInput.setCustomer(null); + aaiCreateTasks.createServiceSubscription(execution); + } + + @Test + public void createVfModuleExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiVfModuleResources).createVfModule(vfModule, genericVnf); + aaiCreateTasks.createVfModule(execution); + } + + @Test + public void connectVfModuleToVolumeGroupTest() throws Exception { + doNothing().when(aaiVfModuleResources).connectVfModuleToVolumeGroup(genericVnf, vfModule, volumeGroup, cloudRegion); + aaiCreateTasks.connectVfModuleToVolumeGroup(execution); + verify(aaiVfModuleResources, times(1)).connectVfModuleToVolumeGroup(genericVnf, vfModule, volumeGroup, cloudRegion); + } + + @Test + public void createNetworkTest() throws Exception { + network.getModelInfoNetwork().setNeutronNetworkType("PROVIDER"); + + doNothing().when(aaiNetworkResources).createNetworkConnectToServiceInstance(network,serviceInstance); + aaiCreateTasks.createNetwork(execution); + verify(aaiNetworkResources, times(1)).createNetworkConnectToServiceInstance(network, serviceInstance); + } + + @Test + public void createNetworkExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + lookupKeyMap.put(ResourceKey.NETWORK_ID, "notfound"); + doThrow(Exception.class).when(aaiNetworkResources).createNetworkConnectToServiceInstance(network,serviceInstance); + aaiCreateTasks.createNetwork(execution); + } + + @Test + public void createCustomerTest() throws Exception { + doNothing().when(aaiVpnBindingResources).createCustomer(customer); + + aaiCreateTasks.createCustomer(execution); + + verify(aaiVpnBindingResources, times(1)).createCustomer(customer); + } + + @Test + public void createCustomerExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiVpnBindingResources).createCustomer(customer); + + aaiCreateTasks.createCustomer(execution); + } + + @Test + public void createNetworkCollectionTest() throws Exception { + doNothing().when(aaiNetworkResources).createNetworkCollection(serviceInstance.getCollection()); + execution.setVariable("networkCollectionName", "testNetworkCollectionName"); + aaiCreateTasks.createNetworkCollection(execution); + verify(aaiNetworkResources, times(1)).createNetworkCollection(serviceInstance.getCollection()); + } + + @Test + public void createNetworkCollectionInstanceGroupTest() throws Exception { + doNothing().when(aaiNetworkResources).createNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup()); + aaiCreateTasks.createNetworkCollectionInstanceGroup(execution); + verify(aaiNetworkResources, times(1)).createNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup()); + } + + @Test + public void connectNetworkToNetworkCollectionServiceInstanceTest() throws Exception { + doNothing().when(aaiNetworkResources).connectNetworkToNetworkCollectionServiceInstance(network, serviceInstance); + aaiCreateTasks.connectNetworkToNetworkCollectionServiceInstance(execution); + verify(aaiNetworkResources, times(1)).connectNetworkToNetworkCollectionServiceInstance(network, serviceInstance); + } + + @Test + public void connectNetworkToNetworkCollectionInstanceGroupTest() throws Exception { + doNothing().when(aaiNetworkResources).connectNetworkToNetworkCollectionInstanceGroup(network, serviceInstance.getCollection().getInstanceGroup()); + aaiCreateTasks.connectNetworkToNetworkCollectionInstanceGroup(execution); + verify(aaiNetworkResources, times(1)).connectNetworkToNetworkCollectionInstanceGroup(network, serviceInstance.getCollection().getInstanceGroup()); + } + + @Test + public void connectNetworkToNullNetworkCollectionInstanceGroupTest() throws Exception { + //reset test data to have no network collection instance group + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("testServiceInstanceId"); + L3Network network = new L3Network(); + network.setNetworkId("testNetworkId"); + serviceInstance.getNetworks().add(network); + lookupKeyMap.put(ResourceKey.NETWORK_ID, network.getNetworkId()); + gBBInput.setServiceInstance(serviceInstance); + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstance.getServiceInstanceId()); + //verify connection call was not executednetwork + exception.expect(BpmnError.class); + aaiCreateTasks.connectNetworkToNetworkCollectionInstanceGroup(execution); + verify(aaiNetworkResources, never()).connectNetworkToNetworkCollectionInstanceGroup(network, null); + } + + @Test + public void connectNetworkToCloudRegionTest() throws Exception { + gBBInput = execution.getGeneralBuildingBlock(); + doNothing().when(aaiNetworkResources).connectNetworkToCloudRegion(network, gBBInput.getCloudRegion()); + aaiCreateTasks.connectNetworkToCloudRegion(execution); + verify(aaiNetworkResources, times(1)).connectNetworkToCloudRegion(network, gBBInput.getCloudRegion()); + } + + @Test + public void connectNetworkToTenantTest() throws Exception { + gBBInput = execution.getGeneralBuildingBlock(); + doNothing().when(aaiNetworkResources).connectNetworkToTenant(network, gBBInput.getCloudRegion()); + aaiCreateTasks.connectNetworkToTenant(execution); + verify(aaiNetworkResources, times(1)).connectNetworkToTenant(network, gBBInput.getCloudRegion()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java new file mode 100644 index 0000000000..6ad263a935 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -0,0 +1,427 @@ +/*- + * ============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.aai.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +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.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.springframework.beans.factory.annotation.Autowired; + +public class AAIUpdateTasksTest extends BaseTaskTest{ + @Autowired + private AAIUpdateTasks aaiUpdateTasks; + + private L3Network network; + private ServiceInstance serviceInstance; + private VfModule vfModule; + private GenericVnf genericVnf; + private VolumeGroup volumeGroup; + private CloudRegion cloudRegion; + + @Before + public void before() { + serviceInstance = setServiceInstance(); + genericVnf = setGenericVnf(); + vfModule = setVfModule(); + volumeGroup = setVolumeGroup(); + cloudRegion = setCloudRegion(); + network = setL3Network(); + } + + @Test + public void updateOrchestrationStatusAssignedServiceTest() throws Exception { + doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED); + + aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution); + + verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED); + } + + @Test + public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED); + + aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution); + } + + @Test + public void updateOrchestrationStatusActiveServiceTest() throws Exception { + doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActiveService(execution); + + verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE); + } + + @Test + public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActiveService(execution); + } + + @Test + public void updateOrchestrationStatusAssignedVnfTest() throws Exception { + doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED); + + aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution); + + verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED); + } + + @Test + public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED); + + aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution); + } + + @Test + public void updateOrchestrationStatusActiveVnfTest() throws Exception { + doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution); + + verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE); + } + + @Test + public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution); + } + + @Test + public void updateOrchestrationStatusAssignVfModuleTest() throws Exception { + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution); + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + assertEquals("", vfModule.getHeatStackId()); + } + + @Test + public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception { + doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + + expectedException.expect(BpmnError.class); + + aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution); + } + + @Test + public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception { + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); + aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution); + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); + } + + @Test + public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception { + doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); + + expectedException.expect(BpmnError.class); + + aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution); + } + + @Test + public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception { + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION); + + aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution); + + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION); + } + + @Test + public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception { + doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION); + + expectedException.expect(BpmnError.class); + + aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution); + } + + @Test + public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception { + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); + + aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution); + + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); + } + + @Test + public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception { + doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED); + + expectedException.expect(BpmnError.class); + + aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution); + } + + @Test + public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception { + doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution); + + verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE); + } + + @Test + public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE); + aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution); + } + + @Test + public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception { + doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED); + + aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution); + + verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED); + } + + @Test + public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED); + aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution); + } + + @Test + public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception { + doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED); + + aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution); + + verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED); + assertEquals("", volumeGroup.getHeatStackId()); + } + + @Test + public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED); + aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution); + } + @Test + public void updateOstatusAssignedNetworkTest() throws Exception { + doNothing().when(aaiNetworkResources).updateNetwork(network); + + aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution); + + verify(aaiNetworkResources, times(1)).updateNetwork(network); + assertEquals("", network.getHeatStackId()); + } + + @Test + public void updateOstatusAssignedNetworkExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network); + + aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution); + } + + @Test + public void updateOstatusActivedNetworkTest() throws Exception { + doNothing().when(aaiNetworkResources).updateNetwork(network); + + aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution); + + verify(aaiNetworkResources, times(1)).updateNetwork(network); + } + + @Test + public void updateOstatusCreatedNetworkTest() throws Exception { + doNothing().when(aaiNetworkResources).updateNetwork(network); + + aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution); + + verify(aaiNetworkResources, times(1)).updateNetwork(network); + } + + @Test + public void updateOstatusActiveNetworkExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network); + + aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution); + } + + @Test + public void updateOstatusActivedNetworkCollectionTest() throws Exception { + doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection()); + aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution); + verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection()); + } + + @Test + public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection()); + aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution); + } + + @Test + public void updateOrchestrationStatusActivateVfModuleTest() throws Exception { + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution); + + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE); + } + + @Test + public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception { + doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE); + + expectedException.expect(BpmnError.class); + + aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution); + } + + @Test + public void updateNetworkCreatedTest() throws Exception { + CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); + createNetworkResponse.setNetworkFqdn("testNetworkFqdn"); + createNetworkResponse.setNetworkStackId("testNetworkStackId"); + + execution.setVariable("createNetworkResponse", createNetworkResponse); + + doNothing().when(aaiNetworkResources).updateNetwork(network); + aaiUpdateTasks.updateNetworkCreated(execution); + verify(aaiNetworkResources, times(1)).updateNetwork(network); + + assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn()); + assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus()); + assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId()); + assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId()); + } + + @Test + public void updateNetworkCreatedkExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network); + aaiUpdateTasks.updateNetworkCreated(execution); + } + + @Test + public void updateObjectNetworkTest() { + doNothing().when(aaiNetworkResources).updateNetwork(network); + + aaiUpdateTasks.updateObjectNetwork(execution); + + verify(aaiNetworkResources, times(1)).updateNetwork(network); + } + + @Test + public void updateObjectNetworkExceptionText() { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network); + + aaiUpdateTasks.updateObjectNetwork(execution); + } + + @Test + public void test_updateServiceInstance() { + doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance); + aaiUpdateTasks.updateServiceInstance(execution); + verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance); + } + + @Test + public void test_updateServiceInstance_exception() { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance); + aaiUpdateTasks.updateServiceInstance(execution); + } + + @Test + public void updateObjectVnfTest() { + doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf); + + aaiUpdateTasks.updateObjectVnf(execution); + + verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf); + } + + @Test + public void updateObjectVnfExceptionTest() { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(genericVnf); + aaiUpdateTasks.updateObjectVnf(execution); + } + + @Test + public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception { + doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + + aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution); + + verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED); + assertEquals("", vfModule.getHeatStackId()); + } + + @Test + public void updateModelVfModuleTest() { + doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf); + aaiUpdateTasks.updateModelVfModule(execution); + verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf); + } + + @Test + public void updateModelVfModuleExceptionTest() { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf); + aaiUpdateTasks.updateModelVfModule(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java new file mode 100644 index 0000000000..64760c03a0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java @@ -0,0 +1,97 @@ +/*- + * ============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.adapter.network.tasks; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Map; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.springframework.beans.factory.annotation.Autowired; + +public class NetworkAdapterCreateTasksTest extends BaseTaskTest{ + @Autowired + private NetworkAdapterCreateTasks networkAdapterCreateTasks; + + private ServiceInstance serviceInstance; + private RequestContext requestContext; + private CloudRegion cloudRegion; + private OrchestrationContext orchestrationContext; + private L3Network l3Network; + private Map<String, String> userInput; + private Customer customer; + + @Before + public void before() { + customer = setCustomer(); + serviceInstance = setServiceInstance(); + l3Network = setL3Network(); + userInput = setUserInput(); + userInput.put("userInputKey1", "userInputValue1"); + requestContext = setRequestContext(); + cloudRegion = setCloudRegion(); + orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + } + + @Test + public void createNetworkTest() throws Exception { + CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); + createNetworkResponse.setNetworkStackId("networkStackId"); + createNetworkResponse.setNetworkCreated(true); + Optional<CreateNetworkResponse> oCreateNetworkResponse = Optional.of(createNetworkResponse); + + String cloudRegionPo = "cloudRegionPo"; + execution.setVariable("cloudRegionPo", cloudRegionPo); + + doReturn(oCreateNetworkResponse).when(networkAdapterResources).createNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo,customer); + networkAdapterCreateTasks.createNetwork(execution); + verify(networkAdapterResources, times(1)).createNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo,customer); + } + + @Test + public void rollbackCreateNetworkTest() throws Exception { + CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); + createNetworkResponse.setNetworkStackId("networkStackId"); + createNetworkResponse.setNetworkCreated(true); + execution.setVariable("createNetworkResponse", createNetworkResponse); + Optional<CreateNetworkResponse> oCreateNetworkResponse = Optional.of(createNetworkResponse); + + String cloudRegionPo = "cloudRegionPo"; + execution.setVariable("cloudRegionPo", cloudRegionPo); + + doReturn(oCreateNetworkResponse).when(networkAdapterResources).rollbackCreateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, createNetworkResponse); + networkAdapterCreateTasks.rollbackCreateNetwork(execution); + verify(networkAdapterResources, times(1)).rollbackCreateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, createNetworkResponse); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java new file mode 100644 index 0000000000..88b654fd45 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java @@ -0,0 +1,82 @@ +/*- + * ============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.adapter.network.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.UnsupportedEncodingException; +import java.util.Optional; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.client.adapter.network.NetworkAdapterClientException; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.springframework.beans.factory.annotation.Autowired; + +public class NetworkAdapterDeleteTasksTest extends BaseTaskTest{ + @Autowired + private NetworkAdapterDeleteTasks networkAdapterDeleteTasks; + + private ServiceInstance serviceInstance; + private L3Network l3Network; + private RequestContext requestContext; + private CloudRegion cloudRegion; + private String cloudRegionPo; + + @Before + public void before() { + serviceInstance = setServiceInstance(); + l3Network = setL3Network(); + requestContext = setRequestContext(); + cloudRegion = setCloudRegion(); + } + + @Test + public void test_deleteNetwork() throws UnsupportedEncodingException, NetworkAdapterClientException { + + DeleteNetworkResponse deleteNetworkResponse = new DeleteNetworkResponse(); + deleteNetworkResponse.setNetworkDeleted(true); + deleteNetworkResponse.setNetworkId(l3Network.getNetworkId()); + Optional<DeleteNetworkResponse> oDeleteNetworkResponse = Optional.of(deleteNetworkResponse); + doReturn(oDeleteNetworkResponse).when(networkAdapterResources).deleteNetwork(requestContext, cloudRegion, serviceInstance, l3Network); + + networkAdapterDeleteTasks.deleteNetwork(execution); + + verify(networkAdapterResources, times(1)).deleteNetwork(requestContext, cloudRegion, serviceInstance, l3Network); + assertEquals(deleteNetworkResponse, execution.getVariable("deleteNetworkResponse")); + } + + @Test + public void test_deleteNetwork_exception() { + expectedException.expect(BpmnError.class); + + networkAdapterDeleteTasks.deleteNetwork(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java new file mode 100644 index 0000000000..6489c9b149 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java @@ -0,0 +1,101 @@ +/*- + * ============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.adapter.network.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Map; +import java.util.Optional; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.springframework.beans.factory.annotation.Autowired; + +public class NetworkAdapterUpdateTasksTest extends BaseTaskTest{ + @Autowired + private NetworkAdapterUpdateTasks networkAdapterUpdateTasks; + + private ServiceInstance serviceInstance; + private L3Network network; + private RequestContext requestContext; + private CloudRegion cloudRegion; + private OrchestrationContext orchestrationContext; + private Map<String, String> userInput; + private Customer customer; + + @Before + public void before() { + customer = setCustomer(); + serviceInstance = setServiceInstance(); + network = setL3Network(); + requestContext = setRequestContext(); + cloudRegion = setCloudRegion(); + orchestrationContext = setOrchestrationContext(); + userInput = setUserInput(); + userInput.put("userInputKey1", "userInputValue1"); + + } + + @Test + public void updateNetworkTest() throws Exception { + UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse(); + updateNetworkResponse.setMessageId("messageId"); + updateNetworkResponse.setNetworkId("networkId"); + Optional<UpdateNetworkResponse> oUpdateNetworkResponse = Optional.of(updateNetworkResponse); + + doReturn(oUpdateNetworkResponse).when(networkAdapterResources).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); + + networkAdapterUpdateTasks.updateNetwork(execution); + + verify(networkAdapterResources, times(1)).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); + assertEquals(updateNetworkResponse, execution.getVariable("NetworkAdapterUpdateNetworkResponse")); + } + + @Test + public void updateNetworkNoResponseTest() throws Exception { + doReturn(Optional.empty()).when(networkAdapterResources).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); + + networkAdapterUpdateTasks.updateNetwork(execution); + + verify(networkAdapterResources, times(1)).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); + assertNull(execution.getVariable("NetworkAdapterUpdateNetworkResponse")); + } + + @Test + public void updateNetworkExceptionTest() { + expectedException.expect(BpmnError.class); + + networkAdapterUpdateTasks.updateNetwork(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasksTest.java new file mode 100644 index 0000000000..f54e3faf1d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterCreateTasksTest.java @@ -0,0 +1,157 @@ +/*- + * ============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.adapter.vnf.tasks; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Test; +import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; +import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class VnfAdapterCreateTasksTest extends BaseTaskTest{ + @Autowired + private VnfAdapterCreateTasks vnfAdapterCreateTasks; + + @Test + public void test_createVolumeGroupRequest() throws Exception { + RequestContext requestContext = setRequestContext(); + + ServiceInstance serviceInstance = setServiceInstance(); + + GenericVnf genericVnf = setGenericVnf(); + + VfModule vfModule = setVfModule(); + vfModule.setSelflink("vfModuleSelfLink"); + VolumeGroup volumeGroup = setVolumeGroup(); + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + CloudRegion cloudRegion = setCloudRegion(); + + OrchestrationContext orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + + String sdncVnfQueryResponse = "SDNCVnfQueryResponse"; + execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncVnfQueryResponse); + + CreateVolumeGroupRequest request = new CreateVolumeGroupRequest(); + request.setVolumeGroupId("volumeGroupStackId"); + + doReturn(request).when(vnfAdapterVolumeGroupResources).createVolumeGroupRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVnfQueryResponse); + + vnfAdapterCreateTasks.createVolumeGroupRequest(execution); + + verify(vnfAdapterVolumeGroupResources, times(1)).createVolumeGroupRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVnfQueryResponse); + + assertEquals(request.toXmlString(), execution.getVariable("VNFREST_Request")); + } + + @Test + public void test_createVolumeGroupRequest_for_alaCarte_flow() throws Exception { + RequestContext requestContext = setRequestContext(); + ServiceInstance serviceInstance = setServiceInstance(); + GenericVnf genericVnf = setGenericVnf(); + VolumeGroup volumeGroup = setVolumeGroup(); + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + CloudRegion cloudRegion = setCloudRegion(); + + OrchestrationContext orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + + CreateVolumeGroupRequest request = new CreateVolumeGroupRequest(); + request.setVolumeGroupId("volumeGroupStackId"); + + doReturn(request).when(vnfAdapterVolumeGroupResources).createVolumeGroupRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, null); + + vnfAdapterCreateTasks.createVolumeGroupRequest(execution); + + verify(vnfAdapterVolumeGroupResources, times(1)).createVolumeGroupRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, null); + + assertEquals(request.toXmlString(), execution.getVariable("VNFREST_Request")); + } + + @Test + public void test_createVolumeGroupRequest_exception() throws Exception { + // run with no data setup, and it will throw a BBObjectNotFoundException + expectedException.expect(BpmnError.class); + + vnfAdapterCreateTasks.createVolumeGroupRequest(execution); + } + + @Test + public void test_createVfModule() throws Exception { + RequestContext requestContext = setRequestContext(); + + ServiceInstance serviceInstance = setServiceInstance(); + + GenericVnf genericVnf = setGenericVnf(); + + VfModule vfModule = setVfModule(); + + CloudRegion cloudRegion = setCloudRegion(); + + OrchestrationContext orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + + CreateVfModuleRequest modRequest = new CreateVfModuleRequest(); + modRequest.setVfModuleId(vfModule.getVfModuleId()); + modRequest.setBaseVfModuleStackId("baseVfModuleStackId"); + modRequest.setVfModuleName(vfModule.getVfModuleName()); + CreateVfModuleRequest createVfModuleRequest = modRequest; + + String sdncVfModuleQueryResponse = "{someJson}"; + execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncVfModuleQueryResponse); + + String sdncVnfQueryResponse = "{someJson}"; + execution.setVariable("SDNCQueryResponse_" + genericVnf.getVnfId(), sdncVnfQueryResponse); + + doReturn(createVfModuleRequest).when(vnfAdapterVfModuleResources).createVfModuleRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, + genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + vnfAdapterCreateTasks.createVfModule(execution); + + verify(vnfAdapterVfModuleResources, times(1)).createVfModuleRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, + genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + assertEquals(execution.getVariable("VNFREST_Request"), createVfModuleRequest.toXmlString()); + } + + @Test + public void createVfModuleExceptionTest() throws Exception { + // run with no data setup, and it will throw a BBObjectNotFoundException + expectedException.expect(BpmnError.class); + vnfAdapterCreateTasks.createVolumeGroupRequest(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterDeleteTasksTest.java new file mode 100644 index 0000000000..4ea11c235b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterDeleteTasksTest.java @@ -0,0 +1,115 @@ +/*- + * ============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.adapter.vnf.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.springframework.beans.factory.annotation.Autowired; + +public class VnfAdapterDeleteTasksTest extends BaseTaskTest{ + @Autowired + private VnfAdapterDeleteTasks vnfAdapterDeleteTasks; + + private VolumeGroup volumeGroup; + private VfModule vfModule; + private GenericVnf genericVnf; + private RequestContext requestContext; + private CloudRegion cloudRegion; + private ServiceInstance serviceInstance; + private OrchestrationContext orchestrationContext; + + @Before + public void before() throws Exception { + requestContext = setRequestContext(); + + serviceInstance = setServiceInstance(); + + cloudRegion = setCloudRegion(); + + genericVnf = setGenericVnf(); + + vfModule = setVfModule(); + + volumeGroup = setVolumeGroup(); + + orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + } + + @Test + public void test_deleteVfModule() throws Exception { + DeleteVfModuleRequest deleteVfModuleRequest = new DeleteVfModuleRequest(); + deleteVfModuleRequest.setVfModuleId("vfModuleId"); + + doReturn(deleteVfModuleRequest).when(vnfAdapterVfModuleResources).deleteVfModuleRequest(requestContext, cloudRegion, serviceInstance, genericVnf, vfModule); + + vnfAdapterDeleteTasks.deleteVfModule(execution); + + verify(vnfAdapterVfModuleResources, times(1)).deleteVfModuleRequest(requestContext, cloudRegion, serviceInstance, genericVnf, vfModule); + assertEquals(execution.getVariable("VNFREST_Request"), deleteVfModuleRequest.toXmlString()); + } + + @Test + public void deleteVfModuleExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(vnfAdapterVfModuleResources).deleteVfModuleRequest(requestContext, cloudRegion, serviceInstance, genericVnf, vfModule); + + vnfAdapterDeleteTasks.deleteVfModule(execution); + } + + @Test + public void test_deleteVolumeGroup() throws Exception { + DeleteVolumeGroupResponse deleteVolumeGroupResponse = new DeleteVolumeGroupResponse(); + + doReturn(deleteVolumeGroupResponse).when(vnfAdapterVolumeGroupResources).deleteVolumeGroup(requestContext, cloudRegion, serviceInstance, volumeGroup); + + vnfAdapterDeleteTasks.deleteVolumeGroup(execution); + + verify(vnfAdapterVolumeGroupResources, times(1)).deleteVolumeGroup(requestContext, cloudRegion, serviceInstance, volumeGroup); + } + + @Test + public void deleteVolumeGroupExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(vnfAdapterVolumeGroupResources).deleteVolumeGroup(requestContext, cloudRegion, serviceInstance, volumeGroup); + + vnfAdapterDeleteTasks.deleteVolumeGroup(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java new file mode 100644 index 0000000000..24a99c97f4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterImplTest.java @@ -0,0 +1,169 @@ +/*- + * ============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.adapter.vnf.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.FileUtil; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +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.springframework.beans.factory.annotation.Autowired; + +public class VnfAdapterImplTest extends BaseTaskTest { + @Autowired + private VnfAdapterImpl vnfAdapterImpl; + + private RequestContext requestContext; + private ServiceInstance serviceInstance; + private VfModule vfModule; + private VolumeGroup volumeGroup; + + private static final String VNF_ADAPTER_REST_DELETE_RESPONSE = FileUtil.readResourceFile("__files/VfModularity/VNFAdapterRestDeleteResponse.xml"); + private static final String VNF_ADAPTER_REST_CREATE_RESPONSE = FileUtil.readResourceFile("__files/VfModularity/VNFAdapterRestCreateCallback.xml"); + private static final String VNF_ADAPTER_VOLUME_CREATE_RESPONSE = FileUtil.readResourceFile("__files/VfModularity/CreateVfModuleVolumeCallbackResponse.xml"); + private static final String TEST_VFMODULE_HEATSTACK_ID = "slowburn"; + private static final String TEST_VOLUME_HEATSTACK_ID = "testHeatStackId1"; + + @Before + public void before() { + requestContext = setRequestContext(); + serviceInstance = setServiceInstance(); + vfModule = setVfModule(); + volumeGroup = setVolumeGroup(); + vfModule.setHeatStackId(null); + } + + @Test + public void preProcessVnfAdapterTest() { + vnfAdapterImpl.preProcessVnfAdapter(execution); + + assertEquals("true", execution.getVariable("isDebugLogEnabled")); + assertEquals(requestContext.getMsoRequestId(), execution.getVariable("mso-request-id")); + assertEquals(serviceInstance.getServiceInstanceId(), execution.getVariable("mso-service-instance-id")); + } + + @Test + public void postProcessVnfAdapter_CreateResponseTest() { + execution.setVariable("vnfAdapterRestV1Response", VNF_ADAPTER_REST_CREATE_RESPONSE); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertEquals(TEST_VFMODULE_HEATSTACK_ID, vfModule.getHeatStackId()); + } + + + @Test + public void postProcessVnfAdapter_CreateResponseTest_EmptyCreateVfModuleResponseTag() { + expectedException.expect(BpmnError.class); + execution.setVariable("vnfAdapterRestV1Response", "<vfModuleStackId></vfModuleStackId>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + } + + @Test + public void postProcessVnfAdapter_CreateResponseTest_EmptyVfModuleStackIdTag() { + execution.setVariable("vnfAdapterRestV1Response", "<createVfModuleResponse></createVfModuleResponse>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + } + + @Test + public void postProcessVnfAdapter_CreateResponseTest_EmptyHeatStackId() { + execution.setVariable("vnfAdapterRestV1Response", "<createVfModuleResponse><vfModuleStackId></vfModuleStackId></createVfModuleResponse>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + } + + @Test + public void postProcessVnfAdapter_DeleteResponseTest() { + execution.setVariable("vnfAdapterRestV1Response", VNF_ADAPTER_REST_DELETE_RESPONSE); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + } + + @Test + public void postProcessVnfAdapter_ResponseNullTest() { + execution.setVariable("vnfAdapterRestV1Response", null); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + } + + @Test + public void postProcessVnfAdapter_ResponseEmptyTest() { + execution.setVariable("vnfAdapterRestV1Response", ""); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + } + + @Test + public void postProcessVnfAdapter_DeleteResponseTest_VfModuleDeletedFalse() { + execution.setVariable("vnfAdapterRestV1Response", "<deleteVfModuleResponse><vfModuleDeleted>false</vfModuleDeleted></deleteVfModuleResponse>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + } + + @Test + public void postProcessVnfAdapter_DeleteResponseTest_EmptyDeleteVfModuleResponseTag() { + expectedException.expect(BpmnError.class); + execution.setVariable("vnfAdapterRestV1Response", "<vfModuleDeleted></vfModuleDeleted>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + } + + @Test + public void postProcessVnfAdapter_DeleteResponseTest_EmptyVfModuleDeletedTag() { + execution.setVariable("vnfAdapterRestV1Response", "<deleteVfModuleResponse></deleteVfModuleResponse>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertNull(vfModule.getHeatStackId()); + } + + @Test + public void preProcessVnfAdapterExceptionTest() { + expectedException.expect(BpmnError.class); + lookupKeyMap.clear(); + vnfAdapterImpl.preProcessVnfAdapter(execution); + } + + @Test + public void postProcessVnfAdapter_CreateVolumeResponseTest() { + execution.setVariable("vnfAdapterRestV1Response", VNF_ADAPTER_VOLUME_CREATE_RESPONSE); + vnfAdapterImpl.postProcessVnfAdapter(execution); + assertEquals(TEST_VOLUME_HEATSTACK_ID, volumeGroup.getHeatStackId()); + } + + @Test + public void postProcessVnfAdapter_CreateVolumeEmptyResponseTest() { + expectedException.expect(BpmnError.class); + execution.setVariable("vnfAdapterRestV1Response", "<createVolumeGroupResponse></createVolumeGroupResponse>"); + vnfAdapterImpl.postProcessVnfAdapter(execution); + } + + @Test + public void postProcessVnfAdapterExceptionTest() { + execution.setVariable("vnfAdapterRestV1Response", VNF_ADAPTER_REST_CREATE_RESPONSE); + expectedException.expect(BpmnError.class); + lookupKeyMap.clear(); + vnfAdapterImpl.postProcessVnfAdapter(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetworkBBUtilsTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetworkBBUtilsTest.java new file mode 100644 index 0000000000..dff953802e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetworkBBUtilsTest.java @@ -0,0 +1,59 @@ +/*- + * ============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.flowspecific.tasks; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; + +public class AssignNetworkBBUtilsTest extends BaseTaskTest { + //Necessary because AssignNetworkBBUtils is already mocked using MockBean in the base class for use in other tests + private AssignNetworkBBUtils nonMockAssignNetworkBBUtils = new AssignNetworkBBUtils(); + + private CloudRegion cloudRegion; + + @Before + public void before() { + cloudRegion = setCloudRegion(); + } + + @Test + public void getCloudRegionTest25() throws Exception { + cloudRegion.setCloudRegionVersion("2.5"); + + nonMockAssignNetworkBBUtils.getCloudRegion(execution); + + assertEquals(cloudRegion.getLcpCloudRegionId(), execution.getVariable("cloudRegionPo")); + assertEquals("AAIAIC25", execution.getVariable("cloudRegionSdnc")); + } + + @Test + public void getCloudRegionTest30() throws Exception { + cloudRegion.setCloudRegionVersion("3.0"); + + nonMockAssignNetworkBBUtils.getCloudRegion(execution); + + assertEquals(cloudRegion.getLcpCloudRegionId(), execution.getVariable("cloudRegionPo")); + assertEquals(cloudRegion.getLcpCloudRegionId(), execution.getVariable("cloudRegionSdnc")); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetworkTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetworkTest.java new file mode 100644 index 0000000000..a206140014 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetworkTest.java @@ -0,0 +1,115 @@ +/*- + * ============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.flowspecific.tasks; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.springframework.beans.factory.annotation.Autowired; + +public class AssignNetworkTest extends BaseTaskTest { + + @Autowired + private AssignNetwork assignNetwork; + + private ServiceInstance serviceInstance; + private L3Network network; + + @Before + public void before() { + serviceInstance = setServiceInstance(); + network = setL3Network(); + } + + @Test + public void hasCollectionTest() throws Exception { + setServiceInstance(); + //collection present by default base test setup + boolean hasCollection = assignNetwork.hasCollection(execution); + assertEquals(true, hasCollection); + + boolean skip = assignNetwork.skipNetworkCreationInAAI(execution); + assertEquals(false, skip); + } + + @Test + public void hasNoCollectionTest() throws Exception { + //clear collection + try { + serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + } catch(BBObjectNotFoundException e) { + serviceInstance = setServiceInstance(); + } + serviceInstance.setCollection(null); + boolean hasCollection = assignNetwork.hasCollection(execution); + assertEquals(false, hasCollection); + + boolean skip = assignNetwork.skipNetworkCreationInAAI(execution); + assertEquals(true, skip); + } + + @Test + public void hasNoCollectionNoNetworkTest() throws Exception { + //clear collection and updated network status to PRECREATED - when it was NOT found by name + try { + serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,execution.getLookupMap().get(ResourceKey.NETWORK_ID)); + } catch(BBObjectNotFoundException e) { + serviceInstance = setServiceInstance(); + } + serviceInstance.setCollection(null); + network.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + boolean hasCollection = assignNetwork.hasCollection(execution); + boolean networkFound = assignNetwork.networkFoundByName(execution); + assertEquals(false, hasCollection); + assertEquals(false, networkFound); + + boolean skip = assignNetwork.skipNetworkCreationInAAI(execution); + assertEquals(true, skip); + } + + @Test + public void hasNetworkNoCollectionTest() throws Exception { + //clear collection and updated network status to INVENTORIED - when it was found by name + try { + serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,execution.getLookupMap().get(ResourceKey.NETWORK_ID)); + } catch(BBObjectNotFoundException e) { + serviceInstance = setServiceInstance(); + } + serviceInstance.setCollection(null); + network.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); + boolean hasCollection = assignNetwork.hasCollection(execution); + boolean networkFound = assignNetwork.networkFoundByName(execution); + assertEquals(false, hasCollection); + assertEquals(true, networkFound); + + boolean skip = assignNetwork.skipNetworkCreationInAAI(execution); + assertEquals(true, skip); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignVnfTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignVnfTest.java new file mode 100644 index 0000000000..e1b652a140 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignVnfTest.java @@ -0,0 +1,110 @@ +/*- + * ============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.flowspecific.tasks; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.List; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup; +import org.springframework.beans.factory.annotation.Autowired; + +public class AssignVnfTest extends BaseTaskTest { + @Autowired + private AssignVnf assignVnf; + + private InstanceGroup instanceGroup1; + private InstanceGroup instanceGroup2; + private InstanceGroup instanceGroup3; + private InstanceGroup instanceGroup4; + private GenericVnf genericVnf; + + @Before + public void before() { + ModelInfoInstanceGroup modelVnfc = new ModelInfoInstanceGroup(); + modelVnfc.setType("VNFC"); + modelVnfc.setFunction("function"); + + ModelInfoInstanceGroup modelNetworkInstanceGroup = new ModelInfoInstanceGroup(); + modelNetworkInstanceGroup.setType("networkInstanceGroup"); + modelNetworkInstanceGroup.setFunction("function"); + + instanceGroup1 = new InstanceGroup(); + instanceGroup1.setId("test-001"); + instanceGroup1.setModelInfoInstanceGroup(modelVnfc); + + instanceGroup2 = new InstanceGroup(); + instanceGroup2.setId("test-002"); + instanceGroup2.setModelInfoInstanceGroup(modelVnfc); + + instanceGroup3 = new InstanceGroup(); + instanceGroup3.setId("test-003"); + instanceGroup3.setModelInfoInstanceGroup(modelNetworkInstanceGroup); + + instanceGroup4 = new InstanceGroup(); + instanceGroup4.setId("test-004"); + instanceGroup4.setModelInfoInstanceGroup(modelNetworkInstanceGroup); + + genericVnf = setGenericVnf(); + genericVnf.setVnfName("vnfName"); + } + + @Test + public void createInstanceGroupsSunnyDayTest() throws Exception { + + List<InstanceGroup> instanceGroupList = genericVnf.getInstanceGroups(); + instanceGroupList.add(instanceGroup1); + instanceGroupList.add(instanceGroup2); + instanceGroupList.add(instanceGroup3); + instanceGroupList.add(instanceGroup4); + + assignVnf.createInstanceGroups(execution); + verify(aaiInstanceGroupResources, times(1)).createInstanceGroup(instanceGroup1); + verify(aaiInstanceGroupResources, times(1)).createInstanceGroup(instanceGroup2); + verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup1, genericVnf); + verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup2, genericVnf); + verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup3, genericVnf); + verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup4, genericVnf); + } + + @Test + public void createVnfcInstanceGroupNoneTest() throws Exception { + assignVnf.createInstanceGroups(execution); + verify(aaiInstanceGroupResources, times(0)).createInstanceGroup(any(InstanceGroup.class)); + verify(aaiInstanceGroupResources, times(0)).connectInstanceGroupToVnf(any(InstanceGroup.class), any(GenericVnf.class)); + } + + @Test + public void createVnfcInstanceGroupExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + genericVnf.setVnfId("test-999"); + assignVnf.createInstanceGroups(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollectionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollectionTest.java new file mode 100644 index 0000000000..cde7797ed0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollectionTest.java @@ -0,0 +1,95 @@ +/*- + * ============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.flowspecific.tasks; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.ArrayList; +import java.util.List; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup; +import org.springframework.beans.factory.annotation.Autowired; + +public class CreateNetworkCollectionTest extends BaseTaskTest{ + @Autowired + private CreateNetworkCollection createNetworkCollection; + + private L3Network network; + private ServiceInstance serviceInstance; + private OrchestrationContext orchestrationContext; + + @Before + public void before() { + serviceInstance = setServiceInstance(); + network = setL3Network(); + + List<L3Network> l3NetworkList = new ArrayList<L3Network>(); + l3NetworkList.add(network); + ModelInfoInstanceGroup modelInfoInstanceGroup = new ModelInfoInstanceGroup(); + modelInfoInstanceGroup.setFunction("function"); + serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(modelInfoInstanceGroup); + + orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + } + + @Test + public void buildCreateNetworkRequestTest() throws Exception { + createNetworkCollection.buildNetworkCollectionName(execution); + + assertEquals(serviceInstance.getServiceInstanceName() + "_" + serviceInstance.getCollection().getInstanceGroup().getModelInfoInstanceGroup().getFunction(), execution.getVariable("networkCollectionName")); + } + + @Test(expected = BpmnError.class) + public void buildCreateNetworkRequestInstanceGroupModelInfoFunctionNullExceptionTest() throws Exception { + ModelInfoInstanceGroup modelInfoInstanceGroup = new ModelInfoInstanceGroup(); + serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(modelInfoInstanceGroup); + createNetworkCollection.buildNetworkCollectionName(execution); + } + + @Test(expected = BpmnError.class) + public void buildCreateNetworkRequestInstanceGroupModelInfoNullTest() throws Exception { + serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(null); + createNetworkCollection.buildNetworkCollectionName(execution); + } + + @Test + public void connectCollectionToInstanceGroupTest() throws Exception { + doNothing().when(aaiNetworkResources).connectNetworkCollectionInstanceGroupToNetworkCollection(serviceInstance.getCollection().getInstanceGroup(), serviceInstance.getCollection()); + createNetworkCollection.connectCollectionToInstanceGroup(execution); + verify(aaiNetworkResources, times(1)).connectNetworkCollectionInstanceGroupToNetworkCollection(serviceInstance.getCollection().getInstanceGroup(), serviceInstance.getCollection()); + } + + @Test + public void connectCollectionToServiceInstanceTest() throws Exception { + doNothing().when(aaiNetworkResources).connectNetworkCollectionToServiceInstance(serviceInstance.getCollection(), serviceInstance); + createNetworkCollection.connectCollectionToServiceInstance(execution); + verify(aaiNetworkResources, times(1)).connectNetworkCollectionToServiceInstance(serviceInstance.getCollection(), serviceInstance); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkTest.java new file mode 100644 index 0000000000..f23df3312f --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkTest.java @@ -0,0 +1,84 @@ +/*- + * ============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.flowspecific.tasks; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.nwrest.CreateNetworkRequest; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.springframework.beans.factory.annotation.Autowired; + +public class CreateNetworkTest extends BaseTaskTest{ + @Autowired + private CreateNetwork createNetwork; + + private L3Network network; + private ServiceInstance serviceInstance; + private CloudRegion cloudRegion; + private OrchestrationContext orchestrationContext; + private Map<String, String> userInput; + private RequestContext requestContext; + private String cloudRegionPo = "testCloudRegionPo"; + private Customer customer; + + @Before + public void before() { + customer = setCustomer(); + serviceInstance = setServiceInstance(); + network = setL3Network(); + cloudRegion = setCloudRegion(); + orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + requestContext = setRequestContext(); + userInput = setUserInput(); + + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + } + + @Test + public void buildCreateNetworkRequestTest() throws Exception { + execution.setVariable("cloudRegionPo", cloudRegionPo); + + CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest(); + + doReturn(expectedCreateNetworkRequest).when(networkAdapterObjectMapper).createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, cloudRegionPo, customer); + + createNetwork.buildCreateNetworkRequest(execution); + + verify(networkAdapterObjectMapper, times(1)).createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, cloudRegionPo, customer); + + assertThat(expectedCreateNetworkRequest, sameBeanAs(execution.getVariable("createNetworkRequest"))); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/NetworkBBUtilsTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/NetworkBBUtilsTest.java new file mode 100644 index 0000000000..4966a8b42d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/NetworkBBUtilsTest.java @@ -0,0 +1,118 @@ +/*- + * ============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.flowspecific.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.aai.domain.yang.L3Network; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.springframework.beans.factory.annotation.Autowired; + +public class NetworkBBUtilsTest extends BaseTaskTest{ + @Autowired + private NetworkBBUtils networkBBUtils; + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/Network/"; + + private CloudRegion cloudRegion; + + @Before + public void before() { + cloudRegion = setCloudRegion(); + } + + @Test + public void isRelationshipRelatedToExistsTrueTest() throws Exception { + final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse); + Optional<L3Network> l3network = aaiResultWrapper.asBean(L3Network.class); + + boolean isVfModule = networkBBUtils.isRelationshipRelatedToExists(l3network, "vf-module"); + assertTrue(isVfModule); + + } + + @Test + public void isRelationshipRelatedToExistsFalseTest() throws Exception { + final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAAIResponse.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse); + Optional<L3Network> l3network = aaiResultWrapper.asBean(L3Network.class); + + boolean isVfModule = networkBBUtils.isRelationshipRelatedToExists(l3network, "vf-module"); + assertFalse(isVfModule); + + } + + @Test + public void getCloudRegionSDNC25Test() throws Exception { + cloudRegion.setCloudRegionVersion("2.5"); + + NetworkBBUtils spyAssign = Mockito.spy(NetworkBBUtils.class); + String cloudRegionId = spyAssign.getCloudRegion(execution, SourceSystem.SDNC); + Mockito.verify(spyAssign).getCloudRegion(execution, SourceSystem.SDNC); + + assertEquals("AAIAIC25", cloudRegionId); + } + + @Test + public void getCloudRegionSDNC30Test() throws Exception { + cloudRegion.setCloudRegionVersion("3.0"); + + NetworkBBUtils spyAssign = Mockito.spy(NetworkBBUtils.class); + String cloudRegionId = spyAssign.getCloudRegion(execution, SourceSystem.SDNC); + Mockito.verify(spyAssign).getCloudRegion(execution, SourceSystem.SDNC); + + assertEquals(cloudRegion.getLcpCloudRegionId(), cloudRegionId); + } + + @Test + public void getCloudRegionPO25Test() throws Exception { + cloudRegion.setCloudRegionVersion("2.5"); + + NetworkBBUtils spyAssign = Mockito.spy(NetworkBBUtils.class); + String cloudRegionId = spyAssign.getCloudRegion(execution, SourceSystem.PO); + Mockito.verify(spyAssign).getCloudRegion(execution, SourceSystem.PO); + + assertEquals(cloudRegion.getLcpCloudRegionId(), cloudRegionId); + } + + @Test + public void getCloudRegionPO30Test() throws Exception { + cloudRegion.setCloudRegionVersion("3.0"); + + NetworkBBUtils spyAssignPO = Mockito.spy(NetworkBBUtils.class); + String cloudRegionIdPO = spyAssignPO.getCloudRegion(execution, SourceSystem.PO); + Mockito.verify(spyAssignPO).getCloudRegion(execution, SourceSystem.PO); + + assertEquals(cloudRegion.getLcpCloudRegionId(), cloudRegionIdPO); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBBTest.java new file mode 100644 index 0000000000..6a117902ea --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBBTest.java @@ -0,0 +1,92 @@ +/*- + * ============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.flowspecific.tasks; + +import static org.junit.Assert.assertEquals; + +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.springframework.beans.factory.annotation.Autowired; + +public class UnassignNetworkBBTest extends BaseTaskTest { + @Autowired + private UnassignNetworkBB unassignNetworkBB; + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/Network/"; + + @Test + public void checkRelationshipRelatedToTrueTest() throws Exception { + expectedException.expect(BpmnError.class); + final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse); + execution.setVariable("l3NetworkAAIResultWrapper", aaiResultWrapper); + + unassignNetworkBB.checkRelationshipRelatedTo(execution, "vf-module"); + } + + @Test + public void checkRelationshipRelatedToFalseTest() throws Exception { + final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse); + execution.setVariable("l3NetworkAAIResultWrapper", aaiResultWrapper); + + unassignNetworkBB.checkRelationshipRelatedTo(execution, "kfc-module"); + //expected result is no exception + } + + @Test + public void getCloudSdncRegion25Test() throws Exception { + CloudRegion cloudRegion = setCloudRegion(); + cloudRegion.setCloudRegionVersion("2.5"); + unassignNetworkBB.getCloudSdncRegion(execution); + assertEquals("AAIAIC25", execution.getVariable("cloudRegionSdnc")); + } + + @Test + public void getCloudSdncRegion30Test() throws Exception { + CloudRegion cloudRegion = setCloudRegion(); + cloudRegion.setCloudRegionVersion("3.0"); + gBBInput.setCloudRegion(cloudRegion); + unassignNetworkBB.getCloudSdncRegion(execution); + assertEquals(cloudRegion.getLcpCloudRegionId(), execution.getVariable("cloudRegionSdnc")); + } + + @Test + public void errorEncounteredTest_rollback() throws Exception { + expectedException.expect(BpmnError.class); + execution.setVariable("ErrorUnassignNetworkBB", "Relationship's RelatedTo still exists in AAI, remove the relationship vf-module first."); + execution.setVariable("isRollbackNeeded", true); + unassignNetworkBB.errorEncountered(execution); + } + + @Test + public void errorEncounteredTest_noRollback() throws Exception { + expectedException.expect(BpmnError.class); + execution.setVariable("ErrorUnassignNetworkBB", "Relationship's RelatedTo still exists in AAI, remove the relationship vf-module first."); + unassignNetworkBB.errorEncountered(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignVnfTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignVnfTest.java new file mode 100644 index 0000000000..98c1f185fe --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignVnfTest.java @@ -0,0 +1,67 @@ +/*- + * ============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.flowspecific.tasks; + +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup; +import org.springframework.beans.factory.annotation.Autowired; + +public class UnassignVnfTest extends BaseTaskTest{ + @Autowired + private UnassignVnf unassignVnf; + + @Test + public void deleteInstanceGroupsSunnyDayTest() throws Exception { + GenericVnf genericVnf = setGenericVnf(); + + ModelInfoInstanceGroup modelVnfc = new ModelInfoInstanceGroup(); + modelVnfc.setType("VNFC"); + + InstanceGroup instanceGroup1 = new InstanceGroup(); + instanceGroup1.setId("test-001"); + instanceGroup1.setModelInfoInstanceGroup(modelVnfc); + genericVnf.getInstanceGroups().add(instanceGroup1); + + InstanceGroup instanceGroup2 = new InstanceGroup(); + instanceGroup2.setId("test-002"); + instanceGroup2.setModelInfoInstanceGroup(modelVnfc); + genericVnf.getInstanceGroups().add(instanceGroup2); + + unassignVnf.deleteInstanceGroups(execution); + verify(aaiInstanceGroupResources, times(1)).deleteInstanceGroup(eq(instanceGroup1)); + verify(aaiInstanceGroupResources, times(1)).deleteInstanceGroup(eq(instanceGroup2)); + } + + @Test + public void deletecreateVnfcInstanceGroupExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + unassignVnf.deleteInstanceGroups(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTaskTest.java new file mode 100644 index 0000000000..d3b421eedb --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCActivateTaskTest.java @@ -0,0 +1,116 @@ +/*- + * ============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.tasks; + +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +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.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.springframework.beans.factory.annotation.Autowired; + + +public class SDNCActivateTaskTest extends BaseTaskTest{ + @Autowired + private SDNCActivateTasks sdncActivateTasks; + + private L3Network network; + private ServiceInstance serviceInstance; + private RequestContext requestContext; + private CloudRegion cloudRegion; + private GenericVnf genericVnf; + private VfModule vfModule; + private Customer customer; + + @Before + public void before() { + serviceInstance = setServiceInstance(); + network = setL3Network(); + genericVnf = setGenericVnf(); + vfModule = setVfModule(); + cloudRegion = setCloudRegion(); + requestContext = setRequestContext(); + customer = setCustomer(); + + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + + } + + @Test + public void activateVnfTest() throws Exception { + doReturn("success").when(sdncVnfResources).activateVnf(genericVnf,serviceInstance, customer, cloudRegion,requestContext); + sdncActivateTasks.activateVnf(execution); + verify(sdncVnfResources, times(1)).activateVnf(genericVnf,serviceInstance, customer,cloudRegion,requestContext); + } + + @Test + public void activateVnfTestException() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncVnfResources).activateVnf(genericVnf,serviceInstance, customer,cloudRegion,requestContext); + sdncActivateTasks.activateVnf(execution); + } + + @Test + public void activateNetworkTest() throws Exception { + doReturn("response").when(sdncNetworkResources).activateNetwork(isA(L3Network.class), isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class), isA(CloudRegion.class)); + sdncActivateTasks.activateNetwork(execution); + verify(sdncNetworkResources, times(1)).activateNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + } + + @Test + public void activateNetworkExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncNetworkResources).activateNetwork(isA(L3Network.class), isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class), isA(CloudRegion.class)); + sdncActivateTasks.activateNetwork(execution); + } + + @Test + public void activateVfModuleTest() throws Exception { + doReturn("success").when(sdncVfModuleResources).activateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + sdncActivateTasks.activateVfModule(execution); + + verify(sdncVfModuleResources, times(1)).activateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + } + + @Test + public void activateVfModuleTestException() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncVfModuleResources).activateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + sdncActivateTasks.activateVfModule(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java new file mode 100644 index 0000000000..6a40db3eaa --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCAssignTasksTest.java @@ -0,0 +1,144 @@ +/*- + * ============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.tasks; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +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.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +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.springframework.beans.factory.annotation.Autowired; + + +public class SDNCAssignTasksTest extends BaseTaskTest{ + @Autowired + private SDNCAssignTasks sdncAssignTasks; + + private L3Network network; + private ServiceInstance serviceInstance; + private RequestContext requestContext; + private CloudRegion cloudRegion; + private GenericVnf genericVnf; + private VfModule vfModule; + private VolumeGroup volumeGroup; + private Customer customer; + + @Before + public void before() { + customer = setCustomer(); + serviceInstance = setServiceInstance(); + network = setL3Network(); + cloudRegion = setCloudRegion(); + requestContext = setRequestContext(); + genericVnf = setGenericVnf(); + vfModule = setVfModule(); + volumeGroup = setVolumeGroup(); + + } + + @Test + public void assignServiceInstanceTest() throws Exception { + doReturn("response").when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext); + + sdncAssignTasks.assignServiceInstance(execution); + + verify(sdncServiceInstanceResources, times(1)).assignServiceInstance(serviceInstance, customer, requestContext); + assertTrue(execution.getVariable("SDNCResponse").equals("response")); + } + + @Test + public void assignServiceInstanceExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncServiceInstanceResources).assignServiceInstance(serviceInstance, customer, requestContext); + + sdncAssignTasks.assignServiceInstance(execution); + } + + @Test + public void assignVnfTest() throws Exception { + doReturn("response").when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false); + + sdncAssignTasks.assignVnf(execution); + + verify(sdncVnfResources, times(1)).assignVnf(genericVnf, serviceInstance,customer, cloudRegion, requestContext, false); + assertTrue(execution.getVariable("SDNCResponse").equals("response")); + } + + @Test + public void assignVnfExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncVnfResources).assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false); + + sdncAssignTasks.assignVnf(execution); + } + + @Test + public void assignVfModuleTest() throws Exception { + doReturn("response").when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + sdncAssignTasks.assignVfModule(execution); + + verify(sdncVfModuleResources, times(1)).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + assertTrue(execution.getVariable("SDNCAssignResponse_" + vfModule.getVfModuleId()).equals("response")); + } + + @Test + public void assignVfModuleExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncVfModuleResources).assignVfModule(vfModule, volumeGroup, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + sdncAssignTasks.assignVfModule(execution); + } + + @Test + public void assignNetworkTest() throws Exception { + doReturn("response").when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + sdncAssignTasks.assignNetwork(execution); + + verify(sdncNetworkResources, times(1)).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + } + + @Test + public void assignNetworkExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncNetworkResources).assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + sdncAssignTasks.assignNetwork(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasksTest.java new file mode 100644 index 0000000000..fc2d182b52 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCChangeAssignTasksTest.java @@ -0,0 +1,100 @@ +/*- + * ============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.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +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.VfModule; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.springframework.beans.factory.annotation.Autowired; + +public class SDNCChangeAssignTasksTest extends BaseTaskTest{ + @Autowired + private SDNCChangeAssignTasks sdncChangeAssignTasks; + + private ServiceInstance serviceInstance; + private RequestContext requestContext; + private CloudRegion cloudRegion; + private VfModule vfModule; + private GenericVnf genericVnf; + private Customer customer; + + @Before + public void before() { + customer = setCustomer(); + serviceInstance = setServiceInstance(); + genericVnf = setGenericVnf(); + vfModule = setVfModule(); + cloudRegion = setCloudRegion(); + requestContext = setRequestContext(); + + } + + @Test + public void changeModelVnfTest() throws Exception { + String response = "sdncChangeModelServiceInstance"; + + doReturn(response).when(sdncServiceInstanceResources).changeModelServiceInstance(serviceInstance, customer, requestContext); + + sdncChangeAssignTasks.changeModelServiceInstance(execution); + + verify(sdncServiceInstanceResources, times(1)).changeModelServiceInstance(serviceInstance, customer, requestContext); + + assertEquals(response, execution.getVariable("SDNCChangeAssignTasks.changeModelServiceInstance.response")); + } + + @Test + public void changeModelVnfExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(sdncVnfResources).changeModelVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + sdncChangeAssignTasks.changeModelVnf(execution); + } + + @Test + public void changeAssignModelVfModuleTest() throws Exception { + String response = "response"; + doReturn(response).when(sdncVfModuleResources).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + sdncChangeAssignTasks.changeAssignModelVfModule(execution); + + verify(sdncVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + assertTrue(execution.getVariable("SDNCChangeAssignVfModuleResponse").equals(response)); + } + + @Test + public void changeAssignModelVfModuleExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(sdncVfModuleResources).changeAssignVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + sdncChangeAssignTasks.changeAssignModelVfModule(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTaskTest.java new file mode 100644 index 0000000000..ed281ce317 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCDeactivateTaskTest.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.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +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.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.springframework.beans.factory.annotation.Autowired; + +public class SDNCDeactivateTaskTest extends BaseTaskTest { + @Autowired + private SDNCDeactivateTasks sdncDeactivateTasks; + + private ServiceInstance serviceInstance; + private CloudRegion cloudRegion; + private RequestContext requestContext; + private GenericVnf genericVnf; + private VfModule vfModule; + private L3Network network; + private Customer customer; + + @Before + public void before() { + customer = setCustomer(); + serviceInstance = setServiceInstance(); + cloudRegion = setCloudRegion(); + requestContext = setRequestContext(); + genericVnf = setGenericVnf(); + vfModule = setVfModule(); + network = setL3Network(); + + } + + @Test + public void deactivateVfModuleTest() throws Exception { + doReturn("success").when(sdncVfModuleResources).deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + sdncDeactivateTasks.deactivateVfModule(execution); + + verify(sdncVfModuleResources, times(1)).deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + } + + @Test + public void deactivateVfModuleExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncVfModuleResources).deactivateVfModule(vfModule, genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + sdncDeactivateTasks.deactivateVfModule(execution); + } + + @Test + public void deactivateVnfTest() throws Exception { + doReturn("success").when(sdncVnfResources).deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + sdncDeactivateTasks.deactivateVnf(execution); + + verify(sdncVnfResources, times(1)).deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + } + + @Test + public void deactivateVnfExceptionTest() throws Exception { + doThrow(Exception.class).when(sdncVnfResources).deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + expectedException.expect(BpmnError.class); + sdncDeactivateTasks.deactivateVnf(execution); + } + + @Test + public void deactivateServiceInstanceTest() throws Exception { + doReturn("response").when(sdncServiceInstanceResources).deactivateServiceInstance(serviceInstance, customer, requestContext); + + sdncDeactivateTasks.deactivateServiceInstance(execution); + + verify(sdncServiceInstanceResources, times(1)).deactivateServiceInstance(serviceInstance, customer, requestContext); + assertEquals("response", execution.getVariable("deactivateServiceInstanceSDNCResponse")); + assertTrue(execution.getVariable("sdncServiceInstanceRollback")); + } + + @Test + public void deactivateServiceInstanceExceptionTest() throws Exception { + doThrow(Exception.class).when(sdncServiceInstanceResources).deactivateServiceInstance(serviceInstance, customer, requestContext); + expectedException.expect(BpmnError.class); + sdncDeactivateTasks.deactivateServiceInstance(execution); + } + + @Test + public void test_deactivateNetwork() throws Exception { + String expectedResponse = "return"; + + doReturn(expectedResponse).when(sdncNetworkResources).deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + sdncDeactivateTasks.deactivateNetwork(execution); + + verify(sdncNetworkResources, times(1)).deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + assertEquals(expectedResponse, execution.getVariable("SDNCDeactivateTasks.deactivateNetwork.response")); + + assertTrue(execution.getVariable("SDNCDeactivateTasks.deactivateNetwork.rollback")); + } + + @Test + public void test_deactivateNetwork_exception() throws Exception { + expectedException.expect(BpmnError.class); + + try { + lookupKeyMap.remove(ResourceKey.NETWORK_ID); + + sdncDeactivateTasks.deactivateNetwork(execution); + } finally { + verify(sdncNetworkResources, times(0)).deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + assertNull(execution.getVariable("SDNCDeactivateTasks.deactivateNetwork.response")); + + assertFalse(execution.getVariable("SDNCDeactivateTasks.deactivateNetwork.rollback")); + } + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java new file mode 100644 index 0000000000..b98ab71d1d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java @@ -0,0 +1,121 @@ +/*- + * ============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.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.springframework.beans.factory.annotation.Autowired; + +public class SDNCQueryTasksTest extends BaseTaskTest{ + @Autowired + private SDNCQueryTasks sdncQueryTasks; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private GenericVnf genericVnf; + private VfModule vfModule; + + @Before + public void before() { + genericVnf = setGenericVnf(); + vfModule = setVfModule(); + } + + @Test + public void queryVfModuleTest() throws Exception { + String sdncQueryResponse = "response"; + vfModule.setSelflink("vfModuleSelfLink"); + + doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule); + + assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId())); + sdncQueryTasks.queryVfModule(execution); + assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId())); + + verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule); + } + + @Test + public void queryVnfTest() throws Exception { + String sdncQueryResponse = "response"; + + doReturn(sdncQueryResponse).when(sdncVnfResources).queryVnf(genericVnf); + + assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId())); + sdncQueryTasks.queryVnf(execution); + assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId())); + + verify(sdncVnfResources, times(1)).queryVnf(genericVnf); + } + + @Test + public void queryVfModuleForVolumeGroupTest() throws Exception { + String sdncQueryResponse = "response"; + vfModule.setSelflink("vfModuleSelfLink"); + + doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule); + + assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId())); + sdncQueryTasks.queryVfModuleForVolumeGroup(execution); + assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId())); + + verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule); + } + + @Test + public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + vfModule.setSelflink(""); + + sdncQueryTasks.queryVfModuleForVolumeGroup(execution); + } + + @Test + public void queryVfModuleForVolumeGroupVfObjectExceptionTest() throws Exception { + gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs().get(0).getVfModules().clear(); + + sdncQueryTasks.queryVfModuleForVolumeGroup(execution); + + verify(sdncVfModuleResources, times(0)).queryVfModule(any(VfModule.class)); + } + + @Test + public void queryVfModuleForVolumeGroupNonVfObjectExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + sdncQueryTasks.queryVfModuleForVolumeGroup(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasksTest.java new file mode 100644 index 0000000000..14243c5909 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCUnassignTasksTest.java @@ -0,0 +1,202 @@ +/*- + * ============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.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +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.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.springframework.beans.factory.annotation.Autowired; + +public class SDNCUnassignTasksTest extends BaseTaskTest{ + @Autowired + private SDNCUnassignTasks sdncUnassignTasks; + + private ServiceInstance serviceInstance; + private RequestContext requestContext; + private GenericVnf genericVnf; + private VfModule vfModule; + private CloudRegion cloudRegion; + private L3Network network; + private Customer customer; + + @Before + public void before() { + customer = setCustomer(); + serviceInstance = setServiceInstance(); + requestContext = setRequestContext(); + genericVnf = setGenericVnf(); + vfModule = setVfModule(); + cloudRegion = setCloudRegion(); + network = setL3Network(); + + } + + @Test + public void unassignServiceInstanceTest() throws Exception { + doReturn("test").when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance, customer, requestContext); + + sdncUnassignTasks.unassignServiceInstance(execution); + + verify(sdncServiceInstanceResources, times(1)).unassignServiceInstance(serviceInstance, customer, requestContext); + } + + @Test + public void unassignServiceInstanceTest_inventoried() throws Exception { + doReturn("test").when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance, customer, requestContext); + + serviceInstance.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); + + sdncUnassignTasks.unassignServiceInstance(execution); + + verify(sdncServiceInstanceResources, times(0)).unassignServiceInstance(serviceInstance, customer, requestContext); + } + + @Test + public void unassignServiceInstanceExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncServiceInstanceResources).unassignServiceInstance(serviceInstance, customer, requestContext); + + sdncUnassignTasks.unassignServiceInstance(execution); + } + + @Test + public void unassignVfModuleTest() throws Exception { + doReturn("response").when(sdncVfModuleResources).unassignVfModule(vfModule, genericVnf, serviceInstance); + + sdncUnassignTasks.unassignVfModule(execution); + + verify(sdncVfModuleResources, times(1)).unassignVfModule(vfModule, genericVnf, serviceInstance); + assertEquals("response", execution.getVariable("SDNCResponse")); + } + + @Test + public void unassignVfModuleTest_inventoried() throws Exception { + vfModule.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); + + sdncUnassignTasks.unassignVfModule(execution); + + verify(sdncVfModuleResources, times(0)).unassignVfModule(vfModule, genericVnf, serviceInstance); + assertNull(execution.getVariable("SDNCResponse")); + } + + @Test + public void unassignVfModuleTest_pendingCreate() throws Exception { + vfModule.setOrchestrationStatus(OrchestrationStatus.PENDING_CREATE); + + sdncUnassignTasks.unassignVfModule(execution); + + verify(sdncVfModuleResources, times(0)).unassignVfModule(vfModule, genericVnf, serviceInstance); + assertNull(execution.getVariable("SDNCResponse")); + } + + @Test + public void unassignVfModuleExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + + doThrow(Exception.class).when(sdncVfModuleResources).unassignVfModule(vfModule, genericVnf, serviceInstance); + + sdncUnassignTasks.unassignVfModule(execution); + } + + @Test + public void unassignVnfTest() throws Exception { + doReturn("response").when(sdncVnfResources).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + sdncUnassignTasks.unassignVnf(execution); + + verify(sdncVnfResources, times(1)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + assertTrue(execution.getVariable("sdncUnassignVnfResponse").equals("response")); + } + + @Test + public void unassignVnfTest_inventoried() throws Exception { + genericVnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); + + sdncUnassignTasks.unassignVnf(execution); + + verify(sdncVnfResources, times(0)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + assertNull(execution.getVariable("sdncUnassignVnfResponse")); + } + + @Test + public void unassignVnfTest_created() throws Exception { + genericVnf.setOrchestrationStatus(OrchestrationStatus.CREATED); + + sdncUnassignTasks.unassignVnf(execution); + + verify(sdncVnfResources, times(0)).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + assertNull(execution.getVariable("sdncUnassignVnfResponse")); + } + + @Test + public void unassignVnfExceptionTest() throws Exception { + expectedException.expect(BpmnError.class); + doThrow(Exception.class).when(sdncVnfResources).unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + sdncUnassignTasks.unassignVnf(execution); + } + + @Test + public void unassignNetworkTest() throws Exception { + String cloudRegionSdnc = "AAIAIC25"; + + cloudRegion.setCloudRegionVersion("2.5"); + + execution.setVariable("cloudRegionSdnc", cloudRegionSdnc); + + doReturn("response").when(sdncNetworkResources).unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + assertNotEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId()); + sdncUnassignTasks.unassignNetwork(execution); + + verify(sdncNetworkResources, times(1)).unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + assertEquals("response", execution.getVariable("SDNCUnAssignNetworkResponse")); + assertEquals(cloudRegionSdnc, cloudRegion.getLcpCloudRegionId()); + } + + @Test + public void unassignNetworkTest_inventoried() throws Exception { + network.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); + + sdncUnassignTasks.unassignNetwork(execution); + + verify(sdncNetworkResources, times(0)).unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + assertNull(execution.getVariable("SDNCUnAssignNetworkResponse")); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java new file mode 100644 index 0000000000..b0b07d8cd7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java @@ -0,0 +1,182 @@ +/*- + * ============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.workflow.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; + +import java.util.ArrayList; +import java.util.List; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.db.catalog.beans.BuildingBlockDetail; +import org.onap.so.db.catalog.beans.OrchestrationAction; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective; +import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective; +import org.onap.so.db.catalog.beans.ResourceType; +import org.springframework.beans.factory.annotation.Autowired; + +public class OrchestrationStatusValidatorTest extends BaseTaskTest { + @Autowired + protected OrchestrationStatusValidator orchestrationStatusValidator; + + @Test + public void test_validateOrchestrationStatus() throws Exception { + String flowToBeCalled = "AssignServiceInstanceBB"; + setServiceInstance().setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + execution.setVariable("flowToBeCalled", flowToBeCalled); + + BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); + buildingBlockDetail.setBuildingBlockName("AssignServiceInstanceBB"); + buildingBlockDetail.setId(1); + buildingBlockDetail.setResourceType(ResourceType.SERVICE); + buildingBlockDetail.setTargetAction(OrchestrationAction.ASSIGN); + + doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); + + OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = new OrchestrationStatusStateTransitionDirective(); + orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE); + orchestrationStatusStateTransitionDirective.setId(1); + orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.SERVICE); + orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ASSIGN); + + doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient).getOrchestrationStatusStateTransitionDirective(ResourceType.SERVICE, OrchestrationStatus.PRECREATED, OrchestrationAction.ASSIGN); + + orchestrationStatusValidator.validateOrchestrationStatus(execution); + + assertEquals(OrchestrationStatusValidationDirective.CONTINUE, execution.getVariable("orchestrationStatusValidationResult")); + } + + @Test + public void test_validateOrchestrationStatusConfiguration() throws Exception { + lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); + String flowToBeCalled = "UnassignFabricConfigurationBB"; + ServiceInstance si = setServiceInstance(); + List<Configuration> configurations = new ArrayList<>(); + Configuration config = new Configuration(); + + si.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + config.setConfigurationId("configurationId"); + config.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + configurations.add(config); + si.setConfigurations(configurations); + + execution.setVariable("flowToBeCalled", flowToBeCalled); + + BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); + buildingBlockDetail.setBuildingBlockName("UnassignFabricConfigurationBB"); + buildingBlockDetail.setId(1); + buildingBlockDetail.setResourceType(ResourceType.CONFIGURATION); + buildingBlockDetail.setTargetAction(OrchestrationAction.UNASSIGN); + + doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); + + OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = new OrchestrationStatusStateTransitionDirective(); + orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); + orchestrationStatusStateTransitionDirective.setId(1); + orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.CONFIGURATION); + orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.UNASSIGN); + + doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient).getOrchestrationStatusStateTransitionDirective(ResourceType.CONFIGURATION, OrchestrationStatus.PRECREATED, OrchestrationAction.UNASSIGN); + + orchestrationStatusValidator.validateOrchestrationStatus(execution); + + assertEquals(OrchestrationStatusValidationDirective.SILENT_SUCCESS, execution.getVariable("orchestrationStatusValidationResult")); + } + + @Test + public void test_validateOrchestrationStatus_buildingBlockDetailNotFound() throws Exception { + expectedException.expect(BpmnError.class); + + String flowToBeCalled = "AssignServiceInstanceBB"; + + execution.setVariable("flowToBeCalled", flowToBeCalled); + + doReturn(null).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); + + orchestrationStatusValidator.validateOrchestrationStatus(execution); + } + + @Test + public void test_validateOrchestrationStatus_orchestrationValidationFail() throws Exception { + expectedException.expect(BpmnError.class); + + String flowToBeCalled = "AssignServiceInstanceBB"; + + execution.setVariable("flowToBeCalled", flowToBeCalled); + + BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); + buildingBlockDetail.setBuildingBlockName("AssignServiceInstanceBB"); + buildingBlockDetail.setId(1); + buildingBlockDetail.setResourceType(ResourceType.SERVICE); + buildingBlockDetail.setTargetAction(OrchestrationAction.ASSIGN); + + doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); + + OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = new OrchestrationStatusStateTransitionDirective(); + orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.FAIL); + orchestrationStatusStateTransitionDirective.setId(1); + orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.SERVICE); + orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ASSIGN); + + doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient).getOrchestrationStatusStateTransitionDirective(ResourceType.SERVICE, OrchestrationStatus.PRECREATED, OrchestrationAction.ASSIGN); + + orchestrationStatusValidator.validateOrchestrationStatus(execution); + } + + @Test + public void test_validateOrchestrationStatus_orchestrationValidationNotFound() throws Exception { + expectedException.expect(BpmnError.class); + + String flowToBeCalled = "AssignServiceInstanceBB"; + + execution.setVariable("flowToBeCalled", flowToBeCalled); + + BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); + buildingBlockDetail.setBuildingBlockName("AssignServiceInstanceBB"); + buildingBlockDetail.setId(1); + buildingBlockDetail.setResourceType(ResourceType.SERVICE); + buildingBlockDetail.setTargetAction(OrchestrationAction.ASSIGN); + + doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); + + OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = new OrchestrationStatusStateTransitionDirective(); + orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.FAIL); + orchestrationStatusStateTransitionDirective.setId(1); + orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.SERVICE); + orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ASSIGN); + + doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient).getOrchestrationStatusStateTransitionDirective(ResourceType.NETWORK, OrchestrationStatus.PRECREATED, OrchestrationAction.ASSIGN); + + orchestrationStatusValidator.validateOrchestrationStatus(execution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java new file mode 100644 index 0000000000..d856b5e184 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -0,0 +1,188 @@ +/*- + * ============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.workflow.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.springframework.beans.factory.annotation.Autowired; + +public class WorkflowActionBBTasksTest extends BaseTaskTest { + + @Autowired + protected WorkflowAction workflowAction; + + @Autowired + protected WorkflowActionBBTasks workflowActionBBTasks; + + private DelegateExecution execution; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance(); + servInstance.setServiceInstanceId("TEST"); + when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance); + workflowAction.setBbInputSetupUtils(bbSetupUtils); + workflowAction.setBbInputSetup(bbInputSetup); + } + + @Test + public void selectBBTest() throws Exception{ + String gAction = "Delete-Network-Collection"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + execution.setVariable("gCurrentSequence", 0); + execution.setVariable("homing", false); + execution.setVariable("calledHoming", false); + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb = new ExecuteBuildingBlock(); + flowsToExecute.add(ebb); + execution.setVariable("flowsToExecute", flowsToExecute); + workflowActionBBTasks.selectBB(execution); + boolean success = (boolean) execution.getVariable("completed"); + assertEquals(true,success); + } + + @Test + public void select2BBTest() throws Exception{ + String gAction = "Delete-Network-Collection"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + execution.setVariable("gCurrentSequence", 0); + execution.setVariable("homing", false); + execution.setVariable("calledHoming", false); + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb = new ExecuteBuildingBlock(); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + flowsToExecute.add(ebb); + flowsToExecute.add(ebb2); + execution.setVariable("flowsToExecute", flowsToExecute); + workflowActionBBTasks.selectBB(execution); + boolean success = (boolean) execution.getVariable("completed"); + assertEquals(false,success); + } + + @Test + public void msoCompleteProcessTest() throws Exception{ + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", "createInstance"); + execution.setVariable("resourceId", "123"); + execution.setVariable("source","MSO"); + execution.setVariable("resourceName", "Service"); + execution.setVariable("aLaCarte", true); + workflowActionBBTasks.setupCompleteMsoProcess(execution); + String response = (String) execution.getVariable("CompleteMsoProcessRequest"); + assertEquals(response,"<aetgt:MsoCompletionRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns=\"http://org.onap/so/request/types/v1\"><request-info xmlns=\"http://org.onap/so/infra/vnf-request/v1\"><request-id>00f704ca-c5e5-4f95-a72c-6889db7b0688</request-id><action>createInstance</action><source>MSO</source></request-info><status-message>ALaCarte-Service-createInstance request was executed correctly.</status-message><serviceInstanceId>123</serviceInstanceId><mso-bpel-name>WorkflowActionBB</mso-bpel-name></aetgt:MsoCompletionRequest>"); + } + + @Test + public void setupFalloutHandlerTest(){ + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("serviceInstanceId", "123"); + execution.setVariable("WorkflowActionErrorMessage", "Error in WorkFlowAction"); + execution.setVariable("requestAction", "createInstance"); + workflowActionBBTasks.setupFalloutHandler(execution); + assertEquals(execution.getVariable("falloutRequest"),"<aetgt:FalloutHandlerRequest xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"xmlns:ns=\"http://org.onap/so/request/types/v1\"xmlns:wfsch=\"http://org.onap/so/workflow/schema/v1\"><request-info xmlns=\"http://org.onap/so/infra/vnf-request/v1\"><request-id>00f704ca-c5e5-4f95-a72c-6889db7b0688</request-id><action>createInstance</action><source>VID</source></request-info><aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>Error in WorkFlowAction</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException></aetgt:FalloutHandlerRequest>"); + } + + @Test + public void rollbackExecutionPathTest(){ + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList(); + ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock(); + BuildingBlock bb1 = new BuildingBlock(); + bb1.setBpmnFlowName("CreateNetworkBB"); + flowsToExecute.add(ebb1); + ebb1.setBuildingBlock(bb1); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("ActivateNetworkBB"); + flowsToExecute.add(ebb2); + ebb2.setBuildingBlock(bb2); + ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock(); + BuildingBlock bb3 = new BuildingBlock(); + bb3.setBpmnFlowName("CreateVolumeGroupBB"); + flowsToExecute.add(ebb3); + ebb3.setBuildingBlock(bb3); + ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock(); + BuildingBlock bb4 = new BuildingBlock(); + bb4.setBpmnFlowName("ActivateVolumeGroupBB"); + flowsToExecute.add(ebb4); + ebb4.setBuildingBlock(bb4); + ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock(); + BuildingBlock bb5 = new BuildingBlock(); + bb5.setBpmnFlowName("CreateVfModuleBB"); + flowsToExecute.add(ebb5); + ebb5.setBuildingBlock(bb5); + ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock(); + BuildingBlock bb6 = new BuildingBlock(); + bb6.setBpmnFlowName("ActivateVfModuleBB"); + flowsToExecute.add(ebb6); + ebb6.setBuildingBlock(bb6); + ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock(); + BuildingBlock bb7 = new BuildingBlock(); + bb7.setBpmnFlowName("ActivateVnfBB"); + ebb7.setBuildingBlock(bb7); + flowsToExecute.add(ebb7); + ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock(); + BuildingBlock bb8 = new BuildingBlock(); + bb8.setBpmnFlowName("ActivateServiceInstance"); + ebb8.setBuildingBlock(bb8); + flowsToExecute.add(ebb8); + + execution.setVariable("flowsToExecute", flowsToExecute); + execution.setVariable("gCurrentSequence", 6); + + workflowActionBBTasks.rollbackExecutionPath(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeactivateVolumeGroupBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"DeleteVolumeGroupBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + } + + @Test + public void checkRetryStatusTest(){ + execution.setVariable("handlingCode","Retry"); + execution.setVariable("retryCount", 1); + execution.setVariable("gCurrentSequence",1); + workflowActionBBTasks.checkRetryStatus(execution); + assertEquals(0,execution.getVariable("gCurrentSequence")); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java new file mode 100644 index 0000000000..c910ad19fa --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -0,0 +1,1494 @@ +/*- + * ============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.workflow.tasks; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.L3Network; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.VfModule; +import org.onap.aai.domain.yang.VfModules; +import org.onap.aai.domain.yang.VolumeGroup; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; +import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; +import org.onap.so.db.catalog.beans.CollectionResource; +import org.onap.so.db.catalog.beans.CollectionResourceCustomization; +import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; +import org.onap.so.db.catalog.beans.HeatEnvironment; +import org.onap.so.db.catalog.beans.HeatTemplate; +import org.onap.so.db.catalog.beans.InstanceGroup; +import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; +import org.onap.so.db.catalog.beans.NetworkResourceCustomization; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; +import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.RequestParameters; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import org.onap.so.serviceinstancebeans.SubscriberInfo; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class WorkflowActionTest extends BaseTaskTest { + @Autowired + protected WorkflowAction workflowAction; + + private DelegateExecution execution; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance(); + servInstance.setServiceInstanceId("TEST"); + when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance); + workflowAction.setBbInputSetupUtils(bbSetupUtils); + workflowAction.setBbInputSetup(bbInputSetup); + } + /** + * ALACARTE TESTS + */ + @Test + public void selectExecutionListALaCarteNetworkCreateTest() throws Exception{ + String gAction = "createInstance"; + String resource = "Network"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", true); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/networks/123"); + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("AssignNetwork1802BB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("CreateNetworkBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("ActivateNetworkBB"); + orchFlows.add(orch3); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,true)).thenReturn(northBoundRequest); + + + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"AssignNetwork1802BB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + } + + @Test + public void selectExecutionListALaCarteNetworkDeleteTest() throws Exception{ + String gAction = "deleteInstance"; + String resource = "Network"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", true); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/networks/123"); + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("DeactivateNetworkBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("DeleteNetworkBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("UnassignNetwork1802BB"); + orchFlows.add(orch3); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,true)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignNetwork1802BB"); + } + + @Test + public void selectExecutionListALaCarteServiceCreateTest() throws Exception{ + String gAction = "createInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", true); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("AssignServiceInstanceBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("ActivateServiceInstanceBB"); + orchFlows.add(orch2); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,true)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"AssignServiceInstanceBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"ActivateServiceInstanceBB"); + } + + /** + * SERVICE MACRO TESTS + */ + @Test + public void selectExecutionListServiceMacroAssignTest() throws Exception{ + String gAction = "assignInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("AssignServiceInstanceBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("AssignNetworkBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("AssignVnfBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("AssignVolumeGroupBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("AssignVfModuleBB"); + orchFlows.add(orch5); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setModelCustomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + HeatEnvironment volumeHeatEnv = new HeatEnvironment(); + vfModuleCustomization.setVolumeHeatEnv(volumeHeatEnv); + org.onap.so.db.catalog.beans.VfModule vfModule = new org.onap.so.db.catalog.beans.VfModule(); + HeatTemplate volumeHeatTemplate = new HeatTemplate(); + vfModule.setVolumeHeatTemplate(volumeHeatTemplate); + vfModuleCustomization.setVfModule(vfModule); + + VfModuleCustomization vfModuleCustomization2 = new VfModuleCustomization(); + vfModuleCustomization2.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + HeatEnvironment heatEnvironment = new HeatEnvironment(); + vfModuleCustomization2.setHeatEnvironment(heatEnvironment); + org.onap.so.db.catalog.beans.VfModule vfModule2 = new org.onap.so.db.catalog.beans.VfModule(); + HeatTemplate moduleHeatTemplate = new HeatTemplate(); + vfModule2.setModuleHeatTemplate(moduleHeatTemplate); + vfModuleCustomization2.setVfModule(vfModule2); + + VfModuleCustomization vfModuleCustomization3 = vfModuleCustomization2; + vfModuleCustomization3.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f")).thenReturn(vfModuleCustomization); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8")).thenReturn(vfModuleCustomization2); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("da4d4327-fb7d-4311-ac7a-be7ba60cf969")).thenReturn(vfModuleCustomization3); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"AssignServiceInstanceBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"AssignVnfBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"AssignVolumeGroupBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"AssignVfModuleBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"AssignVfModuleBB"); + assertEquals(ebbs.get(5).getBuildingBlock().getBpmnFlowName(),"AssignVfModuleBB"); + } + + @Test + public void selectExecutionListServiceMacroActivateTest() throws Exception{ + String gAction = "activateInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/si0"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("CreateNetworkBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("ActivateNetworkBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("CreateVolumeGroupBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("ActivateVolumeGroupBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("CreateVfModuleBB"); + orchFlows.add(orch5); + OrchestrationFlow orch6 = new OrchestrationFlow(); + orch6.setFlowName("ActivateVfModuleBB"); + orchFlows.add(orch6); + OrchestrationFlow orch7 = new OrchestrationFlow(); + orch7.setFlowName("ActivateVnfBB"); + orchFlows.add(orch7); + OrchestrationFlow orch8 = new OrchestrationFlow(); + orch8.setFlowName("ActivateServiceInstanceBB"); + orchFlows.add(orch8); + + ServiceInstance serviceInstanceAAI = new ServiceInstance(); + serviceInstanceAAI.setServiceInstanceId("si0"); + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance(); + org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf(); + vnf.setVnfId("vnf0"); + + org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule(); + vfModule.setVfModuleId("vfModule0"); + vnf.getVfModules().add(vfModule); + org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule(); + vfModule2.setVfModuleId("vfModule1"); + vnf.getVfModules().add(vfModule2); + + org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = new org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroup0"); + vnf.getVolumeGroups().add(volumeGroup); + + serviceInstanceMSO.getVnfs().add(vnf); + + doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("si0"); + doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals("CreateVolumeGroupBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName()); + assertEquals("volumeGroup0", ebbs.get(0).getWorkflowResourceIds().getVolumeGroupId()); + assertEquals("ActivateVolumeGroupBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName()); + assertEquals("volumeGroup0", ebbs.get(1).getWorkflowResourceIds().getVolumeGroupId()); + assertEquals("CreateVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName()); + assertEquals("vfModule0", ebbs.get(2).getWorkflowResourceIds().getVfModuleId()); + assertEquals("CreateVfModuleBB", ebbs.get(3).getBuildingBlock().getBpmnFlowName()); + assertEquals("vfModule1", ebbs.get(3).getWorkflowResourceIds().getVfModuleId()); + assertEquals("ActivateVfModuleBB", ebbs.get(4).getBuildingBlock().getBpmnFlowName()); + assertEquals("vfModule0", ebbs.get(4).getWorkflowResourceIds().getVfModuleId()); + assertEquals("ActivateVfModuleBB", ebbs.get(5).getBuildingBlock().getBpmnFlowName()); + assertEquals("vfModule1", ebbs.get(5).getWorkflowResourceIds().getVfModuleId()); + assertEquals("ActivateVnfBB", ebbs.get(6).getBuildingBlock().getBpmnFlowName()); + assertEquals("vnf0", ebbs.get(6).getWorkflowResourceIds().getVnfId()); + assertEquals("ActivateServiceInstanceBB", ebbs.get(7).getBuildingBlock().getBpmnFlowName()); + assertEquals("si0", ebbs.get(7).getWorkflowResourceIds().getServiceInstanceId()); + + } + + @Test + public void selectExecutionListServiceMacroDeactivateTest() throws Exception{ + String gAction = "deactivateInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch = new OrchestrationFlow(); + orch.setFlowName("DeactivateServiceInstanceBB"); + orchFlows.add(orch); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateServiceInstanceBB"); + } + + @Test + public void selectExecutionListServiceMacroEmptyServiceTest() throws Exception{ + String gAction = "createInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + northBoundRequest.setIsToplevelflow(true); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("AssignServiceInstanceBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("CreateNetworkCollectionBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("AssignNetworkBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("AssignVnfBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("AssignVolumeGroupBB"); + orchFlows.add(orch5); + OrchestrationFlow orch6 = new OrchestrationFlow(); + orch6.setFlowName("AssignVfModuleBB"); + orchFlows.add(orch6); + OrchestrationFlow orch7 = new OrchestrationFlow(); + orch7.setFlowName("CreateNetworkBB"); + orchFlows.add(orch7); + OrchestrationFlow orch8 = new OrchestrationFlow(); + orch8.setFlowName("ActivateNetworkBB"); + orchFlows.add(orch8); + OrchestrationFlow orch9 = new OrchestrationFlow(); + orch9.setFlowName("CreateVolumeGroupBB"); + orchFlows.add(orch9); + OrchestrationFlow orch10 = new OrchestrationFlow(); + orch10.setFlowName("ActivateVolumeGroupBB"); + orchFlows.add(orch10); + OrchestrationFlow orch11 = new OrchestrationFlow(); + orch11.setFlowName("CreateVfModuleBB"); + orchFlows.add(orch11); + OrchestrationFlow orch12 = new OrchestrationFlow(); + orch12.setFlowName("ActivateVfModuleBB"); + orchFlows.add(orch12); + OrchestrationFlow orch13 = new OrchestrationFlow(); + orch13.setFlowName("ActivateVnfBB"); + orchFlows.add(orch13); + OrchestrationFlow orch14 = new OrchestrationFlow(); + orch14.setFlowName("ActivateNetworkCollectionBB"); + orchFlows.add(orch14); + OrchestrationFlow orch15 = new OrchestrationFlow(); + orch15.setFlowName("ActivateServiceInstanceBB"); + orchFlows.add(orch15); + + Service service = new Service(); + doReturn(service).when(catalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a"); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"AssignServiceInstanceBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"ActivateServiceInstanceBB"); + } + + @Test + public void selectExecutionListServiceMacroCreateJustNetworkTest() throws Exception{ + String gAction = "createInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + northBoundRequest.setIsToplevelflow(true); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("AssignServiceInstanceBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("CreateNetworkCollectionBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("AssignNetworkBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("AssignVnfBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("AssignVolumeGroupBB"); + orchFlows.add(orch5); + OrchestrationFlow orch6 = new OrchestrationFlow(); + orch6.setFlowName("AssignVfModuleBB"); + orchFlows.add(orch6); + OrchestrationFlow orch7 = new OrchestrationFlow(); + orch7.setFlowName("CreateNetworkBB"); + orchFlows.add(orch7); + OrchestrationFlow orch8 = new OrchestrationFlow(); + orch8.setFlowName("ActivateNetworkBB"); + orchFlows.add(orch8); + OrchestrationFlow orch9 = new OrchestrationFlow(); + orch9.setFlowName("CreateVolumeGroupBB"); + orchFlows.add(orch9); + OrchestrationFlow orch10 = new OrchestrationFlow(); + orch10.setFlowName("ActivateVolumeGroupBB"); + orchFlows.add(orch10); + OrchestrationFlow orch11 = new OrchestrationFlow(); + orch11.setFlowName("CreateVfModuleBB"); + orchFlows.add(orch11); + OrchestrationFlow orch12 = new OrchestrationFlow(); + orch12.setFlowName("ActivateVfModuleBB"); + orchFlows.add(orch12); + OrchestrationFlow orch13 = new OrchestrationFlow(); + orch13.setFlowName("ActivateVnfBB"); + orchFlows.add(orch13); + OrchestrationFlow orch14 = new OrchestrationFlow(); + orch14.setFlowName("ActivateNetworkCollectionBB"); + orchFlows.add(orch14); + OrchestrationFlow orch15 = new OrchestrationFlow(); + orch15.setFlowName("ActivateServiceInstanceBB"); + orchFlows.add(orch15); + + Service service = new Service(); + NetworkResourceCustomization networkCustomization = new NetworkResourceCustomization(); + networkCustomization.setModelCustomizationUUID("1234"); + service.getNetworkCustomizations().add(networkCustomization); + doReturn(service).when(catalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a"); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"AssignServiceInstanceBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"AssignNetworkBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"ActivateServiceInstanceBB"); + } + + @Test + public void selectExecutionListServiceMacroCreateWithNetworkCollectionTest() throws Exception{ + String gAction = "createInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + northBoundRequest.setIsToplevelflow(true); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("AssignServiceInstanceBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("CreateNetworkCollectionBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("AssignNetworkBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("AssignVnfBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("AssignVolumeGroupBB"); + orchFlows.add(orch5); + OrchestrationFlow orch6 = new OrchestrationFlow(); + orch6.setFlowName("AssignVfModuleBB"); + orchFlows.add(orch6); + OrchestrationFlow orch7 = new OrchestrationFlow(); + orch7.setFlowName("CreateNetworkBB"); + orchFlows.add(orch7); + OrchestrationFlow orch8 = new OrchestrationFlow(); + orch8.setFlowName("ActivateNetworkBB"); + orchFlows.add(orch8); + OrchestrationFlow orch9 = new OrchestrationFlow(); + orch9.setFlowName("CreateVolumeGroupBB"); + orchFlows.add(orch9); + OrchestrationFlow orch10 = new OrchestrationFlow(); + orch10.setFlowName("ActivateVolumeGroupBB"); + orchFlows.add(orch10); + OrchestrationFlow orch11 = new OrchestrationFlow(); + orch11.setFlowName("CreateVfModuleBB"); + orchFlows.add(orch11); + OrchestrationFlow orch12 = new OrchestrationFlow(); + orch12.setFlowName("ActivateVfModuleBB"); + orchFlows.add(orch12); + OrchestrationFlow orch13 = new OrchestrationFlow(); + orch13.setFlowName("ActivateVnfBB"); + orchFlows.add(orch13); + OrchestrationFlow orch14 = new OrchestrationFlow(); + orch14.setFlowName("ActivateNetworkCollectionBB"); + orchFlows.add(orch14); + OrchestrationFlow orch15 = new OrchestrationFlow(); + orch15.setFlowName("ActivateServiceInstanceBB"); + orchFlows.add(orch15); + + Service service = new Service(); + List<NetworkResourceCustomization> networkCustomizations = new ArrayList<>(); + NetworkResourceCustomization networkCust = new NetworkResourceCustomization(); + networkCust.setModelCustomizationUUID("123"); + networkCustomizations.add(networkCust); + service.setNetworkCustomizations(networkCustomizations); + NetworkCollectionResourceCustomization collectionResourceCustomization = new NetworkCollectionResourceCustomization(); + collectionResourceCustomization.setModelCustomizationUUID("123"); + + CollectionResource collectionResource = new CollectionResource(); + collectionResource.setToscaNodeType("NetworkCollection"); + InstanceGroup instanceGroup = new InstanceGroup(); + instanceGroup.setToscaNodeType("NetworkCollectionResource"); + instanceGroup.setCollectionNetworkResourceCustomizations(new ArrayList<>()); + CollectionNetworkResourceCustomization collectionNetworkResourceCust = new CollectionNetworkResourceCustomization(); + collectionNetworkResourceCust.setModelCustomizationUUID("123"); + instanceGroup.getCollectionNetworkResourceCustomizations().add(collectionNetworkResourceCust ); + List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupCustomizations = new ArrayList<>(); + CollectionResourceInstanceGroupCustomization collectionInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization(); + collectionInstanceGroupCustomization.setSubInterfaceNetworkQuantity(3); + collectionInstanceGroupCustomizations.add(collectionInstanceGroupCustomization); + collectionInstanceGroupCustomization.setInstanceGroup(instanceGroup); + instanceGroup.setCollectionInstanceGroupCustomizations(collectionInstanceGroupCustomizations); + collectionResource.setInstanceGroup(instanceGroup); + collectionResourceCustomization.setCollectionResource(collectionResource);; + service.getCollectionResourceCustomizations().add(collectionResourceCustomization); + doReturn(service).when(catalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a"); + doReturn(collectionResourceCustomization).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"AssignServiceInstanceBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"CreateNetworkCollectionBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"AssignNetworkBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + assertEquals(ebbs.get(5).getBuildingBlock().getBpmnFlowName(),"AssignNetworkBB"); + assertEquals(ebbs.get(6).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(ebbs.get(7).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + assertEquals(ebbs.get(8).getBuildingBlock().getBpmnFlowName(),"AssignNetworkBB"); + assertEquals(ebbs.get(9).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(ebbs.get(10).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + assertEquals(ebbs.get(11).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkCollectionBB"); + assertEquals(ebbs.get(12).getBuildingBlock().getBpmnFlowName(),"ActivateServiceInstanceBB"); + } + + @Test + public void selectExecutionListServiceMacroCreateWithUserParams() throws Exception{ + String gAction = "createInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("AssignServiceInstanceBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("CreateNetworkCollectionBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("AssignNetworkBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("AssignVnfBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("AssignVolumeGroupBB"); + orchFlows.add(orch5); + OrchestrationFlow orch6 = new OrchestrationFlow(); + orch6.setFlowName("AssignVfModuleBB"); + orchFlows.add(orch6); + OrchestrationFlow orch7 = new OrchestrationFlow(); + orch7.setFlowName("CreateNetworkBB"); + orchFlows.add(orch7); + OrchestrationFlow orch8 = new OrchestrationFlow(); + orch8.setFlowName("ActivateNetworkBB"); + orchFlows.add(orch8); + OrchestrationFlow orch9 = new OrchestrationFlow(); + orch9.setFlowName("CreateVolumeGroupBB"); + orchFlows.add(orch9); + OrchestrationFlow orch10 = new OrchestrationFlow(); + orch10.setFlowName("ActivateVolumeGroupBB"); + orchFlows.add(orch10); + OrchestrationFlow orch11 = new OrchestrationFlow(); + orch11.setFlowName("CreateVfModuleBB"); + orchFlows.add(orch11); + OrchestrationFlow orch12 = new OrchestrationFlow(); + orch12.setFlowName("ActivateVfModuleBB"); + orchFlows.add(orch12); + OrchestrationFlow orch13 = new OrchestrationFlow(); + orch13.setFlowName("ActivateVnfBB"); + orchFlows.add(orch13); + OrchestrationFlow orch14 = new OrchestrationFlow(); + orch14.setFlowName("ActivateNetworkCollectionBB"); + orchFlows.add(orch14); + OrchestrationFlow orch15 = new OrchestrationFlow(); + orch15.setFlowName("ActivateServiceInstanceBB"); + orchFlows.add(orch15); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setModelCustomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + HeatEnvironment volumeHeatEnv = new HeatEnvironment(); + vfModuleCustomization.setVolumeHeatEnv(volumeHeatEnv); + org.onap.so.db.catalog.beans.VfModule vfModule = new org.onap.so.db.catalog.beans.VfModule(); + HeatTemplate volumeHeatTemplate = new HeatTemplate(); + vfModule.setVolumeHeatTemplate(volumeHeatTemplate); + vfModuleCustomization.setVfModule(vfModule); + + VfModuleCustomization vfModuleCustomization2 = new VfModuleCustomization(); + vfModuleCustomization2.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + HeatEnvironment heatEnvironment = new HeatEnvironment(); + vfModuleCustomization2.setHeatEnvironment(heatEnvironment); + org.onap.so.db.catalog.beans.VfModule vfModule2 = new org.onap.so.db.catalog.beans.VfModule(); + HeatTemplate moduleHeatTemplate = new HeatTemplate(); + vfModule2.setModuleHeatTemplate(moduleHeatTemplate); + vfModuleCustomization2.setVfModule(vfModule2); + + VfModuleCustomization vfModuleCustomization3 = vfModuleCustomization2; + vfModuleCustomization3.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f")).thenReturn(vfModuleCustomization); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa8")).thenReturn(vfModuleCustomization2); + when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("da4d4327-fb7d-4311-ac7a-be7ba60cf969")).thenReturn(vfModuleCustomization3); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"AssignServiceInstanceBB"); + assertEquals(3,ebbs.get(0).getWorkflowResourceIds().getServiceInstanceId().length()); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"AssignVnfBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(1).getWorkflowResourceIds().getVnfId().length()); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"AssignVolumeGroupBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(2).getWorkflowResourceIds().getVolumeGroupId().length()); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"AssignVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(3).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"AssignVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(4).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(5).getBuildingBlock().getBpmnFlowName(),"AssignVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(5).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(6).getBuildingBlock().getBpmnFlowName(),"CreateVolumeGroupBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(6).getWorkflowResourceIds().getVolumeGroupId().length()); + assertEquals(ebbs.get(7).getBuildingBlock().getBpmnFlowName(),"ActivateVolumeGroupBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(7).getWorkflowResourceIds().getVolumeGroupId().length()); + assertEquals(ebbs.get(8).getBuildingBlock().getBpmnFlowName(),"CreateVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(8).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(9).getBuildingBlock().getBpmnFlowName(),"CreateVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(9).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(10).getBuildingBlock().getBpmnFlowName(),"CreateVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(10).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(11).getBuildingBlock().getBpmnFlowName(),"ActivateVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(11).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(12).getBuildingBlock().getBpmnFlowName(),"ActivateVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(12).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(13).getBuildingBlock().getBpmnFlowName(),"ActivateVfModuleBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(13).getWorkflowResourceIds().getVfModuleId().length()); + assertEquals(ebbs.get(14).getBuildingBlock().getBpmnFlowName(),"ActivateVnfBB"); + assertEquals(UUID.randomUUID().toString().length(),ebbs.get(14).getWorkflowResourceIds().getVnfId().length()); + assertEquals(ebbs.get(15).getBuildingBlock().getBpmnFlowName(),"ActivateServiceInstanceBB"); + assertEquals(3,ebbs.get(0).getWorkflowResourceIds().getServiceInstanceId().length()); + + } + + @Test + public void selectExecutionListServiceMacroDeleteTest() throws Exception{ + String gAction = "deleteInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("DeactivateVfModuleBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("DeleteVfModuleBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("DeactivateVolumeGroupBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("DeleteVolumeGroupBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("DeactivateVnfBB"); + orchFlows.add(orch5); + OrchestrationFlow orch6 = new OrchestrationFlow(); + orch6.setFlowName("DeactivateNetworkBB"); + orchFlows.add(orch6); + OrchestrationFlow orch7 = new OrchestrationFlow(); + orch7.setFlowName("DeleteNetworkBB"); + orchFlows.add(orch7); + OrchestrationFlow orch8 = new OrchestrationFlow(); + orch8.setFlowName("DeleteNetworkCollectionBB"); + orchFlows.add(orch8); + OrchestrationFlow orch9 = new OrchestrationFlow(); + orch9.setFlowName("DeactivateServiceInstanceBB"); + orchFlows.add(orch9); + OrchestrationFlow orch10 = new OrchestrationFlow(); + orch10.setFlowName("UnassignVfModuleBB"); + orchFlows.add(orch10); + OrchestrationFlow orch11 = new OrchestrationFlow(); + orch11.setFlowName("UnassignVolumeGroupBB"); + orchFlows.add(orch11); + OrchestrationFlow orch12 = new OrchestrationFlow(); + orch12.setFlowName("UnassignVnfBB"); + orchFlows.add(orch12); + OrchestrationFlow orch13 = new OrchestrationFlow(); + orch13.setFlowName("UnassignNetworkBB"); + orchFlows.add(orch13); + OrchestrationFlow orch14 = new OrchestrationFlow(); + orch14.setFlowName("UnassignServiceInstanceBB"); + orchFlows.add(orch14); + + ServiceInstance serviceInstanceAAI = new ServiceInstance(); + serviceInstanceAAI.setServiceInstanceId("aaisi123"); + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance(); + org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf(); + vnf.setVnfId("vnfId123"); + + org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule(); + vfModule.setVfModuleId("vfModule1"); + vnf.getVfModules().add(vfModule); + org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule(); + vfModule2.setVfModuleId("vfModule2"); + vnf.getVfModules().add(vfModule2); + + org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = new org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup(); + volumeGroup.setVolumeGroupId("vg123"); + vnf.getVolumeGroups().add(volumeGroup); + + serviceInstanceMSO.getVnfs().add(vnf); + + doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123"); + doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"DeactivateVolumeGroupBB"); + assertEquals(ebbs.get(5).getBuildingBlock().getBpmnFlowName(),"DeleteVolumeGroupBB"); + assertEquals(ebbs.get(6).getBuildingBlock().getBpmnFlowName(),"DeactivateVnfBB"); + assertEquals(ebbs.get(7).getBuildingBlock().getBpmnFlowName(),"DeactivateServiceInstanceBB"); + assertEquals(ebbs.get(8).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB"); + assertEquals(ebbs.get(9).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB"); + assertEquals(ebbs.get(10).getBuildingBlock().getBpmnFlowName(),"UnassignVolumeGroupBB"); + assertEquals(ebbs.get(11).getBuildingBlock().getBpmnFlowName(),"UnassignVnfBB"); + assertEquals(ebbs.get(12).getBuildingBlock().getBpmnFlowName(),"UnassignServiceInstanceBB"); + } + + @Test + public void selectExecutionListServiceMacroUnassignTest() throws Exception{ + String gAction = "unassignInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("UnassignVfModuleBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("UnassignVolumeGroupBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("UnassignVnfBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("UnassignNetworkBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("UnassignServiceInstanceBB"); + orchFlows.add(orch5); + + ServiceInstance serviceInstanceAAI = new ServiceInstance(); + serviceInstanceAAI.setServiceInstanceId("aaisi123"); + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance(); + org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf(); + vnf.setVnfId("vnfId123"); + + org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule(); + vfModule.setVfModuleId("vfModule1"); + vnf.getVfModules().add(vfModule); + org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule(); + vfModule2.setVfModuleId("vfModule2"); + vnf.getVfModules().add(vfModule2); + + org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = new org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup(); + volumeGroup.setVolumeGroupId("vg123"); + vnf.getVolumeGroups().add(volumeGroup); + + serviceInstanceMSO.getVnfs().add(vnf); + + doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123"); + doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"UnassignVfModuleBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignVolumeGroupBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"UnassignVnfBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"UnassignServiceInstanceBB"); + } + + @Test + public void selectExecutionListServiceMacroDeleteNetworkCollectionTest() throws Exception{ + String gAction = "deleteInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("DeactivateVfModuleBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("DeleteVfModuleBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("DeactivateVolumeGroupBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("DeleteVolumeGroupBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("DeactivateVnfBB"); + orchFlows.add(orch5); + OrchestrationFlow orch6 = new OrchestrationFlow(); + orch6.setFlowName("DeactivateNetworkBB"); + orchFlows.add(orch6); + OrchestrationFlow orch7 = new OrchestrationFlow(); + orch7.setFlowName("DeleteNetworkBB"); + orchFlows.add(orch7); + OrchestrationFlow orch8 = new OrchestrationFlow(); + orch8.setFlowName("DeleteNetworkCollectionBB"); + orchFlows.add(orch8); + OrchestrationFlow orch9 = new OrchestrationFlow(); + orch9.setFlowName("DeactivateServiceInstanceBB"); + orchFlows.add(orch9); + OrchestrationFlow orch10 = new OrchestrationFlow(); + orch10.setFlowName("UnassignVfModuleBB"); + orchFlows.add(orch10); + OrchestrationFlow orch11 = new OrchestrationFlow(); + orch11.setFlowName("UnassignVolumeGroupBB"); + orchFlows.add(orch11); + OrchestrationFlow orch12 = new OrchestrationFlow(); + orch12.setFlowName("UnassignVnfBB"); + orchFlows.add(orch12); + OrchestrationFlow orch13 = new OrchestrationFlow(); + orch13.setFlowName("UnassignNetworkBB"); + orchFlows.add(orch13); + OrchestrationFlow orch14 = new OrchestrationFlow(); + orch14.setFlowName("UnassignServiceInstanceBB"); + orchFlows.add(orch14); + + ServiceInstance serviceInstanceAAI = new ServiceInstance(); + serviceInstanceAAI.setServiceInstanceId("aaisi123"); + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance(); + + org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network = new org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network(); + network.setNetworkId("123"); + serviceInstanceMSO.getNetworks().add(network); + org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network(); + network2.setNetworkId("321"); + serviceInstanceMSO.getNetworks().add(network2); + + Collection collection = new Collection(); + serviceInstanceMSO.setCollection(collection); + + doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123"); + doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + assertEquals(ebbs.get(5).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); + assertEquals(ebbs.get(6).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkCollectionBB"); + assertEquals(ebbs.get(7).getBuildingBlock().getBpmnFlowName(),"DeactivateServiceInstanceBB"); + assertEquals(ebbs.get(8).getBuildingBlock().getBpmnFlowName(),"UnassignServiceInstanceBB"); + } + + @Ignore + @Test + public void selectExecutionListNetworkCollectionMacroCreate() throws Exception{ + String gAction = "createInstance"; + String resource = "NetworkCollection"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/CreateNetworkCollection.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123/networkCollections/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("CreateNetworkCollectionBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("AssignNetworkBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("CreateNetworkBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("ActivateNetworkBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("ActivateNetworkCollectionBB"); + orchFlows.add(orch5); + + Service service = new Service(); + CollectionResourceCustomization collectionResourceCustomization = new CollectionResourceCustomization(); + CollectionResource collectionResource = new CollectionResource(); + collectionResource.setToscaNodeType("Data NetworkCollection Data"); + collectionResourceCustomization.setCollectionResource(collectionResource); + service.getCollectionResourceCustomizations().add(collectionResourceCustomization); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + when(catalogDbClient.getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a")).thenReturn(service); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"CreateNetworkCollectionBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"AssignNetworkBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"AssignNetworkBB"); + assertEquals(ebbs.get(5).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(ebbs.get(6).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + assertEquals(ebbs.get(7).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkCollectionBB"); + } + + @Ignore + @Test + public void selectExecutionListNetworkCollectionMacroDelete() throws Exception{ + String gAction = "deleteInstance"; + String resource = "NetworkCollection"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/CreateNetworkCollection.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123/networkCollections/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + northBoundRequest.setOrchestrationFlowList(orchFlows); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("DeactivateNetworkBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("DeleteNetworkBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("UnassignNetworkBB"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("DeactivateNetworkCollectionBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("DeleteNetworkCollectionBB"); + orchFlows.add(orch5); + + Service service = new Service(); + CollectionResourceCustomization collectionResourceCustomization = new CollectionResourceCustomization(); + CollectionResource collectionResource = new CollectionResource(); + collectionResource.setToscaNodeType("Data NetworkCollection Data"); + collectionResourceCustomization.setCollectionResource(collectionResource); + service.getCollectionResourceCustomizations().add(collectionResourceCustomization); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(gAction,resource,false)).thenReturn(northBoundRequest); + when(catalogDbClient.getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a")).thenReturn(service); + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); + assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); + assertEquals(ebbs.get(3).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); + assertEquals(ebbs.get(4).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + assertEquals(ebbs.get(5).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); + assertEquals(ebbs.get(6).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkCollectionBB"); + assertEquals(ebbs.get(7).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkCollectionBB"); + } + + /** + * WorkflowActionBB Tests + */ + + @Test + public void pluralTest() { + List<String> items = Arrays.asList( + "serviceInstances, Service", + "vnfs, Vnf", + "vfModules, VfModule", + "networks, Network", + "invalidNames, invalidNames"); + items.forEach(item -> { + String[] split = item.split(","); + String type = split[0].trim(); + String expected = split[1].trim(); + assertThat(workflowAction.convertTypeFromPlural(type), equalTo(expected)); + }); + } + + @Test + public void sortExecutionPathByObjectForVlanTaggingCreateTest() throws Exception{ + List<ExecuteBuildingBlock> executeFlows = new ArrayList<>(); + ExecuteBuildingBlock ebb = new ExecuteBuildingBlock(); + BuildingBlock bb = new BuildingBlock(); + bb.setBpmnFlowName("AssignNetworkBB"); + bb.setKey("0"); + ebb.setBuildingBlock(bb); + executeFlows.add(ebb); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("AssignNetworkBB"); + bb2.setKey("1"); + ebb2.setBuildingBlock(bb2); + executeFlows.add(ebb2); + ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock(); + BuildingBlock bb3 = new BuildingBlock(); + bb3.setBpmnFlowName("CreateNetworkBB"); + bb3.setKey("0"); + ebb3.setBuildingBlock(bb3); + executeFlows.add(ebb3); + ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock(); + BuildingBlock bb4 = new BuildingBlock(); + bb4.setBpmnFlowName("CreateNetworkBB"); + bb4.setKey("1"); + ebb4.setBuildingBlock(bb4); + executeFlows.add(ebb4); + ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock(); + BuildingBlock bb5 = new BuildingBlock(); + bb5.setBpmnFlowName("ActivateNetworkBB"); + bb5.setKey("0"); + ebb5.setBuildingBlock(bb5); + executeFlows.add(ebb5); + ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock(); + BuildingBlock bb6 = new BuildingBlock(); + bb6.setBpmnFlowName("ActivateNetworkBB"); + bb6.setKey("1"); + ebb6.setBuildingBlock(bb6); + executeFlows.add(ebb6); + + List<ExecuteBuildingBlock> sorted = workflowAction.sortExecutionPathByObjectForVlanTagging(executeFlows,"createInstance"); + assertEquals(sorted.get(0).getBuildingBlock().getBpmnFlowName(),"AssignNetworkBB"); + assertEquals(sorted.get(1).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(sorted.get(2).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + assertEquals(sorted.get(3).getBuildingBlock().getBpmnFlowName(),"AssignNetworkBB"); + assertEquals(sorted.get(4).getBuildingBlock().getBpmnFlowName(),"CreateNetworkBB"); + assertEquals(sorted.get(5).getBuildingBlock().getBpmnFlowName(),"ActivateNetworkBB"); + } + + @Test + public void sortExecutionPathByObjectForVlanTaggingDeleteTest() throws Exception{ + List<ExecuteBuildingBlock> executeFlows = new ArrayList<>(); + ExecuteBuildingBlock ebb = new ExecuteBuildingBlock(); + BuildingBlock bb = new BuildingBlock(); + bb.setBpmnFlowName("DeactivateNetworkBB"); + bb.setKey("0"); + ebb.setBuildingBlock(bb); + executeFlows.add(ebb); + ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock(); + BuildingBlock bb2 = new BuildingBlock(); + bb2.setBpmnFlowName("DeactivateNetworkBB"); + bb2.setKey("1"); + ebb2.setBuildingBlock(bb2); + executeFlows.add(ebb2); + ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock(); + BuildingBlock bb3 = new BuildingBlock(); + bb3.setBpmnFlowName("DeleteNetworkBB"); + bb3.setKey("0"); + ebb3.setBuildingBlock(bb3); + executeFlows.add(ebb3); + ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock(); + BuildingBlock bb4 = new BuildingBlock(); + bb4.setBpmnFlowName("DeleteNetworkBB"); + bb4.setKey("1"); + ebb4.setBuildingBlock(bb4); + executeFlows.add(ebb4); + ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock(); + BuildingBlock bb5 = new BuildingBlock(); + bb5.setBpmnFlowName("UnassignNetworkBB"); + bb5.setKey("0"); + ebb5.setBuildingBlock(bb5); + executeFlows.add(ebb5); + ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock(); + BuildingBlock bb6 = new BuildingBlock(); + bb6.setBpmnFlowName("UnassignNetworkBB"); + bb6.setKey("1"); + ebb6.setBuildingBlock(bb6); + executeFlows.add(ebb6); + + List<ExecuteBuildingBlock> sorted = workflowAction.sortExecutionPathByObjectForVlanTagging(executeFlows,"deleteInstance"); + assertEquals(sorted.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); + assertEquals(sorted.get(1).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + assertEquals(sorted.get(2).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); + assertEquals(sorted.get(3).getBuildingBlock().getBpmnFlowName(),"DeactivateNetworkBB"); + assertEquals(sorted.get(4).getBuildingBlock().getBpmnFlowName(),"DeleteNetworkBB"); + assertEquals(sorted.get(5).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); + } + @Test + public void queryNorthBoundRequestCatalogDbNestedTest() throws MalformedURLException { + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = new LinkedList<>(); + OrchestrationFlow orch1 = new OrchestrationFlow(); + orch1.setFlowName("AAICheckVnfInMaintBB"); + orchFlows.add(orch1); + OrchestrationFlow orch2 = new OrchestrationFlow(); + orch2.setFlowName("AAISetVnfInMaintBB"); + orchFlows.add(orch2); + OrchestrationFlow orch3 = new OrchestrationFlow(); + orch3.setFlowName("VNF-Macro-Replace"); + orchFlows.add(orch3); + OrchestrationFlow orch4 = new OrchestrationFlow(); + orch4.setFlowName("SDNOVnfHealthCheckBB"); + orchFlows.add(orch4); + OrchestrationFlow orch5 = new OrchestrationFlow(); + orch5.setFlowName("AAIUnsetVnfInMaintBB"); + orchFlows.add(orch5); + northBoundRequest.setOrchestrationFlowList(orchFlows); + + List<OrchestrationFlow> macroFlows = new LinkedList<>(); + OrchestrationFlow o1 = new OrchestrationFlow(); + o1.setFlowName("DeactivateVfModuleBB"); + macroFlows.add(o1); + OrchestrationFlow o2 = new OrchestrationFlow(); + o2.setFlowName("DeleteVfModuleBB"); + macroFlows.add(o2); + OrchestrationFlow o3 = new OrchestrationFlow(); + o3.setFlowName("DeactivateVnfBB"); + macroFlows.add(o3); + OrchestrationFlow o4 = new OrchestrationFlow(); + o4.setFlowName("CreateVfModuleBB"); + macroFlows.add(o4); + OrchestrationFlow o5 = new OrchestrationFlow(); + o5.setFlowName("ActivateVfModuleBB"); + macroFlows.add(o5); + OrchestrationFlow o6 = new OrchestrationFlow(); + o6.setFlowName("ActivateVnfBB"); + macroFlows.add(o6); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScope("replaceInstance","Vnf",false)).thenReturn(northBoundRequest); + when(catalogDbClient.getOrchestrationFlowByAction("VNF-Macro-Replace")).thenReturn(macroFlows); + List<OrchestrationFlow> flows = workflowAction.queryNorthBoundRequestCatalogDb(execution, "replaceInstance", WorkflowType.VNF, false); + assertEquals(flows.get(0).getFlowName(),"AAICheckVnfInMaintBB"); + assertEquals(flows.get(1).getFlowName(),"AAISetVnfInMaintBB"); + assertEquals(flows.get(2).getFlowName(),"DeactivateVfModuleBB"); + assertEquals(flows.get(3).getFlowName(),"DeleteVfModuleBB"); + assertEquals(flows.get(4).getFlowName(),"DeactivateVnfBB"); + assertEquals(flows.get(5).getFlowName(),"CreateVfModuleBB"); + assertEquals(flows.get(6).getFlowName(),"ActivateVfModuleBB"); + assertEquals(flows.get(7).getFlowName(),"ActivateVnfBB"); + assertEquals(flows.get(8).getFlowName(),"SDNOVnfHealthCheckBB"); + assertEquals(flows.get(9).getFlowName(),"AAIUnsetVnfInMaintBB"); + } + + @Test + public void extractResourceIdAndTypeFromUriTest(){ + String uri = "/v6/serviceInstances/123"; + String uri2 = "/v6/serviceInstances/123/vnfs/1234"; + String uri3 = "/v6/serviceInstances"; + String uri4 = "/v6/serviceInstances/assign"; + String uri5 = "'/v6/serviceInstances/123/vnfs"; + String uri6 = "/v6/serviceInstances/123/vnfs/1234/someAction"; + String uri7 = "/v6/serviceInstances/123/vnfs/1234/vfModules/5678/replace"; + + Resource expected1 = new Resource(WorkflowType.SERVICE, "123", true); + Resource expected2 = new Resource(WorkflowType.VNF, "1234", false); + Resource expected3 = new Resource(WorkflowType.VNF, "1234", false); + Resource expected4 = new Resource(WorkflowType.VFMODULE, "5678", false); + Resource result = workflowAction.extractResourceIdAndTypeFromUri(uri); + assertEquals(expected1.getResourceId(),result.getResourceId()); + assertEquals(expected1.getResourceType(),result.getResourceType()); + result = workflowAction.extractResourceIdAndTypeFromUri(uri2); + assertEquals(expected2.getResourceId(),result.getResourceId()); + assertEquals(expected2.getResourceType(),result.getResourceType()); + result = workflowAction.extractResourceIdAndTypeFromUri(uri3); + assertEquals("Service", result.getResourceType().toString()); + assertEquals(UUID.randomUUID().toString().length(),result.getResourceId().length()); + result = workflowAction.extractResourceIdAndTypeFromUri(uri4); + assertEquals("Service", result.getResourceType().toString()); + assertEquals(UUID.randomUUID().toString().length(),result.getResourceId().length()); + result = workflowAction.extractResourceIdAndTypeFromUri(uri5); + assertEquals("Vnf", result.getResourceType().toString()); + assertEquals(UUID.randomUUID().toString().length(),result.getResourceId().length()); + result = workflowAction.extractResourceIdAndTypeFromUri(uri6); + assertEquals(expected3.getResourceId(),result.getResourceId()); + assertEquals(expected3.getResourceType(),result.getResourceType()); + result = workflowAction.extractResourceIdAndTypeFromUri(uri7); + assertEquals(expected4.getResourceId(),result.getResourceId()); + assertEquals(expected4.getResourceType(),result.getResourceType()); + } + + @Test + public void extractResourceIdAndTypeFromUriInvalidTypeTest() { + this.expectedException.expect(IllegalArgumentException.class); + this.expectedException.expectMessage(containsString("Uri could not be parsed. No type found.")); + workflowAction.extractResourceIdAndTypeFromUri("/v6/serviceInstances/123/vnfs/1234/vfmodules/5678/replace"); + } + + @Test + public void extractResourceIdAndTypeFromUriInvalidUriTest() { + this.expectedException.expect(IllegalArgumentException.class); + this.expectedException.expectMessage(containsString("Uri could not be parsed:")); + workflowAction.extractResourceIdAndTypeFromUri("something that doesn't match anything"); + } + + @Test + public void populateResourceIdsFromApiHandlerTest(){ + execution.setVariable("serviceInstanceId", "123"); + execution.setVariable("vnfId", "888"); + WorkflowResourceIds x = workflowAction.populateResourceIdsFromApiHandler(execution); + assertEquals("123",x.getServiceInstanceId()); + assertEquals("888",x.getVnfId()); + assertNull(x.getVolumeGroupId()); + } + + @Test + public void validateResourceIdInAAITest() throws Exception{ + //SI + RequestDetails reqDetails = new RequestDetails(); + SubscriberInfo subInfo = new SubscriberInfo(); + subInfo.setGlobalSubscriberId("id123"); + reqDetails.setSubscriberInfo(subInfo); + RequestParameters reqParams = new RequestParameters(); + reqParams.setSubscriptionServiceType("subServiceType123"); + reqDetails.setRequestParameters(reqParams ); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + ServiceInstance si = new ServiceInstance(); + si.setServiceInstanceId("siId123"); + Optional<ServiceInstance> siOp = Optional.of(si); + when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp); + when(bbSetupUtils.getAAIServiceInstanceByName("id123", "subServiceType123", "111111")).thenReturn(Optional.empty()); + String id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, workflowResourceIds); + assertEquals("siId123",id); + String id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "111111", reqDetails, workflowResourceIds); + assertEquals("generatedId123",id2); + + //Network + L3Network network = new L3Network(); + network.setNetworkId("id123"); + network.setNetworkName("name123"); + workflowResourceIds.setServiceInstanceId("siId123"); + Optional<L3Network> opNetwork = Optional.of(network); + when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123","name123")).thenReturn(opNetwork); + when(bbSetupUtils.getRelatedNetworkByNameFromServiceInstance("siId123","111111")).thenReturn(Optional.empty()); + id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "name123", reqDetails, workflowResourceIds); + assertEquals("id123",id); + id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.NETWORK, "111111", reqDetails, workflowResourceIds); + assertEquals("generatedId123",id2); + + //Vnf + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("id123"); + vnf.setVnfName("vnfName123"); + Optional<GenericVnf> opVnf = Optional.of(vnf); + when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123","name123")).thenReturn(opVnf); + when(bbSetupUtils.getRelatedVnfByNameFromServiceInstance("siId123","111111")).thenReturn(Optional.empty()); + id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "name123", reqDetails, workflowResourceIds); + assertEquals("id123",id); + id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "111111", reqDetails, workflowResourceIds); + assertEquals("generatedId123",id2); + + //VfModule + VfModules vfModules = new VfModules(); + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("id123"); + vfModule.setVfModuleName("name123"); + vfModules.getVfModule().add(vfModule); + vnf.setVfModules(vfModules); + workflowResourceIds.setVnfId("id123"); + when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf); + id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "name123", reqDetails, workflowResourceIds); + assertEquals("id123",id); + + GenericVnf vnf2 = new GenericVnf(); + VfModules vfModules2 = new VfModules(); + VfModule vfModule2 = new VfModule(); + vfModule2.setVfModuleId("id123"); + vfModule2.setVfModuleName("name123"); + vfModules2.getVfModule().add(vfModule2); + vnf2.setVfModules(vfModules2); + workflowResourceIds.setVnfId("id111"); + when(bbSetupUtils.getAAIGenericVnf("id111")).thenReturn(vnf2); + id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "111111", reqDetails, workflowResourceIds); + assertEquals("generatedId123",id2); + + //VolumeGroup + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("id123"); + volumeGroup.setVolumeGroupName("name123"); + workflowResourceIds.setVnfId("id123"); + Optional<VolumeGroup> opVolumeGroup = Optional.of(volumeGroup); + when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123","name123")).thenReturn(opVolumeGroup); + id = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "name123", reqDetails, workflowResourceIds); + assertEquals("id123",id); + + workflowResourceIds.setVnfId("id444"); + when(bbSetupUtils.getAAIGenericVnf("id444")).thenReturn(vnf); + when(bbSetupUtils.getRelatedVolumeGroupByNameFromVfModule("id123","111111")).thenReturn(opVolumeGroup); + when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id444","111111")).thenReturn(Optional.empty()); + id2 = workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "111111", reqDetails, workflowResourceIds); + assertEquals("id123",id2); + } + + @Test + public void handleRuntimeExceptionTest(){ + execution.setVariable("BPMN_javaExpMsg", "test runtime error message"); + execution.setVariable("testProcessKey", "testProcessKeyValue"); + try{ + workflowAction.handleRuntimeException(execution); + } catch (BpmnError wfe) { + assertEquals("MSOWorkflowException",wfe.getErrorCode()); + } + } + + @Test + public void traverseCatalogDbServiceMultipleNetworkTest() throws IOException{ + execution.setVariable("testProcessKey", "testProcessKeyValue"); + Service service = new Service(); + List<NetworkResourceCustomization> networkCustomizations = new ArrayList<>(); + NetworkResourceCustomization networkCust = new NetworkResourceCustomization(); + networkCust.setModelCustomizationUUID("123"); + networkCustomizations.add(networkCust); + service.setNetworkCustomizations(networkCustomizations); + NetworkCollectionResourceCustomization collectionResourceCustomization = new NetworkCollectionResourceCustomization(); + collectionResourceCustomization.setModelCustomizationUUID("123"); + CollectionResource collectionResource = new CollectionResource(); + collectionResource.setToscaNodeType("NetworkCollection"); + InstanceGroup instanceGroup = new InstanceGroup(); + List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupCustomizations = new ArrayList<>(); + CollectionResourceInstanceGroupCustomization collectionInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization(); + collectionInstanceGroupCustomization.setSubInterfaceNetworkQuantity(3); + collectionInstanceGroupCustomizations.add(collectionInstanceGroupCustomization); + instanceGroup.setCollectionInstanceGroupCustomizations(collectionInstanceGroupCustomizations); + collectionResource.setInstanceGroup(instanceGroup); + collectionResourceCustomization.setCollectionResource(collectionResource);; + service.setModelUUID("abc"); + service.getCollectionResourceCustomizations().add(collectionResourceCustomization); + service.getCollectionResourceCustomizations().add(collectionResourceCustomization); + doReturn(service).when(catalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a"); + doReturn(collectionResourceCustomization).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); + String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroActivateDeleteUnassign.json"))); + ObjectMapper mapper = new ObjectMapper(); + ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); + List<Resource> resourceCounter = new ArrayList<>(); + thrown.expect(BpmnError.class); + workflowAction.traverseCatalogDbService(execution, sIRequest, resourceCounter); + } + + @Test + public void sortVfModulesByBaseFirstTest(){ + List<Resource> resources = new ArrayList<>(); + Resource resource1 = new Resource(WorkflowType.VFMODULE,"111",false); + resource1.setBaseVfModule(false); + resources.add(resource1); + Resource resource2 = new Resource(WorkflowType.VFMODULE,"222",false); + resource2.setBaseVfModule(false); + resources.add(resource2); + Resource resource3 = new Resource(WorkflowType.VFMODULE,"333",false); + resource3.setBaseVfModule(true); + resources.add(resource3); + List<Resource> result = workflowAction.sortVfModulesByBaseFirst(resources); + assertEquals("333",result.get(0).getResourceId()); + assertEquals("222",result.get(1).getResourceId()); + assertEquals("111",result.get(2).getResourceId()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/sdno/tasks/SDNOHealthCheckTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/sdno/tasks/SDNOHealthCheckTasksTest.java new file mode 100644 index 0000000000..10599bdab4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/sdno/tasks/SDNOHealthCheckTasksTest.java @@ -0,0 +1,108 @@ +/*- + * ============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.sdno.tasks; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.SDNOHealthCheckResources; + + +@RunWith(MockitoJUnitRunner.class) +public class SDNOHealthCheckTasksTest extends TestDataSetup { + + @InjectMocks + protected SDNOHealthCheckTasks sdnoHealthCheckTasks = new SDNOHealthCheckTasks(); + + @Mock + SDNOHealthCheckResources MOCK_sdnoHealthCheckResources; + + + @Mock + private ExceptionBuilder exceptionUtil; + + @Mock + private ExtractPojosForBB extractPojosForBB; + + + private RequestContext requestContext; + private GenericVnf genericVnf; + + @Before + public void before() throws BBObjectNotFoundException { + genericVnf = setGenericVnf(); + requestContext = setRequestContext(); + when(extractPojosForBB.extractByKey(any(),any(), any())).thenReturn(genericVnf); + + } + + @Test + public void sdnoHealthCheckTest() throws Exception { + doReturn(true).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext); + sdnoHealthCheckTasks.sdnoHealthCheck(execution); + verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext); + } + + @Test + public void sdnoHealthCheckNoResponseTest() throws Exception { + + doReturn(false).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext); + try { + sdnoHealthCheckTasks.sdnoHealthCheck(execution); + } catch (Exception e) { + verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + } + + } + + @Test + public void sdnoHealthCheckExceptionTest() throws Exception { + doThrow(new Exception("Unknown Error")).when(MOCK_sdnoHealthCheckResources).healthCheck(genericVnf, requestContext); + doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + try { + sdnoHealthCheckTasks.sdnoHealthCheck(execution); + } catch (Exception e) { + verify(MOCK_sdnoHealthCheckResources, times(1)).healthCheck(genericVnf, requestContext); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + } + + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java new file mode 100644 index 0000000000..88f8526f31 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java @@ -0,0 +1,623 @@ +/*- + * ============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.aai.mapper; + +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.assertThat; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.aai.domain.yang.RouteTargets; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CtagAssignment; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Project; +import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTarget; +import org.onap.so.bpmn.servicedecomposition.bbobjects.SegmentationAssignment; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoCollection; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup; +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.db.catalog.beans.OrchestrationStatus; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class AAIObjectMapperTest{ + private AAIObjectMapper aaiObjectMapper = new AAIObjectMapper(); + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + + + @Test + public void mapConfigurationTest() { + Configuration configuration = new Configuration(); + configuration.setConfigurationId("configId"); + configuration.setConfigurationName("VNR"); + configuration.setConfigurationType("VNR-TYPE"); + configuration.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + configuration.setManagementOption("managementOption"); + ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration(); + modelInfoConfiguration.setModelCustomizationId("modelCustId"); + modelInfoConfiguration.setModelInvariantId("modelInvariantId"); + modelInfoConfiguration.setModelVersionId("modelVersionId"); + configuration.setModelInfoConfiguration(modelInfoConfiguration); + + org.onap.aai.domain.yang.Configuration expectedConfiguration = new org.onap.aai.domain.yang.Configuration(); + expectedConfiguration.setConfigurationId(configuration.getConfigurationId()); + expectedConfiguration.setConfigurationName(configuration.getConfigurationName()); + expectedConfiguration.setConfigurationType(configuration.getConfigurationType()); + expectedConfiguration.setOrchestrationStatus(configuration.getOrchestrationStatus().toString()); + expectedConfiguration.setManagementOption(configuration.getManagementOption()); + expectedConfiguration.setModelInvariantId(configuration.getModelInfoConfiguration().getModelInvariantId()); + expectedConfiguration.setModelVersionId(configuration.getModelInfoConfiguration().getModelVersionId()); + expectedConfiguration.setModelCustomizationId(configuration.getModelInfoConfiguration().getModelCustomizationId()); + + org.onap.aai.domain.yang.Configuration actualConfiguration = aaiObjectMapper.mapConfiguration(configuration); + + assertThat(actualConfiguration, sameBeanAs(expectedConfiguration)); + } + + @Test + public void mapVolumeGroupTest() throws Exception { + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setHeatStackId("heatStackId"); + volumeGroup.setModelInfoVfModule(new ModelInfoVfModule()); + volumeGroup.getModelInfoVfModule().setModelCustomizationUUID("modelCustomizationId"); + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ACTIVE); + volumeGroup.setVnfType("vnfType"); + volumeGroup.setVolumeGroupId("volumeGroupId"); + volumeGroup.setVolumeGroupName("volumeGroupName"); + + org.onap.aai.domain.yang.VolumeGroup expectedVolumeGroup = new org.onap.aai.domain.yang.VolumeGroup(); + expectedVolumeGroup.setHeatStackId(volumeGroup.getHeatStackId()); + expectedVolumeGroup.setModelCustomizationId(volumeGroup.getModelInfoVfModule().getModelCustomizationUUID()); + expectedVolumeGroup.setOrchestrationStatus(volumeGroup.getOrchestrationStatus().toString()); + expectedVolumeGroup.setVfModuleModelCustomizationId(volumeGroup.getModelInfoVfModule().getModelCustomizationUUID()); + expectedVolumeGroup.setVnfType(volumeGroup.getVnfType()); + expectedVolumeGroup.setVolumeGroupId(volumeGroup.getVolumeGroupId()); + expectedVolumeGroup.setVolumeGroupName(volumeGroup.getVolumeGroupName()); + + org.onap.aai.domain.yang.VolumeGroup actualVolumeGroup = aaiObjectMapper.mapVolumeGroup(volumeGroup); + + assertThat(actualVolumeGroup, sameBeanAs(expectedVolumeGroup)); + } + + @Test + public void serviceInstanceMap() { + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("SIID"); + serviceInstance.setServiceInstanceName("SINAME"); + serviceInstance.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setServiceType("SITYPE"); + modelInfoServiceInstance.setServiceRole("SIROLE"); + modelInfoServiceInstance.setModelInvariantUuid("MIUUID"); + modelInfoServiceInstance.setModelUuid("MUUID"); + modelInfoServiceInstance.setEnvironmentContext("EC"); + modelInfoServiceInstance.setWorkloadContext("WC"); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + + org.onap.aai.domain.yang.ServiceInstance AAIServiceInstance = aaiObjectMapper.mapServiceInstance(serviceInstance); + + assertEquals(AAIServiceInstance.getServiceInstanceId(),serviceInstance.getServiceInstanceId()); + assertEquals(AAIServiceInstance.getServiceInstanceName(),serviceInstance.getServiceInstanceName()); + assertEquals(AAIServiceInstance.getOrchestrationStatus().toString(),serviceInstance.getOrchestrationStatus().toString()); + assertEquals(AAIServiceInstance.getServiceType(),serviceInstance.getModelInfoServiceInstance().getServiceType()); + assertEquals(AAIServiceInstance.getServiceRole(),serviceInstance.getModelInfoServiceInstance().getServiceRole()); + assertEquals(AAIServiceInstance.getModelInvariantId(),serviceInstance.getModelInfoServiceInstance().getModelInvariantUuid()); + assertEquals(AAIServiceInstance.getModelVersionId(),serviceInstance.getModelInfoServiceInstance().getModelUuid()); + assertEquals(AAIServiceInstance.getEnvironmentContext(),serviceInstance.getModelInfoServiceInstance().getEnvironmentContext()); + assertEquals(AAIServiceInstance.getWorkloadContext(),serviceInstance.getModelInfoServiceInstance().getWorkloadContext()); + } + + @Test + public void projectMap(){ + Project project = new Project(); + project.setProjectName("abc"); + + org.onap.aai.domain.yang.Project AAIProject = aaiObjectMapper.mapProject(project); + + assertEquals(AAIProject.getProjectName(),project.getProjectName()); + } + + @Test + public void serviceSubscriptionMap(){ + ServiceSubscription serviceSubscription = new ServiceSubscription(); + serviceSubscription.setServiceType("IP-FLEX"); + serviceSubscription.setTempUbSubAccountId("Account-ID"); + org.onap.aai.domain.yang.ServiceSubscription serviceSubscriptionMapped = aaiObjectMapper.mapServiceSubscription(serviceSubscription); + assertNotNull(serviceSubscriptionMapped); + assertEquals(serviceSubscription.getTempUbSubAccountId(),serviceSubscriptionMapped.getTempUbSubAccountId()); + assertEquals(serviceSubscription.getServiceType(),serviceSubscriptionMapped.getServiceType()); + } + + @Test + public void owningEntityMap(){ + OwningEntity oe = new OwningEntity(); + oe.setOwningEntityId("abc"); + oe.setOwningEntityName("bbb"); + + org.onap.aai.domain.yang.OwningEntity AAIOwningEntity = aaiObjectMapper.mapOwningEntity(oe); + + assertEquals(AAIOwningEntity.getOwningEntityId(),oe.getOwningEntityId()); + assertEquals(AAIOwningEntity.getOwningEntityName(),oe.getOwningEntityName()); + + } + + @Test + public void vnfMap(){ + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("a"); + vnf.setVnfName("b"); + vnf.setServiceId("c"); + vnf.setVnfType("d"); + vnf.setProvStatus("e"); + vnf.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelCustomizationUuid("f"); + modelInfoGenericVnf.setModelInvariantUuid("g"); + modelInfoGenericVnf.setModelUuid("h"); + modelInfoGenericVnf.setNfRole("i"); + modelInfoGenericVnf.setNfType("j"); + modelInfoGenericVnf.setNfFunction("k"); + modelInfoGenericVnf.setNfNamingCode("l"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + org.onap.aai.domain.yang.GenericVnf AAIVnf = aaiObjectMapper.mapVnf(vnf); + + assertEquals(AAIVnf.getVnfId(),vnf.getVnfId()); + assertEquals(AAIVnf.getVnfName(),vnf.getVnfName()); + assertEquals(AAIVnf.getServiceId(),vnf.getServiceId()); + assertEquals(AAIVnf.getVnfType(),vnf.getVnfType()); + assertEquals(AAIVnf.getProvStatus(),vnf.getProvStatus()); + assertEquals(AAIVnf.getOrchestrationStatus().toString(),vnf.getOrchestrationStatus().toString()); + assertEquals(AAIVnf.getModelCustomizationId(),vnf.getModelInfoGenericVnf().getModelCustomizationUuid()); + assertEquals(AAIVnf.getModelInvariantId(),vnf.getModelInfoGenericVnf().getModelInvariantUuid()); + assertEquals(AAIVnf.getModelVersionId(),vnf.getModelInfoGenericVnf().getModelUuid()); + assertEquals(AAIVnf.getModelVersionId(),vnf.getModelInfoGenericVnf().getModelUuid()); + assertEquals(AAIVnf.getNfType(),vnf.getModelInfoGenericVnf().getNfType()); + assertEquals(AAIVnf.getNfFunction(),vnf.getModelInfoGenericVnf().getNfFunction()); + assertEquals(AAIVnf.getNfNamingCode(),vnf.getModelInfoGenericVnf().getNfNamingCode()); + } + + @Test + public void vfModuleMap() throws Exception { + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("a"); + vfModule.setVfModuleName("b"); + vfModule.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelCustomizationUUID("f"); + modelInfoVfModule.setModelInvariantUUID("g"); + modelInfoVfModule.setModelUUID("h"); + modelInfoVfModule.setIsBaseBoolean(false); + vfModule.setModelInfoVfModule(modelInfoVfModule); + + org.onap.aai.domain.yang.VfModule AAIVfModule = aaiObjectMapper.mapVfModule(vfModule); + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVfModuleMap.json"))); + + ObjectMapper omapper = new ObjectMapper(); + org.onap.aai.domain.yang.VfModule reqMapper1 = omapper.readValue( + jsonToCompare, + org.onap.aai.domain.yang.VfModule.class); + + assertThat(reqMapper1, sameBeanAs(AAIVfModule)); + + } + + @Test + public void testMapInstanceGroup() { + InstanceGroup instanceGroup = new InstanceGroup(); + instanceGroup.setId("test-id"); + instanceGroup.setDescription("test-description"); + instanceGroup.setInstanceGroupName("test-instanceGroupName"); + instanceGroup.setResourceVersion("test-resourceVersion"); + + + ModelInfoInstanceGroup model = new ModelInfoInstanceGroup(); + model.setFunction("test-function"); + model.setInstanceGroupRole("SUB-INTERFACE"); + model.setType("VNFC"); + model.setModelInvariantUUID("modelInvariantUUID-000"); + model.setModelUUID("modelUUID-000"); + model.setDescription("test-description"); + + instanceGroup.setModelInfoInstanceGroup(model); + + + org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup = aaiObjectMapper.mapInstanceGroup(instanceGroup); + + try { + com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper(); + String json = mapper.writeValueAsString(aaiInstanceGroup); + System.out.println("GGG - json:\n" + json); + + } + catch(Exception e) { + e.printStackTrace(); + } + + assertEquals(aaiInstanceGroup.getId(), instanceGroup.getId()); + assertEquals(aaiInstanceGroup.getDescription(), instanceGroup.getDescription()); + assertEquals(aaiInstanceGroup.getInstanceGroupRole(), instanceGroup.getModelInfoInstanceGroup().getInstanceGroupRole()); + assertEquals(aaiInstanceGroup.getModelInvariantId(), instanceGroup.getModelInfoInstanceGroup().getModelInvariantUUID()); + assertEquals(aaiInstanceGroup.getModelVersionId(), instanceGroup.getModelInfoInstanceGroup().getModelUUID()); + assertEquals(aaiInstanceGroup.getResourceVersion(), instanceGroup.getResourceVersion()); + assertEquals(aaiInstanceGroup.getInstanceGroupType(), instanceGroup.getModelInfoInstanceGroup().getType()); + } + + @Test + public void mapCustomerTest() { + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + customer.setSubscriberName("subscriberName"); + customer.setSubscriberType("subscriberType"); + + org.onap.aai.domain.yang.Customer expectedCustomer = new org.onap.aai.domain.yang.Customer(); + expectedCustomer.setGlobalCustomerId("globalCustomerId"); + expectedCustomer.setSubscriberName("subscriberName"); + expectedCustomer.setSubscriberType("subscriberType"); + + org.onap.aai.domain.yang.Customer actualCustomer = aaiObjectMapper.mapCustomer(customer); + + assertThat(actualCustomer, sameBeanAs(expectedCustomer)); + } + + @Test + public void networkMap() throws Exception { + L3Network l3Network = new L3Network(); + l3Network.setNetworkId("networkId"); + l3Network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + l3Network.setNetworkName("networkName"); + l3Network.setNetworkRole("networkRole"); + l3Network.setNetworkTechnology("networkTechnology"); + l3Network.setNeutronNetworkId("neutronNetworkId"); + l3Network.setNetworkRoleInstance(0L); + l3Network.setContrailNetworkFqdn("contrailNetworkFqdn"); + l3Network.setIsBoundToVpn(false); + l3Network.setIsCascaded(false); + l3Network.setIsExternalNetwork(false); + l3Network.setHeatStackId("heatStackId"); + l3Network.setOperationalStatus("operationalStatus"); + l3Network.setPhysicalNetworkName("physicalNetworkName"); + l3Network.setIsProviderNetwork(false); + l3Network.setSelflink("selflink"); + l3Network.setServiceId("serviceId"); + + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUUID"); + modelInfoNetwork.setModelInvariantUUID("modelInvariantUUID"); + modelInfoNetwork.setModelUUID("modelUUID"); + + l3Network.setModelInfoNetwork(modelInfoNetwork); + + org.onap.aai.domain.yang.L3Network aaiL3Network = aaiObjectMapper.mapNetwork(l3Network); + + ObjectMapper omapper = new ObjectMapper(); + org.onap.aai.domain.yang.L3Network network = omapper.readValue( + getJson("aaiL3NetworkMapped.json"), + org.onap.aai.domain.yang.L3Network.class); + + com.shazam.shazamcrest.MatcherAssert.assertThat(aaiL3Network, sameBeanAs(network)); + + } + + @Test + public void mapCollectionTest() { + Collection networkCollection = new Collection(); + networkCollection.setId("networkCollectionId"); + ModelInfoCollection modelInfoCollection = new ModelInfoCollection(); + modelInfoCollection.setCollectionFunction("networkCollectionFunction"); + modelInfoCollection.setCollectionRole("networkCollectionRole"); + networkCollection.setModelInfoCollection(modelInfoCollection); + networkCollection.setName("networkCollectionName"); + + org.onap.aai.domain.yang.Collection expectedCollection = new org.onap.aai.domain.yang.Collection(); + expectedCollection.setCollectionId("networkCollectionId"); + expectedCollection.setCollectionFunction("networkCollectionFunction"); + expectedCollection.setCollectionRole("networkCollectionRole"); + expectedCollection.setCollectionName("networkCollectionName"); + + org.onap.aai.domain.yang.Collection actualCollection = aaiObjectMapper.mapCollection(networkCollection); + + assertThat(actualCollection, sameBeanAs(expectedCollection)); + } + + /* + * Helper method to load JSON data + */ + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + filename))); + } + + @Test + public void mapNetworkTest() throws Exception { + L3Network l3Network = new L3Network(); + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + modelInfoNetwork.setModelCustomizationUUID("modelCustomization_id"); + modelInfoNetwork.setModelInvariantUUID("modelInvariant_id"); + modelInfoNetwork.setModelUUID("modelCustomization_id"); + modelInfoNetwork.setNetworkType("CONTRAIL_EXTERNAL"); + modelInfoNetwork.setNetworkRole("dmz_direct"); + modelInfoNetwork.setNetworkTechnology("contrail"); + l3Network.setModelInfoNetwork(modelInfoNetwork); + l3Network.setNetworkId("TESTING_ID"); + l3Network.setNetworkName("TESTING_NAME"); + l3Network.setIsBoundToVpn(true); + l3Network.setServiceId("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"); + l3Network.setNetworkRoleInstance(1L); + l3Network.setOrchestrationStatus(OrchestrationStatus.CREATED); + l3Network.setHeatStackId("heatStack_id"); + l3Network.setContrailNetworkFqdn("contrailNetwork_fqdn"); + l3Network.setWidgetModelId("widgetModel_id"); + l3Network.setWidgetModelVersion("widgetModel_version"); + l3Network.setPhysicalNetworkName("physicalNetwork_name"); + l3Network.setIsProviderNetwork(true); + l3Network.setIsSharedNetwork(false); + l3Network.setIsExternalNetwork(false); + l3Network.setSelflink("self_link"); + l3Network.setOperationalStatus("operationalStatus"); + + List<Subnet> subnets = new ArrayList<Subnet>(); + Subnet subnet1 = new Subnet(); + subnet1.setSubnetId("57e9a1ff-d14f-4071-a828-b19ae98eb2fc"); + subnet1.setSubnetName("subnetName"); + subnet1.setGatewayAddress("192.168.52.1"); + subnet1.setNetworkStartAddress("192.168.52.0"); + subnet1.setCidrMask("24"); + subnet1.setIpVersion("4"); + subnet1.setOrchestrationStatus(OrchestrationStatus.CREATED); + subnet1.setIpAssignmentDirection("true"); + subnet1.setDhcpEnabled(true); + subnet1.setDhcpStart("dhcpStart"); + subnet1.setDhcpEnd("dhcpEnd"); + subnet1.setSubnetRole("subnetRole"); + subnet1.setIpAssignmentDirection("true"); + subnet1.setSubnetSequence(new Integer(3)); + + List<HostRoute> hostRoutes = new ArrayList<HostRoute>(); + HostRoute hostRoute1 = new HostRoute(); + hostRoute1.setHostRouteId("string"); + hostRoute1.setRoutePrefix("192.10.16.0/24"); + hostRoute1.setNextHop("192.10.16.100/24"); + hostRoute1.setNextHopType("ip-address"); + HostRoute hostRoute2 = new HostRoute(); + hostRoute2.setHostRouteId("string"); + hostRoute2.setRoutePrefix("192.110.17.0/24"); + hostRoute2.setNextHop("192.110.17.110/24"); + hostRoute2.setNextHopType("ip-address"); + hostRoutes.add(hostRoute1); + hostRoutes.add(hostRoute2); + subnet1.getHostRoutes().addAll(hostRoutes); + + subnets.add(subnet1); + subnets.add(subnet1); + l3Network.getSubnets().addAll(subnets); + + List<CtagAssignment> ctagAssignments = new ArrayList<CtagAssignment>(); + CtagAssignment ctagAssignment1 = new CtagAssignment(); + ctagAssignment1.setVlanIdInner(1L); + ctagAssignments.add(ctagAssignment1); + l3Network.getCtagAssignments().addAll(ctagAssignments); + + List<SegmentationAssignment> segmentationAssignments = new ArrayList<SegmentationAssignment>(); + SegmentationAssignment segmentationAssignment1 = new SegmentationAssignment(); + segmentationAssignment1.setSegmentationId("segmentationId1"); + SegmentationAssignment segmentationAssignment2 = new SegmentationAssignment(); + segmentationAssignment2.setSegmentationId("segmentationId2"); + segmentationAssignments.add(segmentationAssignment1); + segmentationAssignments.add(segmentationAssignment2); + l3Network.getSegmentationAssignments().addAll(segmentationAssignments); + + AAIObjectMapper l3NetworkMapper = new AAIObjectMapper(); + org.onap.aai.domain.yang.L3Network v12L3Network = l3NetworkMapper.mapNetwork(l3Network); + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiL3NetworkMapped_to_aai.json"))); + ObjectMapper omapper = new ObjectMapper(); + org.onap.aai.domain.yang.L3Network network = omapper.readValue(jsonToCompare, + org.onap.aai.domain.yang.L3Network.class); + + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String jsonGenerated = ow.writeValueAsString(v12L3Network); + String jsonExpected = ow.writeValueAsString(network); + assertEquals(jsonExpected, jsonGenerated); + + } + + @Test + public void mapToAAISubNetsTest() throws Exception { + List<Subnet> subnets = new ArrayList<Subnet>(); + Subnet subnet1 = new Subnet(); + subnet1.setSubnetId("57e9a1ff-d14f-4071-a828-b19ae98eb2fc"); + subnet1.setSubnetName("subnetName"); + subnet1.setGatewayAddress("192.168.52.1"); + subnet1.setNetworkStartAddress("192.168.52.0"); + subnet1.setCidrMask("24"); + subnet1.setIpVersion("4"); + subnet1.setOrchestrationStatus(OrchestrationStatus.CREATED); + subnet1.setIpAssignmentDirection("true"); + subnet1.setDhcpEnabled(true); + subnet1.setDhcpStart("dhcpStart"); + subnet1.setDhcpEnd("dhcpEnd"); + subnet1.setSubnetRole("subnetRole"); + subnet1.setIpAssignmentDirection("true"); + subnet1.setSubnetSequence(new Integer(3)); + + List<HostRoute> hostRoutes = new ArrayList<HostRoute>(); + HostRoute hostRoute1 = new HostRoute(); + hostRoute1.setHostRouteId("string"); + hostRoute1.setRoutePrefix("192.10.16.0/24"); + hostRoute1.setNextHop("192.10.16.100/24"); + hostRoute1.setNextHopType("ip-address"); + HostRoute hostRoute2 = new HostRoute(); + hostRoute2.setHostRouteId("string"); + hostRoute2.setRoutePrefix("192.110.17.0/24"); + hostRoute2.setNextHop("192.110.17.110/24"); + hostRoute2.setNextHopType("ip-address"); + hostRoutes.add(hostRoute1); + hostRoutes.add(hostRoute2); + subnet1.getHostRoutes().addAll(hostRoutes); + + subnets.add(subnet1); + subnets.add(subnet1); + + AAIObjectMapper aaiObjectMapper = new AAIObjectMapper(); + org.onap.aai.domain.yang.Subnets v12Subnets = aaiObjectMapper.mapToAAISubNets(subnets); + + assertEquals(subnets.get(0).getDhcpEnd(), v12Subnets.getSubnet().get(0).getDhcpEnd()); + assertEquals(subnets.get(0).getCidrMask(), v12Subnets.getSubnet().get(0).getCidrMask()); + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiSubnetsMapped_to_aai.json"))); + ObjectMapper omapper = new ObjectMapper(); + org.onap.aai.domain.yang.Subnets subnet = omapper.readValue(jsonToCompare, + org.onap.aai.domain.yang.Subnets.class); + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String jsonGenerated = ow.writeValueAsString(v12Subnets); + String jsonExpected = ow.writeValueAsString(subnet); + assertEquals(jsonExpected, jsonGenerated); + } + + @Test + public void mapToAAICtagAssignmentListTest() throws Exception { + List<CtagAssignment> ctagAssignments = new ArrayList<CtagAssignment>(); + CtagAssignment ctagAssignment1 = new CtagAssignment(); + ctagAssignment1.setVlanIdInner(1L); + ctagAssignments.add(ctagAssignment1); + + AAIObjectMapper aaiObjectMapper = new AAIObjectMapper(); + org.onap.aai.domain.yang.CtagAssignments v12CtagAssingments = aaiObjectMapper.mapToAAICtagAssignmentList(ctagAssignments); + + assertEquals(ctagAssignments.get(0).getVlanIdInner(), v12CtagAssingments.getCtagAssignment().get(0).getVlanIdInner()); + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiCtagAssingmentsMapped_to_aai.json"))); + ObjectMapper omapper = new ObjectMapper(); + org.onap.aai.domain.yang.CtagAssignments ctagAssignment = omapper.readValue(jsonToCompare, + org.onap.aai.domain.yang.CtagAssignments.class); + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String jsonGenerated = ow.writeValueAsString(v12CtagAssingments); + String jsonExpected = ow.writeValueAsString(ctagAssignment); + assertEquals(jsonExpected, jsonGenerated); + } + + @Test + public void mapToAAISegmentationAssignmentListTest() throws Exception { + List<SegmentationAssignment> segmentationAssignments = new ArrayList<SegmentationAssignment>(); + SegmentationAssignment segmentationAssignment1 = new SegmentationAssignment(); + segmentationAssignment1.setSegmentationId("segmentationId1"); + SegmentationAssignment segmentationAssignment2 = new SegmentationAssignment(); + segmentationAssignment2.setSegmentationId("segmentationId2"); + segmentationAssignments.add(segmentationAssignment1); + segmentationAssignments.add(segmentationAssignment2); + + AAIObjectMapper aaiObjectMapper = new AAIObjectMapper(); + org.onap.aai.domain.yang.SegmentationAssignments v12SegmentationAssignments = aaiObjectMapper.mapToAAISegmentationAssignmentList(segmentationAssignments); + + assertEquals(segmentationAssignments.get(0).getSegmentationId(), v12SegmentationAssignments.getSegmentationAssignment().get(0).getSegmentationId()); + assertEquals(segmentationAssignments.get(1).getSegmentationId(), v12SegmentationAssignments.getSegmentationAssignment().get(1).getSegmentationId()); + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiSegmentationAssignmentsMapped_to_aai.json"))); + ObjectMapper omapper = new ObjectMapper(); + org.onap.aai.domain.yang.SegmentationAssignments segmentationAssignment = omapper.readValue(jsonToCompare, + org.onap.aai.domain.yang.SegmentationAssignments.class); + ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); + String jsonGenerated = ow.writeValueAsString(v12SegmentationAssignments); + String jsonExpected = ow.writeValueAsString(segmentationAssignment); + assertEquals(jsonExpected, jsonGenerated); + + } + + @Test + public void mapVpnBindingTest() { + VpnBinding vpnBinding = new VpnBinding(); + vpnBinding.setVpnId("testVpnId"); + vpnBinding.setVpnName("testVpn"); + vpnBinding.setVpnPlatform("AVPN"); + vpnBinding.setCustomerVpnId("testCustomerVpnId"); + vpnBinding.setVpnType("testVpnType"); + vpnBinding.setVpnRegion("testVpnRegion"); + vpnBinding.setRouteDistinguisher("testRD"); + RouteTarget routeTarget = new RouteTarget(); + routeTarget.setRouteTargetRole("testRtRole"); + routeTarget.setGlobalRouteTarget("testGrt"); + vpnBinding.getRouteTargets().add(routeTarget); + + + org.onap.aai.domain.yang.VpnBinding expectedVpnBinding = new org.onap.aai.domain.yang.VpnBinding(); + expectedVpnBinding.setVpnId("testVpnId"); + expectedVpnBinding.setVpnName("testVpn"); + expectedVpnBinding.setVpnPlatform("AVPN"); + expectedVpnBinding.setCustomerVpnId("testCustomerVpnId"); + expectedVpnBinding.setVpnType("testVpnType"); + expectedVpnBinding.setVpnRegion("testVpnRegion"); + expectedVpnBinding.setRouteDistinguisher("testRD"); + + org.onap.aai.domain.yang.RouteTarget expectedRouteTarget = new org.onap.aai.domain.yang.RouteTarget(); + expectedRouteTarget.setRouteTargetRole("testRtRole"); + expectedRouteTarget.setGlobalRouteTarget("testGrt"); + + RouteTargets expectedRouteTargets = new RouteTargets(); + expectedRouteTargets.getRouteTarget().add(expectedRouteTarget); + + expectedVpnBinding.setRouteTargets(expectedRouteTargets); + + org.onap.aai.domain.yang.VpnBinding actualVpnBinding = aaiObjectMapper.mapVpnBinding(vpnBinding); + + assertThat(actualVpnBinding, sameBeanAs(expectedVpnBinding)); + } + + @Test + public void mapRouteTargetTest() { + RouteTarget routeTarget = new RouteTarget(); + routeTarget.setRouteTargetRole("testRtRole"); + routeTarget.setGlobalRouteTarget("testGrt"); + + org.onap.aai.domain.yang.RouteTarget expectedRouteTarget = new org.onap.aai.domain.yang.RouteTarget(); + expectedRouteTarget.setRouteTargetRole("testRtRole"); + expectedRouteTarget.setGlobalRouteTarget("testGrt"); + + org.onap.aai.domain.yang.RouteTarget actualRouteTarget = aaiObjectMapper.mapRouteTarget(routeTarget); + + assertThat(actualRouteTarget, sameBeanAs(expectedRouteTarget)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java new file mode 100644 index 0000000000..207b9f3f98 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java @@ -0,0 +1,227 @@ +/*- + * ============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.adapter.network; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.so.BaseTest; +import org.onap.so.adapters.nwrest.CreateNetworkError; +import org.onap.so.adapters.nwrest.CreateNetworkRequest; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.adapters.nwrest.DeleteNetworkError; +import org.onap.so.adapters.nwrest.DeleteNetworkRequest; +import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.adapters.nwrest.QueryNetworkError; +import org.onap.so.adapters.nwrest.QueryNetworkResponse; +import org.onap.so.adapters.nwrest.RollbackNetworkError; +import org.onap.so.adapters.nwrest.RollbackNetworkRequest; +import org.onap.so.adapters.nwrest.RollbackNetworkResponse; +import org.onap.so.adapters.nwrest.UpdateNetworkError; +import org.onap.so.adapters.nwrest.UpdateNetworkRequest; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; +import org.onap.so.openstack.beans.NetworkRollback; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import static com.github.tomakehurst.wiremock.client.WireMock.*; + +public class NetworkAdapterClientIT extends BaseTest{ + + private static final String TESTING_ID = "___TESTING___"; + private static final String AAI_NETWORK_ID = "test"; + private static final String REST_ENDPOINT = "/networks/rest/v1/networks"; + + private NetworkAdapterClientImpl client = new NetworkAdapterClientImpl(); + private ObjectMapper mapper = new ObjectMapper(); + + @BeforeClass + public static void setUp() { + System.setProperty("mso.config.path", "src/test/resources"); + } + + @Test + public void createNetworkTest() throws NetworkAdapterClientException, JsonProcessingException { + CreateNetworkRequest request = new CreateNetworkRequest(); + request.setCloudSiteId(TESTING_ID); + + CreateNetworkResponse mockResponse = new CreateNetworkResponse(); + mockResponse.setNetworkCreated(true); + stubFor(post(urlPathEqualTo(REST_ENDPOINT)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + CreateNetworkResponse response = client.createNetwork(request); + assertEquals("Testing CreateVfModule response", true, response.getNetworkCreated()); + } + + @Test(expected = NetworkAdapterClientException.class) + public void createNetworkTestThrowException() throws NetworkAdapterClientException, JsonProcessingException { + CreateNetworkRequest request = new CreateNetworkRequest(); + request.setCloudSiteId(TESTING_ID); + + CreateNetworkError mockResponse = new CreateNetworkError(); + mockResponse.setMessage("Error in create network"); + stubFor(post(urlPathEqualTo(REST_ENDPOINT)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.createNetwork(request); + } + + @Test + public void deleteNetworkTest() throws NetworkAdapterClientException, JsonProcessingException { + DeleteNetworkRequest request = new DeleteNetworkRequest(); + request.setCloudSiteId(TESTING_ID); + + DeleteNetworkResponse mockResponse = new DeleteNetworkResponse(); + mockResponse.setNetworkDeleted(true); + + stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + DeleteNetworkResponse response = client.deleteNetwork(AAI_NETWORK_ID, request); + assertEquals("Testing DeleteVfModule response", true, response.getNetworkDeleted()); + } + + @Test(expected = NetworkAdapterClientException.class) + public void deleteNetworkTestThrowException() throws NetworkAdapterClientException, JsonProcessingException { + DeleteNetworkRequest request = new DeleteNetworkRequest(); + request.setCloudSiteId(TESTING_ID); + + DeleteNetworkError mockResponse = new DeleteNetworkError(); + mockResponse.setMessage("Error in delete network"); + stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.deleteNetwork(AAI_NETWORK_ID, request); + } + + @Test + public void rollbackNetworkTest() throws NetworkAdapterClientException, JsonProcessingException { + RollbackNetworkRequest request = new RollbackNetworkRequest(); + NetworkRollback rollback = new NetworkRollback(); + rollback.setCloudId(TESTING_ID); + request.setNetworkRollback(rollback); + + RollbackNetworkResponse mockResponse = new RollbackNetworkResponse(); + mockResponse.setNetworkRolledBack(true); + + stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + RollbackNetworkResponse response = client.rollbackNetwork(AAI_NETWORK_ID, request); + assertEquals("Testing DeleteVfModule response", true, response.getNetworkRolledBack()); + } + + @Test(expected = NetworkAdapterClientException.class) + public void rollbackNetworkTestThrowException() throws NetworkAdapterClientException, JsonProcessingException { + RollbackNetworkRequest request = new RollbackNetworkRequest(); + NetworkRollback rollback = new NetworkRollback(); + rollback.setCloudId(TESTING_ID); + request.setNetworkRollback(rollback); + + RollbackNetworkError mockResponse = new RollbackNetworkError(); + mockResponse.setMessage("Error in rollback network"); + + stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.rollbackNetwork(AAI_NETWORK_ID, request); + } + + @Test + public void queryNetworkTest() throws NetworkAdapterClientException, JsonProcessingException { + QueryNetworkResponse mockResponse = new QueryNetworkResponse(); + mockResponse.setNetworkExists(true); + + stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) + .withQueryParam("tenantId", equalTo(TESTING_ID)) + .withQueryParam("networkStackId", equalTo("networkStackId")).withQueryParam("skipAAI", equalTo("true")) + .withQueryParam("msoRequest.requestId", equalTo("testRequestId")) + .withQueryParam("msoRequest.serviceInstanceId", equalTo("serviceInstanceId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + QueryNetworkResponse response = client.queryNetwork(AAI_NETWORK_ID, TESTING_ID, TESTING_ID, "networkStackId", + true, "testRequestId", "serviceInstanceId"); + assertEquals("Testing QueryVfModule response", true, response.getNetworkExists()); + } + + @Test(expected = NetworkAdapterClientException.class) + public void queryNetworkTestThrowException() throws NetworkAdapterClientException, JsonProcessingException { + QueryNetworkError mockResponse = new QueryNetworkError(); + mockResponse.setMessage("Error in query network"); + + stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) + .withQueryParam("tenantId", equalTo(TESTING_ID)) + .withQueryParam("networkStackId", equalTo("networkStackId")).withQueryParam("skipAAI", equalTo("true")) + .withQueryParam("msoRequest.requestId", equalTo("testRequestId")) + .withQueryParam("msoRequest.serviceInstanceId", equalTo("serviceInstanceId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.queryNetwork(AAI_NETWORK_ID, TESTING_ID, TESTING_ID, "networkStackId", + true, "testRequestId", "serviceInstanceId"); + } + + @Test + public void updateNetworkTest() throws NetworkAdapterClientException, JsonProcessingException { + UpdateNetworkRequest request = new UpdateNetworkRequest(); + request.setCloudSiteId(TESTING_ID); + request.setNetworkId("test1"); + + UpdateNetworkResponse mockResponse = new UpdateNetworkResponse(); + mockResponse.setNetworkId("test1"); + stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + UpdateNetworkResponse response = client.updateNetwork(AAI_NETWORK_ID, request); + assertEquals("Testing UpdateVfModule response", "test1", response.getNetworkId()); + } + + @Test(expected = NetworkAdapterClientException.class) + public void updateNetworkTestThrowException() throws NetworkAdapterClientException, JsonProcessingException { + UpdateNetworkRequest request = new UpdateNetworkRequest(); + request.setCloudSiteId(TESTING_ID); + request.setNetworkId("test1"); + + UpdateNetworkError mockResponse = new UpdateNetworkError(); + mockResponse.setMessage("Error in update network"); + stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.updateNetwork(AAI_NETWORK_ID, request); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java new file mode 100644 index 0000000000..96fbe7ffb7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java @@ -0,0 +1,301 @@ +/*- + * ============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.adapter.network.mapper; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.mockito.Mockito.doReturn; + +import java.io.UnsupportedEncodingException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.so.adapters.nwrest.ContrailNetwork; +import org.onap.so.adapters.nwrest.CreateNetworkRequest; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.adapters.nwrest.DeleteNetworkRequest; +import org.onap.so.adapters.nwrest.ProviderVlanNetwork; +import org.onap.so.adapters.nwrest.RollbackNetworkRequest; +import org.onap.so.adapters.nwrest.UpdateNetworkRequest; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; +import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference; +import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTarget; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; +import org.onap.so.entity.MsoRequest; +import org.onap.so.openstack.beans.NetworkRollback; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class NetworkAdapterObjectMapperTest extends TestDataSetup{ + + private NetworkAdapterObjectMapper SPY_networkAdapterObjectMapper = Mockito.spy(NetworkAdapterObjectMapper.class); + + private L3Network l3Network; + private RequestContext requestContext; + private ServiceInstance serviceInstance; + private CloudRegion cloudRegion; + private OrchestrationContext orchestrationContext; + private Customer customer; + Map<String, String> userInput; + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/NetworkMapper/"; + + @Before + public void before() { + requestContext = setRequestContext(); + + customer = buildCustomer(); + + serviceInstance = setServiceInstance(); + + cloudRegion = setCloudRegion(); + + orchestrationContext = setOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(false); + + userInput = setUserInput(); + + l3Network = setL3Network(); + + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + } + + @Test + public void buildCreateNetworkRequestFromBbobjectTest() throws Exception { + + String cloudRegionPo = "cloudRegionPo"; + CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest(); + + expectedCreateNetworkRequest.setCloudSiteId(cloudRegionPo); + expectedCreateNetworkRequest.setTenantId(cloudRegion.getTenantId()); + expectedCreateNetworkRequest.setNetworkId(l3Network.getNetworkId()); + expectedCreateNetworkRequest.setNetworkName(l3Network.getNetworkName()); + expectedCreateNetworkRequest.setNetworkType(l3Network.getNetworkType()); + expectedCreateNetworkRequest.setBackout(false); + expectedCreateNetworkRequest.setFailIfExists(true); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedCreateNetworkRequest.setMsoRequest(msoRequest); + expectedCreateNetworkRequest.setSkipAAI(true); + + Subnet openstackSubnet = new Subnet(); + HostRoute hostRoute = new HostRoute(); + hostRoute.setHostRouteId("hostRouteId"); + hostRoute.setNextHop("nextHop"); + hostRoute.setRoutePrefix("routePrefix"); + openstackSubnet.getHostRoutes().add(hostRoute); + List<Subnet> subnetList = new ArrayList<Subnet>(); + subnetList.add(openstackSubnet); + l3Network.getSubnets().add(openstackSubnet); + + CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer); + + assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("networkParams").ignoring("messageId")); + } + + @Test + public void createNetworkRollbackRequestMapperTest() throws Exception { + + String cloudRegionPo = "cloudRegionPo"; + RollbackNetworkRequest expectedRollbackNetworkRequest = new RollbackNetworkRequest(); + + expectedRollbackNetworkRequest.setMessageId(requestContext.getMsoRequestId()); + NetworkRollback networkRollback = new NetworkRollback(); + networkRollback.setCloudId(cloudRegionPo); + networkRollback.setNetworkCreated(true); + networkRollback.setNetworkId(l3Network.getNetworkId()); + networkRollback.setNetworkType(l3Network.getNetworkType()); + networkRollback.setTenantId(cloudRegion.getTenantId()); + expectedRollbackNetworkRequest.setNetworkRollback(networkRollback); + expectedRollbackNetworkRequest.setSkipAAI(true); + + CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); + createNetworkResponse.setNetworkCreated(true); + + RollbackNetworkRequest rollbackNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRollbackRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, createNetworkResponse); + + assertThat(rollbackNetworkRequest, sameBeanAs(expectedRollbackNetworkRequest).ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("networkParams").ignoring("messageId")); + } + + @Test + public void updateNetworkRequestMapperTest() throws UnsupportedEncodingException { + org.onap.so.openstack.beans.Subnet subnet = new org.onap.so.openstack.beans.Subnet(); + subnet.setSubnetId("subnetId"); + subnet.setHostRoutes(new ArrayList<org.onap.so.openstack.beans.HostRoute>()); + + List<org.onap.so.openstack.beans.Subnet> subnets = new ArrayList<>(); + subnets.add(subnet); + + ProviderVlanNetwork providerVlanNetwork = new ProviderVlanNetwork("physicalNetworkName", new ArrayList<Integer>()); + + List<String> policyFqdns = Arrays.asList("networkPolicyFqdn"); + + org.onap.so.openstack.beans.RouteTarget expectedRouteTarget = new org.onap.so.openstack.beans.RouteTarget(); + expectedRouteTarget.setRouteTarget("globalRouteTarget"); + + ContrailNetwork contrailNetwork = new ContrailNetwork(); + contrailNetwork.setPolicyFqdns(policyFqdns); + contrailNetwork.setRouteTableFqdns(new ArrayList<String>()); + contrailNetwork.setRouteTargets(new ArrayList<org.onap.so.openstack.beans.RouteTarget>()); + contrailNetwork.getRouteTargets().add(expectedRouteTarget); + contrailNetwork.getRouteTableFqdns().add("routeTableReferenceFqdn"); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setServiceInstanceId("testServiceInstanceId1"); + + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + modelInfoNetwork.setNetworkType("networkType"); + modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); + modelInfoNetwork.setModelVersion("modelVersion"); + + Subnet actualSubnet = new Subnet(); + actualSubnet.setSubnetId("subnetId"); + actualSubnet.setIpVersion("4"); + + RouteTarget routeTarget = new RouteTarget(); + routeTarget.setGlobalRouteTarget("globalRouteTarget"); + + VpnBinding vpnBinding = new VpnBinding(); + vpnBinding.setVpnId("vpnId"); + vpnBinding.getRouteTargets().add(routeTarget); + + Customer customer = new Customer(); + customer.getVpnBindings().add(vpnBinding); + ServiceSubscription serviceSubscription = new ServiceSubscription(); + customer.setServiceSubscription(serviceSubscription); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + NetworkPolicy networkPolicy = new NetworkPolicy(); + networkPolicy.setNetworkPolicyId("networkPolicyId"); + networkPolicy.setNetworkPolicyFqdn("networkPolicyFqdn"); + + RouteTableReference routeTableReference = new RouteTableReference(); + routeTableReference.setRouteTableReferenceFqdn("routeTableReferenceFqdn"); + + l3Network.setModelInfoNetwork(modelInfoNetwork); + l3Network.setPhysicalNetworkName("physicalNetworkName"); + l3Network.getSubnets().add(actualSubnet); + l3Network.getNetworkPolicies().add(networkPolicy); + l3Network.getContrailNetworkRouteTableReferences().add(routeTableReference); + + UpdateNetworkRequest expectedUpdateNetworkRequest = new UpdateNetworkRequest(); + expectedUpdateNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + expectedUpdateNetworkRequest.setTenantId(cloudRegion.getTenantId()); + expectedUpdateNetworkRequest.setNetworkId(l3Network.getNetworkId()); + expectedUpdateNetworkRequest.setNetworkStackId(l3Network.getHeatStackId()); + expectedUpdateNetworkRequest.setNetworkName(l3Network.getNetworkName()); + expectedUpdateNetworkRequest.setNetworkType(l3Network.getModelInfoNetwork().getNetworkType()); + expectedUpdateNetworkRequest.setNetworkTypeVersion(l3Network.getModelInfoNetwork().getModelVersion()); + expectedUpdateNetworkRequest.setModelCustomizationUuid(l3Network.getModelInfoNetwork().getModelCustomizationUUID()); + expectedUpdateNetworkRequest.setSubnets(subnets); + expectedUpdateNetworkRequest.setProviderVlanNetwork(providerVlanNetwork); + expectedUpdateNetworkRequest.setContrailNetwork(contrailNetwork); + expectedUpdateNetworkRequest.setNetworkParams(userInput); + expectedUpdateNetworkRequest.setMsoRequest(msoRequest); + expectedUpdateNetworkRequest.setSkipAAI(true); + expectedUpdateNetworkRequest.setBackout(!Boolean.valueOf(orchestrationContext.getIsRollbackEnabled())); + expectedUpdateNetworkRequest.setMessageId("messageId"); + expectedUpdateNetworkRequest.setNotificationUrl("http://localhost:28080/mso/WorkflowMesssage/NetworkAResponse/messageId"); + + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); + doReturn("http://localhost:28080/mso/WorkflowMesssage").when(SPY_networkAdapterObjectMapper).getEndpoint(); + UpdateNetworkRequest actualUpdateNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkUpdateRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, customer); + + assertThat(actualUpdateNetworkRequest, sameBeanAs(expectedUpdateNetworkRequest).ignoring("msoRequest.requestId")); + } + + @Test + public void deleteNetworkRequestMapperTest() throws Exception { + DeleteNetworkRequest expectedDeleteNetworkRequest = new DeleteNetworkRequest(); + + String messageId = "messageId"; + expectedDeleteNetworkRequest.setMessageId(messageId); + doReturn(messageId).when(SPY_networkAdapterObjectMapper).getRandomUuid(); + + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + l3Network.setModelInfoNetwork(modelInfoNetwork); + modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); + expectedDeleteNetworkRequest.setModelCustomizationUuid(modelInfoNetwork.getModelCustomizationUUID()); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedDeleteNetworkRequest.setMsoRequest(msoRequest); + + expectedDeleteNetworkRequest.setNetworkId(l3Network.getNetworkId()); + + l3Network.setHeatStackId("heatStackId"); + expectedDeleteNetworkRequest.setNetworkStackId(l3Network.getHeatStackId()); + + expectedDeleteNetworkRequest.setNetworkType(l3Network.getNetworkType()); + + expectedDeleteNetworkRequest.setSkipAAI(true); + + expectedDeleteNetworkRequest.setTenantId(cloudRegion.getTenantId()); + + expectedDeleteNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + + DeleteNetworkRequest deleteNetworkRequest = SPY_networkAdapterObjectMapper.deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); + + assertThat(expectedDeleteNetworkRequest, sameBeanAs(deleteNetworkRequest)); + } + + @Test + public void buildOpenstackSubnetListTest() throws Exception { + + ObjectMapper omapper = new ObjectMapper(); + String bbJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "generalBB.json"))); + org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock gbb = omapper.readValue( + bbJson, + org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock.class); + L3Network myNetwork = gbb.getServiceInstance().getNetworks().get(0); + + String expectedCreateNetworkRequestJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "createNetworkRequest.json"))); + org.onap.so.adapters.nwrest.CreateNetworkRequest expectedCreateNetworkRequest = omapper.readValue( + expectedCreateNetworkRequestJson, + org.onap.so.adapters.nwrest.CreateNetworkRequest.class); + + String cloudRegionPo = "cloudRegionPo"; + CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, myNetwork, userInput, cloudRegionPo, customer); + //ignoring dynamic fields and networkParams that throws parsing exception on json file load + assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("messageId").ignoring("msoRequest.requestId").ignoring("networkParams")); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java new file mode 100644 index 0000000000..85f787faa7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java @@ -0,0 +1,224 @@ +/*- + * ============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.adapter.vnf; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.so.BaseTest; +import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; +import org.onap.so.adapters.vnfrest.CreateVfModuleResponse; +import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; +import org.onap.so.adapters.vnfrest.DeleteVfModuleResponse; +import org.onap.so.adapters.vnfrest.QueryVfModuleResponse; +import org.onap.so.adapters.vnfrest.RollbackVfModuleRequest; +import org.onap.so.adapters.vnfrest.RollbackVfModuleResponse; +import org.onap.so.adapters.vnfrest.UpdateVfModuleRequest; +import org.onap.so.adapters.vnfrest.UpdateVfModuleResponse; +import org.onap.so.adapters.vnfrest.VfModuleExceptionResponse; +import org.onap.so.adapters.vnfrest.VfModuleRollback; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class VnfAdapterClientIT extends BaseTest{ + + private static final String TESTING_ID = "___TESTING___"; + private static final String AAI_VNF_ID = "test"; + private static final String AAI_VF_MODULE_ID = "test"; + private static final String REST_ENDPOINT = "/services/rest/v1/vnfs"; + + private VnfAdapterClientImpl client = new VnfAdapterClientImpl(); + private ObjectMapper mapper = new ObjectMapper(); + + @BeforeClass + public static void setUp() { + System.setProperty("mso.config.path", "src/test/resources"); + } + + @Test + public void createVfModuleTest() throws JsonProcessingException, VnfAdapterClientException { + CreateVfModuleRequest request = new CreateVfModuleRequest(); + request.setCloudSiteId(TESTING_ID); + + CreateVfModuleResponse mockResponse = new CreateVfModuleResponse(); + mockResponse.setVfModuleCreated(true); + stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + CreateVfModuleResponse response = client.createVfModule(AAI_VNF_ID, request); + assertEquals("Testing CreateVfModule response", true, response.getVfModuleCreated()); + } + + @Test(expected = VnfAdapterClientException.class) + public void createVfModuleTestThrowException() throws JsonProcessingException, VnfAdapterClientException { + CreateVfModuleRequest request = new CreateVfModuleRequest(); + request.setCloudSiteId(TESTING_ID); + + VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); + mockResponse.setMessage("Error in create Vf module"); + stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.createVfModule(AAI_VNF_ID, request); + } + + @Test + public void rollbackVfModuleTest() throws JsonProcessingException, VnfAdapterClientException { + RollbackVfModuleRequest request = new RollbackVfModuleRequest(); + VfModuleRollback rollback = new VfModuleRollback(); + rollback.setCloudSiteId(TESTING_ID); + request.setVfModuleRollback(rollback); + + RollbackVfModuleResponse mockResponse = new RollbackVfModuleResponse(); + mockResponse.setVfModuleRolledback(true); + stubFor( + post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + RollbackVfModuleResponse response = client.rollbackVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request); + assertEquals("Testing RollbackVfModule response", true, response.getVfModuleRolledback()); + } + + @Test(expected = VnfAdapterClientException.class) + public void rollbackVfModuleTestThrowException() throws JsonProcessingException, VnfAdapterClientException { + RollbackVfModuleRequest request = new RollbackVfModuleRequest(); + VfModuleRollback rollback = new VfModuleRollback(); + rollback.setCloudSiteId(TESTING_ID); + request.setVfModuleRollback(rollback); + + VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); + mockResponse.setMessage("Error in rollback Vf module"); + stubFor( + post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.rollbackVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request); + } + + @Test + public void deleteVfModuleTest() throws JsonProcessingException, VnfAdapterClientException { + DeleteVfModuleRequest request = new DeleteVfModuleRequest(); + request.setCloudSiteId(TESTING_ID); + + DeleteVfModuleResponse mockResponse = new DeleteVfModuleResponse(); + mockResponse.setVfModuleDeleted(true); + stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + DeleteVfModuleResponse response = client.deleteVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request); + assertEquals("Testing DeleteVfModule response", true, response.getVfModuleDeleted()); + } + + @Test(expected = VnfAdapterClientException.class) + public void deleteVfModuleTestThrowException() throws JsonProcessingException, VnfAdapterClientException { + DeleteVfModuleRequest request = new DeleteVfModuleRequest(); + request.setCloudSiteId(TESTING_ID); + + VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); + mockResponse.setMessage("Error in delete Vf module"); + stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.deleteVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request); + } + + @Test + public void updateVfModuleTest() throws JsonProcessingException, VnfAdapterClientException { + UpdateVfModuleRequest request = new UpdateVfModuleRequest(); + request.setCloudSiteId(TESTING_ID); + request.setVfModuleId("test1"); + + UpdateVfModuleResponse mockResponse = new UpdateVfModuleResponse(); + mockResponse.setVfModuleId("test1"); + stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + + UpdateVfModuleResponse response = client.updateVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request); + assertEquals("Testing UpdateVfModule response", "test1", response.getVfModuleId()); + } + + @Test(expected = VnfAdapterClientException.class) + public void updateVfModuleTestThrowException() throws JsonProcessingException, VnfAdapterClientException { + UpdateVfModuleRequest request = new UpdateVfModuleRequest(); + request.setCloudSiteId(TESTING_ID); + request.setVfModuleId("test1"); + + VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); + mockResponse.setMessage("Error in update Vf module"); + stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + + client.updateVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, request); + } + + @Test + public void queryVfModuleTest() throws JsonProcessingException, VnfAdapterClientException { + QueryVfModuleResponse mockResponse = new QueryVfModuleResponse(); + mockResponse.setVnfId(AAI_VNF_ID); + mockResponse.setVfModuleId(AAI_VF_MODULE_ID); + stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + .withQueryParam("cloudSiteId", equalTo(TESTING_ID)) + .withQueryParam("tenantId", equalTo(TESTING_ID)) + .withQueryParam("vfModuleName", equalTo("someName")) + .withQueryParam("skipAAI", equalTo("true")) + .withQueryParam("msoRequest.requestId", equalTo("testRequestId")) + .withQueryParam("msoRequest.serviceInstanceId", equalTo("serviceInstanceId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); + QueryVfModuleResponse response = client.queryVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, TESTING_ID, TESTING_ID, + "someName", true, "testRequestId", "serviceInstanceId"); + assertEquals("Testing QueryVfModule response", AAI_VF_MODULE_ID, response.getVfModuleId()); + } + + @Test(expected = VnfAdapterClientException.class) + public void queryVfModuleTestThrowException() throws JsonProcessingException, VnfAdapterClientException { + VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); + mockResponse.setMessage("Error in update Vf module"); + stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + .withQueryParam("cloudSiteId", equalTo(TESTING_ID)) + .withQueryParam("tenantId", equalTo(TESTING_ID)) + .withQueryParam("vfModuleName", equalTo("someName")) + .withQueryParam("skipAAI", equalTo("true")) + .withQueryParam("msoRequest.requestId", equalTo("testRequestId")) + .withQueryParam("msoRequest.serviceInstanceId", equalTo("serviceInstanceId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); + client.queryVfModule(AAI_VNF_ID, AAI_VF_MODULE_ID, TESTING_ID, TESTING_ID, + "someName", true, "testRequestId", "serviceInstanceId"); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java new file mode 100644 index 0000000000..b356b21de4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java @@ -0,0 +1,214 @@ +/*- + * ============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.adapter.vnf; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.core.UriBuilder; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.BaseTest; +import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.RollbackVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse; +import org.onap.so.client.adapter.rest.AdapterRestClient; + + +@RunWith(MockitoJUnitRunner.class) +public class VnfVolumeAdapterClientIT extends BaseTest{ + + private static final String TESTING_ID = "___TESTING___"; + private static final String AAI_VOLUME_GROUP_ID = "test"; + private static final String CLOUD_SITE_ID = "test"; + private static final String TENANT_ID = "test"; + private static final String VOLUME_GROUP_STACK_ID = "test"; + private static final boolean SKIP_AAI = true; + private static final String REQUEST_ID = "test"; + private static final String SERVICE_INSTANCE_ID = "test"; + + @Test + public void createVolumeGroupTest() throws VnfAdapterClientException { + CreateVolumeGroupRequest request = new CreateVolumeGroupRequest(); + request.setCloudSiteId(TESTING_ID); + + CreateVolumeGroupResponse mockResponse = new CreateVolumeGroupResponse(); + mockResponse.setVolumeGroupCreated(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + + doReturn(mockClient).when(client).getAdapterRestClient(""); + when(mockClient.post(request, CreateVolumeGroupResponse.class)).thenReturn(mockResponse); + + CreateVolumeGroupResponse response = client.createVNFVolumes(request); + assertEquals("Testing CreateVolumeGroup response", mockResponse.getVolumeGroupCreated(), + response.getVolumeGroupCreated()); + } + + @Test(expected = VnfAdapterClientException.class) + public void createVolumeGroupTestThrowException() throws VnfAdapterClientException { + CreateVolumeGroupRequest request = new CreateVolumeGroupRequest(); + request.setCloudSiteId(TESTING_ID); + + CreateVolumeGroupResponse mockResponse = new CreateVolumeGroupResponse(); + mockResponse.setVolumeGroupCreated(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + + doReturn(mockClient).when(client).getAdapterRestClient(""); + when(mockClient.post(request, CreateVolumeGroupResponse.class)).thenThrow(new InternalServerErrorException("Error in create volume group")); + + client.createVNFVolumes(request); + } + + @Test + public void deleteVolumeGroupTest() throws VnfAdapterClientException { + DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest(); + request.setCloudSiteId(TESTING_ID); + + DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse(); + mockResponse.setVolumeGroupDeleted(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); + when(mockClient.delete(request, DeleteVolumeGroupResponse.class)).thenReturn(mockResponse); + MockitoAnnotations.initMocks(this); + + DeleteVolumeGroupResponse response = client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request); + assertEquals("Testing DeleteVolumeGroup response", mockResponse.getVolumeGroupDeleted(), + response.getVolumeGroupDeleted()); + } + + @Test(expected = VnfAdapterClientException.class) + public void deleteVolumeGroupTestThrowException() throws VnfAdapterClientException { + DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest(); + request.setCloudSiteId(TESTING_ID); + + DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse(); + mockResponse.setVolumeGroupDeleted(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); + when(mockClient.delete(request, DeleteVolumeGroupResponse.class)) + .thenThrow(new InternalServerErrorException("Error in delete volume group")); + MockitoAnnotations.initMocks(this); + + client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request); + } + + @Test + public void rollbackVolumeGroupTest() throws VnfAdapterClientException { + RollbackVolumeGroupRequest request = new RollbackVolumeGroupRequest(); + + RollbackVolumeGroupResponse mockResponse = new RollbackVolumeGroupResponse(); + mockResponse.setVolumeGroupRolledBack(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID + "/rollback"); + when(mockClient.delete(request, RollbackVolumeGroupResponse.class)).thenReturn(mockResponse); + MockitoAnnotations.initMocks(this); + + RollbackVolumeGroupResponse response = client.rollbackVNFVolumes(AAI_VOLUME_GROUP_ID, request); + assertEquals("Testing RollbackVolumeGroup response", mockResponse.getVolumeGroupRolledBack(), + response.getVolumeGroupRolledBack()); + } + + @Test(expected = VnfAdapterClientException.class) + public void rollbackVolumeGroupTestThrowException() throws VnfAdapterClientException { + RollbackVolumeGroupRequest request = new RollbackVolumeGroupRequest(); + + RollbackVolumeGroupResponse mockResponse = new RollbackVolumeGroupResponse(); + mockResponse.setVolumeGroupRolledBack(true); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID + "/rollback"); + when(mockClient.delete(request, RollbackVolumeGroupResponse.class)) + .thenThrow(new InternalServerErrorException("Error in rollback volume group")); + MockitoAnnotations.initMocks(this); + + client.rollbackVNFVolumes(AAI_VOLUME_GROUP_ID, request); + } + + @Test + public void updateVolumeGroupTest() throws VnfAdapterClientException { + UpdateVolumeGroupRequest request = new UpdateVolumeGroupRequest(); + + UpdateVolumeGroupResponse mockResponse = new UpdateVolumeGroupResponse(); + mockResponse.setVolumeGroupId(AAI_VOLUME_GROUP_ID); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); + when(mockClient.put(request, UpdateVolumeGroupResponse.class)).thenReturn(mockResponse); + MockitoAnnotations.initMocks(this); + + UpdateVolumeGroupResponse response = client.updateVNFVolumes(AAI_VOLUME_GROUP_ID, request); + assertEquals("Testing DeleteVfModule response", mockResponse.getVolumeGroupId(), response.getVolumeGroupId()); + } + + @Test(expected = VnfAdapterClientException.class) + public void updateVolumeGroupTestThrowException() throws VnfAdapterClientException { + UpdateVolumeGroupRequest request = new UpdateVolumeGroupRequest(); + + UpdateVolumeGroupResponse mockResponse = new UpdateVolumeGroupResponse(); + mockResponse.setVolumeGroupId(AAI_VOLUME_GROUP_ID); + + VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class); + AdapterRestClient mockClient = mock(AdapterRestClient.class); + doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID); + when(mockClient.put(request, UpdateVolumeGroupResponse.class)) + .thenThrow(new InternalServerErrorException("Error in update volume group")); + MockitoAnnotations.initMocks(this); + + client.updateVNFVolumes(AAI_VOLUME_GROUP_ID, request); + } + + public void buildQueryPathTest() { + String expectedOutput = "/" + AAI_VOLUME_GROUP_ID + "?cloudSiteId=" + CLOUD_SITE_ID + "&tenantId=" + TENANT_ID + + "&volumeGroupStackId=" + VOLUME_GROUP_STACK_ID + "&skipAAI=" + SKIP_AAI + "&msoRequest.requestId=" + + REQUEST_ID + "&msoRequest.serviceInstanceId=" + SERVICE_INSTANCE_ID; + VnfVolumeAdapterClientImpl client = new VnfVolumeAdapterClientImpl(); + assertEquals("Test build query path", expectedOutput, client.buildQueryPath(AAI_VOLUME_GROUP_ID, CLOUD_SITE_ID, + TENANT_ID, VOLUME_GROUP_STACK_ID, SKIP_AAI, REQUEST_ID, SERVICE_INSTANCE_ID)); + } + + protected UriBuilder getUri(String path) { + return UriBuilder.fromPath(path); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterRestPropertiesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterRestPropertiesTest.java new file mode 100644 index 0000000000..df48596893 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterRestPropertiesTest.java @@ -0,0 +1,46 @@ +/*- + * ============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.adapter.vnf; + +import static org.junit.Assert.assertEquals; + +import java.net.MalformedURLException; + +import org.junit.Test; + +public class VnfVolumeAdapterRestPropertiesTest{ + private VnfVolumeAdapterRestProperties props = new VnfVolumeAdapterRestProperties(); + + @Test + public void testGetAuth(){ + assertEquals("mso.adapters.po.auth", VnfVolumeAdapterRestProperties.authProp); + } + + @Test + public void testGetKey(){ + assertEquals("mso.msoKey", VnfVolumeAdapterRestProperties.keyProp); + } + + @Test + public void testGetUrl() throws MalformedURLException{ + assertEquals("mso.adapters.volume-groups.rest.endpoint", VnfVolumeAdapterRestProperties.endpointProp); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapperTest.java new file mode 100644 index 0000000000..25149aea13 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterObjectMapperTest.java @@ -0,0 +1,372 @@ +/*- + * ============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.adapter.vnf.mapper; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.reset; + +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.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.entity.MsoRequest; + +public class VnfAdapterObjectMapperTest { + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + + @Spy + private VnfAdapterObjectMapper vnfAdapterObjectMapper = new VnfAdapterObjectMapper(); + + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + } + + @After + public void after() { + reset(vnfAdapterObjectMapper); + } + + @Test + public void test_createVolumeGroupRequestMapper() throws Exception { + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("msoRequestId"); + + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelVersion("modelVersion"); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("vnfId"); + genericVnf.setVnfName("vnfName"); + genericVnf.setVnfType("vnfType"); + serviceInstance.getVnfs().add(genericVnf); + + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelName("modelName"); + modelInfoVfModule.setModelCustomizationUUID("modelCustomizationUUID"); + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + volumeGroup.setVolumeGroupName("volumeGroupName"); + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + volumeGroup.setModelInfoVfModule(modelInfoVfModule); + + serviceInstance.getVnfs().get(0).getVolumeGroups().add(volumeGroup); + + + CloudRegion cloudRegion = new CloudRegion(); + cloudRegion.setLcpCloudRegionId("lcpCloudRegionId"); + cloudRegion.setTenantId("tenantId"); + + OrchestrationContext orchestrationContext = new OrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + + String sdncVfModuleQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVfModuleTopology.json"))); + + CreateVolumeGroupRequest expectedCreateVolumeGroupRequest = new CreateVolumeGroupRequest(); + + expectedCreateVolumeGroupRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + expectedCreateVolumeGroupRequest.setTenantId(cloudRegion.getTenantId()); + expectedCreateVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId()); + expectedCreateVolumeGroupRequest.setVolumeGroupName(volumeGroup.getVolumeGroupName()); + expectedCreateVolumeGroupRequest.setVnfType(genericVnf.getVnfType()); + expectedCreateVolumeGroupRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion()); + expectedCreateVolumeGroupRequest.setVfModuleType(volumeGroup.getModelInfoVfModule().getModelName()); + expectedCreateVolumeGroupRequest.setModelCustomizationUuid(volumeGroup.getModelInfoVfModule().getModelCustomizationUUID()); + + Map<String, String> volumeGroupParams = new HashMap<>(); + volumeGroupParams.put("vnf_id", genericVnf.getVnfId()); + volumeGroupParams.put("vnf_name", genericVnf.getVnfName()); + volumeGroupParams.put("vf_module_id", volumeGroup.getVolumeGroupId()); + volumeGroupParams.put("vf_module_name", volumeGroup.getVolumeGroupName()); + volumeGroupParams.put("paramOne", "paramOneValue"); + volumeGroupParams.put("paramTwo", "paramTwoValue"); + volumeGroupParams.put("paramThree", "paramThreeValue"); + expectedCreateVolumeGroupRequest.setVolumeGroupParams(volumeGroupParams); + + expectedCreateVolumeGroupRequest.setSkipAAI(true); + expectedCreateVolumeGroupRequest.setSuppressBackout(orchestrationContext.getIsRollbackEnabled()); + expectedCreateVolumeGroupRequest.setFailIfExists(true); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedCreateVolumeGroupRequest.setMsoRequest(msoRequest); + + expectedCreateVolumeGroupRequest.setMessageId("messageId"); + expectedCreateVolumeGroupRequest.setNotificationUrl("endpoint/VNFAResponse/messageId"); + + doReturn("endpoint/").when(vnfAdapterObjectMapper).getProperty(isA(String.class)); + doReturn("messageId").when(vnfAdapterObjectMapper).getRandomUuid(); + + CreateVolumeGroupRequest actualCreateVolumeGroupRequest = vnfAdapterObjectMapper.createVolumeGroupRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse); + + assertThat(actualCreateVolumeGroupRequest, sameBeanAs(expectedCreateVolumeGroupRequest)); + } + + @Test + public void test_createVolumeGroupRequestMapper_for_alaCarte_flow() throws Exception { + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("msoRequestId"); + + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelVersion("modelVersion"); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("vnfId"); + genericVnf.setVnfName("vnfName"); + genericVnf.setVnfType("vnfType"); + serviceInstance.getVnfs().add(genericVnf); + + + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelName("modelName"); + modelInfoVfModule.setModelCustomizationUUID("modelCustomizationUUID"); + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + volumeGroup.setVolumeGroupName("volumeGroupName"); + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + volumeGroup.setModelInfoVfModule(modelInfoVfModule); + serviceInstance.getVnfs().get(0).getVolumeGroups().add(volumeGroup); + + CloudRegion cloudRegion = new CloudRegion(); + cloudRegion.setLcpCloudRegionId("lcpCloudRegionId"); + cloudRegion.setTenantId("tenantId"); + + OrchestrationContext orchestrationContext = new OrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + + CreateVolumeGroupRequest expectedCreateVolumeGroupRequest = new CreateVolumeGroupRequest(); + + expectedCreateVolumeGroupRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + expectedCreateVolumeGroupRequest.setTenantId(cloudRegion.getTenantId()); + expectedCreateVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId()); + expectedCreateVolumeGroupRequest.setVolumeGroupName(volumeGroup.getVolumeGroupName()); + expectedCreateVolumeGroupRequest.setVnfType(genericVnf.getVnfType()); + expectedCreateVolumeGroupRequest.setVnfVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion()); + expectedCreateVolumeGroupRequest.setVfModuleType(volumeGroup.getModelInfoVfModule().getModelName()); + expectedCreateVolumeGroupRequest.setModelCustomizationUuid(volumeGroup.getModelInfoVfModule().getModelCustomizationUUID()); + + Map<String, String> volumeGroupParams = new HashMap<>(); + volumeGroupParams.put("vnf_id", genericVnf.getVnfId()); + volumeGroupParams.put("vnf_name", genericVnf.getVnfName()); + volumeGroupParams.put("vf_module_id", volumeGroup.getVolumeGroupId()); + volumeGroupParams.put("vf_module_name", volumeGroup.getVolumeGroupName()); + + expectedCreateVolumeGroupRequest.setVolumeGroupParams(volumeGroupParams); + + expectedCreateVolumeGroupRequest.setSkipAAI(true); + expectedCreateVolumeGroupRequest.setSuppressBackout(orchestrationContext.getIsRollbackEnabled()); + expectedCreateVolumeGroupRequest.setFailIfExists(true); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedCreateVolumeGroupRequest.setMsoRequest(msoRequest); + + expectedCreateVolumeGroupRequest.setMessageId("messageId"); + expectedCreateVolumeGroupRequest.setNotificationUrl("endpoint/VNFAResponse/messageId"); + + doReturn("endpoint/").when(vnfAdapterObjectMapper).getProperty(isA(String.class)); + doReturn("messageId").when(vnfAdapterObjectMapper).getRandomUuid(); + + CreateVolumeGroupRequest actualCreateVolumeGroupRequest = vnfAdapterObjectMapper.createVolumeGroupRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, null); + + assertThat(actualCreateVolumeGroupRequest, sameBeanAs(expectedCreateVolumeGroupRequest)); + } + + @Test + public void test_deleteVolumeGroupRequestMapper() throws Exception { + DeleteVolumeGroupRequest expectedDeleteVolumeGroupRequest = new DeleteVolumeGroupRequest(); + + CloudRegion cloudRegion = new CloudRegion(); + cloudRegion.setLcpCloudRegionId("lcpCloudRegionId"); + expectedDeleteVolumeGroupRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + + cloudRegion.setTenantId("tenantId"); + expectedDeleteVolumeGroupRequest.setTenantId(cloudRegion.getTenantId()); + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + expectedDeleteVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId()); + + volumeGroup.setHeatStackId("heatStackId"); + expectedDeleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId()); + + expectedDeleteVolumeGroupRequest.setSkipAAI(true); + + MsoRequest msoRequest = new MsoRequest(); + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("msoRequestId"); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedDeleteVolumeGroupRequest.setMsoRequest(msoRequest); + + String messageId = "messageId"; + String endpoint = "endpoint"; + doReturn(messageId).when(vnfAdapterObjectMapper).getRandomUuid(); + doReturn(endpoint).when(vnfAdapterObjectMapper).getProperty(isA(String.class)); + expectedDeleteVolumeGroupRequest.setMessageId(messageId); + expectedDeleteVolumeGroupRequest.setNotificationUrl(endpoint + "/VNFAResponse/" + messageId); + + DeleteVolumeGroupRequest actualDeleteVolumeGroupRequest = vnfAdapterObjectMapper.deleteVolumeGroupRequestMapper(requestContext, cloudRegion, serviceInstance, volumeGroup); + + assertThat(actualDeleteVolumeGroupRequest, sameBeanAs(expectedDeleteVolumeGroupRequest)); + } + + @Test + public void test_createVolumeGroupParams() throws Exception { + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("vnfId"); + genericVnf.setVnfName("vnfName"); + + RequestContext requestContext = new RequestContext(); + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + volumeGroup.setVolumeGroupName("volumeGroupName"); + + String sdncVfModuleQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVfModuleTopology.json"))); + + Map<String, String> expectedVolumeGroupParams = new HashMap<>(); + expectedVolumeGroupParams.put("vnf_id", genericVnf.getVnfId()); + expectedVolumeGroupParams.put("vnf_name", genericVnf.getVnfName()); + expectedVolumeGroupParams.put("vf_module_id", volumeGroup.getVolumeGroupId()); + expectedVolumeGroupParams.put("vf_module_name", volumeGroup.getVolumeGroupName()); + expectedVolumeGroupParams.put("paramOne", "paramOneValue"); + expectedVolumeGroupParams.put("paramTwo", "paramTwoValue"); + expectedVolumeGroupParams.put("paramThree", "paramThreeValue"); + + Map<String, String> actualVolumeGroupParams = vnfAdapterObjectMapper.createVolumeGroupParams(requestContext,genericVnf, volumeGroup, sdncVfModuleQueryResponse); + + assertEquals(expectedVolumeGroupParams, actualVolumeGroupParams); + } + + @Test + public void test_createVolumeGroupParams_without_sdncResponse() throws Exception { + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("vnfId"); + genericVnf.setVnfName("vnfName"); + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + volumeGroup.setVolumeGroupName("volumeGroupName"); + + Map<String, String> expectedVolumeGroupParams = new HashMap<>(); + expectedVolumeGroupParams.put("vnf_id", genericVnf.getVnfId()); + expectedVolumeGroupParams.put("vnf_name", genericVnf.getVnfName()); + expectedVolumeGroupParams.put("vf_module_id", volumeGroup.getVolumeGroupId()); + expectedVolumeGroupParams.put("vf_module_name", volumeGroup.getVolumeGroupName()); + RequestContext requestContext = new RequestContext(); + Map<String, String> actualVolumeGroupParams = vnfAdapterObjectMapper.createVolumeGroupParams(requestContext,genericVnf, volumeGroup, null); + + assertEquals(expectedVolumeGroupParams, actualVolumeGroupParams); + } + + @Test + public void test_createVolumeGroupParams_with_user_params() throws Exception { + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("vnfId"); + genericVnf.setVnfName("vnfName"); + + RequestContext requestContext = new RequestContext(); + Map<String, Object> userParamsMap = new HashMap<>(); + userParamsMap.put("name", "userParamKey"); + userParamsMap.put("value", "userParamValue"); + List<Map<String, Object>> userParams = new ArrayList<>(); + userParams.add(userParamsMap); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(userParams); + requestContext.setRequestParameters(requestParameters); + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + volumeGroup.setVolumeGroupName("volumeGroupName"); + + String sdncVfModuleQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVfModuleTopology.json"))); + + Map<String, String> expectedVolumeGroupParams = new HashMap<>(); + expectedVolumeGroupParams.put("vnf_id", genericVnf.getVnfId()); + expectedVolumeGroupParams.put("vnf_name", genericVnf.getVnfName()); + expectedVolumeGroupParams.put("vf_module_id", volumeGroup.getVolumeGroupId()); + expectedVolumeGroupParams.put("vf_module_name", volumeGroup.getVolumeGroupName()); + expectedVolumeGroupParams.put("paramOne", "paramOneValue"); + expectedVolumeGroupParams.put("paramTwo", "paramTwoValue"); + expectedVolumeGroupParams.put("paramThree", "paramThreeValue"); + expectedVolumeGroupParams.put("userParamKey", "userParamValue"); + + Map<String, String> actualVolumeGroupParams = vnfAdapterObjectMapper.createVolumeGroupParams(requestContext,genericVnf, volumeGroup, sdncVfModuleQueryResponse); + + assertEquals(expectedVolumeGroupParams, actualVolumeGroupParams); + } + + @Test + public void test_createMsoRequest() { + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("msoRequestId"); + + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + + MsoRequest expectedMsoRequest = new MsoRequest(); + expectedMsoRequest.setRequestId(requestContext.getMsoRequestId()); + expectedMsoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + + MsoRequest actualMsoRequest = vnfAdapterObjectMapper.createMsoRequest(requestContext, serviceInstance); + + assertThat(expectedMsoRequest, sameBeanAs(actualMsoRequest)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperIntegrationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperIntegrationTest.java new file mode 100644 index 0000000000..bbc5e56141 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperIntegrationTest.java @@ -0,0 +1,449 @@ +/*- + * ============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.adapter.vnf.mapper; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; + +import org.junit.Test; +import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; +import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; +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.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +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 com.fasterxml.jackson.databind.ObjectMapper; + +public class VnfAdapterVfModuleObjectMapperIntegrationTest { + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + + @Test + public void createVfModuleRequestMapperTest() 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"); + modelInfoServiceInstance.setEnvironmentContext("environmentContext"); + modelInfoServiceInstance.setWorkloadContext("workloadContext"); + 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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setMsoRequestId("requestId"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("vnfId"); + vnf.setVnfType("vnfType"); + vnf.setVnfName("vnfName"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); + modelInfoGenericVnf.setModelName("vnfModelName"); + modelInfoGenericVnf.setModelVersion("vnfModelVersion"); + modelInfoGenericVnf.setModelUuid("vnfModelUuid"); + modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + Integer vfModuleIndex = 1; + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("vfModuleId"); + vfModule.setVfModuleName("vfModuleName"); + vfModule.setModuleIndex(vfModuleIndex); + 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(); + cloudRegion.setLcpCloudRegionId("cloudRegionId"); + cloudRegion.setTenantId("tenantId"); + + OrchestrationContext orchestrationContext = new OrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(false); + + String sdncVnfQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVnfTopology.json"))); + String sdncVfModuleQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVfModuleTopology.json"))); + + VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper(); + mapper.vnfAdapterObjectMapperUtils = new VnfAdapterObjectMapperUtils(); + + CreateVfModuleRequest vfModuleVNFAdapterRequest = mapper.createVfModuleRequestMapper( + requestContext, cloudRegion, orchestrationContext, serviceInstance, + vnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "vnfAdapterCreateVfModuleRequest.json"))); + + ObjectMapper omapper = new ObjectMapper(); + CreateVfModuleRequest reqMapper1 = omapper.readValue( + jsonToCompare, + CreateVfModuleRequest.class); + + assertThat(vfModuleVNFAdapterRequest, sameBeanAs(reqMapper1).ignoring("messageId").ignoring("notificationUrl")); + } + + @Test + public void createVfModuleRequestMapperWithCloudResourcesTest() 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"); + modelInfoServiceInstance.setEnvironmentContext("environmentContext"); + modelInfoServiceInstance.setWorkloadContext("workloadContext"); + 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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setMsoRequestId("requestId"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("vnfId"); + vnf.setVnfType("vnfType"); + vnf.setVnfName("vnfName"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); + modelInfoGenericVnf.setModelName("vnfModelName"); + modelInfoGenericVnf.setModelVersion("vnfModelVersion"); + modelInfoGenericVnf.setModelUuid("vnfModelUuid"); + modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + Integer vfModuleIndex = 1; + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("vfModuleId"); + vfModule.setVfModuleName("vfModuleName"); + vfModule.setModuleIndex(vfModuleIndex); + 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(); + cloudRegion.setLcpCloudRegionId("cloudRegionId"); + cloudRegion.setTenantId("tenantId"); + + OrchestrationContext orchestrationContext = new OrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(false); + + String sdncVnfQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVnfTopologyWithCloudResources.json"))); + String sdncVfModuleQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVfModuleTopologyWithCloudResources.json"))); + + VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper(); + mapper.vnfAdapterObjectMapperUtils = new VnfAdapterObjectMapperUtils(); + + CreateVfModuleRequest vfModuleVNFAdapterRequest = mapper.createVfModuleRequestMapper( + requestContext, cloudRegion, orchestrationContext, serviceInstance, + vnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "vnfAdapterCreateVfModuleRequestWithCloudResources.json"))); + + ObjectMapper omapper = new ObjectMapper(); + CreateVfModuleRequest reqMapper1 = omapper.readValue( + jsonToCompare, + CreateVfModuleRequest.class); + + assertThat(vfModuleVNFAdapterRequest, sameBeanAs(reqMapper1).ignoring("messageId").ignoring("notificationUrl")); + } + + @Test + public void createVfModuleRequestMapperDhcpDisabledTest() 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"); + modelInfoServiceInstance.setEnvironmentContext("environmentContext"); + modelInfoServiceInstance.setWorkloadContext("workloadContext"); + 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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setMsoRequestId("requestId"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("vnfId"); + vnf.setVnfType("vnfType"); + vnf.setVnfName("vnfName"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); + modelInfoGenericVnf.setModelName("vnfModelName"); + modelInfoGenericVnf.setModelVersion("vnfModelVersion"); + modelInfoGenericVnf.setModelUuid("vnfModelUuid"); + modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + Integer vfModuleIndex = 1; + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("vfModuleId"); + vfModule.setVfModuleName("vfModuleName"); + vfModule.setModuleIndex(vfModuleIndex); + 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(); + cloudRegion.setLcpCloudRegionId("cloudRegionId"); + cloudRegion.setTenantId("tenantId"); + + OrchestrationContext orchestrationContext = new OrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(false); + + String sdncVnfQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVnfTopologySubnetDhcpDisabled.json"))); + String sdncVfModuleQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVfModuleTopology.json"))); + + VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper(); + mapper.vnfAdapterObjectMapperUtils = new VnfAdapterObjectMapperUtils(); + + CreateVfModuleRequest vfModuleVNFAdapterRequest = mapper.createVfModuleRequestMapper( + requestContext, cloudRegion, orchestrationContext, serviceInstance, + vnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "vnfAdapterCreateVfModuleRequestDhcpDisabled.json"))); + + ObjectMapper omapper = new ObjectMapper(); + CreateVfModuleRequest reqMapper1 = omapper.readValue( + jsonToCompare, + CreateVfModuleRequest.class); + + assertThat(vfModuleVNFAdapterRequest, sameBeanAs(reqMapper1).ignoring("messageId").ignoring("notificationUrl")); + } + + @Test + public void createVfModuleRequestMapperMultipleDhcpTest() 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"); + modelInfoServiceInstance.setEnvironmentContext("environmentContext"); + modelInfoServiceInstance.setWorkloadContext("workloadContext"); + 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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setMsoRequestId("requestId"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("vnfId"); + vnf.setVnfType("vnfType"); + vnf.setVnfName("vnfName"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInvariantUuid("vnfModelInvariantUuid"); + modelInfoGenericVnf.setModelName("vnfModelName"); + modelInfoGenericVnf.setModelVersion("vnfModelVersion"); + modelInfoGenericVnf.setModelUuid("vnfModelUuid"); + modelInfoGenericVnf.setModelCustomizationUuid("vnfModelCustomizationUuid"); + vnf.setModelInfoGenericVnf(modelInfoGenericVnf); + + Integer vfModuleIndex = 1; + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("vfModuleId"); + vfModule.setVfModuleName("vfModuleName"); + vfModule.setModuleIndex(vfModuleIndex); + 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(); + cloudRegion.setLcpCloudRegionId("cloudRegionId"); + cloudRegion.setTenantId("tenantId"); + + OrchestrationContext orchestrationContext = new OrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(false); + + String sdncVnfQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVnfTopologySubnetMultipleDhcp.json"))); + String sdncVfModuleQueryResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleSdncVfModuleTopology.json"))); + + VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper(); + mapper.vnfAdapterObjectMapperUtils = new VnfAdapterObjectMapperUtils(); + + CreateVfModuleRequest vfModuleVNFAdapterRequest = mapper.createVfModuleRequestMapper( + requestContext, cloudRegion, orchestrationContext, serviceInstance, + vnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "vnfAdapterCreateVfModuleRequestMultipleDhcp.json"))); + + ObjectMapper omapper = new ObjectMapper(); + CreateVfModuleRequest reqMapper1 = omapper.readValue( + jsonToCompare, + CreateVfModuleRequest.class); + + assertThat(vfModuleVNFAdapterRequest, sameBeanAs(reqMapper1).ignoring("messageId").ignoring("notificationUrl")); + } + + @Test + public void DeleteVfModuleRequestMapperTest() throws Exception { + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelInvariantUuid("serviceModelInvariantUuid"); + modelInfoServiceInstance.setModelName("serviceModelName"); + modelInfoServiceInstance.setModelUuid("serviceModelUuid"); + modelInfoServiceInstance.setModelVersion("serviceModelVersion"); + modelInfoServiceInstance.setEnvironmentContext("environmentContext"); + modelInfoServiceInstance.setWorkloadContext("workloadContext"); + 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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setMsoRequestId("requestId"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("vnfId"); + vnf.setVnfType("vnfType"); + vnf.setVnfName("vnfName"); + 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("vfModuleId"); + vfModule.setVfModuleName("vfModuleName"); + 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(); + cloudRegion.setLcpCloudRegionId("cloudRegionId"); + cloudRegion.setTenantId("tenantId"); + + OrchestrationContext orchestrationContext = new OrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(false); + + VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper(); + mapper.vnfAdapterObjectMapperUtils = new VnfAdapterObjectMapperUtils(); + + DeleteVfModuleRequest vfModuleVNFAdapterRequest = mapper.deleteVfModuleRequestMapper( + requestContext, cloudRegion, serviceInstance, + vnf, vfModule); + + + String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "vnfAdapterDeleteVfModuleRequest.json"))); + + ObjectMapper omapper = new ObjectMapper(); + DeleteVfModuleRequest reqMapper1 = omapper.readValue( + jsonToCompare, + DeleteVfModuleRequest.class); + + assertThat(vfModuleVNFAdapterRequest, sameBeanAs(reqMapper1).ignoring("messageId").ignoring("notificationUrl")); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperTest.java new file mode 100644 index 0000000000..c8f4a222f3 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapperTest.java @@ -0,0 +1,67 @@ +/*- + * ============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.adapter.vnf.mapper; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class VnfAdapterVfModuleObjectMapperTest{ + + private VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper(); + + @Test + public void createVnfcSubInterfaceKeyTest() { + + assertEquals("type_0_subint_role_port_0", mapper.createVnfcSubInterfaceKey("type", 0, "role", 0)); + } + + @Test + public void createGlobalVnfcSubInterfaceKeyTest() { + + assertEquals("type_subint_role_port_0", mapper.createGlobalVnfcSubInterfaceKey("type", "role", 0)); + } + + @Test + public void addPairToMapTest() { + Map<String, String> map = new HashMap<>(); + + mapper.addPairToMap(map, "test", "_key", Arrays.asList("a", "b")); + + assertEquals("a,b", map.get("test_key")); + + mapper.addPairToMap(map, "test", "_key2", Arrays.asList()); + + assertThat(map.containsKey("test_key2"), equalTo(false)); + + mapper.addPairToMap(map, "test", "_key3", "myVal"); + + assertEquals("myVal", map.get("test_key3")); + + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAICollectionResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAICollectionResourcesTest.java new file mode 100644 index 0000000000..fff4fc72fb --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAICollectionResourcesTest.java @@ -0,0 +1,91 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +@RunWith(MockitoJUnitRunner.class) +public class AAICollectionResourcesTest extends TestDataSetup{ + + @InjectMocks + private AAICollectionResources aaiCollectionResources = new AAICollectionResources(); + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + private Collection networkCollection; + + @Before + public void before() { + networkCollection = buildCollection(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + @Test + public void createCollectionTest() throws Exception { + networkCollection.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + doReturn(new org.onap.aai.domain.yang.Collection()).when(MOCK_aaiObjectMapper).mapCollection(networkCollection); + + aaiCollectionResources.createCollection(networkCollection); + + assertEquals(OrchestrationStatus.INVENTORIED, networkCollection.getOrchestrationStatus()); + verify(MOCK_aaiResourcesClient, times(1)).create(eq(AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, networkCollection.getId())), isA(org.onap.aai.domain.yang.Collection.class)); + } + + @Test + public void updateCollectionTest() throws Exception { + doReturn(new org.onap.aai.domain.yang.Collection()).when(MOCK_aaiObjectMapper).mapCollection(networkCollection); + aaiCollectionResources.updateCollection(networkCollection); + verify(MOCK_aaiResourcesClient, times(1)).update(eq(AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, networkCollection.getId())), isA(org.onap.aai.domain.yang.Collection.class)); + } + + @Test + public void deleteCollectionTest() throws Exception { + aaiCollectionResources.deleteCollection(networkCollection); + verify(MOCK_aaiResourcesClient, times(1)).delete(eq(AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, networkCollection.getId()))); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java new file mode 100644 index 0000000000..cc48c46508 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIConfigurationResourcesTest.java @@ -0,0 +1,180 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.bpmn.common.data.TestDataSetup; + + +@RunWith(MockitoJUnitRunner.class) +public class AAIConfigurationResourcesTest extends TestDataSetup{ + + + + private Configuration configuration; + private ServiceProxy serviceProxy; + private ServiceInstance serviceInstance; + private GenericVnf genericVnf; + private VpnBinding vpnBinding; + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @InjectMocks + private AAIConfigurationResources aaiConfigurationResources = new AAIConfigurationResources(); + + @Before + public void before() { + configuration = buildConfiguration(); + serviceProxy = buildServiceProxy(); + serviceInstance = buildServiceInstance(); + genericVnf = buildGenericVnf(); + vpnBinding = buildVpnBinding(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + @Test + public void createConfigurationTest() { + doReturn(new org.onap.aai.domain.yang.Configuration()).when(MOCK_aaiObjectMapper).mapConfiguration(configuration); + doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Configuration.class)); + + aaiConfigurationResources.createConfiguration(configuration); + + assertEquals(OrchestrationStatus.INVENTORIED, configuration.getOrchestrationStatus()); + verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Configuration.class)); + } + + @Test + public void updateConfigurationTest() { + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Configuration.class)); + configuration.setConfigurationType("VNR"); + configuration.setOrchestrationStatus(OrchestrationStatus.ACTIVE); + aaiConfigurationResources.updateConfiguration(configuration); + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.Configuration.class)); + } + + @Test + public void connectConfigurationToServiceInstanceTest() { + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + aaiConfigurationResources.connectConfigurationToServiceInstance(configuration.getConfigurationId(), serviceInstance.getServiceInstanceId()); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void disconnectConfigurationToServiceInstanceTest(){ + doNothing().when(MOCK_aaiResourcesClient).disconnect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + aaiConfigurationResources.disconnectConfigurationToServiceInstance("TEST_CONFIGURATION_ID", "TEST_SERVICE_INSTANCE_ID"); + verify(MOCK_aaiResourcesClient, times(1)).disconnect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void connectConfigurationToGenericVnfTest() { + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + aaiConfigurationResources.connectConfigurationToGenericVnf(configuration.getConfigurationId(), genericVnf.getVnfId()); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void connectConfigurationToVpnBindingTest() { + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + aaiConfigurationResources.connectConfigurationToVpnBinding(configuration.getConfigurationId(), vpnBinding.getVpnId()); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void getConfigurationFromRelatedLinkTest () { + Optional<org.onap.aai.domain.yang.Configuration> configuration = Optional.of(new org.onap.aai.domain.yang.Configuration()); + configuration.get().setConfigurationId("config1"); + doReturn(configuration).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.Configuration.class),isA(AAIResourceUri.class)); + aaiConfigurationResources.getConfigurationFromRelatedLink("http://localhost:8090/aai/v12/network/configurations/configuration/config1"); + verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.Configuration.class),isA(AAIResourceUri.class)); + } + + @Test + public void connectVrfConfigurationToVnrConfigurationTest() throws Exception { + Configuration vrfConfiguration = buildConfiguration(); + Configuration vnrConfiguration = buildConfiguration(); + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + aaiConfigurationResources.connectVrfConfigurationToVnrConfiguration(vrfConfiguration.getConfigurationId(),vnrConfiguration.getConfigurationId()); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void connectConfigurationToPnfObjectTest() throws Exception { + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + + Pnf primaryPnf = serviceProxy.getServiceInstance().getPnfs().stream().filter(o -> o.getRole().equals("Primary")).findFirst().get(); + + aaiConfigurationResources.connectConfigurationToPnfObject(primaryPnf.getPnfId(), configuration.getConfigurationId()); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void getConfigurationTest() { + AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, "configurationId"); + doReturn(Optional.of(new org.onap.aai.domain.yang.Configuration())).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.Configuration.class, aaiResourceUri); + aaiConfigurationResources.getConfiguration("configurationId"); + verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.Configuration.class, aaiResourceUri); + } + + @Test + public void deleteConfigurationTest() { + AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, "configurationId"); + doNothing().when(MOCK_aaiResourcesClient).delete(aaiResourceUri); + aaiConfigurationResources.deleteConfiguration("configurationId"); + verify(MOCK_aaiResourcesClient, times(1)).delete(aaiResourceUri); + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIInstanceGroupResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIInstanceGroupResourcesTest.java new file mode 100644 index 0000000000..aef25e5ded --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIInstanceGroupResourcesTest.java @@ -0,0 +1,95 @@ +/*- + * ============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.orchestration; + +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +@RunWith(MockitoJUnitRunner.class) +public class AAIInstanceGroupResourcesTest extends TestDataSetup{ + + @InjectMocks + private AAIInstanceGroupResources aaiInstanceGroupResources = new AAIInstanceGroupResources(); + + private InstanceGroup instanceGroup; + private GenericVnf vnf; + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @Before + public void before() { + instanceGroup = buildInstanceGroup(); + vnf = buildGenericVnf(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + @Test + public void createInstanceGroupTest() throws Exception { + doReturn(new org.onap.aai.domain.yang.InstanceGroup()).when(MOCK_aaiObjectMapper).mapInstanceGroup(instanceGroup); + aaiInstanceGroupResources.createInstanceGroup(instanceGroup); + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId())), isA(Optional.class)); + } + + @Test + public void deleteInstanceGroupTest() throws Exception { + aaiInstanceGroupResources.deleteInstanceGroup(instanceGroup); + verify(MOCK_aaiResourcesClient, times(1)).delete(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()))); + } + + @Test + public void connectInstanceGroupTest() throws Exception { + aaiInstanceGroupResources.connectInstanceGroupToVnf(instanceGroup, vnf); + verify(MOCK_aaiResourcesClient, times(1)).connect(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId())), eq(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()))); + } + + @Test + public void existsTest() throws Exception { + aaiInstanceGroupResources.exists(instanceGroup); + verify(MOCK_aaiResourcesClient, times(1)).exists(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()))); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java new file mode 100644 index 0000000000..fa3324840c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java @@ -0,0 +1,317 @@ +/*- + * ============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.orchestration; + +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.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.aai.domain.yang.NetworkPolicy; +import org.onap.aai.domain.yang.RouteTableReference; +import org.onap.aai.domain.yang.VpnBinding; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; +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.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; + +@RunWith(MockitoJUnitRunner.class) +public class AAINetworkResourcesTest extends TestDataSetup{ + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + + private L3Network network; + private Collection collection; + private InstanceGroup instanceGroup; + private ServiceInstance serviceInstance; + private CloudRegion cloudRegion; + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @InjectMocks + private AAINetworkResources aaiNetworkResources = new AAINetworkResources(); + + @Before + public void before() { + network = buildL3Network(); + + collection = buildCollection(); + + List<L3Network> l3NetworkList = new ArrayList<L3Network>(); + l3NetworkList.add(network); + + instanceGroup = buildInstanceGroup(); + + serviceInstance = buildServiceInstance(); + + cloudRegion = buildCloudRegion(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + + @Test + public void updateNetworkTest() throws Exception { + + network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doReturn(new org.onap.aai.domain.yang.L3Network()).when(MOCK_aaiObjectMapper).mapNetwork(network); + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.L3Network.class)); + + aaiNetworkResources.updateNetwork(network); + + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), isA(org.onap.aai.domain.yang.L3Network.class)); + assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus()); + } + + @Test + public void createNetworkConnectToServiceInstanceTest() throws Exception { + + network.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + doReturn(new org.onap.aai.domain.yang.L3Network()).when(MOCK_aaiObjectMapper).mapNetwork(network); + doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), any(AAIResourceUri.class)); + + aaiNetworkResources.createNetworkConnectToServiceInstance(network, serviceInstance); + + assertEquals(OrchestrationStatus.INVENTORIED, network.getOrchestrationStatus()); + + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void deleteNetworkTest() throws Exception { + + network.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); + + doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class)); + + aaiNetworkResources.deleteNetwork(network); + + verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class)); + } + + @Test + public void getVpnBindingTest() throws Exception { + final String content = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAaiVpnBinding.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content); + Optional<VpnBinding> oVpnBinding = Optional.empty(); + AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING, "ModelInvariantUUID", "serviceModelVersionId"); + + doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class)); + oVpnBinding = aaiNetworkResources.getVpnBinding(aaiUri); + verify(MOCK_aaiResourcesClient, times(1)).get(any(AAIResourceUri.class)); + + if (oVpnBinding.isPresent()) { + VpnBinding vpnBinding = oVpnBinding.get(); + assertThat(aaiResultWrapper.asBean(VpnBinding.class).get(), sameBeanAs(vpnBinding)); + } + } + + @Test + public void getNetworkPolicyTest() throws Exception { + final String content = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAaiNetworkPolicy.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content); + Optional<NetworkPolicy> oNetPolicy = Optional.empty(); + AAIResourceUri netPolicyUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, "ModelInvariantUUID", "serviceModelVersionId"); + + doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class)); + oNetPolicy = aaiNetworkResources.getNetworkPolicy(netPolicyUri); + verify(MOCK_aaiResourcesClient, times(1)).get(any(AAIResourceUri.class)); + + if (oNetPolicy.isPresent()) { + NetworkPolicy networkPolicy = oNetPolicy.get(); + assertThat(aaiResultWrapper.asBean(NetworkPolicy.class).get(), sameBeanAs(networkPolicy)); + } + } + + @Test + public void getRouteTableTest() throws Exception { + final String content = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAaiNetworkTableRefs.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content); + Optional<RouteTableReference> oRtref = Optional.empty(); + AAIResourceUri rTRefUri = AAIUriFactory.createResourceUri(AAIObjectType.ROUTE_TABLE_REFERENCE, "ModelInvariantUUID", "serviceModelVersionId"); + + doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class)); + oRtref = aaiNetworkResources.getRouteTable(rTRefUri); + verify(MOCK_aaiResourcesClient, times(1)).get(any(AAIResourceUri.class)); + + if (oRtref.isPresent()) { + RouteTableReference rTref = oRtref.get(); + assertThat(aaiResultWrapper.asBean(RouteTableReference.class).get(), sameBeanAs(rTref)); + } + } + + @Test + public void queryNetworkByIdTest() throws Exception { + final String content = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiQueryAAIResponse-Wrapper.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content); + L3Network network = new L3Network(); + network.setNetworkId("0384d743-f69b-4cc8-9aa8-c3ae66662c44"); + network.setNetworkName("Dev_Bindings_1802_020118"); + network.setOrchestrationStatus(OrchestrationStatus.CREATED); + + doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class)); + Optional<org.onap.aai.domain.yang.L3Network> l3NetworkOpt = aaiNetworkResources.queryNetworkById(network); + org.onap.aai.domain.yang.L3Network l3Network = l3NetworkOpt.isPresent() ? l3NetworkOpt.get() : null; + + verify(MOCK_aaiResourcesClient, times(1)).get(isA(AAIResourceUri.class)); + assertNotNull(l3Network); + assertEquals("0384d743-f69b-4cc8-9aa8-c3ae66662c44", l3Network.getNetworkId()); + assertEquals("Dev_Bindings_1802_020118", l3Network.getNetworkName()); + } + + @Test + public void queryNetworkWrapperByIdTest() throws Exception { + final String content = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiQueryAAIResponse-Wrapper.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(content); + L3Network network = new L3Network(); + network.setNetworkId("0384d743-f69b-4cc8-9aa8-c3ae66662c44"); + network.setNetworkName("Dev_Bindings_1802_020118"); + network.setOrchestrationStatus(OrchestrationStatus.CREATED); + + doReturn(aaiResultWrapper).when(MOCK_aaiResourcesClient).get(isA(AAIResourceUri.class)); + AAIResultWrapper result = aaiNetworkResources.queryNetworkWrapperById(network); + + verify(MOCK_aaiResourcesClient, times(1)).get(isA(AAIResourceUri.class)); + assertEquals(aaiResultWrapper.getJson(), result.getJson()); + assertNotNull(result); + Optional<Relationships> resultNetworkRelationships = result.getRelationships(); + assertTrue(resultNetworkRelationships.isPresent()); + Optional<org.onap.aai.domain.yang.L3Network> aaiL3Network = result.asBean(org.onap.aai.domain.yang.L3Network.class); + assertEquals(network.getNetworkId(),aaiL3Network.get().getNetworkId()); + assertEquals(network.getNetworkName(),aaiL3Network.get().getNetworkName()); + + + } + + @Test + public void createNetworkCollectionTest() throws Exception { + + doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Collection.class)); + doReturn(new org.onap.aai.domain.yang.Collection()).when(MOCK_aaiObjectMapper).mapCollection(collection); + collection.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + aaiNetworkResources.createNetworkCollection(collection); + assertEquals(OrchestrationStatus.INVENTORIED, collection.getOrchestrationStatus()); + verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Collection.class)); + } + + @Test + public void createNetworkInstanceGroupTest() throws Exception { + doReturn(new org.onap.aai.domain.yang.InstanceGroup()).when(MOCK_aaiObjectMapper).mapInstanceGroup(instanceGroup); + doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.InstanceGroup.class)); + aaiNetworkResources.createNetworkInstanceGroup(instanceGroup); + verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), isA(org.onap.aai.domain.yang.InstanceGroup.class)); + } + + @Test + public void connectNetworkToNetworkCollectionInstanceGroupTest() throws Exception { + aaiNetworkResources.connectNetworkToNetworkCollectionInstanceGroup(network, instanceGroup); + verify(MOCK_aaiResourcesClient, times(1)).connect(eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId())), eq(AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, network.getNetworkId()))); + } + + @Test + public void connectNetworkToNetworkCollectionServiceInstanceTest() throws Exception { + aaiNetworkResources.connectNetworkToNetworkCollectionServiceInstance(network, serviceInstance); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), eq(AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, network.getNetworkId()))); + } + + @Test + public void connectNetworkToCloudRegionTest() throws Exception { + aaiNetworkResources.connectNetworkToCloudRegion(network, cloudRegion); + verify(MOCK_aaiResourcesClient, times(1)).connect(eq(AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, + cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId())), eq(AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, network.getNetworkId()))); + } + + @Test + public void connectNetworkToTenantTest() throws Exception { + aaiNetworkResources.connectNetworkToTenant(network, cloudRegion); + verify(MOCK_aaiResourcesClient, times(1)).connect(eq(AAIUriFactory.createResourceUri(AAIObjectType.TENANT, + cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), cloudRegion.getTenantId())), + eq(AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, network.getNetworkId()))); + } + + @Test + public void connectNetworkCollectionInstanceGroupToNetworkCollectionTest() throws Exception { + aaiNetworkResources.connectNetworkCollectionInstanceGroupToNetworkCollection(instanceGroup, collection); + verify(MOCK_aaiResourcesClient, times(1)).connect(eq(AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, collection.getId())), eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()))); + } + + @Test + public void connectNetworkCollectionToServiceInstanceTest() throws Exception { + aaiNetworkResources.connectNetworkCollectionToServiceInstance(collection, serviceInstance); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void deleteCollectionTest() throws Exception { + doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class)); + aaiNetworkResources.deleteCollection(collection); + verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class)); + } + + @Test + public void deleteInstanceGroupTest() throws Exception { + doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class)); + aaiNetworkResources.deleteNetworkInstanceGroup(instanceGroup); + verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java new file mode 100644 index 0000000000..46d4135b6d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java @@ -0,0 +1,181 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Project; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; + +@RunWith(MockitoJUnitRunner.class) +public class AAIServiceInstanceResourcesTest extends TestDataSetup{ + + @InjectMocks + private AAIServiceInstanceResources aaiServiceInstanceResources = new AAIServiceInstanceResources(); + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + private ServiceInstance serviceInstance; + private ServiceSubscription serviceSubscription; + private Customer customer; + private Project project; + private OwningEntity owningEntity; + + @Before + public void before() { + serviceInstance = buildServiceInstance(); + serviceSubscription = buildServiceSubscription(); + customer = buildCustomer(); + project = buildProject(); + owningEntity = buildOwningEntity(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + @Test + public void deleteServiceInstanceSuccessTest() throws Exception { + aaiServiceInstanceResources.deleteServiceInstance(serviceInstance); + verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class)); + } + + @Test + public void deleteServiceInstanceExceptionTest() throws Exception { + expectedException.expect(Exception.class); + doThrow(Exception.class).when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class)); + aaiServiceInstanceResources.deleteServiceInstance(serviceInstance); + } + + @Test + public void existsServiceInstanceTest() { + aaiServiceInstanceResources.existsServiceInstance(serviceInstance); + verify(MOCK_aaiResourcesClient, times(1)).exists(any(AAIResourceUri.class)); + } + + @Test + public void createServiceSubscriptionTest() { + serviceSubscription.setServiceType("IP-FLEX"); + customer.setServiceSubscription(serviceSubscription); + doReturn(new org.onap.aai.domain.yang.ServiceSubscription()).when(MOCK_aaiObjectMapper).mapServiceSubscription(customer.getServiceSubscription()); + aaiServiceInstanceResources.createServiceSubscription(customer); + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + } + + @Test + public void createServiceInstanceTest() { + serviceSubscription.setServiceType("testSubscriberType"); + customer.setServiceSubscription(serviceSubscription); + doReturn(new org.onap.aai.domain.yang.ServiceInstance()).when(MOCK_aaiObjectMapper).mapServiceInstance(serviceInstance); + serviceInstance.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + aaiServiceInstanceResources.createServiceInstance(serviceInstance, customer); + + assertEquals(OrchestrationStatus.INVENTORIED, serviceInstance.getOrchestrationStatus()); + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + } + + @Test + public void createProjectTest() { + doReturn(new org.onap.aai.domain.yang.Project()).when(MOCK_aaiObjectMapper).mapProject(project); + aaiServiceInstanceResources.createProject(project); + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + } + + @Test + public void createProjectandConnectServiceInstanceTest() { + doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + doNothing().when(MOCK_aaiResourcesClient).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + doReturn(new org.onap.aai.domain.yang.Project()).when(MOCK_aaiObjectMapper).mapProject(project); + aaiServiceInstanceResources.createProjectandConnectServiceInstance(project, serviceInstance); + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void createOwningEntityTest() { + doReturn(new org.onap.aai.domain.yang.OwningEntity()).when(MOCK_aaiObjectMapper).mapOwningEntity(owningEntity); + aaiServiceInstanceResources.createOwningEntity(owningEntity); + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + } + + @Test + public void existsOwningEntityTest() { + aaiServiceInstanceResources.existsOwningEntity(owningEntity); + verify(MOCK_aaiResourcesClient, times(1)).exists(any(AAIResourceUri.class)); + } + + @Test + public void connectOwningEntityandServiceInstanceTest() { + aaiServiceInstanceResources.connectOwningEntityandServiceInstance(owningEntity, serviceInstance); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void createOwningEntityandConnectServiceInstanceTest() { + doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + doNothing().when(MOCK_aaiResourcesClient).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + doReturn(new org.onap.aai.domain.yang.OwningEntity()).when(MOCK_aaiObjectMapper).mapOwningEntity(owningEntity); + aaiServiceInstanceResources.createOwningEntityandConnectServiceInstance(owningEntity, serviceInstance); + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void updateOrchestrationStatusServiceInstanceTest() { + aaiServiceInstanceResources.updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE); + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.ServiceInstance.class)); + } + + @Test + public void test_updateServiceInstance() { + aaiServiceInstanceResources.updateServiceInstance(serviceInstance); + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.ServiceInstance.class)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java new file mode 100644 index 0000000000..0c4c8fc443 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVfModuleResourcesTest.java @@ -0,0 +1,127 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; + +@RunWith(MockitoJUnitRunner.class) +public class AAIVfModuleResourcesTest extends TestDataSetup{ + @InjectMocks + private AAIVfModuleResources aaiVfModuleResources = new AAIVfModuleResources(); + + private VfModule vfModule; + private GenericVnf vnf; + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @Before + public void before() { + vfModule = buildVfModule(); + vnf = buildGenericVnf(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + @Test + public void updateOrchestrationStatusVfModuleTest() throws Exception { + vfModule.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class)); + + aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, OrchestrationStatus.ACTIVE); + + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VfModule.class)); + + assertEquals(OrchestrationStatus.ACTIVE, vfModule.getOrchestrationStatus()); + } + + @Test + public void createVfModuleTest() throws Exception { + vfModule.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + doReturn(new org.onap.aai.domain.yang.VfModule()).when(MOCK_aaiObjectMapper).mapVfModule(vfModule); + doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class)); + aaiVfModuleResources.createVfModule(vfModule, vnf); + + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + assertEquals(OrchestrationStatus.INVENTORIED, vfModule.getOrchestrationStatus()); + } + + @Test + public void deleteVfModuleTest() throws Exception { + doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class)); + + aaiVfModuleResources.deleteVfModule(vfModule, vnf); + + verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class)); + } + + @Test + public void changeAssignVfModuleTest() throws Exception { + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VfModule.class)); + + aaiVfModuleResources.changeAssignVfModule(vfModule, vnf); + + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VfModule.class)); + } + + @Test + public void connectVfModuleToVolumeGroupTest() throws Exception { + VolumeGroup volumeGroup = buildVolumeGroup(); + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + CloudRegion cloudRegion = buildCloudRegion(); + + aaiVfModuleResources.connectVfModuleToVolumeGroup(vnf, vfModule, volumeGroup, cloudRegion); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java new file mode 100644 index 0000000000..db719d3151 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java @@ -0,0 +1,161 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; + +@RunWith(MockitoJUnitRunner.class) +public class AAIVnfResourcesTest extends TestDataSetup { + + private GenericVnf genericVnf; + + private ServiceInstance serviceInstance; + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @InjectMocks + AAIVnfResources aaiVnfResources = new AAIVnfResources(); + + @Before + public void before() { + serviceInstance = buildServiceInstance(); + genericVnf = buildGenericVnf(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + @Test + public void createVnfandConnectServiceInstanceTest() { + doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(MOCK_aaiObjectMapper).mapVnf(genericVnf); + doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class)); + doNothing().when(MOCK_aaiResourcesClient).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + genericVnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + aaiVnfResources.createVnfandConnectServiceInstance(genericVnf, serviceInstance); + + assertEquals(OrchestrationStatus.INVENTORIED, genericVnf.getOrchestrationStatus()); + verify(MOCK_aaiObjectMapper, times(1)).mapVnf(genericVnf); + verify(MOCK_aaiResourcesClient, times(1)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void createPlatformandConnectVnfTest() { + Platform platform = new Platform(); + platform.setPlatformName("a123"); + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class)); + doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class)); + aaiVnfResources.createPlatformandConnectVnf(platform, genericVnf); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class),isA(AAIResourceUri.class)); + } + + @Test + public void createLineOfBusinessandConnectVnfTest() { + LineOfBusiness lob = new LineOfBusiness(); + lob.setLineOfBusinessName("a123"); + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class),isA(AAIResourceUri.class)); + doReturn(MOCK_aaiResourcesClient).when(MOCK_aaiResourcesClient).createIfNotExists(isA(AAIResourceUri.class), any(Optional.class)); + aaiVnfResources.createLineOfBusinessandConnectVnf(lob, genericVnf); + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class),isA(AAIResourceUri.class)); + } + + @Test + public void deleteVnfTest() { + doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class)); + + aaiVnfResources.deleteVnf(genericVnf); + + verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class)); + } + + @Test + public void updateOrchestrationStatusVnfTest() { + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Vnf.class)); + + aaiVnfResources.updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE); + + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.Vnf.class)); + + assertEquals(OrchestrationStatus.ACTIVE, genericVnf.getOrchestrationStatus()); + } + + @Test + public void updateObjectVnfTest() { + doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(MOCK_aaiObjectMapper).mapVnf(genericVnf); + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.GenericVnf.class)); + + aaiVnfResources.updateObjectVnf(genericVnf); + + verify(MOCK_aaiObjectMapper, times(1)).mapVnf(genericVnf); + verify(MOCK_aaiResourcesClient, times(1)).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.GenericVnf.class)); + } + + @Test + public void getGenericVnfTest () { + Optional<org.onap.aai.domain.yang.GenericVnf> vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf()); + vnf.get().setVnfId("vnfId"); + doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); + aaiVnfResources.getGenericVnf("vnfId"); + verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); + } + + @Test + public void checkInMaintFlagTest () { + Optional<org.onap.aai.domain.yang.GenericVnf> vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf()); + vnf.get().setVnfId("vnfId"); + vnf.get().setInMaint(true); + doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); + boolean inMaintFlag = aaiVnfResources.checkInMaintFlag("vnfId"); + verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); + assertEquals(inMaintFlag, true); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVolumeGroupResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVolumeGroupResourcesTest.java new file mode 100644 index 0000000000..de15e0a550 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVolumeGroupResourcesTest.java @@ -0,0 +1,132 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.mapper.AAIObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; + +@RunWith(MockitoJUnitRunner.class) +public class AAIVolumeGroupResourcesTest extends TestDataSetup{ + @InjectMocks + private AAIVolumeGroupResources aaiVolumeGroupResources = new AAIVolumeGroupResources(); + + private CloudRegion cloudRegion; + private VolumeGroup volumeGroup; + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @Before + public void before() { + cloudRegion = buildCloudRegion(); + volumeGroup = buildVolumeGroup(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + + + @Test + public void updateOrchestrationStatusVolumeGroupTest() throws Exception { + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doNothing().when(MOCK_aaiResourcesClient).update(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VolumeGroup.class)); + + aaiVolumeGroupResources.updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE); + + verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VolumeGroup.class)); + + assertEquals(OrchestrationStatus.ACTIVE, volumeGroup.getOrchestrationStatus()); + } + + @Test + public void createVolumeGroupTest() throws Exception { + volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VolumeGroup.class)); + + aaiVolumeGroupResources.createVolumeGroup(volumeGroup, cloudRegion); + + verify(MOCK_aaiResourcesClient, times(1)).create(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.VolumeGroup.class)); + + assertEquals(OrchestrationStatus.ASSIGNED, volumeGroup.getOrchestrationStatus()); + } + + @Test + public void connectVolumeGroupToVnfTest() throws Exception { + + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + + aaiVolumeGroupResources.connectVolumeGroupToTenant(volumeGroup, cloudRegion); + + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void connectVolumeGroupToTenantTest() throws Exception { + GenericVnf genericVnf = buildGenericVnf(); + + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + + aaiVolumeGroupResources.connectVolumeGroupToVnf(genericVnf, volumeGroup, cloudRegion); + + verify(MOCK_aaiResourcesClient, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); + } + + @Test + public void deleteVolumeGroupTest() { + doNothing().when(MOCK_aaiResourcesClient).delete(isA(AAIResourceUri.class)); + + aaiVolumeGroupResources.deleteVolumeGroup(volumeGroup, cloudRegion); + + verify(MOCK_aaiResourcesClient, times(1)).delete(any(AAIResourceUri.class)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVpnBindingResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVpnBindingResourcesTest.java new file mode 100644 index 0000000000..7c31040f1d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVpnBindingResourcesTest.java @@ -0,0 +1,132 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.aai.domain.yang.VpnBindings; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.mapper.AAIObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class AAIVpnBindingResourcesTest extends TestDataSetup{ + + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + + @Mock + protected AAIObjectMapper MOCK_aaiObjectMapper; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @InjectMocks + private AAIVpnBindingResources aaiVpnBindingResources = new AAIVpnBindingResources(); + + private Customer customer; + + @Before + public void before() { + customer = buildCustomer(); + doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); + } + + @Test + public void createCustomerTest() { + org.onap.aai.domain.yang.Customer mappedCustomer = new org.onap.aai.domain.yang.Customer(); + mappedCustomer.setGlobalCustomerId(customer.getGlobalCustomerId()); + + doReturn(mappedCustomer).when(MOCK_aaiObjectMapper).mapCustomer(customer); + doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Customer.class)); + + aaiVpnBindingResources.createCustomer(customer); + + verify(MOCK_aaiResourcesClient, times(1)).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Customer.class)); + verify(MOCK_aaiObjectMapper, times(1)).mapCustomer(customer); + } + + @Test + public void getVpnBindingTest () { + org.onap.aai.domain.yang.VpnBinding vpnBinding = new org.onap.aai.domain.yang.VpnBinding(); + vpnBinding.setVpnId("vnfId"); + when(MOCK_aaiResourcesClient.get(eq(org.onap.aai.domain.yang.VpnBinding.class),isA(AAIResourceUri.class))).thenReturn(Optional.of(vpnBinding)); + aaiVpnBindingResources.getVpnBinding("vpnId"); + verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.VpnBinding.class),isA(AAIResourceUri.class)); + } + + @Test + public void existsCustomerTest() { + when(MOCK_aaiResourcesClient.exists(isA(AAIResourceUri.class))).thenReturn(true); + boolean isCustomerExist = aaiVpnBindingResources.existsCustomer(customer); + verify(MOCK_aaiResourcesClient, times(1)).exists(isA(AAIResourceUri.class)); + assertEquals(true,isCustomerExist); + } + + @Test + public void getVpnBindingByCustomerVpnIdTest() { + when(MOCK_aaiResourcesClient.get(eq(VpnBindings.class),isA(AAIResourceUri.class))).thenReturn(Optional.of(new VpnBindings())); + Optional<VpnBindings> vpnBindings = aaiVpnBindingResources.getVpnBindingByCustomerVpnId("testCustomerVpnId"); + assertNotNull(vpnBindings.get()); + verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.VpnBindings.class),isA(AAIResourceUri.class)); + } + + @Test + public void createVpnBindingTest() { + doNothing().when(MOCK_aaiResourcesClient).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VpnBinding.class)); + org.onap.aai.domain.yang.VpnBinding mappedVpnBinding = new org.onap.aai.domain.yang.VpnBinding(); + mappedVpnBinding.setVpnName("test"); + + doReturn(mappedVpnBinding).when(MOCK_aaiObjectMapper).mapVpnBinding(isA(VpnBinding.class)); + VpnBinding vpnBinding = buildVpnBinding(); + aaiVpnBindingResources.createVpnBinding(vpnBinding); + + verify(MOCK_aaiResourcesClient, times(1)).create(isA(AAIResourceUri.class), isA(org.onap.aai.domain.yang.VpnBinding.class)); + verify(MOCK_aaiObjectMapper, times(1)).mapVpnBinding(isA(VpnBinding.class)); + } + + @Test + public void connectCustomerToVpnBinding() { + doNothing().when(MOCK_aaiResourcesClient).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + aaiVpnBindingResources.connectCustomerToVpnBinding("testCustId","testVpnId"); + verify(MOCK_aaiResourcesClient,times(1)).connect(isA(AAIResourceUri.class), isA(AAIResourceUri.class)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NetworkAdapterResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NetworkAdapterResourcesTest.java new file mode 100644 index 0000000000..0669b84fd6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NetworkAdapterResourcesTest.java @@ -0,0 +1,219 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.adapters.nwrest.CreateNetworkRequest; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.adapters.nwrest.DeleteNetworkRequest; +import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.adapters.nwrest.RollbackNetworkRequest; +import org.onap.so.adapters.nwrest.RollbackNetworkResponse; +import org.onap.so.adapters.nwrest.UpdateNetworkRequest; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.adapter.network.NetworkAdapterClientException; +import org.onap.so.client.adapter.network.NetworkAdapterClientImpl; +import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.entity.MsoRequest; + +import com.shazam.shazamcrest.matcher.Matchers; + + +@RunWith(MockitoJUnitRunner.class) +public class NetworkAdapterResourcesTest extends TestDataSetup{ + + @InjectMocks + private NetworkAdapterResources networkAdapterResources = new NetworkAdapterResources(); + + @Mock + protected NetworkAdapterClientImpl MOCK_networkAdapterClient; + + @Mock + protected NetworkAdapterObjectMapper MOCK_networkAdapterObjectMapper; + + private L3Network l3Network; + private RequestContext requestContext; + private ServiceInstance serviceInstance; + private CloudRegion cloudRegion; + private OrchestrationContext orchestrationContext; + private Customer customer; + Map<String, String> userInput; + + @Before + public void before() { + requestContext = buildRequestContext(); + + customer = buildCustomer(); + + serviceInstance = buildServiceInstance(); + + cloudRegion = buildCloudRegion(); + + orchestrationContext = buildOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + + userInput = buildUserInput(); + + l3Network = buildL3Network(); + } + + @Test + public void createNetworTest() throws Exception { + String cloudRegionPo = "cloudRegionPo"; + CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest(); + + expectedCreateNetworkRequest.setCloudSiteId(cloudRegionPo); + expectedCreateNetworkRequest.setTenantId(cloudRegion.getTenantId()); + expectedCreateNetworkRequest.setNetworkId(l3Network.getNetworkId()); + expectedCreateNetworkRequest.setNetworkName(l3Network.getNetworkName()); + expectedCreateNetworkRequest.setBackout(false); + expectedCreateNetworkRequest.setFailIfExists(true); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedCreateNetworkRequest.setMsoRequest(msoRequest); + expectedCreateNetworkRequest.setSkipAAI(true); + + Subnet openstackSubnet = new Subnet(); + HostRoute hostRoute = new HostRoute(); + hostRoute.setHostRouteId("hostRouteId"); + hostRoute.setNextHop("nextHop"); + hostRoute.setRoutePrefix("routePrefix"); + openstackSubnet.getHostRoutes().add(hostRoute); + List<Subnet> subnetList = new ArrayList<Subnet>(); + subnetList.add(openstackSubnet); + l3Network.getSubnets().add(openstackSubnet); + + l3Network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + CreateNetworkRequest createNetworkRequest = new CreateNetworkRequest(); + createNetworkRequest.setCloudSiteId("cloudSiteId"); + + CreateNetworkResponse expectedCreateNetworkResponse = new CreateNetworkResponse(); + expectedCreateNetworkResponse.setNetworkStackId("networkStackId"); + expectedCreateNetworkResponse.setNetworkCreated(true); + + + doReturn(expectedCreateNetworkResponse).when(MOCK_networkAdapterClient).createNetwork(isA(CreateNetworkRequest.class)); + + doReturn(createNetworkRequest).when(MOCK_networkAdapterObjectMapper).createNetworkRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(String.class), isA(Customer.class)); + + CreateNetworkResponse actualCreateNetwrokResponse = (networkAdapterResources.createNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer)).get(); + + verify(MOCK_networkAdapterClient, times(1)).createNetwork(createNetworkRequest); + + verify(MOCK_networkAdapterObjectMapper, times(1)).createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer); + + assertThat(expectedCreateNetworkResponse, Matchers.sameBeanAs(actualCreateNetwrokResponse)); + } + + @Test + public void rollbackCreateNetworkTest() throws Exception { + String cloudRegionPo = "cloudRegionPo"; + RollbackNetworkResponse expectedRollbackNetworkResponse = new RollbackNetworkResponse(); + expectedRollbackNetworkResponse.setMessageId("messageId"); + expectedRollbackNetworkResponse.setNetworkRolledBack(true); + + RollbackNetworkRequest rollbackNetworkRequest = new RollbackNetworkRequest(); + rollbackNetworkRequest.setMessageId("messageId"); + + RollbackNetworkResponse rollbackNetworkResponse = new RollbackNetworkResponse(); + rollbackNetworkResponse.setMessageId("messageId"); + rollbackNetworkResponse.setNetworkRolledBack(true); + + CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); + createNetworkResponse.setMessageId("messageId"); + + doReturn(rollbackNetworkResponse).when(MOCK_networkAdapterClient).rollbackNetwork(isA(String.class), isA(RollbackNetworkRequest.class)); + + doReturn(rollbackNetworkRequest).when(MOCK_networkAdapterObjectMapper).createNetworkRollbackRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(String.class), isA(CreateNetworkResponse.class)); + + RollbackNetworkResponse actualRollbackCreateNetwrokResponse = (networkAdapterResources.rollbackCreateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, createNetworkResponse)).get(); + + verify(MOCK_networkAdapterClient, times(1)).rollbackNetwork(l3Network.getNetworkId(), rollbackNetworkRequest); + + verify(MOCK_networkAdapterObjectMapper, times(1)).createNetworkRollbackRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, createNetworkResponse); + + assertThat(expectedRollbackNetworkResponse, Matchers.sameBeanAs(actualRollbackCreateNetwrokResponse)); + } + + @Test + public void updateNetworkTest() throws UnsupportedEncodingException, NetworkAdapterClientException { + + doReturn(new UpdateNetworkRequest()).when(MOCK_networkAdapterObjectMapper).createNetworkUpdateRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(Customer.class)); + + doReturn(new UpdateNetworkResponse()).when(MOCK_networkAdapterClient).updateNetwork(isA(String.class), isA(UpdateNetworkRequest.class)); + + Optional<UpdateNetworkResponse> actualUpdateNetworkResponse = networkAdapterResources.updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, customer); + + + verify(MOCK_networkAdapterObjectMapper, times(1)).createNetworkUpdateRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, customer); + verify(MOCK_networkAdapterClient, times(1)).updateNetwork(isA(String.class), isA(UpdateNetworkRequest.class)); + assertNotNull(actualUpdateNetworkResponse); + } + + @Test + public void deleteNetwork_DeleteAction_Test() throws UnsupportedEncodingException, NetworkAdapterClientException { + + DeleteNetworkRequest deleteNetworkRequest = new DeleteNetworkRequest(); + doReturn(deleteNetworkRequest).when(MOCK_networkAdapterObjectMapper).deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); + + DeleteNetworkResponse expectedDeleteNetworkResponse = new DeleteNetworkResponse(); + + doReturn(expectedDeleteNetworkResponse).when(MOCK_networkAdapterClient).deleteNetwork(l3Network.getNetworkId(), deleteNetworkRequest); + + Optional<DeleteNetworkResponse> actualODeleteNetworkResponse = networkAdapterResources.deleteNetwork(requestContext, cloudRegion, serviceInstance, l3Network); + DeleteNetworkResponse actualDeleteNetworkResponse = actualODeleteNetworkResponse.get(); + + verify(MOCK_networkAdapterObjectMapper, times(1)).deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); + verify(MOCK_networkAdapterClient, times(1)).deleteNetwork(l3Network.getNetworkId(), deleteNetworkRequest); + assertThat(expectedDeleteNetworkResponse, Matchers.sameBeanAs(actualDeleteNetworkResponse)); + } +} 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 new file mode 100644 index 0000000000..7de5faac0c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCConfigurationResourcesTest.java @@ -0,0 +1,116 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +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.VpnBondingLink; +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.SDNCClient; +import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.onap.so.client.sdnc.mapper.GCTopologyOperationRequestMapper; + +import org.onap.sdnc.apps.client.model.GenericResourceApiGcTopologyOperationInformation; + +@RunWith(MockitoJUnitRunner.class) +public class SDNCConfigurationResourcesTest extends TestDataSetup{ + + @InjectMocks + private SDNCConfigurationResources sdncConfigurationResources = new SDNCConfigurationResources(); + + @Spy + GCTopologyOperationRequestMapper MOCK_gcTopologyMapper ; + + @Mock + protected SDNCClient MOCK_sdncClient; + + private RequestContext requestContext; + private ServiceInstance serviceInstance; + private VpnBondingLink vpnBondingLink; + private GenericVnf vnf; + private Customer customer; + + @Before + public void setUp(){ + + customer = buildCustomer(); + + requestContext = buildRequestContext(); + + serviceInstance = buildServiceInstance(); + + vpnBondingLink = buildVpnBondingLink(); + + vnf = vpnBondingLink.getInfrastructureServiceProxy().getServiceInstance().getVnfs().get(0); + } + + @Test + public void activateVnrConfigurationTest() throws BadResponseException, MapperException { + + doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); + String response = sdncConfigurationResources.activateVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + assertNotNull(response); + } + + @Test + public void assignVnrConfigurationTest() throws BadResponseException, MapperException { + + doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); + String response = sdncConfigurationResources.assignVnrConfiguration(serviceInstance,requestContext,customer,vpnBondingLink.getVnrConfiguration(),vnf); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + assertNotNull(response); + } + + @Test + public void unAssignVnrConfigurationTest() throws BadResponseException, MapperException { + doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); + String response = sdncConfigurationResources.unAssignVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration()); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + assertNotNull(response); + } + + @Test + public void deactivateVnrConfigurationTest() throws BadResponseException, MapperException { + doReturn("success").when(MOCK_sdncClient).post(isA(GenericResourceApiGcTopologyOperationInformation.class), isA(SDNCTopology.class)); + String response = sdncConfigurationResources.deactivateVnrConfiguration(serviceInstance,requestContext,vpnBondingLink.getVnrConfiguration()); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiGcTopologyOperationInformation.class), any(SDNCTopology.class)); + assertNotNull(response); + } +} 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 new file mode 100644 index 0000000000..b91d935c8e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCNetworkResourcesTest.java @@ -0,0 +1,204 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +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.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.beans.SDNCSvcOperation; +import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.onap.so.client.sdnc.mapper.NetworkTopologyOperationRequestMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; + +import org.onap.sdnc.apps.client.model.GenericResourceApiNetworkOperationInformation; +import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration; + +@RunWith(MockitoJUnitRunner.class) +public class SDNCNetworkResourcesTest extends TestDataSetup{ + + @InjectMocks + private SDNCNetworkResources sdncNetworkResources; + + @Mock + protected SDNCClient MOCK_sdncClient; + + @Mock + protected NetworkTopologyOperationRequestMapper MOCK_networkTopologyOperationRequestMapper; + + private L3Network network; + private ServiceInstance serviceInstance; + private Customer customer; + private RequestContext requestContext; + private CloudRegion cloudRegion; + + @Before + public void before() { + network = buildL3Network(); + + customer = buildCustomer(); + + serviceInstance = buildServiceInstance(); + + requestContext = buildRequestContext(); + + cloudRegion = new CloudRegion(); + } + + @Test + public void assignNetworkTest() throws Exception { + network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + sdncNetworkResources.assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus()); + } + + @Test + public void rollbackAssignNetworkTest() throws Exception { + network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + sdncNetworkResources.rollbackAssignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus()); + } + + @Test + public void activateNetworkTest() throws Exception { + network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + sdncNetworkResources.activateNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus()); + } + + @Test + public void deleteNetworkTest() throws Exception { + network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + sdncNetworkResources.deleteNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus()); + } + + @Test + public void test_deactivateNetwork() throws MapperException, BadResponseException { + serviceInstance.getNetworks().add(network); + + Customer customer = new Customer(); + customer.setGlobalCustomerId("gcustId"); + customer.setServiceSubscription(new ServiceSubscription()); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + GenericResourceApiNetworkOperationInformation expectedGenericResourceApiNetworkOperationInformation = new GenericResourceApiNetworkOperationInformation(); + + String expectedResponse = "response"; + + doReturn(expectedResponse).when(MOCK_sdncClient).post(expectedGenericResourceApiNetworkOperationInformation, SDNCTopology.NETWORK); + + doReturn(expectedGenericResourceApiNetworkOperationInformation).when(MOCK_networkTopologyOperationRequestMapper).reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE, GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer, requestContext, cloudRegion); + + String actualResponse = sdncNetworkResources.deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE, GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer, requestContext, cloudRegion); + + verify(MOCK_sdncClient).post(expectedGenericResourceApiNetworkOperationInformation, SDNCTopology.NETWORK); + + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void changeAssignNetworkTest() throws MapperException, BadResponseException { + String expectedSdncResponse = "SDNCChangeAssignNetworkResponse"; + + serviceInstance.getNetworks().add(network); + + Customer customer = new Customer(); + customer.setGlobalCustomerId("globalCustomerId"); + customer.setServiceSubscription(new ServiceSubscription()); + // set Customer on service instance + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + + GenericResourceApiNetworkOperationInformation sdncReq = new GenericResourceApiNetworkOperationInformation(); + + doReturn(sdncReq).when(MOCK_networkTopologyOperationRequestMapper).reqMapper(isA(SDNCSvcOperation.class), isA(SDNCSvcAction.class), isA(GenericResourceApiRequestActionEnumeration.class), isA(L3Network.class), isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class), isA(CloudRegion.class)); + + doReturn(expectedSdncResponse).when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), isA(SDNCTopology.class)); + + String actualSdncResponse = sdncNetworkResources.changeAssignNetwork(network, serviceInstance, customer, requestContext, cloudRegion); + + verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer, requestContext, cloudRegion); + verify(MOCK_sdncClient, times(1)).post(sdncReq, SDNCTopology.NETWORK); + assertEquals(actualSdncResponse, expectedSdncResponse); + } + + @Test + public void unassignNetwork_Test() throws Exception { + network.setOrchestrationStatus(OrchestrationStatus.CREATED); + + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + sdncNetworkResources.unassignNetwork(network, serviceInstance, customer, + requestContext, cloudRegion); + + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK)); + + assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus()); + } +}
\ No newline at end of file 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 new file mode 100644 index 0000000000..79419c342e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCServiceInstanceResourcesTest.java @@ -0,0 +1,149 @@ +/*- + * ============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.orchestration; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +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.SDNCClient; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; +import org.onap.so.client.sdnc.beans.SDNCSvcOperation; +import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.onap.so.client.sdnc.mapper.ServiceTopologyOperationMapper; + +import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration; +import org.onap.sdnc.apps.client.model.GenericResourceApiServiceOperationInformation; + +@RunWith(MockitoJUnitRunner.class) +public class SDNCServiceInstanceResourcesTest extends TestDataSetup{ + @InjectMocks + private SDNCServiceInstanceResources sdncServiceInstanceResources; + + + @Mock + protected ServiceTopologyOperationMapper MOCK_serviceTopologyOperationMapper; + + private RequestContext requestContext; + private ServiceInstance serviceInstance; + private Customer customer; + + @Mock + protected SDNCClient MOCK_sdncClient; + + @Before + public void before() { + requestContext = buildRequestContext(); + + serviceInstance = buildServiceInstance(); + + customer = buildCustomer(); + + customer.getServiceSubscription().getServiceInstances().add(serviceInstance); + } + + @Test + public void assignServiceInstanceSuccessTest() throws Exception { + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + } + + @Test + public void assignServiceInstanceExceptionTest() throws Exception { + expectedException.expect(Exception.class); + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext); + } + + @Test + public void deleteServiceInstanceSuccessTest() throws Exception { + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + } + + @Test + public void deleteServiceInstanceExceptionTest() throws Exception { + expectedException.expect(Exception.class); + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext); + } + + @Test + public void unassignServiceInstanceSuccessTest() throws Exception { + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.unassignServiceInstance(serviceInstance, customer, requestContext); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + } + + @Test + public void unassignServiceInstanceExceptionTest() throws Exception { + expectedException.expect(Exception.class); + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.unassignServiceInstance(serviceInstance,customer, requestContext); + } + + @Test + public void deactivateServiceInstanceSuccessTest() throws Exception { + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + } + + @Test + public void deactivateServiceInstanceExceptionTest() throws Exception { + expectedException.expect(Exception.class); + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext); + } + + @Test + public void test_changeModelServiceInstance() throws MapperException, BadResponseException { + doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.CHANGE_ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class)); + doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + sdncServiceInstanceResources.changeModelServiceInstance(serviceInstance, customer, requestContext); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE)); + } +} 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 new file mode 100644 index 0000000000..c7ab47ba5a --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVfModuleResourcesTest.java @@ -0,0 +1,126 @@ +/*- + * ============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.orchestration; + +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +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.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +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.SDNCClient; +import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.onap.so.client.sdnc.mapper.VfModuleTopologyOperationRequestMapper; + +import org.onap.sdnc.apps.client.model.GenericResourceApiVfModuleOperationInformation;; + +@RunWith(MockitoJUnitRunner.class) +public class SDNCVfModuleResourcesTest extends TestDataSetup{ + @InjectMocks + private SDNCVfModuleResources sdncVfModuleResources = new SDNCVfModuleResources(); + + private VfModule vfModule; + private GenericVnf vnf; + private ServiceInstance serviceInstance; + private VolumeGroup volumeGroup; + private Customer customer; + private CloudRegion cloudRegion; + private RequestContext requestContext; + + @Mock + protected SDNCClient MOCK_sdncClient; + + @Spy + protected VfModuleTopologyOperationRequestMapper vfModuleTopologyMapper; + + @Before + public void before() { + vfModule = buildVfModule(); + vnf = buildGenericVnf(); + serviceInstance = buildServiceInstance(); + volumeGroup = buildVolumeGroup(); + customer = buildCustomer(); + cloudRegion = buildCloudRegion(); + requestContext = buildRequestContext(); + } + + @Test + public void assignVfModuleTest() throws MapperException, BadResponseException { + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiVfModuleOperationInformation.class), isA(SDNCTopology.class)); + + sdncVfModuleResources.assignVfModule(vfModule, volumeGroup, vnf, serviceInstance, customer, cloudRegion, requestContext); + + verify(MOCK_sdncClient, times(1)).post(isA(GenericResourceApiVfModuleOperationInformation.class), eq(SDNCTopology.VFMODULE)); + } + + @Test + public void unassignVfModuleTest() throws MapperException, BadResponseException { + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiVfModuleOperationInformation.class), eq(SDNCTopology.VFMODULE)); + + sdncVfModuleResources.unassignVfModule(vfModule, vnf, serviceInstance); + + verify(MOCK_sdncClient, times(1)).post(isA(GenericResourceApiVfModuleOperationInformation.class), eq(SDNCTopology.VFMODULE)); + } + + @Test + public void activateVfModuleTest() throws MapperException, BadResponseException { + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiVfModuleOperationInformation.class), isA(SDNCTopology.class)); + + sdncVfModuleResources.activateVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext); + + verify(MOCK_sdncClient, times(1)).post(isA(GenericResourceApiVfModuleOperationInformation.class), eq(SDNCTopology.VFMODULE)); + } + + @Test + public void deactivateVfModuleTest() throws MapperException, BadResponseException { + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiVfModuleOperationInformation.class), isA(SDNCTopology.class)); + + sdncVfModuleResources.deactivateVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext); + + verify(MOCK_sdncClient, times(1)).post(isA(GenericResourceApiVfModuleOperationInformation.class), eq(SDNCTopology.VFMODULE)); + } + + @Test + public void changeAssignVfModuleTest() throws MapperException, BadResponseException { + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiVfModuleOperationInformation.class), isA(SDNCTopology.class)); + + sdncVfModuleResources.changeAssignVfModule(vfModule, vnf, serviceInstance, customer, cloudRegion, requestContext); + + verify(MOCK_sdncClient, times(1)).post(isA(GenericResourceApiVfModuleOperationInformation.class), eq(SDNCTopology.VFMODULE)); + } +} 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 new file mode 100644 index 0000000000..46764c221c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNCVnfResourcesTest.java @@ -0,0 +1,185 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration; +import org.onap.sdnc.apps.client.model.GenericResourceApiVnfOperationInformation; +import org.onap.so.bpmn.common.data.TestDataSetup; +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.generalobjects.RequestContext; +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.beans.SDNCSvcOperation; +import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.onap.so.client.sdnc.mapper.VnfTopologyOperationRequestMapper; + +@RunWith(MockitoJUnitRunner.class) +public class SDNCVnfResourcesTest extends TestDataSetup{ + @InjectMocks + private SDNCVnfResources sdncVnfResources; + + @Mock + protected VnfTopologyOperationRequestMapper MOCK_vnfTopologyOperationRequestMapper; + + @Mock + protected SDNCClient MOCK_sdncClient; + + private GenericVnf genericVnf; + private ServiceInstance serviceInstance; + private Customer customer; + private CloudRegion cloudRegion; + private RequestContext requestContext; + private GenericResourceApiVnfOperationInformation sdncReq; + + @Before + public void before() { + serviceInstance = buildServiceInstance(); + + genericVnf = buildGenericVnf(); + + customer = buildCustomer(); + + cloudRegion = buildCloudRegion(); + + requestContext = buildRequestContext(); + + sdncReq = new GenericResourceApiVnfOperationInformation(); + } + + @Test + public void assignVnfTest() throws MapperException, BadResponseException { + doReturn(sdncReq).when(MOCK_vnfTopologyOperationRequestMapper).reqMapper(isA(SDNCSvcOperation.class), isA(SDNCSvcAction.class),isA(GenericResourceApiRequestActionEnumeration.class), isA(GenericVnf.class), isA(ServiceInstance.class), isA(Customer.class), isA(CloudRegion.class), isA(RequestContext.class), anyBoolean()); + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + + sdncVnfResources.assignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext, false); + + verify(MOCK_sdncClient, times(1)).post(isA(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + } + + @Test + public void activateVnfTest() throws MapperException, BadResponseException { + doReturn(sdncReq).when(MOCK_vnfTopologyOperationRequestMapper).reqMapper(isA(SDNCSvcOperation.class), isA(SDNCSvcAction.class),isA(GenericResourceApiRequestActionEnumeration.class), isA(GenericVnf.class), isA(ServiceInstance.class), isA(Customer.class), isA(CloudRegion.class), isA(RequestContext.class), anyBoolean()); + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + + sdncVnfResources.activateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + verify(MOCK_sdncClient, times(1)).post(isA(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + } + + @Test + public void deleteVnfTest() throws MapperException, BadResponseException { + doReturn(sdncReq).when(MOCK_vnfTopologyOperationRequestMapper).reqMapper(isA(SDNCSvcOperation.class), isA(SDNCSvcAction.class),isA(GenericResourceApiRequestActionEnumeration.class), isA(GenericVnf.class), isA(ServiceInstance.class), isA(Customer.class), isA(CloudRegion.class), isA(RequestContext.class), anyBoolean()); + doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + + sdncVnfResources.deleteVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + verify(MOCK_sdncClient, times(1)).post(isA(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + } + + @Test + public void queryVnfTest() throws MapperException, BadResponseException { + doReturn("test").when(MOCK_sdncClient).get(isA(String.class)); + + genericVnf.setSelflink("testSelflink"); + + sdncVnfResources.queryVnf(genericVnf); + + verify(MOCK_sdncClient, times(1)).get(isA(String.class)); + } + + @Test + public void queryVnfWithResourcePrefixTest() throws MapperException, BadResponseException { + doReturn("test").when(MOCK_sdncClient).get(isA(String.class)); + + genericVnf.setSelflink("restconf/test:testSelflink"); + + sdncVnfResources.queryVnf(genericVnf); + + verify(MOCK_sdncClient, times(1)).get(isA(String.class)); + } + + @Test + public void changeModelVnfTest() throws MapperException, BadResponseException { + doReturn(sdncReq).when(MOCK_vnfTopologyOperationRequestMapper).reqMapper(isA(SDNCSvcOperation.class), isA(SDNCSvcAction.class),isA(GenericResourceApiRequestActionEnumeration.class), isA(GenericVnf.class), isA(ServiceInstance.class), isA(Customer.class), isA(CloudRegion.class), isA(RequestContext.class), anyBoolean()); + doReturn("SDNCChangeModelVnfResponse").when(MOCK_sdncClient).post(isA(GenericResourceApiVnfOperationInformation.class), isA(SDNCTopology.class)); + + String actualResponse = sdncVnfResources.changeModelVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + + verify(MOCK_vnfTopologyOperationRequestMapper, times(1)).reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, genericVnf, serviceInstance, customer, cloudRegion, requestContext, false); + verify(MOCK_sdncClient, times(1)).post(sdncReq, SDNCTopology.VNF); + assertEquals("SDNCChangeModelVnfResponse", actualResponse); + } + + @Test + public void deactivateVnfSuccessTest() throws Exception { + doReturn(sdncReq).when(MOCK_vnfTopologyOperationRequestMapper).reqMapper(eq(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE),isA(GenericResourceApiRequestActionEnumeration.class), any(GenericVnf.class),any(ServiceInstance.class), any(Customer.class), any(CloudRegion.class),any(RequestContext.class), anyBoolean()); + doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + sdncVnfResources.deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + + } + + @Test(expected = Exception.class) + public void deactivateVnfExceptionTest() throws Exception { + doReturn(sdncReq).when(MOCK_vnfTopologyOperationRequestMapper).reqMapper(eq(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE),isA(GenericResourceApiRequestActionEnumeration.class), any(GenericVnf.class),any(ServiceInstance.class), any(Customer.class), any(CloudRegion.class),any(RequestContext.class), anyBoolean()); + doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + sdncVnfResources.deactivateVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + } + + @Test + public void unassignVnfSuccessTest() throws Exception { + doReturn(sdncReq).when(MOCK_vnfTopologyOperationRequestMapper).reqMapper(eq(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION), eq(SDNCSvcAction.UNASSIGN),isA(GenericResourceApiRequestActionEnumeration.class), any(GenericVnf.class),any(ServiceInstance.class), any(Customer.class), any(CloudRegion.class),any(RequestContext.class), anyBoolean()); + doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + sdncVnfResources.unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + } + + @Test(expected = Exception.class) + public void unassignVnfExceptionTest() throws Exception { + doReturn(sdncReq).when(MOCK_vnfTopologyOperationRequestMapper).reqMapper(eq(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION), eq(SDNCSvcAction.UNASSIGN),isA(GenericResourceApiRequestActionEnumeration.class), any(GenericVnf.class),any(ServiceInstance.class), any(Customer.class), any(CloudRegion.class),any(RequestContext.class), anyBoolean()); + doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiVnfOperationInformation.class), eq(SDNCTopology.VNF)); + sdncVnfResources.unassignVnf(genericVnf, serviceInstance, customer, cloudRegion, requestContext); + //verify(client, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.VNF)); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java new file mode 100644 index 0000000000..38113b8078 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java @@ -0,0 +1,67 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; + +import java.util.UUID; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.sdno.SDNOValidator; + +@RunWith(MockitoJUnitRunner.class) +public class SDNOHealthCheckResourcesTest extends TestDataSetup{ + @InjectMocks + private SDNOHealthCheckResources sdnoHealthCheckResources = new SDNOHealthCheckResources(); + + private GenericVnf genericVnf; + private RequestContext requestContext; + + @Mock + protected SDNOValidator MOCK_sdnoValidator; + + @Mock + protected InjectionHelper MOCK_injectionHelper; + + @Before + public void before() { + genericVnf = buildGenericVnf(); + requestContext = buildRequestContext(); + doReturn(MOCK_sdnoValidator).when(MOCK_injectionHelper).getSdnoValidator(); + } + + @Test + public void healthCheckTest() throws Exception { + doReturn(true).when(MOCK_sdnoValidator).healthDiagnostic(isA(String.class), isA(UUID.class), isA(String.class)); + assertTrue(sdnoHealthCheckResources.healthCheck(genericVnf, requestContext)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/VnfAdapterVfModuleResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/VnfAdapterVfModuleResourcesTest.java new file mode 100644 index 0000000000..dfed3c8929 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/VnfAdapterVfModuleResourcesTest.java @@ -0,0 +1,122 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.adapters.vnfrest.CreateVfModuleRequest; +import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.client.adapter.vnf.mapper.VnfAdapterVfModuleObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class VnfAdapterVfModuleResourcesTest extends TestDataSetup{ + @InjectMocks + private VnfAdapterVfModuleResources vnfAdapterVfModuleResources = new VnfAdapterVfModuleResources(); + + @Mock + protected VnfAdapterVfModuleObjectMapper MOCK_vnfAdapterVfModuleObjectMapper; + + private RequestContext requestContext; + private ServiceInstance serviceInstance; + private ModelInfoServiceInstance modelInfoServiceInstance; + private GenericVnf genericVnf; + private VfModule vfModule; + private ModelInfoVfModule modelInfoVfModule; + private CloudRegion cloudRegion; + private OrchestrationContext orchestrationContext; + private CreateVfModuleRequest createVfModuleRequest; + private String sdncVnfQueryResponse; + private String sdncVfModuleQueryResponse; + private DeleteVfModuleRequest deleteVfModuleRequest; + + @Before + public void before() { + requestContext = buildRequestContext(); + + serviceInstance = buildServiceInstance(); + + genericVnf = buildGenericVnf(); + + vfModule = buildVfModule(); + + cloudRegion = buildCloudRegion(); + + orchestrationContext = buildOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + + sdncVnfQueryResponse = new String(); + sdncVfModuleQueryResponse = new String(); + + createVfModuleRequest = new CreateVfModuleRequest(); + createVfModuleRequest.setCloudSiteId("cloudSiteId"); + + deleteVfModuleRequest = new DeleteVfModuleRequest(); + deleteVfModuleRequest.setCloudSiteId("cloudSiteId"); + } + + @Test + public void test_createVfModule() throws Exception { + doReturn(createVfModuleRequest).when(MOCK_vnfAdapterVfModuleObjectMapper).createVfModuleRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, + genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + CreateVfModuleRequest actualCreateVfModuleRequest = vnfAdapterVfModuleResources.createVfModuleRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, + genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + verify(MOCK_vnfAdapterVfModuleObjectMapper, times(1)).createVfModuleRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, + genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + + assertNotNull(createVfModuleRequest); + assertNotNull(actualCreateVfModuleRequest); + assertEquals(createVfModuleRequest, actualCreateVfModuleRequest); + } + + @Test + public void test_deleteVfModule() throws Exception { + doReturn(deleteVfModuleRequest).when(MOCK_vnfAdapterVfModuleObjectMapper).deleteVfModuleRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(ServiceInstance.class), + isA(GenericVnf.class), isA(VfModule.class)); + + DeleteVfModuleRequest actualDeleteVfModuleRequest = vnfAdapterVfModuleResources.deleteVfModuleRequest(requestContext, cloudRegion, serviceInstance, + genericVnf, vfModule); + + verify(MOCK_vnfAdapterVfModuleObjectMapper, times(1)).deleteVfModuleRequestMapper(requestContext, cloudRegion, serviceInstance, genericVnf, vfModule); + assertEquals(deleteVfModuleRequest, actualDeleteVfModuleRequest); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/VnfAdapterVolumeGroupResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/VnfAdapterVolumeGroupResourcesTest.java new file mode 100644 index 0000000000..ee0e60c38a --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/VnfAdapterVolumeGroupResourcesTest.java @@ -0,0 +1,122 @@ +/*- + * ============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.orchestration; + +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest; +import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.adapter.vnf.VnfVolumeAdapterClientImpl; +import org.onap.so.client.adapter.vnf.mapper.VnfAdapterObjectMapper; +import org.onap.so.db.catalog.beans.OrchestrationStatus; + +import com.shazam.shazamcrest.matcher.Matchers; + +@RunWith(MockitoJUnitRunner.class) +public class VnfAdapterVolumeGroupResourcesTest extends TestDataSetup { + @InjectMocks + private VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources; + + @Mock + protected VnfAdapterObjectMapper MOCK_vnfAdapterObjectMapper; + + @Mock + protected VnfVolumeAdapterClientImpl MOCK_vnfVolumeAdapterClient; + + private RequestContext requestContext; + private ServiceInstance serviceInstance; + private GenericVnf genericVnf; + private VfModule vfModule; + private VolumeGroup volumeGroup; + private CloudRegion cloudRegion; + private OrchestrationContext orchestrationContext; + + @Before + public void before() { + requestContext = buildRequestContext(); + serviceInstance = buildServiceInstance(); + genericVnf = buildGenericVnf(); + serviceInstance.getVnfs().add(genericVnf); + vfModule = buildVfModule(); + genericVnf.getVfModules().add(vfModule); + volumeGroup = buildVolumeGroup(); + serviceInstance.getVnfs().get(0).getVolumeGroups().add(volumeGroup); + cloudRegion = buildCloudRegion(); + orchestrationContext = buildOrchestrationContext(); + orchestrationContext.setIsRollbackEnabled(true); + } + + @Test + public void test_createVolumeGroup() throws Exception { + volumeGroup.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); + + CreateVolumeGroupRequest createVolumeGroupRequest = new CreateVolumeGroupRequest(); + createVolumeGroupRequest.setCloudSiteId("cloudSiteId"); + + CreateVolumeGroupResponse expectedCreateVolumeGroupResponse = new CreateVolumeGroupResponse(); + expectedCreateVolumeGroupResponse.setVolumeGroupStackId("volumeGroupStackId"); + expectedCreateVolumeGroupResponse.setVolumeGroupCreated(true); + + String sdncVfModuleQueryResponse = "sdncVfModuleQueryResponse"; + + doReturn(createVolumeGroupRequest).when(MOCK_vnfAdapterObjectMapper).createVolumeGroupRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse); + + CreateVolumeGroupRequest actualCreateVolumeGroupResponse = vnfAdapterVolumeGroupResources.createVolumeGroupRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse); + + verify(MOCK_vnfAdapterObjectMapper, times(1)).createVolumeGroupRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse); + + assertThat(createVolumeGroupRequest, Matchers.sameBeanAs(actualCreateVolumeGroupResponse)); + } + + @Test + public void test_deleteVolumeGroup() throws Exception { + DeleteVolumeGroupRequest deleteVolumeGroupRequest = new DeleteVolumeGroupRequest(); + doReturn(deleteVolumeGroupRequest).when(MOCK_vnfAdapterObjectMapper).deleteVolumeGroupRequestMapper(requestContext, cloudRegion, serviceInstance, volumeGroup); + + DeleteVolumeGroupResponse expectedDeleteVolumeGroupResponse = new DeleteVolumeGroupResponse(); + doReturn(expectedDeleteVolumeGroupResponse).when(MOCK_vnfVolumeAdapterClient).deleteVNFVolumes(volumeGroup.getVolumeGroupId(), deleteVolumeGroupRequest); + + DeleteVolumeGroupResponse actualDeleteVolumeGroupResponse = vnfAdapterVolumeGroupResources.deleteVolumeGroup(requestContext, cloudRegion, serviceInstance, volumeGroup); + + verify(MOCK_vnfVolumeAdapterClient, times(1)).deleteVNFVolumes(volumeGroup.getVolumeGroupId(), deleteVolumeGroupRequest); + verify(MOCK_vnfAdapterObjectMapper, times(1)).deleteVolumeGroupRequestMapper(requestContext, cloudRegion, serviceInstance, volumeGroup); + assertThat(expectedDeleteVolumeGroupResponse, Matchers.sameBeanAs(actualDeleteVolumeGroupResponse)); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/policy/CommonObjectMapperProviderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/policy/CommonObjectMapperProviderTest.java new file mode 100644 index 0000000000..e3f6a1829e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/policy/CommonObjectMapperProviderTest.java @@ -0,0 +1,46 @@ +/*- + * ============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.policy; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +public class CommonObjectMapperProviderTest { + + @Test + public void shouldSetCorrectMapperProperties() throws Exception { + // given + CommonObjectMapperProvider provider = new CommonObjectMapperProvider(); + // when + ObjectMapper context = provider.getMapper(); + // then + assertTrue(context.isEnabled(MapperFeature.USE_ANNOTATIONS)); + assertFalse(context.isEnabled(SerializationFeature.WRAP_ROOT_VALUE)); + assertFalse(context.isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)); + } +}
\ No newline at end of file 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 new file mode 100644 index 0000000000..eb17ad0ff9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.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.client.sdn.common; + +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; + + +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() { + Assert.assertNotNull(sdnCommonTasks.getHttpHeaders("")); + } + + @Test + public void validateSDNResponseTest() throws BadResponseException { + LinkedHashMap responseMap = new LinkedHashMap(); + responseMap.put("response-code", "0"); + responseMap.put("response-message", "success"); + Assert.assertNotNull(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(); + responseMap.put("response-code", "300"); + responseMap.put("response-message", "Failed"); + Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap)); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java new file mode 100644 index 0000000000..2492638520 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientTest.java @@ -0,0 +1,58 @@ +/*- + * ============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.urlEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.junit.Rule; +import org.junit.Test; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.exception.MapperException; +import org.skyscreamer.jsonassert.JSONAssert; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +public class SDNCClientTest extends BaseTaskTest { + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/"; + + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8446)); + + @Test + public void getTest() throws BadResponseException, MapperException, IOException { + String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json"))); + String queryLink = "/topologyQuery"; + + wireMockRule.stubFor(get(urlEqualTo(queryLink)) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json").withBody(responseJson))); + String response = SPY_sdncClient.get(queryLink); + JSONAssert.assertEquals(responseJson, response, false); + } +} 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 new file mode 100644 index 0000000000..d0d2510b73 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java @@ -0,0 +1,138 @@ +/*- + * ============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.util.HashMap; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +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; + +import org.onap.sdnc.apps.client.model.GenericResourceApiGcTopologyOperationInformation; + + +public class GCTopologyOperationRequestMapperTest extends TestDataSetup{ + + private GCTopologyOperationRequestMapper genObjMapper = new GCTopologyOperationRequestMapper(); + + @Test + public void deactivateOrUnassignVnrReqMapperTest() { + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("MsoRequestId"); + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("ServiceInstanceId"); + Configuration Configuration = new Configuration(); + Configuration.setConfigurationId("ConfigurationId"); + GenericResourceApiGcTopologyOperationInformation genericInfo = genObjMapper.deactivateOrUnassignVnrReqMapper + (SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, Configuration); + + Assert.assertNotNull(genericInfo); + Assert.assertNotNull(genericInfo.getSdncRequestHeader().getSvcRequestId()); + } + + + + 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"); + HashMap<String, String> userParams = getUserParams(); + requestContext.setUserParams(userParams); + return requestContext; + } + + private HashMap<String, String> getUserParams() { + HashMap<String,String> 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<GenericVnf> 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 new file mode 100644 index 0000000000..6f3d137541 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapperTest.java @@ -0,0 +1,225 @@ +/*- + * ============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.util.HashMap; + +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.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.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; + +import org.onap.sdnc.apps.client.model.GenericResourceApiConfigurationinformationConfigurationInformation; +import org.onap.sdnc.apps.client.model.GenericResourceApiGcrequestinputGcRequestInput; +import org.onap.sdnc.apps.client.model.GenericResourceApiParam; +import org.onap.sdnc.apps.client.model.GenericResourceApiParamParam; +import org.onap.sdnc.apps.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader; +import org.onap.sdnc.apps.client.model.GenericResourceApiServiceinformationServiceInformation; +import org.onap.sdnc.apps.client.model.GenericResourceApiSvcActionEnumeration; +import org.onap.sdnc.apps.client.model.GenericResourceApiVnfinformationVnfInformation; + + +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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + 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()); + } +} 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 new file mode 100644 index 0000000000..615f8a5710 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java @@ -0,0 +1,198 @@ +/*- + * ============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.assertNull; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; + +import org.junit.Before; +import org.junit.Test; +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 org.onap.sdnc.apps.client.model.GenericResourceApiNetworkOperationInformation; +import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration; +import com.fasterxml.jackson.databind.ObjectMapper; + +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; + + @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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + 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 { + + NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper(); + 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")); + } + + @Test + public void reqMapperTest() throws Exception { + + NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper(); + 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 { + NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper(); + 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 = new NetworkTopologyOperationRequestMapper(); + 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")); + + } + + @Test + public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception { + + NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper(); + //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 new file mode 100644 index 0000000000..727a088d80 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java @@ -0,0 +1,85 @@ +/*- + * ============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 java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; + +import org.junit.Test; +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.apps.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation; +import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration; +import org.onap.sdnc.apps.client.model.GenericResourceApiServiceOperationInformation; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ServiceTopologyOperationMapperTest { + + @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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + ServiceTopologyOperationMapper mapper = new ServiceTopologyOperationMapper(); + GenericResourceApiServiceOperationInformation serviceOpInformation = mapper.reqMapper( + SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, + requestContext); + + 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())); + } +} 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 new file mode 100644 index 0000000000..2ebe6d4f0f --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java @@ -0,0 +1,221 @@ +/*- + * ============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.assertNull; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; + +import org.junit.Test; +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.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.client.sdnc.beans.SDNCSvcAction; +import org.onap.so.client.sdnc.beans.SDNCSvcOperation; + +import org.onap.sdnc.apps.client.model.GenericResourceApiVfModuleOperationInformation; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class VfModuleTopologyOperationRequestMapperTest { + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + + @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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + 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); + + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + volumeGroup.setVolumeGroupName("volumeGroupName"); + + CloudRegion cloudRegion = new CloudRegion(); + + VfModuleTopologyOperationRequestMapper mapper = new VfModuleTopologyOperationRequestMapper(); + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, volumeGroup, vnf, serviceInstance, customer, + cloudRegion, requestContext, null); + + 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(reqMapper1, sameBeanAs(vfModuleSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") + .ignoring("requestInformation.requestId")); + } + + @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"); + + VfModuleTopologyOperationRequestMapper mapper = new VfModuleTopologyOperationRequestMapper(); + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, + null, null, null); + + 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(reqMapper1, sameBeanAs(vfModuleSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") + .ignoring("requestInformation.requestId")); + } + + @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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + 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"); + 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(); + + VfModuleTopologyOperationRequestMapper mapper = new VfModuleTopologyOperationRequestMapper(); + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, vfModule, null, vnf, serviceInstance, customer, + cloudRegion, requestContext, null); + + assertNull(vfModuleSDNCrequest.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); + 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 new file mode 100644 index 0000000000..ed61486ff3 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java @@ -0,0 +1,129 @@ +/*- + * ============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.assertNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.junit.Test; +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; + +import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration; +import org.onap.sdnc.apps.client.model.GenericResourceApiVnfOperationInformation; + +public class VnfTopologyOperationRequestMapperTest { + + @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("networkInstanceGroup"); + + 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<String> entitlementPoolUuids = new ArrayList<>(); + entitlementPoolUuids.add("entitlementPoolUuid"); + List<String> 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(); + HashMap<String, String> userParams = new HashMap<String, String>(); + userParams.put("key1", "value1"); + requestContext.setUserParams(userParams); + requestContext.setProductFamilyId("productFamilyId"); + + CloudRegion cloudRegion = new CloudRegion(); + + VnfTopologyOperationRequestMapper mapper = new VnfTopologyOperationRequestMapper(); + GenericResourceApiVnfOperationInformation vnfOpInformation = mapper.reqMapper( + SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, + cloudRegion, requestContext,true); + + 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()); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java new file mode 100644 index 0000000000..e5eb6bce54 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java @@ -0,0 +1,175 @@ +/*- + * ============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.sniro; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import org.junit.Test; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.client.sniro.beans.SniroConductorRequest; +import org.onap.so.client.sniro.beans.SniroManagerRequest; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.core.JsonProcessingException; +import static com.github.tomakehurst.wiremock.client.WireMock.*; + + +public class SniroClientTestIT{ + + @Autowired + private SniroClient client; + + + @Test(expected = Test.None.class) + public void testPostDemands_success() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}"; + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + client.postDemands(new SniroManagerRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException { + String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}"; + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + + client.postDemands(new SniroManagerRequest()); + + //TODO assertEquals("missing data", ); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException { + String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + + client.postDemands(new SniroManagerRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException { + String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}"; + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + + client.postDemands(new SniroManagerRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException { + String mockResponse = "{ }"; + + stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + + client.postDemands(new SniroManagerRequest()); + } + + @Test(expected = Test.None.class) + public void testPostRelease_success() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}"; + + stubFor(post(urlEqualTo("/v1/release-orders")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + } + + @Test(expected = BadResponseException.class) + public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}"; + + stubFor(post(urlEqualTo("/v1/release-orders")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + } + + @Test(expected = BadResponseException.class) + public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}"; + + stubFor(post(urlEqualTo("/v1/release-orders")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException { + String mockResponse = "{\"status\": \"failure\", \"message\": null}"; + + stubFor(post(urlEqualTo("/v1/release-orders")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + + } + + @Test(expected = BadResponseException.class) + public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException { + String mockResponse = "{ }"; + + stubFor(post(urlEqualTo("/v1/release-orders")) + .willReturn(aResponse().withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(mockResponse))); + + client.postRelease(new SniroConductorRequest()); + + } + +} |