Clean CsarUtils::MainYamlWithDependencies 21/109621/4
authorFrancis Toth <francis.toth@yoppworks.com>
Fri, 26 Jun 2020 23:53:26 +0000 (19:53 -0400)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Sun, 5 Jul 2020 07:56:41 +0000 (07:56 +0000)
Signed-off-by: Francis Toth <francis.toth@yoppworks.com>
Change-Id: I593dd7bb6a20445899a14da793e8c550e1e14e09
Issue-ID: SDC-2812

asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/internal/tool/CsarGenerator.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/internal/tool/CsarGeneratorTest.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaRepresentation.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ZipWriter.java
catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaRepresentationTest.java [deleted file]
catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsConverterTest.java

index e21594d..291605e 100644 (file)
@@ -1237,9 +1237,8 @@ public class ArtifactUuidFix {
                                        return Either.right(exportComponent.right().value());
                                }
                                log.debug("Tosca yaml exported for component {} ", parent.getUniqueId());
-                               String payload = exportComponent.left().value().getMainYaml();
 
-                               toscaArtifact.setPayloadData(payload);
+                               toscaArtifact.setPayload(exportComponent.left().value().getMainYaml());
                                byte[] decodedPayload = toscaArtifact.getPayloadData();
 
                                String uniqueId = UniqueIdBuilder.buildPropertyUniqueId(parent.getUniqueId(),
index 8d74ea5..6c5ffb7 100644 (file)
@@ -38,6 +38,7 @@ import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
 import org.openecomp.sdc.be.resources.data.DAOArtifactData;
 import org.openecomp.sdc.be.tosca.CsarUtils;
 import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.openecomp.sdc.be.tosca.ToscaRepresentation;
 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
 import org.openecomp.sdc.common.log.wrappers.Logger;
 import org.openecomp.sdc.common.util.GeneralUtility;
@@ -152,7 +153,7 @@ public class CsarGenerator extends CommonInternalTool {
         return csarUtils.createCsar(component, true, true).either( l -> l, r -> null);
     }
     private byte[] generateToscaPayload(Component component){
-       return toscaExportHandler.exportComponent(component).either(l -> l.getMainYaml().getBytes(), r -> null);
+       return toscaExportHandler.exportComponent(component).either(ToscaRepresentation::getMainYaml, r -> null);
     }
 
     private JanusGraphOperationStatus savePayload(org.openecomp.sdc.be.model.Component component, ArtifactDefinition csarArtifact, Supplier<byte[]> supplier) {
index c297c23..b3bd487 100644 (file)
@@ -95,9 +95,6 @@ public class CsarGeneratorTest {
     @Mock
     private ArtifactDefinition toscaCsar;
 
-    @Mock
-    ToscaRepresentation toscaRepresentation;
-
     private static final String ANSWER = "yes";
     private static final String UUID = "123";
     private static final String UNIQUE_ID = "321";
@@ -235,9 +232,8 @@ public class CsarGeneratorTest {
         when(janusGraphDao.getChildVertex(graphVertex, EdgeLabelEnum.TOSCA_ARTIFACTS,
             JsonParseFlagEnum.ParseJson)).thenReturn(Either.left(graphVertex));
 
-        when(toscaRepresentation.getMainYaml()).thenReturn(PAYLOAD);
         when(toscaExportHandler.exportComponent(component))
-            .thenReturn(Either.left(toscaRepresentation));
+            .thenReturn(Either.left(ToscaRepresentation.make(PAYLOAD.getBytes())));
 
         when(csarUtils.createCsar(component, true, true))
             .thenReturn(Either.left(PAYLOAD.getBytes()));
index d8f8561..cac36cb 100644 (file)
@@ -396,7 +396,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
                 .exportComponent(parent)
                 .left().map(toscaRepresentation -> {
                     log.debug("Tosca yaml exported for component {} ", parent.getUniqueId());
-                    return toscaRepresentation.getMainYaml().getBytes();
+                    return toscaRepresentation.getMainYaml();
                 }).right().map(toscaError -> {
                     log.debug("Failed export tosca yaml for component {} error {}", parent.getUniqueId(), toscaError);
                     return new ByActionStatusComponentException(componentsUtils.convertFromToscaError(toscaError));
index 291d2bb..241148b 100644 (file)
@@ -253,7 +253,7 @@ public class CsarUtils {
             .getToscaArtifacts()
             .get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
 
-        Either<MainYamlWithDependencies, ResponseFormat> toscaRepresentation =
+        Either<ToscaRepresentation, ResponseFormat> toscaRepresentation =
             fetchToscaRepresentation(component, getFromCS, artifactDef);
 
         // This should not be done but in order to keep the refactoring small enough we stop here.
@@ -261,8 +261,8 @@ public class CsarUtils {
         byte[] mainYaml;
         List<Triple<String, String, Component>> dependencies;
         if(toscaRepresentation.isLeft()) {
-            mainYaml = toscaRepresentation.left().value().mainYaml;
-            dependencies = toscaRepresentation.left().value().dependencies.orElse(null);
+            mainYaml = toscaRepresentation.left().value().getMainYaml();
+            dependencies = toscaRepresentation.left().value().getDependencies().getOrElse(new ArrayList<>());
         } else {
             return Either.right(toscaRepresentation.right().value());
         }
@@ -315,7 +315,7 @@ public class CsarUtils {
         return writeAllFilesToCsar(component, collectedComponentCsarDefinition.left().value(), zip, isInCertificationRequest);
     }
 
-    private Either<MainYamlWithDependencies, ResponseFormat> fetchToscaRepresentation(
+    private Either<ToscaRepresentation, ResponseFormat> fetchToscaRepresentation(
         Component component,
         boolean getFromCS,
         ArtifactDefinition artifactDef
@@ -326,14 +326,14 @@ public class CsarUtils {
             !(lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN ||
                 lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
 
-        Either<MainYamlWithDependencies, ResponseFormat> toscaRepresentation =
+        Either<ToscaRepresentation, ResponseFormat> toscaRepresentation =
             shouldBeFetchedFromCassandra ?
                 fetchToscaRepresentation(artifactDef) :
                 generateToscaRepresentation(component);
 
         return toscaRepresentation.left().bind(iff(
-            myd -> !myd.dependencies.isPresent(),
-            myd -> fetchToscaTemplateDependencies(myd.mainYaml, component)
+            myd -> !myd.getDependencies().isDefined(),
+            myd -> fetchToscaTemplateDependencies(myd.getMainYaml(), component)
         ));
     }
 
@@ -341,7 +341,7 @@ public class CsarUtils {
         return l -> p.test(l) ? ifTrue.apply(l) : Either.left(l);
     }
 
-    private Either<MainYamlWithDependencies, ResponseFormat> fetchToscaTemplateDependencies(
+    private Either<ToscaRepresentation, ResponseFormat> fetchToscaTemplateDependencies(
         byte[] mainYml,
         Component component
     ) {
@@ -349,47 +349,21 @@ public class CsarUtils {
             log.debug("Failed to retrieve dependencies for component {}, error {}",
                 component.getUniqueId(), toscaError);
             return componentsUtils.getResponseFormat(componentsUtils.convertFromToscaError(toscaError));
-        }).left().map(tt -> MainYamlWithDependencies.make(mainYml, tt));
+        }).left().map(tt -> ToscaRepresentation.make(mainYml, tt));
     }
 
-    private Either<MainYamlWithDependencies, ResponseFormat> generateToscaRepresentation(Component component) {
+    private Either<ToscaRepresentation, ResponseFormat> generateToscaRepresentation(Component component) {
         return toscaExportUtils.exportComponent(component).right().map(toscaError -> {
-            log.debug("exportComponent failed", toscaError);
+            log.debug("exportComponent failed {}", toscaError);
             return componentsUtils.getResponseFormat(componentsUtils.convertFromToscaError(toscaError));
-        }).left().map(MainYamlWithDependencies::make);
+        });
     }
 
-    private Either<MainYamlWithDependencies, ResponseFormat> fetchToscaRepresentation(ArtifactDefinition artifactDef) {
+    private Either<ToscaRepresentation, ResponseFormat> fetchToscaRepresentation(ArtifactDefinition artifactDef) {
         return getFromCassandra(artifactDef.getEsId()).right().map(as -> {
             log.debug(ARTIFACT_NAME_UNIQUE_ID, artifactDef.getArtifactName(), artifactDef.getUniqueId());
             return componentsUtils.getResponseFormat(as);
-        }).left().map(MainYamlWithDependencies::make);
-    }
-
-    // TODO: Refactor the ToscaRepresentation class in order to remove the following one
-    // This will be done in a separate change
-    private static class MainYamlWithDependencies {
-
-        private final byte[] mainYaml;
-        private final Optional<List<Triple<String, String, Component>>> dependencies;
-
-        private MainYamlWithDependencies(byte[] mainYaml,
-            Optional<List<Triple<String, String, Component>>> dependencies) {
-            this.mainYaml = mainYaml;
-            this.dependencies = dependencies;
-        }
-
-        public static MainYamlWithDependencies make(byte[] mainYaml) {
-            return new MainYamlWithDependencies(mainYaml, Optional.empty());
-        }
-
-        public static MainYamlWithDependencies make(ToscaRepresentation tr) {
-            return new MainYamlWithDependencies(tr.getMainYaml().getBytes(), Optional.ofNullable(tr.getDependencies()));
-        }
-
-        public static MainYamlWithDependencies make(byte[] mainYaml, ToscaTemplate tt) {
-            return new MainYamlWithDependencies(mainYaml, Optional.ofNullable(tt.getDependencies()));
-        }
+        }).left().map(ToscaRepresentation::make);
     }
 
     /**
@@ -686,7 +660,7 @@ public class CsarUtils {
         boolean isAssociatedComponent,
         ZipWriter zw
     ) {
-        Either<String, ToscaError> yml = toscaExportUtils
+        Either<byte[], ToscaError> yml = toscaExportUtils
             .exportComponentInterface(component, isAssociatedComponent)
             .left().map(ToscaRepresentation::getMainYaml);
 
@@ -705,7 +679,7 @@ public class CsarUtils {
         if (cassandraId == null || cassandraId.isEmpty()) {
             return toscaExportUtils.exportComponent(childComponent)
                 .right().map(toscaErrorToActionStatus(childComponent))
-                .left().map(toscaRepresentation -> toscaRepresentation.getMainYaml().getBytes());
+                .left().map(ToscaRepresentation::getMainYaml);
         } else {
             return getFromCassandra(cassandraId);
         }
index a492f01..aa9cd8c 100644 (file)
@@ -170,15 +170,7 @@ public class ToscaExportHandler {
     public ToscaExportHandler(){}
 
     public Either<ToscaRepresentation, ToscaError> exportComponent(Component component) {
-
-        Either<ToscaTemplate, ToscaError> toscaTemplateRes = convertToToscaTemplate(component);
-        if (toscaTemplateRes.isRight()) {
-            return Either.right(toscaTemplateRes.right().value());
-        }
-
-        ToscaTemplate toscaTemplate = toscaTemplateRes.left().value();
-        ToscaRepresentation toscaRepresentation = this.createToscaRepresentation(toscaTemplate);
-        return Either.left(toscaRepresentation);
+        return convertToToscaTemplate(component).left().map(this::createToscaRepresentation);
     }
 
     public Either<ToscaRepresentation, ToscaError> exportComponentInterface(final Component component,
@@ -227,11 +219,7 @@ public class ToscaExportHandler {
         sb.append(yamlAsString);
         sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactFooter());
 
-        ToscaRepresentation toscaRepresentation = new ToscaRepresentation();
-        toscaRepresentation.setMainYaml(sb.toString());
-        toscaRepresentation.setDependencies(toscaTemplate.getDependencies());
-
-        return toscaRepresentation;
+        return ToscaRepresentation.make(sb.toString().getBytes(), toscaTemplate);
     }
 
     public Either<ToscaTemplate, ToscaError> getDependencies(Component component) {
index 49fd91c..1ca9557 100644 (file)
 
 package org.openecomp.sdc.be.tosca;
 
+import io.vavr.control.Option;
+import lombok.Getter;
 import org.apache.commons.lang3.tuple.Triple;
 import org.openecomp.sdc.be.model.Component;
 
 import java.util.List;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
 
 public class ToscaRepresentation {
 
-    private String mainYaml;
-    private List<Triple<String, String, Component>> dependencies;
+    @Getter
+    private final byte[] mainYaml;
 
-    public String getMainYaml() {
-        return mainYaml;
-    }
+    @Getter
+    private final Option<List<Triple<String, String, Component>>> dependencies;
 
-    public void setMainYaml(String mainYaml) {
+    private ToscaRepresentation(byte[] mainYaml, Option<List<Triple<String, String, Component>>> dependencies) {
         this.mainYaml = mainYaml;
+        this.dependencies = dependencies;
     }
 
-    public List<Triple<String, String, Component>> getDependencies() {
-        return dependencies;
+    public static ToscaRepresentation make(byte[] mainYaml) {
+        return new ToscaRepresentation(mainYaml, Option.none());
     }
 
-    public void setDependencies(List<Triple<String, String, Component>> dependancies) {
-        this.dependencies = dependancies;
+    public static ToscaRepresentation make(byte[] mainYaml, List<Triple<String, String, Component>> dependencies) {
+        return new ToscaRepresentation(mainYaml, Option.of(dependencies));
     }
 
+    public static ToscaRepresentation make(byte[] mainYaml, ToscaTemplate tt) {
+        return new ToscaRepresentation(mainYaml, Option.of(tt.getDependencies()));
+    }
 }
index 4740fb2..916895f 100644 (file)
@@ -54,10 +54,14 @@ public interface ZipWriter {
      *
      * @param entryName The entry's name to use in the zip file
      */
-    default Function<String, Try<Void>> write(String entryName) {
+    default Function<String, Try<Void>> writeString(String entryName) {
         return payload -> write(entryName, payload.getBytes());
     }
 
+    default Function<byte[], Try<Void>> write(String entryName) {
+        return payload -> write(entryName, payload);
+    }
+
     /**
      * Builds a ZipWriter that outputs the data on a {@link java.util.zip.ZipOutputStream}
      * @param zos the target {@link java.util.zip.ZipOutputStream}
index 07cf727..4aa967b 100644 (file)
@@ -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 (file)
index 3da1708..0000000
+++ /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);
-       }
-}
index 07ad8d5..93a45ad 100644 (file)
 
 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()