diff options
16 files changed, 492 insertions, 126 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java index 359c8cd46e..e276faf5d0 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java @@ -27,6 +27,7 @@ import javax.ws.rs.ApplicationPath; import org.glassfish.jersey.server.ResourceConfig; import org.onap.logging.filter.base.Constants; import org.onap.logging.filter.base.ONAPComponents; +import org.onap.so.adapters.catalogdb.rest.BuildingBlockRollbackRestImpl; import org.onap.so.adapters.catalogdb.rest.CatalogDbAdapterRest; import org.onap.so.adapters.catalogdb.rest.ServiceRestImpl; import org.onap.so.adapters.catalogdb.rest.VnfRestImpl; @@ -53,6 +54,7 @@ public class JerseyConfiguration extends ResourceConfig { register(AcceptHeaderOpenApiResource.class); register(ServiceRestImpl.class); register(VnfRestImpl.class); + register(BuildingBlockRollbackRestImpl.class); OpenAPI oas = new OpenAPI(); Info info = new Info(); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/BuildingBlockRollbackRestImpl.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/BuildingBlockRollbackRestImpl.java new file mode 100644 index 0000000000..bd247e1a4f --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/BuildingBlockRollbackRestImpl.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Bell Canada + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.catalogdb.rest; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import java.util.List; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import org.onap.so.db.catalog.beans.BuildingBlockRollback; +import org.onap.so.db.catalog.data.repository.BuildingBlockRollbackRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + + +@OpenAPIDefinition(info = @Info(title = "/v1", description = "model")) +@Path("/v1/buildingBlockRollback") +@Component +public class BuildingBlockRollbackRestImpl { + + @Autowired + private BuildingBlockRollbackRepository bbRollbackRepo; + + @GET + @Path("/{id}") + @Produces({MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public BuildingBlockRollback findService(@PathParam("id") Integer id) { + return bbRollbackRepo.findOneById(id); + } + + @GET + @Operation(description = "Look up BuildingBlock Rollback List", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = BuildingBlockRollback.class))))) + @Produces({MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public List<BuildingBlockRollback> getBBRollbackList() { + return bbRollbackRepo.findAll(); + } +} diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.9.1__AddBuildingBlockRollback.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.9.1__AddBuildingBlockRollback.sql new file mode 100644 index 0000000000..11dd1ecfb3 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.9.1__AddBuildingBlockRollback.sql @@ -0,0 +1,10 @@ +use catalogdb; + +CREATE TABLE IF NOT EXISTS `building_block_rollback` ( + `ID` INT NOT NULL AUTO_INCREMENT, + `BUILDING_BLOCK_NAME` varchar(200) NOT NULL, + `ACTION` varchar(200) null, + `ROLLBACK_BUILDING_BLOCK_NAME` varchar(200) NOT NULL, + `ROLLBACK_ACTION` varchar(200) NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index 78b9bf1ee6..228e1bd0d8 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -59,6 +59,8 @@ import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.client.RequestsDbClient; import org.springframework.core.env.Environment; +// deprecated because of task SO-3772, this class will be deleted after all its usage is removed +@Deprecated @RunWith(MockitoJUnitRunner.Silent.class) public abstract class BaseTaskTest extends TestDataSetup { @Mock 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 index cb46d2de8a..6a94ee9990 100644 --- 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 @@ -37,7 +37,6 @@ import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.common.data.TestDataSetup; @@ -45,29 +44,34 @@ 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.aaiclient.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; - - -public class AAIFlagTasksTest extends BaseTaskTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class AAIFlagTasksTest extends TestDataSetup { + @Mock + protected AAIResourcesClient MOCK_aaiResourcesClient; + @Mock + protected InjectionHelper MOCK_injectionHelper; + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected AAIVnfResources aaiVnfResources; + @Mock + protected ExtractPojosForBB extractPojosForBBMock; @InjectMocks - private AAIFlagTasks aaiFlagTasks = new AAIFlagTasks(); - - private GenericVnf genericVnf; + private AAIFlagTasks aaiFlagTasks; @Before public void before() throws BBObjectNotFoundException { - genericVnf = setGenericVnf(); + GenericVnf genericVnf = setGenericVnf(); doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); - when(extractPojosForBB.extractByKey(any(), any())).thenReturn(genericVnf); + when(extractPojosForBBMock.extractByKey(any(), any())).thenReturn(genericVnf); } @Test - public void checkVnfInMaintTestTrue() throws Exception { + public void checkVnfInMaintTestTrue() { 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)); @@ -82,7 +86,7 @@ public class AAIFlagTasksTest extends BaseTaskTest { } @Test - public void checkVnfInMaintTestFalse() throws Exception { + public void checkVnfInMaintTestFalse() { doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class)); aaiFlagTasks.checkVnfInMaintFlag(execution); verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), @@ -106,7 +110,7 @@ public class AAIFlagTasksTest extends BaseTaskTest { } @Test - public void modifyVnfInMaintFlagTest() throws Exception { + public void modifyVnfInMaintFlagTest() { doNothing().when(aaiVnfResources).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class)); aaiFlagTasks.modifyVnfInMaintFlag(execution, true); verify(aaiVnfResources, times(1)).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class)); @@ -128,7 +132,7 @@ public class AAIFlagTasksTest extends BaseTaskTest { } @Test - public void checkVnfClosedLoopDisabledTestTrue() throws Exception { + public void checkVnfClosedLoopDisabledTestTrue() { doThrow(new BpmnError("VNF Closed Loop Disabled in A&AI")).when(exceptionUtil) .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); doReturn(false).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class)); @@ -142,7 +146,7 @@ public class AAIFlagTasksTest extends BaseTaskTest { } @Test - public void checkVnfClosedLoopDisabledTestFalse() throws Exception { + public void checkVnfClosedLoopDisabledTestFalse() { doReturn(false).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class)); aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution); verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), @@ -165,7 +169,7 @@ public class AAIFlagTasksTest extends BaseTaskTest { } @Test - public void modifyVnfClosedLoopDisabledFlagTest() throws Exception { + public void modifyVnfClosedLoopDisabledFlagTest() { doNothing().when(aaiVnfResources).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class)); aaiFlagTasks.modifyVnfClosedLoopDisabledFlag(execution, true); verify(aaiVnfResources, times(1)).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class)); 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 index e1d3a7cbc4..857807ef2e 100644 --- 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 @@ -37,19 +37,21 @@ import java.util.List; import java.util.Optional; import java.util.TreeSet; import java.util.stream.Collectors; -import com.google.common.base.Strings; 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.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.mockito.Captor; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Mockito; -import org.onap.so.bpmn.BaseTaskTest; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; @@ -68,14 +70,50 @@ import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; import org.onap.aaiclient.client.aai.entities.uri.AAIBaseResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; +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.AAIConfigurationResources; +import org.onap.so.client.orchestration.AAIInstanceGroupResources; +import org.onap.so.client.orchestration.AAINetworkResources; +import org.onap.so.client.orchestration.AAIPnfResources; +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.db.catalog.beans.OrchestrationStatus; - -public class AAICreateTasksTest extends BaseTaskTest { - +import org.springframework.core.env.Environment; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class AAICreateTasksTest extends TestDataSetup { + + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected AAIServiceInstanceResources aaiServiceInstanceResources; + @Mock + protected AAIVolumeGroupResources aaiVolumeGroupResources; + @Mock + protected AAIVnfResources aaiVnfResources; + @Mock + protected AAINetworkResources aaiNetworkResources; + @Mock + protected AAIVfModuleResources aaiVfModuleResources; + @Mock + protected AAIPnfResources aaiPnfResources; + @Mock + protected AAIVpnBindingResources aaiVpnBindingResources; + @Mock + protected AAIInstanceGroupResources aaiInstanceGroupResources; + @Mock + protected AAIConfigurationResources aaiConfigurationResources; + @Mock + protected Environment env; + @Mock + protected ExtractPojosForBB extractPojosForBBMock; @InjectMocks - private AAICreateTasks aaiCreateTasks = new AAICreateTasks(); - + private AAICreateTasks aaiCreateTasks; private ServiceInstance serviceInstance; private L3Network network; @@ -107,17 +145,19 @@ public class AAICreateTasksTest extends BaseTaskTest { configuration = setConfiguration(); instanceGroup = setInstanceGroupVnf(); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) .thenReturn(genericVnf); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))) + .thenReturn(vfModule); + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))) + .thenReturn(network); + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID))) .thenReturn(volumeGroup); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID))) .thenReturn(configuration); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID))) .thenReturn(instanceGroup); @@ -129,7 +169,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createServiceInstanceTest() throws Exception { + public void createServiceInstanceTest() { doReturn(false).when(aaiServiceInstanceResources).checkInstanceServiceNameInUse(serviceInstance); doNothing().when(aaiServiceInstanceResources).createServiceInstance(serviceInstance, customer); aaiCreateTasks.createServiceInstance(execution); @@ -137,7 +177,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createServiceInstanceExceptionTest() throws Exception { + public void createServiceInstanceExceptionTest() { expectedException.expect(BpmnError.class); lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "notfound"); @@ -147,7 +187,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createVolumeGroupTest() throws Exception { + public void createVolumeGroupTest() { volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED); execution.setVariable("aLaCarte", Boolean.FALSE); doNothing().when(aaiVolumeGroupResources).createVolumeGroup(volumeGroup, cloudRegion); @@ -161,7 +201,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createVolumeGroupExceptionTest() throws Exception { + public void createVolumeGroupExceptionTest() { expectedException.expect(BpmnError.class); volumeGroup.setOrchestrationStatus(OrchestrationStatus.PRECREATED); @@ -181,7 +221,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createPlatformTest() throws Exception { + public void createPlatformTest() { doNothing().when(aaiVnfResources).createPlatformandConnectVnf(genericVnf.getPlatform(), genericVnf); aaiCreateTasks.createPlatform(execution); ArgumentCaptor<Platform> platformCaptor = ArgumentCaptor.forClass(Platform.class); @@ -197,7 +237,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createPlatformNetworkTest() throws Exception { + public void createPlatformNetworkTest() { doNothing().when(aaiNetworkResources).createPlatformAndConnectNetwork(network.getPlatform(), network); aaiCreateTasks.createPlatformForNetwork(execution); ArgumentCaptor<Platform> platformCaptor = ArgumentCaptor.forClass(Platform.class); @@ -221,7 +261,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createLineOfBusinessTest() throws Exception { + public void createLineOfBusinessTest() { doNothing().when(aaiVnfResources).createLineOfBusinessandConnectVnf(genericVnf.getLineOfBusiness(), genericVnf); aaiCreateTasks.createLineOfBusiness(execution); @@ -243,7 +283,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void splitCDL_Test() throws Exception { + public void splitCDL_Test() { List<String> strings = aaiCreateTasks.splitCDL("Test"); assertEquals(strings.get(0), "Test"); @@ -252,7 +292,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createProjectExceptionTest() throws Exception { + public void createProjectExceptionTest() { expectedException.expect(BpmnError.class); lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "notfound"); @@ -262,7 +302,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createProjectNullProjectNameTest() throws Exception { + public void createProjectNullProjectNameTest() { serviceInstance.getProject().setProjectName(null); doNothing().when(aaiServiceInstanceResources) .createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); @@ -272,7 +312,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createProjectEmptyProjectNameTest() throws Exception { + public void createProjectEmptyProjectNameTest() { serviceInstance.getProject().setProjectName(""); doNothing().when(aaiServiceInstanceResources) .createProjectandConnectServiceInstance(serviceInstance.getProject(), serviceInstance); @@ -282,7 +322,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createOwningEntityTest() throws Exception { + public void createOwningEntityTest() { doReturn(true).when(aaiServiceInstanceResources).existsOwningEntity(serviceInstance.getOwningEntity()); doNothing().when(aaiServiceInstanceResources) .connectOwningEntityandServiceInstance(serviceInstance.getOwningEntity(), serviceInstance); @@ -293,7 +333,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createOwningEntityNotExistsOwningEntityTest() throws Exception { + public void createOwningEntityNotExistsOwningEntityTest() { doReturn(false).when(aaiServiceInstanceResources).existsOwningEntity(serviceInstance.getOwningEntity()); doNothing().when(aaiServiceInstanceResources) .createOwningEntityandConnectServiceInstance(serviceInstance.getOwningEntity(), serviceInstance); @@ -320,7 +360,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createOwningEntityNullOwningEntityNameTest() throws Exception { + public void createOwningEntityNullOwningEntityNameTest() { expectedException.expect(BpmnError.class); serviceInstance.getOwningEntity().setOwningEntityName(null); @@ -331,7 +371,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createOwningEntityEmptyOwningEntityNameTest() throws Exception { + public void createOwningEntityEmptyOwningEntityNameTest() { expectedException.expect(BpmnError.class); serviceInstance.getOwningEntity().setOwningEntityName(""); @@ -342,7 +382,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createOwningEntityExceptionTest() throws Exception { + public void createOwningEntityExceptionTest() { expectedException.expect(BpmnError.class); doReturn(true).when(aaiServiceInstanceResources).existsOwningEntity(serviceInstance.getOwningEntity()); @@ -354,7 +394,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createVnfTest() throws Exception { + public void createVnfTest() { doNothing().when(aaiVnfResources).createVnfandConnectServiceInstance(genericVnf, serviceInstance); execution.setVariable("aLaCarte", Boolean.FALSE); aaiCreateTasks.createVnf(execution); @@ -365,7 +405,7 @@ public class AAICreateTasksTest extends BaseTaskTest { public void createVnfExceptionTest() throws Exception { expectedException.expect(BpmnError.class); lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "notfound"); - doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(any(), + doThrow(BBObjectNotFoundException.class).when(extractPojosForBBMock).extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)); doNothing().when(aaiVnfResources).createVnfandConnectServiceInstance(genericVnf, serviceInstance); aaiCreateTasks.createVnf(execution); @@ -374,7 +414,7 @@ public class AAICreateTasksTest extends BaseTaskTest { @Test public void createPnfShouldCallCreatePnfAndConnectServiceInstance() throws BBObjectNotFoundException { - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf); + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf); aaiCreateTasks.createPnf(execution); verify(aaiPnfResources, times(1)).createPnfAndConnectServiceInstance(pnf, serviceInstance); } @@ -382,7 +422,7 @@ public class AAICreateTasksTest extends BaseTaskTest { @Test public void createPnfShouldThrowBpmnErrorWhenPnfIsNotFound() throws BBObjectNotFoundException { expectedException.expect(BpmnError.class); - doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(execution, ResourceKey.PNF); + doThrow(BBObjectNotFoundException.class).when(extractPojosForBBMock).extractByKey(execution, ResourceKey.PNF); aaiCreateTasks.createPnf(execution); } @@ -393,7 +433,7 @@ public class AAICreateTasksTest extends BaseTaskTest { newVfModule.setModuleIndex(null); newVfModule.getModelInfoVfModule().setModelInvariantUUID("testModelInvariantUUID1"); doNothing().when(aaiVfModuleResources).createVfModule(newVfModule, genericVnf); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))) .thenReturn(newVfModule); assertEquals(null, newVfModule.getModuleIndex()); @@ -425,7 +465,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createVfModuleExceptionTest() throws Exception { + public void createVfModuleExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiVfModuleResources).createVfModule(vfModule, genericVnf); @@ -433,7 +473,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void connectVfModuleToVolumeGroupTest() throws Exception { + public void connectVfModuleToVolumeGroupTest() { doNothing().when(aaiVfModuleResources).connectVfModuleToVolumeGroup(genericVnf, vfModule, volumeGroup, cloudRegion); aaiCreateTasks.connectVfModuleToVolumeGroup(execution); @@ -442,7 +482,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createNetworkTest() throws Exception { + public void createNetworkTest() { network.getModelInfoNetwork().setNeutronNetworkType("PROVIDER"); execution.setVariable("aLaCarte", Boolean.FALSE); doNothing().when(aaiNetworkResources).createNetworkConnectToServiceInstance(network, serviceInstance); @@ -451,7 +491,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createNetworkExceptionTest() throws Exception { + public void createNetworkExceptionTest() { expectedException.expect(BpmnError.class); lookupKeyMap.put(ResourceKey.NETWORK_ID, "notfound"); @@ -479,7 +519,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createNetworkCollectionTest() throws Exception { + public void createNetworkCollectionTest() { doNothing().when(aaiNetworkResources).createNetworkCollection(serviceInstance.getCollection()); execution.setVariable("networkCollectionName", "testNetworkCollectionName"); aaiCreateTasks.createNetworkCollection(execution); @@ -487,7 +527,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createNetworkCollectionInstanceGroupTest() throws Exception { + public void createNetworkCollectionInstanceGroupTest() { doNothing().when(aaiNetworkResources) .createNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup()); execution.setVariable("aLaCarte", Boolean.FALSE); @@ -497,7 +537,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void connectNetworkToNetworkCollectionServiceInstanceTest() throws Exception { + public void connectNetworkToNetworkCollectionServiceInstanceTest() { doNothing().when(aaiNetworkResources).connectNetworkToNetworkCollectionServiceInstance(network, serviceInstance); aaiCreateTasks.connectNetworkToNetworkCollectionServiceInstance(execution); @@ -506,7 +546,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void connectNetworkToNetworkCollectionInstanceGroupTest() throws Exception { + public void connectNetworkToNetworkCollectionInstanceGroupTest() { doNothing().when(aaiNetworkResources).connectNetworkToNetworkCollectionInstanceGroup(network, serviceInstance.getCollection().getInstanceGroup()); aaiCreateTasks.connectNetworkToNetworkCollectionInstanceGroup(execution); @@ -526,9 +566,9 @@ public class AAICreateTasksTest extends BaseTaskTest { gBBInput.setServiceInstance(serviceInstance); lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstance.getServiceInstanceId()); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))) .thenReturn(serviceInstance); // verify connection call was not executednetwork exception.expect(BpmnError.class); @@ -537,7 +577,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void connectNetworkToCloudRegionTest() throws Exception { + public void connectNetworkToCloudRegionTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiNetworkResources).connectNetworkToCloudRegion(network, gBBInput.getCloudRegion()); aaiCreateTasks.connectNetworkToCloudRegion(execution); @@ -545,7 +585,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void connectNetworkToTenantTest() throws Exception { + public void connectNetworkToTenantTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiNetworkResources).connectNetworkToTenant(network, gBBInput.getCloudRegion()); aaiCreateTasks.connectNetworkToTenant(execution); @@ -553,7 +593,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createConfigurationTest() throws Exception { + public void createConfigurationTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiConfigurationResources).createConfiguration(configuration); execution.setVariable("aLaCarte", Boolean.FALSE); @@ -562,7 +602,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void connectVnfToCloudRegionTest() throws Exception { + public void connectVnfToCloudRegionTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiVnfResources).connectVnfToCloudRegion(genericVnf, gBBInput.getCloudRegion()); aaiCreateTasks.connectVnfToCloudRegion(execution); @@ -570,7 +610,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void connectNoneToVnfToCloudRegionTest() throws Exception { + public void connectNoneToVnfToCloudRegionTest() { String[] arr = new String[1]; arr[0] = "test25Region2"; doReturn(arr).when(env).getProperty("mso.bpmn.cloudRegionIdsToSkipAddingVnfEdgesTo", String[].class); @@ -582,7 +622,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void connectVnfTenantTest() throws Exception { + public void connectVnfTenantTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiVnfResources).connectVnfToTenant(genericVnf, gBBInput.getCloudRegion()); aaiCreateTasks.connectVnfToTenant(execution); @@ -590,7 +630,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createInstanceGroupVnfTest() throws Exception { + public void createInstanceGroupVnfTest() { doReturn(false).when(aaiInstanceGroupResources) .checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName()); doNothing().when(aaiInstanceGroupResources).createInstanceGroupandConnectServiceInstance(instanceGroup, @@ -602,7 +642,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createInstanceGroupVnfExceptionTest() throws Exception { + public void createInstanceGroupVnfExceptionTest() { expectedException.expect(BpmnError.class); doThrow(RuntimeException.class).when(aaiInstanceGroupResources) .createInstanceGroupandConnectServiceInstance(instanceGroup, serviceInstance); @@ -610,7 +650,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createNetworkPolicyNeedToCreateAllTest() throws Exception { + public void createNetworkPolicyNeedToCreateAllTest() { execution.setVariable("heatStackId", "testHeatStackId"); execution.setVariable("contrailNetworkPolicyFqdnList", "ABC123,ED456"); Optional<NetworkPolicy> networkPolicy = Optional.empty(); @@ -625,7 +665,7 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createNetworkPolicyNeedToCreateNoneTest() throws Exception { + public void createNetworkPolicyNeedToCreateNoneTest() { execution.setVariable("heatStackId", "testHeatStackId"); execution.setVariable("contrailNetworkPolicyFqdnList", "ABC123"); NetworkPolicy networkPolicy = new NetworkPolicy(); @@ -636,14 +676,14 @@ public class AAICreateTasksTest extends BaseTaskTest { } @Test - public void createNetworkPolicyNoNetworkPoliciesTest() throws Exception { + public void createNetworkPolicyNoNetworkPoliciesTest() { execution.setVariable("heatStackId", "testHeatStackId"); aaiCreateTasks.createNetworkPolicies(execution); verify(aaiNetworkResources, times(0)).createNetworkPolicy(any(NetworkPolicy.class)); } @Test - public void createVfModuleGetLowestIndexTest() throws Exception { + public void createVfModuleGetLowestIndexTest() { GenericVnf vnf = new GenericVnf(); ModelInfoGenericVnf vnfInfo = new ModelInfoGenericVnf(); vnf.setModelInfoGenericVnf(vnfInfo); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasksTest.java index 243b452d18..60dbadd426 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIDeleteTasksTest.java @@ -35,13 +35,16 @@ import java.util.Optional; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.mockito.Captor; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.NetworkPolicies; -import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -53,14 +56,41 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.uri.AAIBaseResourceUri; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; - - -public class AAIDeleteTasksTest extends BaseTaskTest { +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.AAIConfigurationResources; +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; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class AAIDeleteTasksTest extends TestDataSetup { private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected AAIVfModuleResources aaiVfModuleResources; + @Mock + protected AAIServiceInstanceResources aaiServiceInstanceResources; + @Mock + protected AAIVnfResources aaiVnfResources; + @Mock + protected AAINetworkResources aaiNetworkResources; + @Mock + protected AAIVolumeGroupResources aaiVolumeGroupResources; + @Mock + protected AAIConfigurationResources aaiConfigurationResources; + @Mock + protected AAIInstanceGroupResources aaiInstanceGroupResources; + @Mock + protected ExtractPojosForBB extractPojosForBBMock; @InjectMocks - private AAIDeleteTasks aaiDeleteTasks = new AAIDeleteTasks(); + private AAIDeleteTasks aaiDeleteTasks; private L3Network network; private ServiceInstance serviceInstance; @@ -85,17 +115,19 @@ public class AAIDeleteTasksTest extends BaseTaskTest { configuration = setConfiguration(); instanceGroup = setInstanceGroupVnf(); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) .thenReturn(genericVnf); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))) + .thenReturn(vfModule); + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))) + .thenReturn(network); + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID))) .thenReturn(volumeGroup); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID))) .thenReturn(configuration); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID))) .thenReturn(instanceGroup); @@ -195,7 +227,7 @@ public class AAIDeleteTasksTest extends BaseTaskTest { } @Test - public void deleteConfigurationTest() throws Exception { + public void deleteConfigurationTest() { gBBInput = execution.getGeneralBuildingBlock(); doNothing().when(aaiConfigurationResources).deleteConfiguration(configuration); aaiDeleteTasks.deleteConfiguration(execution); @@ -203,7 +235,7 @@ public class AAIDeleteTasksTest extends BaseTaskTest { } @Test - public void deleteInstanceGroupVnfTest() throws Exception { + public void deleteInstanceGroupVnfTest() { doNothing().when(aaiInstanceGroupResources).deleteInstanceGroup(instanceGroup); aaiDeleteTasks.deleteInstanceGroupVnf(execution); verify(aaiInstanceGroupResources, times(1)).deleteInstanceGroup(instanceGroup); @@ -231,7 +263,7 @@ public class AAIDeleteTasksTest extends BaseTaskTest { } @Test - public void deleteNetworkPolicyNeedToDeleteNoneTest() throws Exception { + public void deleteNetworkPolicyNeedToDeleteNoneTest() { execution.setVariable("contrailNetworkPolicyFqdnList", "ABC123"); Optional<NetworkPolicies> networkPolicies = Optional.empty(); doReturn(networkPolicies).when(aaiNetworkResources).getNetworkPolicies(any(AAIBaseResourceUri.class)); @@ -240,7 +272,7 @@ public class AAIDeleteTasksTest extends BaseTaskTest { } @Test - public void deleteNetworkPolicyNoNetworkPoliciesTest() throws Exception { + public void deleteNetworkPolicyNoNetworkPoliciesTest() { aaiDeleteTasks.deleteNetworkPolicies(execution); verify(aaiNetworkResources, times(0)).deleteNetworkPolicy(any(String.class)); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java index 1fde3f4fbc..5917bd5e36 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java @@ -20,7 +20,6 @@ package org.onap.so.bpmn.infrastructure.activity; - import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -33,19 +32,22 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.onap.so.bpmn.BaseTaskTest; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.core.WorkflowException; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.client.exception.ExceptionBuilder; -public class ExecuteActivityTest extends BaseTaskTest { +@RunWith(MockitoJUnitRunner.Silent.class) +public class ExecuteActivityTest extends TestDataSetup { @InjectMocks - protected ExecuteActivity executeActivity = new ExecuteActivity(); + protected ExecuteActivity executeActivity; @InjectMocks @Spy @@ -105,7 +107,7 @@ public class ExecuteActivityTest extends BaseTaskTest { } @Test - public void buildAndThrowException_Test() throws Exception { + public void buildAndThrowException_Test() { doNothing().when(workflowActionBBFailure).updateRequestStatusToFailed(execution); doReturn("Process key").when(exceptionBuilder).getProcessKey(execution); thrown.expect(BpmnError.class); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java index f23bbd8c91..ab0704430c 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java @@ -35,21 +35,37 @@ import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.appc.client.lcm.model.Action; -import org.onap.so.bpmn.BaseTaskTest; 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.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.appc.ApplicationControllerAction; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.db.catalog.beans.ControllerSelectionReference; - -public class GenericVnfHealthCheckTest extends BaseTaskTest { - +import org.onap.so.db.catalog.client.CatalogDbClient; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class GenericVnfHealthCheckTest extends TestDataSetup { + + @Mock + protected ExceptionBuilder exceptionUtil; + @Mock + protected CatalogDbClient catalogDbClient; + @Mock + protected ApplicationControllerAction appCClient; + @Mock + protected ExtractPojosForBB extractPojosForBBMock; @InjectMocks - private GenericVnfHealthCheck genericVnfHealthCheck = new GenericVnfHealthCheck(); + private GenericVnfHealthCheck genericVnfHealthCheck; private GenericVnf genericVnf; private RequestContext requestContext; @@ -65,12 +81,12 @@ public class GenericVnfHealthCheckTest extends BaseTaskTest { doThrow(new BpmnError("BPMN Error")).when(exceptionUtil) .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); - when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) + when(extractPojosForBBMock.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) .thenReturn(genericVnf); } @Test - public void setParamsForGenericVnfHealthCheckTest() throws Exception { + public void setParamsForGenericVnfHealthCheckTest() { ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference(); controllerSelectionReference.setControllerName("testName"); controllerSelectionReference.setActionCategory("testAction"); @@ -91,12 +107,12 @@ public class GenericVnfHealthCheckTest extends BaseTaskTest { } @Test - public void callAppcClientTest() throws Exception { + public void callAppcClientTest() { Action action = Action.HealthCheck; String vnfId = genericVnf.getVnfId(); String payload = "{\"testName\":\"testValue\",}"; String controllerType = "testType"; - HashMap<String, String> payloadInfo = new HashMap<String, String>(); + HashMap<String, String> payloadInfo = new HashMap<>(); payloadInfo.put("vnfName", "testVnfName"); payloadInfo.put("vfModuleId", "testVfModuleId"); payloadInfo.put("oamIpAddress", "testOamIpAddress"); @@ -120,13 +136,13 @@ public class GenericVnfHealthCheckTest extends BaseTaskTest { } @Test - public void callAppcClientExceptionTest() throws Exception { + public void callAppcClientExceptionTest() { expectedException.expect(BpmnError.class); Action action = Action.HealthCheck; String vnfId = genericVnf.getVnfId(); String payload = "{\"testName\":\"testValue\",}"; String controllerType = "testType"; - HashMap<String, String> payloadInfo = new HashMap<String, String>(); + HashMap<String, String> payloadInfo = new HashMap<>(); payloadInfo.put("vnfName", "testVnfName"); payloadInfo.put("vfModuleId", "testVfModuleId"); payloadInfo.put("oamIpAddress", "testOamIpAddress"); @@ -160,7 +176,7 @@ public class GenericVnfHealthCheckTest extends BaseTaskTest { String vnfId = genericVnf.getVnfId(); String payload = "{\"testName\":\"testValue\",}"; String controllerType = "testType"; - HashMap<String, String> payloadInfo = new HashMap<String, String>(); + HashMap<String, String> payloadInfo = new HashMap<>(); payloadInfo.put("vnfName", "testVnfName"); payloadInfo.put("vfModuleId", "testVfModuleId"); payloadInfo.put("oamIpAddress", "testOamIpAddress"); diff --git a/docs/conf.py b/docs/conf.py index 5371015c66..d211470a62 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,4 +12,4 @@ intersphinx_mapping = {} html_last_updated_fmt = '%d-%b-%y %H:%M' def setup(app): - app.add_stylesheet("css/ribbon.css") + app.add_css_file("css/ribbon.css") diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index b3188ddd38..74a3b7a3fd 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -1,15 +1 @@ -tox -Sphinx -doc8 -docutils -setuptools -six -sphinx_rtd_theme>=0.4.3 -sphinxcontrib-blockdiag -sphinxcontrib-needs>=0.2.3 -sphinxcontrib-nwdiag -sphinxcontrib-seqdiag -sphinxcontrib-swaggerdoc -sphinxcontrib-plantuml -sphinx_bootstrap_theme lfdocs-conf diff --git a/docs/tox.ini b/docs/tox.ini index edac8c35fc..811bb5e8ad 100644 --- a/docs/tox.ini +++ b/docs/tox.ini @@ -1,11 +1,14 @@ [tox] minversion = 1.6 -envlist = docs, +envlist = docs skipsdist = true [testenv:docs] basepython = python3 -deps = -r{toxinidir}/requirements-docs.txt +deps = + -r{toxinidir}/requirements-docs.txt + -chttps://git.onap.org/doc/plain/etc/upper-constraints.os.txt + -chttps://git.onap.org/doc/plain/etc/upper-constraints.onap.txt commands = sphinx-build -b html -n -d {envtmpdir}/doctrees ./ {toxinidir}/_build/html echo "Generated docs available in {toxinidir}/_build/html" @@ -16,7 +19,10 @@ whitelist_externals = [testenv:docs-linkcheck] basepython = python3 -#deps = -r{toxinidir}/requirements-docs.txt +deps = + -r{toxinidir}/requirements-docs.txt + -chttps://git.onap.org/doc/plain/etc/upper-constraints.os.txt + -chttps://git.onap.org/doc/plain/etc/upper-constraints.onap.txt commands = echo "Link Checking not enforced" #commands = sphinx-build -b linkcheck -d {envtmpdir}/doctrees ./ {toxinidir}/_build/linkcheck whitelist_externals = echo diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/BuildingBlockRollback.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/BuildingBlockRollback.java new file mode 100644 index 0000000000..798604e4fb --- /dev/null +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/BuildingBlockRollback.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2021 Bell Canada. 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.db.catalog.beans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.openpojo.business.annotation.BusinessKey; +import java.io.Serializable; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import uk.co.blackpepper.bowman.annotation.RemoteResource; + +@Entity +@RemoteResource("/buildingBlockRollback") +@Table(name = "building_block_rollback") +public class BuildingBlockRollback implements Serializable { + + private static final long serialVersionUID = 1; + + @Id + @BusinessKey + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ID", nullable = false, updatable = false) + private Integer id; + + @BusinessKey + @JsonProperty("building_block_name") + @Column(name = "BUILDING_BLOCK_NAME", nullable = false, length = 200) + private String buildingBlockName; + + @BusinessKey + @JsonProperty("action") + @Column(name = "ACTION", length = 200) + private String action; + + @BusinessKey + @JsonProperty("rollback_building_block_name") + @Column(name = "ROLLBACK_BUILDING_BLOCK_NAME", nullable = false, length = 200) + private String rollbackBuildingBlockName; + + @BusinessKey + @JsonProperty("rollback_action") + @Column(name = "ROLLBACK_ACTION", length = 200) + private String rollbackAction; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getBuildingBlockName() { + return buildingBlockName; + } + + public void setBuildingBlockName(String buildingBlockName) { + this.buildingBlockName = buildingBlockName; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getRollbackBuildingBlockName() { + return rollbackBuildingBlockName; + } + + public void setRollbackBuildingBlockName(String rollbackBuildingBlockName) { + this.rollbackBuildingBlockName = rollbackBuildingBlockName; + } + + public String getRollbackAction() { + return rollbackAction; + } + + public void setRollbackAction(String rollbackAction) { + this.rollbackAction = rollbackAction; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BuildingBlockRollback that = (BuildingBlockRollback) o; + return id.equals(that.id) && buildingBlockName.equals(that.buildingBlockName) + && Objects.equals(action, that.action) + && rollbackBuildingBlockName.equals(that.rollbackBuildingBlockName) + && Objects.equals(rollbackAction, that.rollbackAction); + } + + @Override + public int hashCode() { + return Objects.hash(id, buildingBlockName, action, rollbackBuildingBlockName, rollbackAction); + } + + @Override + public String toString() { + return "BuildingBlockRollback{" + "id='" + id + '\'' + ", buildingBlockName='" + buildingBlockName + '\'' + + ", action='" + action + '\'' + ", rollbackBuildingBlockName='" + rollbackBuildingBlockName + '\'' + + ", rollbackAction='" + rollbackAction + '\'' + '}'; + } +} diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index ae6d51c6a2..45d6a878ed 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -25,6 +25,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.persistence.EntityNotFoundException; @@ -35,6 +36,7 @@ import org.onap.logging.filter.base.Constants; import org.onap.logging.filter.spring.SpringClientPayloadFilter; import org.onap.so.db.catalog.beans.BBNameSelectionReference; import org.onap.so.db.catalog.beans.BuildingBlockDetail; +import org.onap.so.db.catalog.beans.BuildingBlockRollback; import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.CloudifyManager; import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; @@ -126,6 +128,7 @@ public class CatalogDbClient { private static final String WORKFLOW = "/workflow"; private static final String BB_NAME_SELECTION_REFERENCE = "/bbNameSelectionReference"; private static final String PROCESSING_FLAGS = "/processingFlags"; + private static final String BB_ROLLBACK = "/buildingBlockRollback"; private static final String SEARCH = "/search"; @@ -236,6 +239,7 @@ public class CatalogDbClient { private String pnfResourceURI; private String pnfResourceCustomizationURI; private String workflowURI; + private String buildingBlockRollbacksURI; private final Client<Service> serviceClient; @@ -299,6 +303,8 @@ public class CatalogDbClient { private final Client<ProcessingFlags> processingFlagsClient; + private final Client<BuildingBlockRollback> buildingBlockRollbackClient; + @Value("${mso.catalog.db.spring.endpoint:#{null}}") private String endpoint; @@ -391,7 +397,7 @@ public class CatalogDbClient { pnfResourceURI = endpoint + PNF_RESOURCE + URI_SEPARATOR; pnfResourceCustomizationURI = endpoint + PNF_RESOURCE_CUSTOMIZATION + URI_SEPARATOR; workflowURI = endpoint + WORKFLOW + URI_SEPARATOR; - + buildingBlockRollbacksURI = endpoint + BB_ROLLBACK + URI_SEPARATOR; } public CatalogDbClient() { @@ -445,6 +451,7 @@ public class CatalogDbClient { bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class); processingFlagsClient = clientFactory.create(ProcessingFlags.class); networkResourceClient = clientFactory.create(NetworkResource.class); + buildingBlockRollbackClient = clientFactory.create(BuildingBlockRollback.class); } public CatalogDbClient(String baseUri, String auth) { @@ -498,6 +505,7 @@ public class CatalogDbClient { bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class); processingFlagsClient = clientFactory.create(ProcessingFlags.class); networkResourceClient = clientFactory.create(NetworkResource.class); + buildingBlockRollbackClient = clientFactory.create(BuildingBlockRollback.class); } public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID( @@ -1224,6 +1232,20 @@ public class CatalogDbClient { getUri(UriBuilder.fromUri(findProcessingFlagsByFlag).queryParam(FLAG, flag).build().toString())); } + // TODO: redo using buildingBlockRollbackClient + public List<BuildingBlockRollback> getBuildingBlockRollbackEntries() { + try { + HttpEntity<?> entity = getHttpEntity(); + return restTemplate.exchange( + UriComponentsBuilder.fromUriString(endpoint + "/ecomp/mso/catalog/v1/buildingBlockRollback").build() + .encode().toString(), + HttpMethod.GET, entity, new ParameterizedTypeReference<List<BuildingBlockRollback>>() {}).getBody(); + } catch (HttpClientErrorException e) { + logger.error("Error Calling catalog database", e); + throw e; + } + } + public String getEndpoint() { return endpoint; } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/BuildingBlockRollbackRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/BuildingBlockRollbackRepository.java new file mode 100644 index 0000000000..24dd713197 --- /dev/null +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/BuildingBlockRollbackRepository.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Bell Canada + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.catalog.data.repository; + +import java.util.List; +import org.onap.so.db.catalog.beans.BuildingBlockRollback; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource(collectionResourceRel = "buildingBlockRollback", path = "buildingBlockRollback") +public interface BuildingBlockRollbackRepository extends JpaRepository<BuildingBlockRollback, Integer> { + + List<BuildingBlockRollback> findAll(); + + BuildingBlockRollback findOneById(Integer ID); +} diff --git a/mso-catalog-db/src/test/resources/schema.sql b/mso-catalog-db/src/test/resources/schema.sql index 86f56ca3a5..db800b2b49 100644 --- a/mso-catalog-db/src/test/resources/schema.sql +++ b/mso-catalog-db/src/test/resources/schema.sql @@ -1415,3 +1415,12 @@ CREATE TABLE IF NOT EXISTS `processing_flags` ( PRIMARY KEY (`ID`), UNIQUE KEY `UK_processing_flags` (`FLAG`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +CREATE TABLE IF NOT EXISTS `building_block_rollback` ( + `ID` INT NOT NULL AUTO_INCREMENT, + `BUILDING_BLOCK_NAME` varchar(200) NOT NULL, + `ACTION` varchar(200) null, + `ROLLBACK_BUILDING_BLOCK_NAME` varchar(200) NOT NULL, + `ROLLBACK_ACTION` varchar(200) NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; |