UT-ArtifactsBL handleDelete
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ArtifactBusinessLogicTest.java
index 43430ad..0668134 100644 (file)
@@ -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<String, ArtifactTypeConfig> componentDeploymentArtifacts =
-                    ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts();
+                ConfigurationManager.getConfigurationManager().getConfiguration().getResourceDeploymentArtifacts();
         Map<String, ArtifactTypeConfig> 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<List<org.openecomp.sdc.be.model.Component>, StorageOperationStatus> getServiceRes = Either.left(serviceList);
         when(toscaOperationFacade.getBySystemName(ComponentTypeEnum.SERVICE, serviceName)).thenReturn(getServiceRes);
         Either<byte[], ResponseFormat> 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<Either<ArtifactDefinition, Operation>, ResponseFormat> result;
+        Resource resource = new Resource();
+        String uniqueId = "uniqueId";
+        resource.setUniqueId(uniqueId);
+        Map<String, ArtifactDefinition> 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();