summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java112
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java84
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java2
3 files changed, 169 insertions, 29 deletions
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 e8a698fec1..4227e5d5cc 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
@@ -55,6 +55,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.Resource;
@@ -88,7 +89,7 @@ public class InterfaceOperationBusinessLogicTest {
private final String operationId = "uniqueId1";
private Operation operation;
- private static final String RESOURCE_NAME = "My-Resource_Name with space";
+ private static final String RESOURCE_NAME = "Resource1";
private final ServletContext servletContext = Mockito.mock(ServletContext.class);
private final TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
@@ -175,13 +176,6 @@ public class InterfaceOperationBusinessLogicTest {
//InterfaceOperation
when(operationValidator.validateInterfaceOperations(anyCollection(), anyObject(), anyBoolean())).thenReturn(Either.left(true));
- when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
- when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
- when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
- when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
- when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
- when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
- when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK);
// BL object
@@ -211,6 +205,8 @@ public class InterfaceOperationBusinessLogicTest {
validateUserRoles(Role.ADMIN, Role.DESIGNER);
when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
operation = InterfaceOperationTestUtils.createMockOperation();
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+
Either<Operation, ResponseFormat> interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true);
Assert.assertTrue(interfaceOperation.isLeft());
Assert.assertNotNull(interfaceOperation.left().value().getWorkflowId());
@@ -218,27 +214,96 @@ public class InterfaceOperationBusinessLogicTest {
}
@Test
+ public void createInterfaceOperationWithoutInterfaceTest() {
+ Resource resource = createResourceObjectCsar(true);
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ resource.setInterfaces(new HashMap<>());
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ operation = InterfaceOperationTestUtils.createMockOperation();
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+ when(interfaceOperation.addInterface(anyString(), any())).thenReturn(Either.left(new InterfaceDefinition()));
+
+ Either<Operation, ResponseFormat> interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true);
+ Assert.assertTrue(interfaceOperation.isLeft());
+
+ }
+
+ @Test
+ public void shouldFailCreateInterfaceOperationWhenCreateOperationFailedTest() {
+ Resource resource = createResourceObjectCsar(true);
+ resource.setInterfaces(new HashMap<>());
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ operation = InterfaceOperationTestUtils.createMockOperation();
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+ when(interfaceOperation.addInterface(anyString(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+
+ Either<Operation, ResponseFormat> interfaceOperation = bl.createInterfaceOperation(resourceId, operation, user, true);
+ Assert.assertTrue(interfaceOperation.isRight());
+
+ }
+
+ @Test()
+ public void shouldFailWhenCreateInterfaceOperationFailedTest() {
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ operation = InterfaceOperationTestUtils.createMockOperation();
+
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ Assert.assertTrue(bl.createInterfaceOperation(resourceId, operation, user, true).isRight());
+ }
+
+ @Test
public void updateInterfaceOperationTest() {
validateUserRoles(Role.ADMIN, Role.DESIGNER);
operation = InterfaceOperationTestUtils.createMockOperation();
Resource resource = createResourceForInterfaceOperation();
resource.setComponentType(ComponentTypeEnum.RESOURCE);
when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(interfaceOperation.updateInterfaceOperation(any(), any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
+
Either<Operation, ResponseFormat> interfaceOperation = bl.updateInterfaceOperation(resourceId, operation, user, true);
Assert.assertTrue(interfaceOperation.isLeft());
}
+ @Test()
+ public void shouldFailWhenFailedToUpdateInterfaceOperationTest() {
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ operation = InterfaceOperationTestUtils.createMockOperation();
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(interfaceOperation.addInterfaceOperation(any(), any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ Either<Operation, ResponseFormat> interfaceOperation = bl.updateInterfaceOperation(resourceId, operation, user, true);
+ Assert.assertTrue(interfaceOperation.isRight());
+ }
+
@Test
public void deleteInterfaceOperationTest() {
Resource resource = createResourceForInterfaceOperation();
resource.setComponentType(ComponentTypeEnum.RESOURCE);
validateUserRoles(Role.ADMIN, Role.DESIGNER);
when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
Either<Operation, ResponseFormat> deleteResourceResponseFormatEither = bl.deleteInterfaceOperation(resourceId, operationId, user, true);
Assert.assertTrue(deleteResourceResponseFormatEither.isLeft());
}
+ @Test()
+ public void shouldFailWhenDeleteInterfaceOperationFailedTest() {
+ Resource resource = createResourceForInterfaceOperation();
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
+ when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
+ Assert.assertTrue(bl.deleteInterfaceOperation(resourceId, operationId, user, true).isRight());
+
+ }
@Test
public void getInterfaceOperationTest() {
Resource resource = createResourceForInterfaceOperation();
@@ -249,6 +314,37 @@ public class InterfaceOperationBusinessLogicTest {
Assert.assertTrue(getResourceResponseFormatEither.isLeft());
}
+ @Test
+ public void updateToscaResourceNameWhenComponentNameChanged() {
+ Component newComponent = new Resource();
+ newComponent.setName("newComponent");
+ Component oldComponent = createResourceForInterfaceOperation();
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(interfaceOperation.updateInterface(anyString(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME)));
+ Assert.assertTrue(bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isLeft());
+ }
+
+ @Test
+ public void shouldFailWhenComponentNameChangedButUpdateOperationFailed() {
+ Component newComponent = new Resource();
+ newComponent.setName("newComponent");
+ Component oldComponent = createResourceForInterfaceOperation();
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
+ Assert.assertTrue(bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isRight());
+ }
+
+ @Test(expected = Exception.class)
+ public void shouldThrowExceptionWhenComponentNameChangedButUpdateOperationFailed() {
+ Component newComponent = new Resource();
+ newComponent.setName("newComponent");
+ Component oldComponent = createResourceForInterfaceOperation();
+ validateUserRoles(Role.ADMIN, Role.DESIGNER);
+ when(interfaceOperation.updateInterface(anyString(), anyObject())).thenThrow(new Exception());
+ bl.validateComponentNameAndUpdateInterfaces(oldComponent, newComponent).isRight();
+ }
+
private void validateUserRoles(Role... roles) {
List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList());
}
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 6fe2f1308c..1a112c583b 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
@@ -66,7 +66,7 @@ public class InterfaceOperationValidationTest {
}
@Test
- public void testValidInterfaceOperation() {
+ public void shouldPassOperationValidationForHappyScenario() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
@@ -78,7 +78,7 @@ public class InterfaceOperationValidationTest {
}
@Test
- public void testInterfaceOperationDescriptionLength() {
+ public void shouldFailWhenOperationOperationDescriptionLengthInvalid() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
@@ -94,7 +94,7 @@ public class InterfaceOperationValidationTest {
@Test
- public void testInterfaceOperationForEmptyType() {
+ public void shouldFailWhenOperationNameIsEmpty() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
@@ -106,19 +106,7 @@ public class InterfaceOperationValidationTest {
}
@Test
- public void testInterfaceOperationForEmptyInputParam() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
- Collection<Operation> operations = createInterfaceOperationData("op2",
- "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
- operationOutputDefinitionList,"input2");
- Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
- .validateInterfaceOperations(operations, component, false);
- Assert.assertTrue(booleanResponseFormatEither.isRight());
- }
-
- @Test
- public void testInterfaceOperationForNonUniqueType() {
+ public void shouldFailWhenOperationNamesAreNotUnique() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
@@ -130,7 +118,7 @@ public class InterfaceOperationValidationTest {
}
@Test
- public void testInterfaceOperationTypeLength() {
+ public void shouldFailWhenOperationNameLengthIsInvalid() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
Collection<Operation> operations = createInterfaceOperationData("op2",
@@ -146,7 +134,7 @@ public class InterfaceOperationValidationTest {
@Test
- public void testInterfaceOperationUniqueInputParamNameInvalid() {
+ public void shouldFailWhenOperationInputParamNamesAreNotUnique() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2"));
@@ -162,7 +150,7 @@ public class InterfaceOperationValidationTest {
}
@Test
- public void testInterfaceOperationUniqueInputParamNameValid() {
+ public void shouldPassWhenOperationInputParamNamesAreUnique() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
@@ -170,14 +158,28 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"update");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isLeft());
+ }
+ @Test
+ public void shouldPassWhenOperationInputParamNamesHasSubProperty() {
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label2"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+ operationInputDefinitionList.getListToscaDataDefinition().get(0).setInputId(operationInputDefinitionList
+ .getListToscaDataDefinition().get(0).getInputId().concat(".subproperty"));
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
.validateInterfaceOperations(operations, component, false);
Assert.assertTrue(booleanResponseFormatEither.isLeft());
}
@Test
- public void testInterfaceOperationInputParamNameEmpty() {
+ public void shouldFailWhenOperationInputParamNameEmpty() {
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(" "));
operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
@@ -185,6 +187,48 @@ public class InterfaceOperationValidationTest {
"interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
operationOutputDefinitionList,"update");
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
+ @Test
+ public void shouldFailWhenOperationOutputParamNameEmpty() {
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("inputParam"));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(" "));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isRight());
+ }
+
+ @Test
+ public void shouldPassWhenInterfaceOperationOutputParamNamesUnique() {
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label2"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
+
+ Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
+ .validateInterfaceOperations(operations, component, false);
+ Assert.assertTrue(booleanResponseFormatEither.isLeft());
+ }
+
+ @Test
+ public void shouldFailWhenOperationOutputParamNamesAreNotUnique() {
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("inputParam1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam1"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam2"));
+ operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("outParam2"));
+ Collection<Operation> operations = createInterfaceOperationData("op2",
+ "interface operation2",new ArtifactDefinition(), operationInputDefinitionList,
+ operationOutputDefinitionList,"update");
Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest
.validateInterfaceOperations(operations, component, false);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
index ac53a6d930..8f34e0e29b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java
@@ -146,7 +146,7 @@ public class InterfacesOperationsToscaUtilTest {
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
- InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, true);
+ InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null);
ToscaTemplate template = new ToscaTemplate("testService");