summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-06-26 19:53:26 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-07-05 07:56:41 +0000
commitdf10d0be06468d55818fa734321c14827fef61bb (patch)
treedf383e3c85999c362a965a6851bd625622b2d91b /catalog-be/src/test/java
parent0a6a27ea1abf4fe990ac0b3e204a16dd0aca84c3 (diff)
Clean CsarUtils::MainYamlWithDependencies
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I593dd7bb6a20445899a14da793e8c550e1e14e09 Issue-ID: SDC-2812
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java15
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaRepresentationTest.java79
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java122
3 files changed, 72 insertions, 144 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
index 07cf727a9e..4aa967be47 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
@@ -235,8 +235,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
ByteBuffer bufferData = ByteBuffer.wrap(data);
artifactData.setData(bufferData);
- ToscaRepresentation tosca = new ToscaRepresentation();
- tosca.setMainYaml("value");
+ ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
@@ -322,8 +321,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
dependencies.add(triple);
toscaTemplate.setDependencies(dependencies);
- ToscaRepresentation tosca = new ToscaRepresentation();
- tosca.setMainYaml("value");
+ ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
@@ -438,8 +436,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
dependencies.add(triple);
toscaTemplate.setDependencies(dependencies);
- ToscaRepresentation tosca = new ToscaRepresentation();
- tosca.setMainYaml(new String(contentData, StandardCharsets.UTF_8));
+ ToscaRepresentation tosca = ToscaRepresentation.make(contentData);
Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
@@ -489,8 +486,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
dependencies.add(triple);
toscaTemplate.setDependencies(dependencies);
- ToscaRepresentation tosca = new ToscaRepresentation();
- tosca.setMainYaml(new String(contentData, StandardCharsets.UTF_8));
+ ToscaRepresentation tosca = ToscaRepresentation.make(contentData);
Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
@@ -579,8 +575,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
@Test
public void testWriteComponentInterface() throws IOException {
String fileName = "name.hello";
- ToscaRepresentation tosca = new ToscaRepresentation();
- tosca.setMainYaml("value");
+ ToscaRepresentation tosca = ToscaRepresentation.make("value".getBytes());
Mockito.when(toscaExportUtils.exportComponentInterface(Mockito.any(Component.class), Mockito.any(Boolean.class)))
.thenReturn(Either.left(tosca));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaRepresentationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaRepresentationTest.java
deleted file mode 100644
index 3da170883b..0000000000
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaRepresentationTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.tosca;
-
-import org.apache.commons.lang3.tuple.Triple;
-import org.junit.Test;
-import org.openecomp.sdc.be.model.Component;
-
-import java.util.List;
-
-
-public class ToscaRepresentationTest {
-
- private ToscaRepresentation createTestSubject() {
- return new ToscaRepresentation();
- }
-
-
- @Test
- public void testGetMainYaml() throws Exception {
- ToscaRepresentation testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMainYaml();
- }
-
-
- @Test
- public void testSetMainYaml() throws Exception {
- ToscaRepresentation testSubject;
- String mainYaml = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setMainYaml(mainYaml);
- }
-
-
- @Test
- public void testGetDependencies() throws Exception {
- ToscaRepresentation testSubject;
- List<Triple<String, String, Component>> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDependencies();
- }
-
-
- @Test
- public void testSetDependencies() throws Exception {
- ToscaRepresentation testSubject;
- List<Triple<String, String, Component>> dependencies = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setDependencies(dependencies);
- }
-}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java
index 07ad8d5db9..93a45ad20f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java
@@ -16,9 +16,20 @@
package org.openecomp.sdc.be.tosca.utils;
+import static org.mockito.Mockito.mock;
+import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.SELF;
+import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.addInterfaceTypeElement;
+
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
import org.apache.commons.collections4.MapUtils;
import org.junit.Assert;
import org.junit.Before;
@@ -41,7 +52,6 @@ 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.model.ServiceMetadataDefinition;
-import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.openecomp.sdc.be.tosca.InterfacesOperationsConverter;
import org.openecomp.sdc.be.tosca.PropertyConvertor;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
@@ -49,17 +59,8 @@ import org.openecomp.sdc.be.tosca.ToscaRepresentation;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
import org.openecomp.sdc.common.util.YamlToObjectConverter;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import static org.mockito.Mockito.mock;
-import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.SELF;
-import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.addInterfaceTypeElement;
@RunWith(MockitoJUnitRunner.class)
public class InterfacesOperationsConverterTest {
@@ -109,8 +110,10 @@ public class InterfacesOperationsConverterTest {
template.setInterface_types(interfaceTypeElement);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("NodeTypeName"));
+ Assert.assertTrue(all(
+ containsAll("NodeTypeName"),
+ containsNone("operations")
+ ).apply(new String(toscaRepresentation.getMainYaml())));
}
@Test
@@ -135,8 +138,10 @@ public class InterfacesOperationsConverterTest {
template.setInterface_types(interfaceTypeElement);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("NodeTypeName"));
+ Assert.assertTrue(all(
+ containsAll("NodeTypeName"),
+ containsNone("operations")
+ ).apply(new String(toscaRepresentation.getMainYaml())));
}
@Test
@@ -161,15 +166,13 @@ public class InterfacesOperationsConverterTest {
template.setNode_types(nodeTypes);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- String mainYaml = toscaRepresentation.getMainYaml();
- Assert.assertFalse(mainYaml.contains("operations"));
- Assert.assertTrue(mainYaml.contains("resourceName:"));
- Assert.assertTrue(mainYaml.contains("inputs:"));
+ String mainYaml = new String(toscaRepresentation.getMainYaml());
+ Assert.assertTrue(all(
+ containsAll("resourceName:", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.resource.or.other.resourceName"),
+ containsNone("operations", "defaultp")
+ ).apply(mainYaml));
+
validateOperationInputs(mainYaml, 2, null);
- Assert.assertFalse(mainYaml.contains("defaultp"));
- Assert.assertTrue(mainYaml.contains("has description"));
- Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME));
- Assert.assertTrue(mainYaml.contains("com.some.resource.or.other.resourceName"));
}
@Test
@@ -192,15 +195,12 @@ public class InterfacesOperationsConverterTest {
nodeTypes.put(NODE_TYPE_NAME, nodeType);
template.setNode_types(nodeTypes);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- String mainYaml = toscaRepresentation.getMainYaml();
- Assert.assertFalse(mainYaml.contains("operations"));
- Assert.assertTrue(mainYaml.contains("serviceName:"));
- Assert.assertTrue(mainYaml.contains("inputs:"));
+ String mainYaml = new String(toscaRepresentation.getMainYaml());
+ Assert.assertTrue(all(
+ containsAll("serviceName", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.service.or.other.serviceName"),
+ containsNone("operations", "defaultp")
+ ).apply(mainYaml));
validateOperationInputs(mainYaml, 2, null);
- Assert.assertFalse(mainYaml.contains("defaultp"));
- Assert.assertTrue(mainYaml.contains("has description"));
- Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME));
- Assert.assertTrue(mainYaml.contains("com.some.service.or.other.serviceName"));
}
@@ -226,15 +226,12 @@ public class InterfacesOperationsConverterTest {
template.setNode_types(nodeTypes);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- String mainYaml = toscaRepresentation.getMainYaml();
- Assert.assertFalse(mainYaml.contains("operations"));
- Assert.assertTrue(mainYaml.contains("resourceName:"));
- Assert.assertTrue(mainYaml.contains("inputs:"));
+ String mainYaml = new String(toscaRepresentation.getMainYaml());
+ Assert.assertTrue(all(
+ containsAll("resourceName:", "inputs:", "has description", MAPPED_PROPERTY_NAME, "com.some.resource.or.other.resourceName"),
+ containsNone("operations", "defaultp")
+ ).apply(mainYaml));
validateServiceProxyOperationInputs(mainYaml);
- Assert.assertFalse(mainYaml.contains("defaultp"));
- Assert.assertTrue(mainYaml.contains("has description"));
- Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME));
- Assert.assertTrue(mainYaml.contains("com.some.resource.or.other.resourceName"));
}
@Test
@@ -258,12 +255,10 @@ public class InterfacesOperationsConverterTest {
template.setNode_types(nodeTypes);
final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template);
- Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations"));
- Assert.assertFalse(toscaRepresentation.getMainYaml().contains(INPUT_NAME_PREFIX));
- Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceNameNoInputs:"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description"));
- Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName"));
+ Assert.assertTrue(all(
+ containsAll("resourceNameNoInputs", "has description", "com.some.resource.or.other.resourceName"),
+ containsNone("operations", INPUT_NAME_PREFIX, "defaultp")
+ ).apply(new String(toscaRepresentation.getMainYaml())));
}
@Test
@@ -293,10 +288,11 @@ public class InterfacesOperationsConverterTest {
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:"));
+ String mainYaml = new String(toscaRepresentation.getMainYaml());
+ Assert.assertTrue(all(
+ containsAll("resourceNameInputMappedToOutput:", "inputs:"),
+ containsNone("operations")
+ ).apply(mainYaml));
validateOperationInputs(mainYaml, 2, "name_for_op_1");
}
@@ -342,13 +338,29 @@ public class InterfacesOperationsConverterTest {
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:"));
+ String mainYaml = new String(toscaRepresentation.getMainYaml());
+ Assert.assertTrue(all(
+ containsAll("resourceNameInputMappedToOutput:", "inputs:"),
+ containsNone("operations")
+ ).apply(mainYaml));
validateOperationInputs(mainYaml, 2, "name_for_op_1");
}
+ @FunctionalInterface
+ interface MainYamlAssertion extends Function<String, Boolean> {}
+
+ private static Function<String, Boolean> all(MainYamlAssertion...fs) {
+ return s -> io.vavr.collection.List.of(fs).map(f -> f.apply(s)).fold(true, (l, r) -> l && r);
+ }
+
+ private static MainYamlAssertion containsNone(String...expected) {
+ return s -> io.vavr.collection.List.of(expected).map(e -> !s.contains(e)).fold(true, (l, r) -> l && r);
+ }
+
+ private static MainYamlAssertion containsAll(String...expected) {
+ return s -> io.vavr.collection.List.of(expected).map(s::contains).fold(true, (l, r) -> l && r);
+ }
+
private void addOperationsToInterface(Component component, InterfaceDefinition addedInterface, int numOfOps,
int numOfInputsPerOp, boolean hasInputs, boolean hasOutputs) {
@@ -426,17 +438,17 @@ public class InterfacesOperationsConverterTest {
operationInputDefinition.setName(outputName);
operationInputDefinition.setType(inputTypes[index]);
operationInputDefinition.setRequired(index % 2 == 0);
- Map<String, List<String>> toscaDefaultValueMap = new HashMap<>();
List<String> toscaDefaultValues = new ArrayList<>();
toscaDefaultValues.add(SELF);
toscaDefaultValues.add(interfaceName);
toscaDefaultValues.add(operationName);
toscaDefaultValues.add(outputName);
+ Map<String, List<String>> toscaDefaultValueMap = new HashMap<>();
toscaDefaultValueMap.put(ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName(), toscaDefaultValues);
return operationInputDefinition;
}
- private void validateOperationInputs(String mainYaml, int numOfInputsPerOp, String mappedOperationName) {
+ private void validateOperationInputs(final 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()