aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authorojasdubey <ojas.dubey@amdocs.com>2019-01-28 21:47:09 +0530
committerojasdubey <ojas.dubey@amdocs.com>2019-01-29 13:19:58 +0530
commit9c0aa250313380895e9543e7e6fe83b9daf3849e (patch)
treee4a6f852e7585aa8df6b47b83769112cebbaf7a8 /catalog-be/src/test/java/org
parentc0693cd275a0d35ab7acefd2ea2a936179041f41 (diff)
Operation Outputs - Operation screen BE
1. Added implementation for using operation outputs as mapping to input from create/update operation screen 2. Handled populating the mapped outputs to Tosca 3. Unit tests Change-Id: I3d4761b07be0d4e363ff84710e92438e694a3b07 Issue-ID: SDC-2085 Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java50
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java10
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java469
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java172
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java60
5 files changed, 517 insertions, 244 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 8509f3e749..df4ef646ee 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
@@ -24,12 +24,13 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
-import fj.data.Either;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
+import fj.data.Either;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -70,6 +71,8 @@ public class InterfaceOperationBusinessLogicTest {
private static final String RESOURCE_NAME = "Resource1";
private static final String operationId1 = "operationId1";
private static final String interfaceId1 = "interfaceId1";
+ private static final String operationName = "createOperation";
+
@InjectMocks
private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
@Mock
@@ -97,7 +100,8 @@ public class InterfaceOperationBusinessLogicTest {
public void setup() {
resource = new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setUniqueId(resourceId)
.setName(RESOURCE_NAME).build();
- resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
+ resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId,
+ operationName));
resource.setInputs(createInputsForResource());
user = new User();
@@ -126,11 +130,11 @@ public class InterfaceOperationBusinessLogicTest {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperationEither.isLeft());
}
@@ -141,13 +145,13 @@ public class InterfaceOperationBusinessLogicTest {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperation.addInterfaces(any(), any())).thenReturn(Either.left(
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperationEither.isLeft());
}
@@ -162,7 +166,7 @@ public class InterfaceOperationBusinessLogicTest {
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperationEither.isRight());
}
@@ -174,7 +178,7 @@ public class InterfaceOperationBusinessLogicTest {
when(interfaceOperation.updateInterfaces(any(), any()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)),
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)),
user, true).isRight());
}
@@ -185,11 +189,11 @@ public class InterfaceOperationBusinessLogicTest {
when(artifactCassandraDao.getCountOfArtifactById(any(String.class))).thenReturn(Either.left(new Long(1)));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperation.isLeft());
}
@@ -203,7 +207,7 @@ public class InterfaceOperationBusinessLogicTest {
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperation.isRight());
}
@@ -215,11 +219,11 @@ public class InterfaceOperationBusinessLogicTest {
when(artifactCassandraDao.getCountOfArtifactById(any(String.class)))
.thenReturn(Either.right(CassandraOperationStatus.NOT_FOUND));
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId))));
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperation.isLeft());
}
@@ -231,7 +235,7 @@ public class InterfaceOperationBusinessLogicTest {
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperation.isRight());
}
@@ -244,7 +248,7 @@ public class InterfaceOperationBusinessLogicTest {
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperationEither.isRight());
}
@@ -256,7 +260,7 @@ public class InterfaceOperationBusinessLogicTest {
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperationEither.isRight());
}
@@ -271,7 +275,7 @@ public class InterfaceOperationBusinessLogicTest {
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
- operationId)),
+ operationId, operationName)),
user, true);
Assert.assertTrue(interfaceOperationEither.isRight());
}
@@ -291,7 +295,7 @@ public class InterfaceOperationBusinessLogicTest {
@Test
public void deleteInterfaceOperationTestSuccess() {
resource.getInterfaces().get(interfaceId).getOperations()
- .putAll(InterfaceOperationTestUtils.createMockOperationMap(operationId1));
+ .putAll(InterfaceOperationTestUtils.createMockOperationMap(operationId1, operationName));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
@@ -374,7 +378,7 @@ public class InterfaceOperationBusinessLogicTest {
Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
Collections.singletonList(operationId), user, true).isRight());
Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)),
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)),
user, true).isRight());
}
@@ -387,8 +391,8 @@ public class InterfaceOperationBusinessLogicTest {
Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
Collections.singletonList(operationId), user, true).isRight());
Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
- Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId)),
- user, true).isRight());
+ Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId,
+ operationName)), user, true).isRight());
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java
index 59f95ba8da..8ceac17d46 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtilsTest.java
@@ -15,6 +15,7 @@ public class InterfaceOperationUtilsTest {
private static final String TEST_RESOURCE_NAME = "TestResource";
private static final String operationId = "operationId";
+ private static final String operationName = "createOperation";
private static final String interfaceId = "interfaceId";
private static Resource resource;
@@ -22,7 +23,8 @@ public class InterfaceOperationUtilsTest {
public void setup() {
resource =
new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setName(TEST_RESOURCE_NAME).build();
- resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
+ resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId,
+ operationName));
}
@Test
@@ -72,20 +74,20 @@ public class InterfaceOperationUtilsTest {
@Test
public void testGetOperationFromInterfaceDefinitionSuccess() {
Assert.assertTrue(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
- InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), operationId).isPresent());
+ InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName), operationId).isPresent());
}
@Test
public void testGetOperationFromInterfaceDefinitionFailure() {
Assert.assertFalse(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
- InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), TEST_RESOURCE_NAME)
+ InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName), TEST_RESOURCE_NAME)
.isPresent());
}
@Test
public void testGetOperationFromInterfaceDefinitionNoOperationMap() {
InterfaceDefinition interfaceDefinition =
- InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId);
+ InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName);
interfaceDefinition.getOperations().clear();
Optional<Map.Entry<String, Operation>> operationEntry =
InterfaceOperationUtils.getOperationFromInterfaceDefinition(interfaceDefinition, TEST_RESOURCE_NAME);
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 fc1b03ed78..e2d83aef29 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
@@ -18,12 +18,14 @@ package org.openecomp.sdc.be.components.validation;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperation;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -46,317 +48,476 @@ import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
public class InterfaceOperationValidationTest {
private static final String resourceId = "resourceId";
- private static final String interfaceId = "interfaceId";
private static final String operationId = "operationId";
- private static final String interfaceType = "interfaceType";
- private static final String operationType = "operationType";
private static final String operationId2 = "operationId2";
- private static final String inputId = "inputId";
- private static final String outputId = "outputId";
+ private static final String interfaceType1 = "org.test.lifecycle.standard.interfaceType.first";
+ private static final String interfaceType2 = "org.test.lifecycle.standard.interfaceType.second";
+ private static final String interfaceType3 = "org.test.lifecycle.standard.interfaceType.third";
+ private static final String operationType1 = "createOperation";
+ private static final String operationType2 = "updateOperation";
+ private static final String inputName1 = "Input1";
+ private static final String outputName1 = "Output1";
+ private static final String outputName2 = "Output2";
+
private final InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest =
new InterfaceOperationValidationUtilTest();
private final ListDataDefinition<OperationInputDefinition> operationInputDefinitionList =
new ListDataDefinition<>();
private final ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList =
new ListDataDefinition<>();
+
private Component component;
private ResponseFormatManager responseFormatManagerMock;
@Before
public void setup() {
+
MockitoAnnotations.initMocks(this);
responseFormatManagerMock = Mockito.mock(ResponseFormatManager.class);
when(responseFormatManagerMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
when(responseFormatManagerMock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
when(responseFormatManagerMock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
- component = new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setUniqueId(resourceId)
- .setName(resourceId).build();
- component.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
+ component = new ResourceBuilder()
+ .setComponentType(ComponentTypeEnum.RESOURCE)
+ .setUniqueId(resourceId)
+ .setName(resourceId)
+ .build();
+ component.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType1,
+ operationId, operationType1));
component.setInputs(createInputsForComponent());
}
- private List<InputDefinition> createInputsForComponent() {
- InputDefinition inputDefinition1 = new InputDefinition();
- inputDefinition1.setName(inputId);
- inputDefinition1.setInputId(inputId);
- inputDefinition1.setUniqueId(inputId);
- inputDefinition1.setValue(inputId);
- inputDefinition1.setDefaultValue(inputId);
-
- InputDefinition inputDefinition2 = new InputDefinition();
- inputDefinition2.setName(outputId);
- inputDefinition2.setInputId(outputId);
- inputDefinition2.setUniqueId(outputId);
- inputDefinition2.setValue(outputId);
- inputDefinition2.setDefaultValue(outputId);
-
- return Arrays.asList(inputDefinition1, inputDefinition2);
- }
-
@Test
public void shouldPassOperationValidationForHappyScenario() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "upgrade");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false)
.isLeft());
}
- private InterfaceDefinition createInterfaceOperationData(String uniqueId, String description,
- ArtifactDefinition artifactDefinition, ListDataDefinition<OperationInputDefinition> inputs,
- ListDataDefinition<OperationOutputDefinition> outputs, String name) {
- Operation operation = new Operation();
- operation.setUniqueId(uniqueId);
- operation.setDescription(description);
- operation.setImplementation(artifactDefinition);
- operation.setInputs(inputs);
- operation.setOutputs(outputs);
- operation.setName(name);
- Map<String, Operation> operationMap = new HashMap<>();
- operationMap.put(operation.getUniqueId(), operation);
- InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
- interfaceDefinition.setOperationsMap(operationMap);
- return interfaceDefinition;
- }
-
@Test
public void shouldFailWhenOperationNameIsEmpty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isRight());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isRight());
}
@Test
public void shouldFailWhenOperationNamesAreNotUniqueForCreate() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- InterfaceDefinition interfaceDefinition =
- createInterfaceOperationData(operationId, operationId2, new ArtifactDefinition(),
- operationInputDefinitionList, operationOutputDefinitionList, operationId);
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
+ InterfaceDefinition interfaceDefinition = createInterfaceOperationData(operationId, operationId2,
+ new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList, operationType1);
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isRight());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isRight());
}
@Test
public void shouldNotFailWhenOperationNamesAreNotUniqueForUpdate() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, operationId);
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), true)
- .isLeft());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), true).isLeft());
}
@Test
public void shouldFailWhenOperationNameLengthIsInvalid() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
- operationInputDefinitionList, operationOutputDefinitionList,
+ operationInputDefinitionList,operationOutputDefinitionList,
+
"interface operation2 - The Spring Initializer provides a project generator to make you "
+ "productive with the certain technology stack from the beginning. "
- + "You can create a skeleton project"
- + "with web, data access (relational and NoSQL data stores), "
- + "cloud, or messaging support");
+ + "You can create a "
+ + "skeleton project with web, data access (relational and NoSQL data stores), "
+ + "cloud, "
+ + "or messaging support");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces()
- .get(interfaceId), Collections.emptyMap(), false)
- .isRight());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isRight());
}
@Test
public void shouldFailWhenOperationInputParamNamesAreNotUnique() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(outputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationInputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationInputDefinition(outputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "create");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isRight());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isRight());
}
@Test
public void shouldPassWhenOperationInputParamNamesAreUnique() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(outputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationInputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationInputDefinition(outputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "update");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isLeft());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isLeft());
}
@Test
public void shouldPassWhenOperationInputParamNamesHasSubProperty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "update");
operationInputDefinitionList.getListToscaDataDefinition().get(0).setInputId(
operationInputDefinitionList.getListToscaDataDefinition().get(0).getInputId().concat(".subproperty"));
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isLeft());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isLeft());
}
@Test
public void shouldFailWhenOperationInputParamNameEmpty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(" "));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(" ", 1));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "update");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isRight());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isRight());
}
@Test
public void shouldFailWhenOperationOutputParamNameEmpty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(" "));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "update");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isRight());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isRight());
}
@Test
public void shouldPassWhenInterfaceOperationOutputParamNamesUnique() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(inputName1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "update");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isLeft());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isLeft());
}
@Test
public void shouldFailWhenOperationOutputParamNamesAreNotUnique() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(inputName1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "update");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isRight());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isRight());
}
@Test
public void shouldPassWhenOperationInputParamExistInComponentProperty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "update");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isLeft());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isLeft());
}
@Test
public void shouldFailWhenOperationInputParamDoesntExistInComponentProperty() {
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputId));
- operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(operationId));
- operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputId));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 2));
+ operationOutputDefinitionList
+ .add(InterfaceOperationTestUtils.createMockOperationOutputDefinition(outputName1));
InterfaceDefinition interfaceDefinition =
createInterfaceOperationData(operationId2, operationId2, new ArtifactDefinition(),
operationInputDefinitionList, operationOutputDefinitionList, "update");
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(interfaceDefinition, component,
- component.getInterfaces().get(interfaceId), Collections.emptyMap(), false)
- .isRight());
+ .validateInterfaceOperations(interfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1), Collections.emptyMap(), false).isRight());
}
@Test
public void shouldFailValidateAllowedOperationCountOnLocalInterfaceType() {
InterfaceDefinition inputInterfaceDefinition =
- InterfaceOperationTestUtils.createMockInterface(interfaceId, operationType);
+ InterfaceOperationTestUtils.createMockInterface(interfaceType1
+ , operationId, operationType1);
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(inputInterfaceDefinition, component,
- component.getInterfaces().get(interfaceId),
- InterfaceOperationTestUtils.createMockInterfaceTypeMap(interfaceType,
- operationType),
- false).isRight());
+ .validateInterfaceOperations(inputInterfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1),
+ InterfaceOperationTestUtils.createMockInterfaceTypeMap(
+ interfaceType2, operationType1), false).isRight());
}
@Test
public void shouldFailValidateAllowedOperationsOnGlobalInterfaceType() {
InterfaceDefinition inputInterfaceDefinition =
- InterfaceOperationTestUtils.createMockInterface(interfaceType, operationId);
+ InterfaceOperationTestUtils.createMockInterface(interfaceType1
+ , operationId, operationType1);
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(inputInterfaceDefinition, component,
- component.getInterfaces().get(interfaceId),
- InterfaceOperationTestUtils.createMockInterfaceTypeMap(interfaceType,
- operationType),
- false).isRight());
+ .validateInterfaceOperations(inputInterfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1),
+ InterfaceOperationTestUtils.createMockInterfaceTypeMap(
+ interfaceType1, operationType1), false).isRight());
}
@Test
public void shouldPassValidateAllowedOperationsOnGlobalInterfaceType() {
InterfaceDefinition inputInterfaceDefinition =
- InterfaceOperationTestUtils.createMockInterface(interfaceType, operationType);
+ InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId2, operationType2);
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(inputInterfaceDefinition, component,
- component.getInterfaces().get(interfaceId),
- InterfaceOperationTestUtils.createMockInterfaceTypeMap(interfaceType,
- operationType),
- false).isLeft());
+ .validateInterfaceOperations(inputInterfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1),
+ InterfaceOperationTestUtils.createMockInterfaceTypeMap(
+ interfaceType2, operationType2), false).isLeft());
}
@Test
public void shouldFailValidateOperationNameUniquenessInCollection() {
- InterfaceDefinition inputInterfaceDefinition =
- InterfaceOperationTestUtils.createMockInterface(interfaceType, operationType);
- inputInterfaceDefinition.getOperations()
- .put(operationId, InterfaceOperationTestUtils.createMockOperation(operationType));
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType1,
+ operationId, operationType1);
+ inputInterfaceDefinition.getOperations().put(operationId,
+ createMockOperation(operationId, operationType1));
Assert.assertTrue(interfaceOperationValidationUtilTest
- .validateInterfaceOperations(inputInterfaceDefinition, component,
- component.getInterfaces().get(interfaceId),
- InterfaceOperationTestUtils.createMockInterfaceTypeMap(interfaceType,
- operationType),
- false).isRight());
+ .validateInterfaceOperations(inputInterfaceDefinition, component,
+ component.getInterfaces().get(interfaceType1),
+ InterfaceOperationTestUtils.createMockInterfaceTypeMap(
+ interfaceType1, operationType1), false).isRight());
+ }
+
+ @Test
+ public void shouldPassValidateWhenInputIsMappedToValidOutput() {
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1);
+ inputInterfaceDefinition.getOperationsMap().values()
+ .forEach(operation -> operation.getInputs().getListToscaDataDefinition()
+ .forEach(operationInputDefinition -> operationInputDefinition.setInputId(interfaceType1 +
+ "." + operationType1 + "." + outputName1)));
+ Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition,
+ component, null, Collections.emptyMap(), false).isLeft());
+ }
+
+ @Test
+ public void shouldPassValidateWhenOutputNameIsUnchanged() {
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1);
+ InterfaceDefinition inputParamOutputMappedInterface = InterfaceOperationTestUtils.createMockInterface(
+ interfaceType2, operationId, operationType1);
+ inputParamOutputMappedInterface.getOperationsMap().values()
+ .forEach(operation -> operation.getInputs().getListToscaDataDefinition()
+ .forEach(operationInputDefinition -> operationInputDefinition.setInputId(interfaceType2 +
+ "." + operationType2 + "." + outputName1)));
+ component.getInterfaces().put(interfaceType2, inputParamOutputMappedInterface);
+ component.getInterfaces().put(interfaceType3, InterfaceOperationTestUtils.createMockInterface(interfaceType3,
+ operationId, operationType2));
+ Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition,
+ component, component.getInterfaces().get(interfaceType1),
+ Collections.emptyMap(), true).isLeft());
+ }
+
+ @Test
+ public void shouldPassValidateWhenDeletedOutputIsUnMapped() {
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1);
+ inputInterfaceDefinition.getOperationsMap().values()
+ .forEach(operation -> operation.getOutputs().getListToscaDataDefinition()
+ .forEach(operationOutputDefinition -> operationOutputDefinition.setName(outputName2)));
+ component.getInterfaces().put(interfaceType3, InterfaceOperationTestUtils.createMockInterface(
+ interfaceType3, operationId, operationType2));
+ component.getInterfaces().put(interfaceType2, InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1));
+ Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition,
+ component, component.getInterfaces().get(interfaceType2),
+ Collections.emptyMap(), true).isLeft());
+ }
+
+ @Test
+ public void shouldPassValidateNoOutputsInExistingInterfaceOperation() {
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType1,
+ operationId, operationType1);
+ inputInterfaceDefinition.getOperationsMap().values()
+ .forEach(operation -> operation.getOutputs().getListToscaDataDefinition()
+ .forEach(operationOutputDefinition -> operationOutputDefinition.setName(outputName2)));
+ operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(inputName1, 1));
+ InterfaceDefinition noOutputInterface = createInterfaceOperationData(operationId, "desc",
+ new ArtifactDefinition(), operationInputDefinitionList, null, operationType1);
+ component.getInterfaces().put(interfaceType1, noOutputInterface);
+ component.getInterfaces().put(interfaceType3, InterfaceOperationTestUtils.createMockInterface(
+ interfaceType3, operationId, operationType2));
+ Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition,
+ component, component.getInterfaces().get(interfaceType1),
+ Collections.emptyMap(), true).isLeft());
+ }
+
+ @Test
+ public void shouldFailValidateMappedOutputDoesNotExistInComponent() {
+ //Input parameter is mapped to invalid output (which does not exist in any of the other operations)
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1);
+ inputInterfaceDefinition.getOperationsMap().values()
+ .forEach(operation -> operation.getInputs().getListToscaDataDefinition()
+ .forEach(operationInputDefinition -> operationInputDefinition.setInputId(outputName2)));
+
+ Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition,
+ component, null, Collections.emptyMap(), false).isRight());
+ }
+
+ @Test
+ public void shouldFailValidateComponentFirstInterfaceInvalidInputMapping() {
+ //Input parameter is mapped to invalid output (which does not exist in any of the other operations)
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1);
+ inputInterfaceDefinition.getOperationsMap().values()
+ .forEach(operation -> operation.getInputs().getListToscaDataDefinition()
+ .forEach(operationInputDefinition -> operationInputDefinition.setInputId(outputName2)));
+ component.setInterfaces(null);
+ Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition,
+ component, null, Collections.emptyMap(), false).isRight());
+ }
+
+
+ @Test
+ public void shouldFailValidateMappedOutputDeletion() {
+ //Input interface from user with new output name (Output2)
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1);
+ inputInterfaceDefinition.getOperationsMap().values()
+ .forEach(operation -> operation.getOutputs().getListToscaDataDefinition()
+ .forEach(operationOutputDefinition -> operationOutputDefinition.setName(outputName2)));
+
+ InterfaceDefinition inputParamOutputMappedInterface = InterfaceOperationTestUtils.createMockInterface(
+ interfaceType3, operationId, operationType2);
+ inputParamOutputMappedInterface.getOperationsMap().values()
+ .forEach(operation -> operation.getInputs().getListToscaDataDefinition()
+ .forEach(operationInputDefinition -> operationInputDefinition.setInputId(interfaceType2 +
+ "." + operationType1 + "." + outputName1)));
+ component.getInterfaces().put(interfaceType3, inputParamOutputMappedInterface);
+ component.getInterfaces().put(interfaceType2, InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1));
+ Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition,
+ component, component.getInterfaces().get(interfaceType2),
+ Collections.emptyMap(), true).isRight());
+ }
+
+ @Test
+ public void shouldFailValidateAllMappedOutputsDeleted() {
+ //Input interface from user with all outputs deleted
+ InterfaceDefinition inputInterfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1);
+ Map<String, Operation> operationsMap = inputInterfaceDefinition.getOperationsMap();
+ for (Map.Entry<String, Operation> operationEntry : operationsMap.entrySet()) {
+ operationEntry.getValue().setOutputs(null);
+ }
+ inputInterfaceDefinition.setOperationsMap(operationsMap);
+
+ InterfaceDefinition inputParamOutputMappedInterface = InterfaceOperationTestUtils.createMockInterface(
+ interfaceType3, operationId, operationType2);
+ inputParamOutputMappedInterface.getOperationsMap().values()
+ .forEach(operation -> operation.getInputs().getListToscaDataDefinition()
+ .forEach(operationInputDefinition -> operationInputDefinition.setInputId(interfaceType2 +
+ "." + operationType1 + "." + outputName1)));
+ component.getInterfaces().put(interfaceType3, inputParamOutputMappedInterface);
+ component.getInterfaces().put(interfaceType2, InterfaceOperationTestUtils.createMockInterface(interfaceType2,
+ operationId, operationType1));
+ Assert.assertTrue(interfaceOperationValidationUtilTest.validateInterfaceOperations(inputInterfaceDefinition,
+ component, component.getInterfaces().get(interfaceType2),
+ Collections.emptyMap(), true).isRight());
+ }
+
+
+ private InterfaceDefinition createInterfaceOperationData(String uniqueID, String description,
+ ArtifactDefinition artifactDefinition,
+ ListDataDefinition<OperationInputDefinition> inputs,
+ ListDataDefinition<OperationOutputDefinition> outputs,
+ String name) {
+ Operation operation = new Operation();
+ operation.setUniqueId(uniqueID);
+ operation.setDescription(description);
+ operation.setImplementation(artifactDefinition);
+ operation.setInputs(inputs);
+ operation.setOutputs(outputs);
+ operation.setName(name);
+ Map<String, Operation> operationMap = new HashMap<>();
+ operationMap.put(operation.getUniqueId(), operation);
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType(interfaceType2);
+ interfaceDefinition.setOperationsMap(operationMap);
+ return interfaceDefinition;
+ }
+
+ private List<InputDefinition> createInputsForComponent() {
+ String componentInputName = "ComponentInput1";
+ InputDefinition inputDefinition1 = new InputDefinition();
+ inputDefinition1.setName(componentInputName);
+ inputDefinition1.setInputId(componentInputName + "_inputId");
+ inputDefinition1.setUniqueId(componentInputName + "_uniqueId");
+ inputDefinition1.setValue(componentInputName + "_value");
+ inputDefinition1.setDefaultValue(componentInputName + "_defaultValue");
+
+ String componentInputName2 = "ComponentInput2";
+ InputDefinition inputDefinition2 = new InputDefinition();
+ inputDefinition2.setName(componentInputName2);
+ inputDefinition2.setInputId(componentInputName2 + "_inputId");
+ inputDefinition2.setUniqueId(componentInputName2 + "_uniqueId");
+ inputDefinition2.setValue(componentInputName2 + "_value");
+ inputDefinition2.setDefaultValue(componentInputName2 + "_defaultValue");
+
+ return Arrays.asList(inputDefinition1, inputDefinition2);
}
private class InterfaceOperationValidationUtilTest extends InterfaceOperationValidation {
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 983ef91a8c..36dd5d9796 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
@@ -16,12 +16,20 @@
package org.openecomp.sdc.be.tosca.utils;
+import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.GET_OPERATION_OUTPUT;
+import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.GET_PROPERTY;
+import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
+import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.addInterfaceDefinitionElement;
+import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.addInterfaceTypeElement;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Objects;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -31,15 +39,15 @@ import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.be.tosca.ToscaRepresentation;
-import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
-import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
import org.openecomp.sdc.common.util.YamlToObjectConverter;
@@ -47,6 +55,7 @@ public class InterfacesOperationsToscaUtilTest {
private static final String MAPPED_PROPERTY_NAME = "mapped_property";
private static final String INPUT_NAME_PREFIX = "input_";
+ private static final String OUTPUT_NAME_PREFIX = "output_";
private static final String NODE_TYPE_NAME = "test";
private String[] inputTypes = {"string", "integer", "float", "boolean"};
private static ObjectMapper mapper;
@@ -65,12 +74,12 @@ public class InterfacesOperationsToscaUtilTest {
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("interface.types.test_resource_name");
- addOperationsToInterface(addedInterface, 5, 3, true);
+ addOperationsToInterface(component, addedInterface, 5, 3, true, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
final Map<String, Object> interfaceTypeElement =
- InterfacesOperationsToscaUtil.addInterfaceTypeElement(component, new ArrayList<>());
+ addInterfaceTypeElement(component, new ArrayList<>());
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
ToscaTemplate template = new ToscaTemplate("test");
@@ -87,12 +96,12 @@ public class InterfacesOperationsToscaUtilTest {
component.setNormalizedName("normalizedServiceComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("interface.types.test_service_name");
- addOperationsToInterface(addedInterface, 5, 3, true);
+ addOperationsToInterface(component, addedInterface, 5, 3, true, false);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
final Map<String, Object> interfaceTypeElement =
- InterfacesOperationsToscaUtil.addInterfaceTypeElement(component, new ArrayList<>());
+ addInterfaceTypeElement(component, new ArrayList<>());
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
ToscaTemplate template = new ToscaTemplate("testService");
@@ -110,12 +119,12 @@ public class InterfacesOperationsToscaUtilTest {
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.resource.or.other.resourceName");
- addOperationsToInterface(addedInterface, 3, 2, true);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
- InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
+ addInterfaceDefinitionElement(component, nodeType, false);
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME);
@@ -128,7 +137,7 @@ public class InterfacesOperationsToscaUtilTest {
Assert.assertFalse(mainYaml.contains("operations"));
Assert.assertTrue(mainYaml.contains("resourceName:"));
Assert.assertTrue(mainYaml.contains("inputs:"));
- validateOperationInputs(mainYaml);
+ validateOperationInputs(mainYaml, 2, null);
Assert.assertFalse(mainYaml.contains("defaultp"));
Assert.assertTrue(mainYaml.contains("has description"));
Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME));
@@ -141,12 +150,12 @@ public class InterfacesOperationsToscaUtilTest {
component.setNormalizedName("normalizedServiceComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.service.or.other.serviceName");
- addOperationsToInterface(addedInterface, 3, 2, true);
+ addOperationsToInterface(component, addedInterface, 3, 2, true, false);
final String interfaceType = "normalizedServiceComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
- InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
+ addInterfaceDefinitionElement(component, nodeType, false);
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
ToscaTemplate template = new ToscaTemplate("testService");
@@ -158,7 +167,7 @@ public class InterfacesOperationsToscaUtilTest {
Assert.assertFalse(mainYaml.contains("operations"));
Assert.assertTrue(mainYaml.contains("serviceName:"));
Assert.assertTrue(mainYaml.contains("inputs:"));
- validateOperationInputs(mainYaml);
+ validateOperationInputs(mainYaml, 2, null);
Assert.assertFalse(mainYaml.contains("defaultp"));
Assert.assertTrue(mainYaml.contains("has description"));
Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME));
@@ -171,12 +180,12 @@ public class InterfacesOperationsToscaUtilTest {
component.setNormalizedName("normalizedComponentName");
InterfaceDefinition addedInterface = new InterfaceDefinition();
addedInterface.setType("com.some.resource.or.other.resourceNameNoInputs");
- addOperationsToInterface(addedInterface, 3, 3, false);
+ addOperationsToInterface(component, addedInterface, 3, 3, false, false);
final String interfaceType = "normalizedComponentName-interface";
component.setInterfaces(new HashMap<>());
component.getInterfaces().put(interfaceType, addedInterface);
ToscaNodeType nodeType = new ToscaNodeType();
- InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType, false);
+ addInterfaceDefinitionElement(component, nodeType, false);
ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
ToscaTemplate template = new ToscaTemplate("test");
@@ -193,9 +202,42 @@ public class InterfacesOperationsToscaUtilTest {
Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName"));
}
+ @Test
+ public void addInterfaceDefinitionElementInputMappedToOtherOperationOutput() {
+ String addedInterfaceType = "com.some.resource.or.other.resourceNameInputMappedToOutput";
+ Component component = new Resource();
+ component.setNormalizedName("normalizedComponentName");
+ InterfaceDefinition addedInterface = new InterfaceDefinition();
+ addedInterface.setType(addedInterfaceType);
+ addOperationsToInterface(component, addedInterface, 2, 2, true, true);
+ addedInterface.getOperationsMap().values().stream()
+ .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
+ "name_for_op_0"))
+ .forEach(operation -> operation.getInputs().getListToscaDataDefinition().stream()
+ .filter(operationInputDefinition -> operationInputDefinition.getName().contains("integer"))
+ .forEach(operationInputDefinition -> operationInputDefinition.setInputId(addedInterfaceType +
+ ".name_for_op_1.output_integer_1")));
+ component.setInterfaces(new HashMap<>());
+ component.getInterfaces().put(addedInterfaceType, addedInterface);
+ ToscaNodeType nodeType = new ToscaNodeType();
+ addInterfaceDefinitionElement(component, nodeType, false);
+
+ ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null, null);
+ ToscaTemplate template = new ToscaTemplate("test");
+ Map<String, ToscaNodeType> nodeTypes = new HashMap<>();
+ nodeTypes.put("test", nodeType);
+ template.setNode_types(nodeTypes);
+ final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
+
+ String mainYaml = toscaRepresentation.getMainYaml();
+ Assert.assertFalse(mainYaml.contains("operations"));
+ Assert.assertTrue(mainYaml.contains("resourceNameInputMappedToOutput:"));
+ Assert.assertTrue(mainYaml.contains("inputs:"));
+ validateOperationInputs(mainYaml, 2, "name_for_op_1");
+ }
- private void addOperationsToInterface(InterfaceDefinition addedInterface, int numOfOps, int numOfInputsPerOp,
- boolean hasInputs) {
+ private void addOperationsToInterface(Component component, InterfaceDefinition addedInterface, int numOfOps,
+ int numOfInputsPerOp, boolean hasInputs, boolean hasOutputs) {
addedInterface.setOperations(new HashMap<>());
for (int i = 0; i < numOfOps; i++) {
@@ -206,23 +248,46 @@ public class InterfacesOperationsToscaUtilTest {
implementation.setArtifactName(i + "_createBPMN.bpmn");
operation.setImplementation(implementation);
if (hasInputs) {
- operation.setInputs(createInputs(numOfInputsPerOp));
+ operation.setInputs(createInputs(component, numOfInputsPerOp));
+ }
+ if (hasOutputs) {
+ operation.setOutputs(createOutputs(numOfInputsPerOp));
}
addedInterface.getOperations().put(operation.getName(), operation);
}
}
- private ListDataDefinition<OperationInputDefinition> createInputs(int numOfInputs) {
+ private ListDataDefinition<OperationInputDefinition> createInputs(Component component, int numOfInputs) {
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
for (int i = 0; i < numOfInputs; i++) {
+ String mappedPropertyName = java.util.UUID.randomUUID().toString() + "." + MAPPED_PROPERTY_NAME + i;
operationInputDefinitionList.add(createMockOperationInputDefinition(
- INPUT_NAME_PREFIX + inputTypes[i] + "_" + i,
- java.util.UUID.randomUUID().toString() + "." + MAPPED_PROPERTY_NAME, i));
+ INPUT_NAME_PREFIX + inputTypes[i] + "_" + i, mappedPropertyName, i));
+ addMappedPropertyAsComponentInput(component, mappedPropertyName);
+
}
return operationInputDefinitionList;
}
+ private void addMappedPropertyAsComponentInput(Component component, String mappedPropertyName) {
+ InputDefinition componentInput = new InputDefinition();
+ componentInput.setUniqueId(mappedPropertyName.split("\\.")[0]);
+ componentInput.setName(mappedPropertyName.split("\\.")[1]);
+ if (Objects.isNull(component.getInputs())) {
+ component.setInputs(new ArrayList<>());
+ }
+ component.getInputs().add(componentInput);
+ }
+
+ private ListDataDefinition<OperationOutputDefinition> createOutputs(int numOfOutputs) {
+ ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>();
+ for (int i = 0; i < numOfOutputs; i++) {
+ operationOutputDefinitionList.add(createMockOperationOutputDefinition(
+ OUTPUT_NAME_PREFIX + inputTypes[i] + "_" + i, i));
+ }
+ return operationOutputDefinitionList;
+ }
private OperationInputDefinition createMockOperationInputDefinition(String name, String id, int index) {
OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
@@ -233,31 +298,70 @@ public class InterfacesOperationsToscaUtilTest {
return operationInputDefinition;
}
- private void validateOperationInputs(String mainYaml) {
+ private OperationOutputDefinition createMockOperationOutputDefinition(String name, int index) {
+ OperationOutputDefinition operationInputDefinition = new OperationOutputDefinition();
+ operationInputDefinition.setName(name);
+ operationInputDefinition.setType(inputTypes[index]);
+ operationInputDefinition.setRequired(index % 2 == 0);
+ return operationInputDefinition;
+ }
+
+ private void validateOperationInputs(String mainYaml, int numOfInputsPerOp, String mappedOperationName) {
String nodeTypeKey = NODE_TYPE_NAME + ":";
String nodeTypesRepresentation = mainYaml.substring(mainYaml.indexOf(nodeTypeKey) + nodeTypeKey.length(),
- mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length());
+ mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length()
+ + String.valueOf(numOfInputsPerOp).length());
YamlToObjectConverter objectConverter = new YamlToObjectConverter();
ToscaNodeType toscaNodeType = objectConverter.convert(nodeTypesRepresentation.getBytes(), ToscaNodeType.class);
Map<String, Object> interfaces = toscaNodeType.getInterfaces();
- for (Object interfaceVal : interfaces.values()) {
- Map<String, Object> interfaceDefinition = mapper.convertValue(interfaceVal, Map.class);
- for (Object operationVal : interfaceDefinition.values()) {
+ for (Map.Entry<String, Object> interfaceEntry : interfaces.entrySet()) {
+ Map<String, Object> interfaceDefinition = mapper.convertValue(interfaceEntry.getValue(), Map.class);
+ for (Map.Entry<String, Object> operationEntry : interfaceDefinition.entrySet()) {
+ Object operationVal = operationEntry.getValue();
if (operationVal instanceof Map) {
- validateOperationInputDefinition(operationVal);
+ validateOperationInputDefinition((String) interfaceDefinition.get("type"), mappedOperationName,
+ operationVal);
}
}
}
}
- private void validateOperationInputDefinition(Object operationVal) {
- ToscaLifecycleOperationDefinition operation =
- mapper.convertValue(operationVal, ToscaLifecycleOperationDefinition.class);
- Map<String, ToscaProperty> inputs = operation.getInputs();
- for (Map.Entry<String, ToscaProperty> inputEntry : inputs.entrySet()) {
- Assert.assertEquals(inputEntry.getKey().split("_")[1], inputEntry.getValue().getType());
- Boolean expectedIsRequired = Integer.parseInt(inputEntry.getKey().split("_")[2]) % 2 == 0;
- Assert.assertEquals(expectedIsRequired, inputEntry.getValue().getRequired());
+ private void validateOperationInputDefinition(String interfaceType, String operationName, Object operationVal) {
+ Map<String, Object> operation = mapper.convertValue(operationVal, Map.class);
+ Map<String, Object> inputs = (Map<String, Object>) operation.get("inputs");
+ for (Map.Entry<String, Object> inputEntry : inputs.entrySet()) {
+ String[] inputNameSplit = inputEntry.getKey().split("_");
+ Map<String, Object> inputValueObject = (Map<String, Object>) inputEntry.getValue();
+ Assert.assertEquals(inputNameSplit[1], inputValueObject.get("type"));
+ Boolean expectedIsRequired = Integer.parseInt(inputNameSplit[2]) % 2 == 0;
+ Assert.assertEquals(expectedIsRequired, inputValueObject.get("required"));
+ validateOperationInputDefinitionDefaultValue(interfaceType, operationName, inputNameSplit[1],
+ Integer.parseInt(inputNameSplit[2]), inputValueObject);
+ }
+ }
+
+
+ private void validateOperationInputDefinitionDefaultValue(String interfaceType, String operationName,
+ String inputType, int index,
+ Map<String, Object> inputValueObject) {
+ Map<String, Object> mappedInputValue = (Map<String, Object>) inputValueObject.get("default");
+ if(mappedInputValue.containsKey(GET_PROPERTY)) {
+ String mappedPropertyValue = MAPPED_PROPERTY_NAME + index;
+ List<String> mappedPropertyDefaultValue = (List<String>) mappedInputValue.get(GET_PROPERTY);
+ Assert.assertEquals(2, mappedPropertyDefaultValue.size());
+ Assert.assertTrue(mappedPropertyDefaultValue.contains(SELF));
+ Assert.assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
+ } else if(mappedInputValue.containsKey(GET_OPERATION_OUTPUT)) {
+ List<String> mappedPropertyDefaultValue = (List<String>) mappedInputValue.get(GET_OPERATION_OUTPUT);
+ Assert.assertEquals(4, mappedPropertyDefaultValue.size());
+ String mappedPropertyValue = OUTPUT_NAME_PREFIX + inputType + "_" + index;
+ Assert.assertTrue(mappedPropertyDefaultValue.contains(SELF));
+ Assert.assertTrue(mappedPropertyDefaultValue.contains(interfaceType));
+ Assert.assertTrue(mappedPropertyDefaultValue.contains(operationName));
+ Assert.assertTrue(mappedPropertyDefaultValue.contains(mappedPropertyValue));
+ } else {
+ Assert.fail("Invalid Tosca function in default value. Allowed values: "+ GET_PROPERTY +
+ "/"+ GET_OPERATION_OUTPUT);
}
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
index f21d5a9dcf..c614c6e6e9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java
@@ -18,6 +18,7 @@ package org.openecomp.sdc.test.utils;
import java.util.HashMap;
import java.util.Map;
+
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
@@ -27,17 +28,6 @@ import org.openecomp.sdc.be.model.Operation;
public class InterfaceOperationTestUtils {
- public static Map<String, InterfaceDefinition> createMockInterfaceDefinitionMap(String interfaceId,
- String operationId) {
- Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
- interfaceDefinitionMap.put(interfaceId, createMockInterface(interfaceId, operationId));
- return interfaceDefinitionMap;
- }
-
- public static InterfaceDefinition createMockInterface(String interfaceId, String operationId) {
- return createInterface(interfaceId, interfaceId, interfaceId, interfaceId, createMockOperationMap(operationId));
- }
-
private static InterfaceDefinition createInterface(String uniqueId, String description, String type,
String toscaResourceName, Map<String, Operation> op) {
InterfaceDefinition id = new InterfaceDefinition();
@@ -49,24 +39,37 @@ public class InterfaceOperationTestUtils {
return id;
}
- public static Map<String, Operation> createMockOperationMap(String operationId) {
+ public static Map<String, InterfaceDefinition> createMockInterfaceDefinitionMap(String interfaceId,
+ String operationId,
+ String operationName) {
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
+ interfaceDefinitionMap.put(interfaceId, createMockInterface(interfaceId, operationId, operationName));
+ return interfaceDefinitionMap;
+ }
+
+ public static InterfaceDefinition createMockInterface(String interfaceId, String operationId, String operationName) {
+ return createInterface(interfaceId, interfaceId, interfaceId, interfaceId, createMockOperationMap(operationId,
+ operationName));
+ }
+
+ public static Map<String, Operation> createMockOperationMap(String operationId, String operationName) {
Map<String, Operation> operationMap = new HashMap<>();
- operationMap.put(operationId, createMockOperation(operationId));
+ operationMap.put(operationId, createMockOperation(operationId, operationName));
return operationMap;
}
- public static Operation createMockOperation(String operationId) {
+ public static Operation createMockOperation(String operationId, String operationName) {
Operation operation = new Operation();
ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>();
- operationInputDefinitionList.add(createMockOperationInputDefinition("inputId"));
+ operationInputDefinitionList.add(createMockOperationInputDefinition("Input1", 1));
operation.setInputs(operationInputDefinitionList);
ListDataDefinition<OperationOutputDefinition> operationOutputDefList = new ListDataDefinition<>();
- operationOutputDefList.add(createMockOperationOutputDefinition("outputId"));
+ operationOutputDefList.add(createMockOperationOutputDefinition("Output1"));
operation.setOutputs(operationOutputDefList);
operation.setDefinition(false);
- operation.setName(operationId);
+ operation.setName(operationName);
operation.setUniqueId(operationId);
ArtifactDefinition implementation = new ArtifactDefinition();
implementation.setUniqueId("uniqId");
@@ -77,23 +80,22 @@ public class InterfaceOperationTestUtils {
return operation;
}
- public static OperationInputDefinition createMockOperationInputDefinition(String inputId) {
+ public static OperationInputDefinition createMockOperationInputDefinition(String inputName, int num) {
OperationInputDefinition operationInputDefinition = new OperationInputDefinition();
- operationInputDefinition.setName(inputId);
- operationInputDefinition.setUniqueId(inputId);
- operationInputDefinition.setInputId(inputId);
- operationInputDefinition.setValue(inputId);
- operationInputDefinition.setDefaultValue(inputId);
+ operationInputDefinition.setName(inputName);
+ operationInputDefinition.setUniqueId(inputName + "_uniqueId");
+ operationInputDefinition.setInputId("ComponentInput" + num + "_uniqueId");
+ operationInputDefinition.setValue(inputName + "_value");
+ operationInputDefinition.setDefaultValue(inputName + "_defaultValue");
return operationInputDefinition;
}
- public static OperationOutputDefinition createMockOperationOutputDefinition(String outputId) {
+ public static OperationOutputDefinition createMockOperationOutputDefinition(String outputName) {
OperationOutputDefinition operationOutputDefinition = new OperationOutputDefinition();
- operationOutputDefinition.setName(outputId);
- operationOutputDefinition.setUniqueId(outputId);
- operationOutputDefinition.setInputId(outputId);
- operationOutputDefinition.setValue(outputId);
- operationOutputDefinition.setDefaultValue(outputId);
+ operationOutputDefinition.setName(outputName);
+ operationOutputDefinition.setUniqueId(outputName + "_uniqueId");
+ operationOutputDefinition.setValue(outputName + "_value");
+ operationOutputDefinition.setDefaultValue(outputName + "_defaultValue");
return operationOutputDefinition;
}