aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorshrek2000 <orenkle@amdocs.com>2018-04-24 16:46:33 +0300
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-04-25 14:22:16 +0000
commitd71a8de8c7b688eabb250e524dc4f6000b3233b6 (patch)
tree38c550f0f78084cd19c79e997f5a5ece37751bd5 /catalog-be/src/test
parentad3c41b5693b4f0b2a151e9c3221551e24f8264d (diff)
Delete workflow artifact and add artifact to CSAR
Added delete artifact codes, add artifact to CSAR and refactored operation Business logic. Change-Id: Iaad3f26795633076d1362bfd33631acc9fcf7aa1 Issue-ID: SDC-1060 Signed-off-by: shrek2000 <orenkle@amdocs.com>
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactBusinessLogicTest.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java24
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java19
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java13
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java46
6 files changed, 108 insertions, 5 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
index 52b71c5743..18116a4d56 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/InterfaceOperationTestUtils.java
@@ -58,7 +58,6 @@ public interface InterfaceOperationTestUtils {
return operation;
}
-
default Map<String, Operation> createMockOperationMap() {
Operation operation = new Operation();
@@ -69,6 +68,10 @@ public interface InterfaceOperationTestUtils {
operation.setDefinition(false);
operation.setName("CREATE");
operation.setUniqueId("uniqueId1");
+ ArtifactDefinition implementation = new ArtifactDefinition();
+ implementation.setUniqueId("uniqId");
+ implementation.setArtifactUUID("artifactId");
+ operation.setImplementation(implementation);
Map<String, Operation> operationMap = new HashMap<>();
operationMap.put("op1", operation);
return operationMap;
@@ -90,5 +93,5 @@ public interface InterfaceOperationTestUtils {
return interfaceDefinitionMap;
}
-
+
}
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 bebe29f13e..4ce0740887 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
@@ -375,7 +375,7 @@ public class ArtifactBusinessLogicTest {
artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.TOSCA);
when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
- when(artifactsOperations.updateArifactOnResource(any(ArtifactDefinition.class), any(), any(), any(NodeTypeEnum.class)
+ when(artifactsOperations.updateArtifactOnResource(any(ArtifactDefinition.class), any(), any(), any(NodeTypeEnum.class)
, any(String.class))).thenReturn(Either.left(artifactDefinition));
when(artifactCassandraDao.saveArtifact(any())).thenReturn(CassandraOperationStatus.OK);
when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat());
@@ -394,7 +394,7 @@ public class ArtifactBusinessLogicTest {
artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.TOSCA);
when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
- when(artifactsOperations.updateArifactOnResource(any(ArtifactDefinition.class), any(), any(), any(NodeTypeEnum.class)
+ when(artifactsOperations.updateArtifactOnResource(any(ArtifactDefinition.class), any(), any(), any(NodeTypeEnum.class)
, any(String.class))).thenReturn(Either.left(artifactDefinition));
when(artifactCassandraDao.saveArtifact(any())).thenReturn(CassandraOperationStatus.OK);
when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat());
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java
index 18af7a035a..dc89156ee9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactResolverTest.java
@@ -25,10 +25,13 @@ import org.junit.Test;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
@@ -68,6 +71,7 @@ public class ArtifactResolverTest {
resource.setDeploymentArtifacts(artifact1Map);
resource.setArtifacts(artifact2Map);
+ resource.setInterfaces(createInterfaceArtifact());
service.setDeploymentArtifacts(artifact1Map);
service.setArtifacts(artifact2Map);
@@ -77,6 +81,26 @@ public class ArtifactResolverTest {
componentInstance.setArtifacts(artifact2Map);
}
+ private Map<String, InterfaceDefinition> createInterfaceArtifact() {
+ Operation operation = new Operation();
+ ArtifactDefinition artifact4 = new ArtifactDefinition();
+ artifact4.setUniqueId("a4");
+ operation.setImplementation(artifact4);
+ HashMap<String, Operation> operationsMap = new HashMap<>();
+ operationsMap.put("operation", operation);
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setOperationsMap(operationsMap);
+ Map<String, InterfaceDefinition> interfaces = new HashMap<>(1);
+ interfaces.put("someKey", interfaceDefinition);
+ return interfaces;
+ }
+
+ @Test
+ public void findArtifactOnComponent_resourceInterfaceOperation() throws Exception {
+ assertNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "someId"));
+ assertNotNull(testInstance.findArtifactOnComponent(resource, ComponentTypeEnum.RESOURCE, "a4"));
+ }
+
@Test
public void findArtifactOnComponent_noArtifactsOnComponent() throws Exception {
assertNull(testInstance.findArtifactOnComponent(noArtifactsResource, ComponentTypeEnum.RESOURCE, "someId"));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
index f51d06d53a..bde1bbb3a1 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
@@ -31,6 +31,8 @@ import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -108,7 +110,7 @@ public class InterfaceOperationBusinessLogicTest implements InterfaceOperationTe
WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
UserValidations userValidations = Mockito.mock(UserValidations.class);
WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
-
+ ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class);
@@ -208,6 +210,7 @@ public class InterfaceOperationBusinessLogicTest implements InterfaceOperationTe
bl.setUserValidations(userValidations);
bl.setInterfaceOperation(interfaceOperation);
bl.setInterfaceOperationValidation(operationValidator);
+ bl.setArtifactCassandraDao(artifactCassandraDao);
Resource resourceCsar = createResourceObjectCsar(true);
setCanWorkOnResource(resourceCsar);
Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
@@ -240,6 +243,7 @@ public class InterfaceOperationBusinessLogicTest implements InterfaceOperationTe
public void deleteInterfaceOperationTest() {
validateUserRoles(Role.ADMIN, Role.DESIGNER);
when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(createResourceForInterfaceOperation()));
+ when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
Set<String> idsToDelete = new HashSet<>();
idsToDelete.add(operationId);
@@ -257,6 +261,19 @@ public class InterfaceOperationBusinessLogicTest implements InterfaceOperationTe
Assert.assertFalse(deleteResourceResponseFormatEither.isLeft());
}
+
+ @Test
+ public void deleteInterfaceOperationFailToDeleteArtifactTest() {
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(createResourceForInterfaceOperation()));
+ when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ Set<String> idsToDelete = new HashSet<>();
+ idsToDelete.add(operationId);
+
+ Either<Resource, ResponseFormat> deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, idsToDelete, user, true);
+ Assert.assertTrue(deleteResourceResponseFormatEither.isRight());
+ }
+
@Test
public void interfaceOperationFailedScenarioTest() {
validateUserRoles(Role.ADMIN, Role.DESIGNER);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
index 792521c484..7e8d1b2081 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java
@@ -166,6 +166,19 @@ public class InterfaceOperationValidationTest implements InterfaceOperationTestU
Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
+ @Test
+ public void testInterfaceOperationeInputParamNameEmpty() {
+ operationInputDefinitionList.add(createMockOperationInputDefinition(" "));
+ operationInputDefinitionList.add(createMockOperationInputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,"update");
+
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, RESOURCE_ID, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
private Set<Operation> createInterfaceOperationData( String uniqueID, String description, ArtifactDefinition artifactDefinition,
ListDataDefinition<OperationInputDefinition> inputs, String name) {
return Sets.newHashSet(createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, name));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java
new file mode 100644
index 0000000000..c44d50dff4
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtilTest.java
@@ -0,0 +1,46 @@
+package org.openecomp.sdc.be.tosca.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.util.HashMap;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openecomp.sdc.be.DummyConfigurationManager;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Resource;
+
+public class OperationArtifactUtilTest {
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ new DummyConfigurationManager();
+ }
+
+ @Test
+ public void testCorrectPathForOperationArtifacts() {
+ Component component = new Resource();
+ component.setNormalizedName("normalizedComponentName");
+ final InterfaceDefinition addedInterface = new InterfaceDefinition();
+ final OperationDataDefinition op = new OperationDataDefinition();
+ final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
+ implementation.setArtifactName("createBPMN.bpmn");
+ op.setImplementation(implementation);
+ addedInterface.setOperations(new HashMap<>());
+ addedInterface.getOperations().put("create", op);
+ final String interfaceType = "normalizedComponentName-interface";
+ ((Resource) component).setInterfaces(new HashMap<>());
+ ((Resource) component).getInterfaces().put(interfaceType, addedInterface);
+ final String actualArtifactPath = OperationArtifactUtil.createOperationArtifactPath(component.getNormalizedName(), interfaceType, op);
+ String expectedArtifactPath ="Artifacts"+ File.separator+"normalizedComponentName"+File.separator
+ +"normalizedComponentName-interface"+File.separator+"Deployment"
+ +File.separator+"Workflows"+File.separator+"BPMN"
+ +File.separator+"createBPMN.bpmn";
+
+
+ assertEquals(expectedArtifactPath,actualArtifactPath);
+ }
+} \ No newline at end of file