From 32320724e9fa45d18593cf81314ac068f02560dd Mon Sep 17 00:00:00 2001 From: "Sindhuri.A" Date: Tue, 23 Oct 2018 18:33:14 +0530 Subject: UT-ArtifactsBL handleDelete UT for catalog be ArtifactsBusinessLogic class handleDelete method Issue-ID: SDC-1775 Change-Id: I1ef9807208cca1dc7ad1d23c5096642ea35b072b Signed-off-by: Sindhuri.A --- .../components/impl/ArtifactBusinessLogicTest.java | 50 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'catalog-be/src/test') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java index 43430adb9e..066813448f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -51,6 +51,7 @@ import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations; import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.model.operations.api.*; import org.openecomp.sdc.be.model.operations.impl.ArtifactOperation; import org.openecomp.sdc.be.resources.data.ESArtifactData; @@ -117,10 +118,10 @@ public class ArtifactBusinessLogicTest { TitanDao titanDao; @Mock private IInterfaceLifecycleOperation interfaceLifecycleOperation; - - // public static final InformationDeployedArtifactsBusinessLogic - // informationDeployedArtifactsBusinessLogic = - // Mockito.mock(InformationDeployedArtifactsBusinessLogic.class); + @Mock + private ResponseFormat responseFormat; + @Mock + private User user; public static final Resource resource = Mockito.mock(Resource.class); private Gson gson = new GsonBuilder().setPrettyPrinting().create(); @@ -428,9 +429,9 @@ public class ArtifactBusinessLogicTest { @Test public void testValidMibAritactsConfiguration() { Map componentDeploymentArtifacts = - ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts(); + ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts(); Map componentInstanceDeploymentArtifacts = - ConfigurationManager.getConfigurationManager().getConfiguration().getResourceInstanceDeploymentArtifacts(); + ConfigurationManager.getConfigurationManager().getConfiguration().getResourceInstanceDeploymentArtifacts(); assertThat(componentDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_POLL.getType())).isTrue(); assertThat(componentDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_TRAP.getType())).isTrue(); assertThat(componentInstanceDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_POLL.getType())).isTrue(); @@ -471,7 +472,7 @@ public class ArtifactBusinessLogicTest { Either, StorageOperationStatus> getServiceRes = Either.left(serviceList); when(toscaOperationFacade.getBySystemName(ComponentTypeEnum.SERVICE, serviceName)).thenReturn(getServiceRes); Either downloadServiceArtifactByNamesRes = - artifactBL.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName); + artifactBL.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName); assertThat(downloadServiceArtifactByNamesRes.isLeft()).isTrue(); assertThat(downloadServiceArtifactByNamesRes.left().value() !=null && downloadServiceArtifactByNamesRes.left().value().length == payload.length).isTrue(); @@ -562,6 +563,37 @@ public class ArtifactBusinessLogicTest { verify(titanDao, times(1)).commit(); } + @Test + public void testDeleteComponent_ArtifactNotFound(){ + Either, ResponseFormat> result; + Resource resource = new Resource(); + String uniqueId = "uniqueId"; + resource.setUniqueId(uniqueId); + Map toscaArtifacts = new HashMap<>(); + ArtifactDefinition artifact = new ArtifactDefinition(); + artifact.setArtifactName("artifactName"); + artifact.setEsId("esId"); + artifact.setArtifactUUID("artifactUUID"); + artifact.setArtifactType("YANG"); + artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT); + artifact.setDescription("description"); + artifact.setArtifactLabel("artifactLabel"); + toscaArtifacts.put("artifactId", artifact); + resource.setArtifacts(toscaArtifacts); + resource.setToscaArtifacts(toscaArtifacts); + when(graphLockOperation.lockComponent(uniqueId, NodeTypeEnum.Resource)) + .thenReturn(StorageOperationStatus.OK); + when(graphLockOperation.unlockComponent(uniqueId, NodeTypeEnum.Resource)) + .thenReturn(StorageOperationStatus.OK); + when(toscaOperationFacade.getToscaElement(uniqueId)).thenReturn(Either.left(resource)); + when(componentsUtils.getResponseFormatByArtifactId(ActionStatus.ARTIFACT_NOT_FOUND, "artifactId")). + thenReturn(responseFormat); + result = artifactBL.handleDelete("parentId", "artifactId", user, AuditingActionEnum.ARTIFACT_DELETE, + ComponentTypeEnum.RESOURCE, resource, + true, false); + assertThat(result.isRight()); + } + private void verifyHeatParam(HeatParameterDefinition heatEnvParam, HeatParameterDefinition heatYamlParam) { assertThat(heatYamlParam.getCurrentValue()).isEqualTo(heatEnvParam.getDefaultValue()); assertThat(heatEnvParam.getCurrentValue()).isNull(); -- cgit 1.2.3-korg