Enable selection of base type of service
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / tosca / CsarUtilsTest.java
index 8b1fe5f..ce7a10e 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
 
 package org.openecomp.sdc.be.tosca;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.openecomp.sdc.be.tosca.ComponentCache.MergeStrategy.overwriteIfSameVersions;
+import static org.openecomp.sdc.be.tosca.ComponentCache.entry;
 
+import fj.data.Either;
+import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
-
+import mockit.Deencapsulation;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.ImmutableTriple;
 import org.apache.commons.lang3.tuple.Triple;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.InjectMocks;
@@ -45,37 +67,36 @@ import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.openecomp.sdc.be.components.BeConfDependentTest;
 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
+import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
+import org.openecomp.sdc.be.config.ConfigurationManager;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
 import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
 import org.openecomp.sdc.be.impl.ComponentsUtils;
 import org.openecomp.sdc.be.model.ArtifactDefinition;
 import org.openecomp.sdc.be.model.Component;
 import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
 import org.openecomp.sdc.be.model.LifecycleStateEnum;
 import org.openecomp.sdc.be.model.Resource;
 import org.openecomp.sdc.be.model.Service;
 import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.resources.data.DAOArtifactData;
 import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
+import org.openecomp.sdc.be.tosca.ComponentCache.CacheEntry;
 import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
 import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
 import org.openecomp.sdc.exception.ResponseFormat;
 
-import fj.data.Either;
-import mockit.Deencapsulation;
-
 public class CsarUtilsTest extends BeConfDependentTest {
 
        @InjectMocks
@@ -99,14 +120,33 @@ public class CsarUtilsTest extends BeConfDependentTest {
        @Mock
        private ArtifactsBusinessLogic artifactsBusinessLogic;
 
+       public CsarUtilsTest() throws IOException {
+       }
+
        @Before
        public void setUpMock() throws Exception {
+               ExternalConfiguration.setAppName("catalog-be");
                MockitoAnnotations.initMocks(this);
-               
+               initConfigurationManager();
+       }
+
+       private static void initConfigurationManager() {
+               final String confPath = new File(Objects
+                       .requireNonNull(
+                               CsarUtilsTest.class.getClassLoader().getResource("config/catalog-be/configuration.yaml"))
+                       .getFile()).getParent();
+               final ConfigurationSource confSource =
+                       new FSConfigurationSource(ExternalConfiguration.getChangeListener(), confPath);
+               new ConfigurationManager(confSource);
        }
 
+       private final List<String> nodesFromPackage = Arrays.asList("tosca.nodes.Root", "tosca.nodes.Container.Application");
+
+       private final byte[] contentData = getFileResource("yamlValidation/resource-serviceTemplate.yml");
+
+
        private NonMetaArtifactInfo createNonMetaArtifactInfoTestSubject() {
-               return new CsarUtils.NonMetaArtifactInfo("mock", "mock", ArtifactTypeEnum.AAI_SERVICE_MODEL,
+               return new CsarUtils.NonMetaArtifactInfo("mock", "mock", ArtifactTypeEnum.AAI_SERVICE_MODEL.getType(),
                                ArtifactGroupTypeEnum.DEPLOYMENT, new byte[0], "mock", true);
        }
 
@@ -144,9 +184,10 @@ public class CsarUtilsTest extends BeConfDependentTest {
                component.setToscaArtifacts(toscaArtifacts);
                component.setDeploymentArtifacts(toscaArtifacts);
                component.setArtifacts(toscaArtifacts);
-               ESArtifactData artifactData = new ESArtifactData();
+               DAOArtifactData artifactData = new DAOArtifactData();
                byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
+               ByteBuffer bufferData = ByteBuffer.wrap(data);
+               artifactData.setData(bufferData);
 
                ToscaTemplate toscaTemplate = new ToscaTemplate("version");
                List<Triple<String, String, Component>> dependencies = new ArrayList<>();
@@ -172,12 +213,6 @@ public class CsarUtilsTest extends BeConfDependentTest {
                testSubject.createCsar(component, false, true);
        }
 
-       @Test
-       public void testGenerateCsarZipThrowsIOException() {
-
-               Deencapsulation.invoke(testSubject, "generateCsarZip", new byte[]{},new  byte[]{}, new Resource(), true, false);
-       }
-
        @Test
        public void testPopulateZipWhenGetDependenciesIsRight() {
                Component component = new Service();
@@ -195,12 +230,12 @@ public class CsarUtilsTest extends BeConfDependentTest {
                component.setDeploymentArtifacts(toscaArtifacts);
                component.setArtifacts(toscaArtifacts);
                component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
-               ESArtifactData artifactData = new ESArtifactData();
+               DAOArtifactData artifactData = new DAOArtifactData();
                byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
+               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));
 
@@ -233,9 +268,10 @@ public class CsarUtilsTest extends BeConfDependentTest {
                component.setDeploymentArtifacts(toscaArtifacts);
                component.setArtifacts(toscaArtifacts);
                component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
-               ESArtifactData artifactData = new ESArtifactData();
+               DAOArtifactData artifactData = new DAOArtifactData();
                byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
+               ByteBuffer bufferData = ByteBuffer.wrap(data);
+               artifactData.setData(bufferData);
 
                Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class)))
                                .thenReturn(Either.right(ToscaError.GENERAL_ERROR));
@@ -270,13 +306,13 @@ public class CsarUtilsTest extends BeConfDependentTest {
                component.setVersion("1.0");
                component.setLastUpdaterUserId("userId");
                component.setUniqueId("uid");
-               ESArtifactData artifactData = new ESArtifactData();
-               byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
+               DAOArtifactData artifactData = new DAOArtifactData();
+               ByteBuffer bufferData = ByteBuffer.wrap(contentData);
+               artifactData.setData(bufferData);
 
                List<SdcSchemaFilesData> filesData = new ArrayList<>();
                SdcSchemaFilesData filedata = new SdcSchemaFilesData();
-               filedata.setPayloadAsArray(data);
+               filedata.setPayloadAsArray(contentData);
                filesData.add(filedata);
 
                ToscaTemplate toscaTemplate = new ToscaTemplate("version");
@@ -285,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));
 
@@ -302,15 +337,15 @@ public class CsarUtilsTest extends BeConfDependentTest {
                Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
                                .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
 
-               Mockito.when(artifactsBusinessLogic.validateUserExists(Mockito.any(String.class), Mockito.any(String.class),
-                               Mockito.any(Boolean.class))).thenReturn(new User());
+               Mockito.when(artifactsBusinessLogic.validateUserExists(Mockito.any(User.class))).thenReturn(new User());
+
 
                Mockito.when(artifactsBusinessLogic.validateAndHandleArtifact(Mockito.any(String.class),
                                Mockito.any(ComponentTypeEnum.class), Mockito.any(ArtifactOperationInfo.class), Mockito.isNull(),
                                Mockito.any(ArtifactDefinition.class), Mockito.any(String.class), Mockito.any(String.class),
                                Mockito.isNull(), Mockito.isNull(), Mockito.any(User.class), Mockito.any(Component.class),
                                Mockito.any(Boolean.class), Mockito.any(Boolean.class), Mockito.any(Boolean.class)))
-                               .thenReturn(Either.left(Mockito.any(Either.class)));
+                               .thenReturn(Either.left(Mockito.any(ArtifactDefinition.class)));
 
                try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
                        Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
@@ -342,9 +377,10 @@ public class CsarUtilsTest extends BeConfDependentTest {
                component.setVersion("1.0");
                component.setLastUpdaterUserId("userId");
                component.setUniqueId("uid");
-               ESArtifactData artifactData = new ESArtifactData();
+               DAOArtifactData artifactData = new DAOArtifactData();
                byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
+               ByteBuffer bufferData = ByteBuffer.wrap(data);
+               artifactData.setData(bufferData);
 
                ToscaTemplate toscaTemplate = new ToscaTemplate("version");
                List<Triple<String, String, Component>> dependencies = new ArrayList<>();
@@ -390,9 +426,9 @@ public class CsarUtilsTest extends BeConfDependentTest {
                component.setVersion("1.0");
                component.setLastUpdaterUserId("userId");
                component.setUniqueId("uid");
-               ESArtifactData artifactData = new ESArtifactData();
-               byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
+               DAOArtifactData artifactData = new DAOArtifactData();
+               ByteBuffer bufferData = ByteBuffer.wrap(contentData);
+               artifactData.setData(bufferData);
 
                ToscaTemplate toscaTemplate = new ToscaTemplate("version");
                List<Triple<String, String, Component>> dependencies = new ArrayList<>();
@@ -400,8 +436,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
                dependencies.add(triple);
                toscaTemplate.setDependencies(dependencies);
 
-               ToscaRepresentation tosca = new ToscaRepresentation();
-               tosca.setMainYaml("value");
+               ToscaRepresentation tosca = ToscaRepresentation.make(contentData);
 
                Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
 
@@ -441,9 +476,9 @@ public class CsarUtilsTest extends BeConfDependentTest {
                component.setVersion("1.0");
                component.setLastUpdaterUserId("userId");
                component.setUniqueId("uid");
-               ESArtifactData artifactData = new ESArtifactData();
-               byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
+               DAOArtifactData artifactData = new DAOArtifactData();
+               ByteBuffer bufferData = ByteBuffer.wrap(contentData);
+               artifactData.setData(bufferData);
 
                ToscaTemplate toscaTemplate = new ToscaTemplate("version");
                List<Triple<String, String, Component>> dependencies = new ArrayList<>();
@@ -451,8 +486,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
                dependencies.add(triple);
                toscaTemplate.setDependencies(dependencies);
 
-               ToscaRepresentation tosca = new ToscaRepresentation();
-               tosca.setMainYaml("value");
+               ToscaRepresentation tosca = ToscaRepresentation.make(contentData);
 
                Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
 
@@ -472,150 +506,9 @@ public class CsarUtilsTest extends BeConfDependentTest {
                }
        }
 
-       @Test
-       public void testPopulateZipWhenAddSchemaFilesFromCassandraIsRight() {
-               Component component = new Service();
-               boolean getFromCS = false;
-
-               Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
-               ArtifactDefinition artifact = new ArtifactDefinition();
-               artifact.setArtifactName("artifactName");
-               artifact.setEsId("esId");
-               artifact.setArtifactUUID("artifactUUID");
-               artifact.setArtifactType("YANG");
-               artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
-               artifact.setDescription("description");
-               artifact.setArtifactLabel("artifactLabel");
-               toscaArtifacts.put("assettoscatemplate", artifact);
-
-               component.setToscaArtifacts(toscaArtifacts);
-               component.setDeploymentArtifacts(toscaArtifacts);
-               component.setArtifacts(toscaArtifacts);
-               component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
-               component.setVersion("1.0");
-               component.setLastUpdaterUserId("userId");
-               component.setUniqueId("uid");
-               ESArtifactData artifactData = new ESArtifactData();
-               byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
-
-               ToscaTemplate toscaTemplate = new ToscaTemplate("version");
-               List<Triple<String, String, Component>> dependencies = new ArrayList<>();
-               Triple<String, String, Component> triple = Triple.of("fileName", "", component);
-               dependencies.add(triple);
-               toscaTemplate.setDependencies(dependencies);
-
-               ToscaRepresentation tosca = new ToscaRepresentation();
-               tosca.setMainYaml("value");
-
-               List<SdcSchemaFilesData> schemaList = new ArrayList<>();
-               SdcSchemaFilesData schemaData = new SdcSchemaFilesData();
-               schemaData.setPayloadAsArray(null);
-               schemaList.add(schemaData);
-
-               Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
-
-               Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
-
-               Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
-                               .thenReturn(Either.left(toscaTemplate));
-
-               Mockito.when(
-                               sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
-                               .thenReturn(Either.left(schemaList));
-
-               try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
-                       Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
-       @Test
-       public void testPopulateZipWhenHandleAllAAIArtifactsInDataModelIsRight() {
-               Component component = new Service();
-               boolean getFromCS = false;
-
-               Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
-               ArtifactDefinition artifact = new ArtifactDefinition();
-               artifact.setArtifactName("artifactName");
-               artifact.setEsId("esId");
-               artifact.setArtifactUUID("artifactUUID");
-               artifact.setArtifactType("YANG");
-               artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
-               artifact.setDescription("description");
-               artifact.setArtifactLabel("artifactLabel");
-               toscaArtifacts.put("assettoscatemplate", artifact);
-
-               component.setToscaArtifacts(toscaArtifacts);
-               component.setDeploymentArtifacts(toscaArtifacts);
-               component.setArtifacts(toscaArtifacts);
-               component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
-               component.setVersion("1.0");
-               component.setLastUpdaterUserId("userId");
-               component.setUniqueId("uid");
-               ESArtifactData artifactData = new ESArtifactData();
-               byte[] data = "value".getBytes();
-               artifactData.setDataAsArray(data);
-
-               ToscaTemplate toscaTemplate = new ToscaTemplate("version");
-               List<Triple<String, String, Component>> dependencies = new ArrayList<>();
-               Triple<String, String, Component> triple = Triple.of("fileName", "", component);
-               dependencies.add(triple);
-               toscaTemplate.setDependencies(dependencies);
-
-               ToscaRepresentation tosca = new ToscaRepresentation();
-               tosca.setMainYaml("value");
-
-               List<SdcSchemaFilesData> schemaList = new ArrayList<>();
-               SdcSchemaFilesData schemaData = new SdcSchemaFilesData();
-               schemaData.setPayloadAsArray(data);
-               schemaList.add(schemaData);
-
-               Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class))).thenReturn(Either.left(artifactData));
-
-               Mockito.when(toscaExportUtils.exportComponent(Mockito.any(Component.class))).thenReturn(Either.left(tosca));
-
-               Mockito.when(toscaExportUtils.getDependencies(Mockito.any(Component.class)))
-                               .thenReturn(Either.left(toscaTemplate));
-
-               Mockito.when(
-                               sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
-                               .thenReturn(Either.left(schemaList));
-
-               Mockito.when(artifactsBusinessLogic.validateUserExists(Mockito.any(String.class), Mockito.any(String.class),
-                               Mockito.any(Boolean.class))).thenReturn(new User());
-
-               try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
-                       Deencapsulation.invoke(testSubject, "populateZip", component, getFromCS, zip, true);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
-       @Test
-       public void testAddSchemaFilesFromCassandra() {
-               try (ByteArrayOutputStream out = new ByteArrayOutputStream();
-                               ZipOutputStream zip = new ZipOutputStream(out);
-                               ByteArrayOutputStream outMockStream = new ByteArrayOutputStream();
-                               ZipOutputStream outMock = new ZipOutputStream(outMockStream);) {
-
-                       outMock.putNextEntry(new ZipEntry("mock1"));
-                       outMock.write(new byte[1]);
-                       outMock.putNextEntry(new ZipEntry("mock2"));
-                       outMock.write(new byte[3]);
-                       outMock.close();
-                       byte[] byteArray = outMockStream.toByteArray();
-                       Deencapsulation.invoke(testSubject, "addSchemaFilesFromCassandra", zip, byteArray);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-
-       }
-
        @Test
        public void testAddInnerComponentsToCache() {
-               Map<String, ImmutableTriple<String, String, Component>> componentCache = new HashMap<>();
+               ComponentCache componentCache = ComponentCache.overwritable(overwriteIfSameVersions());
                Component childComponent = new Resource();
                Component componentRI = new Service();
                List<ComponentInstance> componentInstances = new ArrayList<>();
@@ -641,6 +534,9 @@ public class CsarUtilsTest extends BeConfDependentTest {
                                .thenReturn(Either.left(componentRI));
 
                Deencapsulation.invoke(testSubject, "addInnerComponentsToCache", componentCache, childComponent);
+
+               io.vavr.collection.List<CacheEntry> expected = io.vavr.collection.List.of(entry("esId","artifactName",componentRI));
+               assertEquals(expected, componentCache.all().toList());
        }
 
        @Test
@@ -650,6 +546,7 @@ public class CsarUtilsTest extends BeConfDependentTest {
 
                List<ComponentInstance> componentInstances = new ArrayList<>();
                ComponentInstance instance = new ComponentInstance();
+               instance.setComponentUid("abc");
                componentInstances.add(instance);
                childComponent.setComponentInstances(componentInstances);
 
@@ -671,41 +568,24 @@ public class CsarUtilsTest extends BeConfDependentTest {
                Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class)))
                                .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
 
-               Deencapsulation.invoke(testSubject, "addInnerComponentsToCache", componentCache, childComponent);
-       }
 
-       @Test
-       public void testAddComponentToCache() {
-               Map<String, ImmutableTriple<String, String, Component>> componentCache = new HashMap<>();
-               String id = "id";
-               String fileName = "fileName";
-               Component component = new Resource();
-               component.setInvariantUUID("key");
-               component.setVersion("1.0");
-
-               Component cachedComponent = new Resource();
-               cachedComponent.setVersion("0.3");
-
-               componentCache.put("key", new ImmutableTriple<String, String, Component>(id, fileName, cachedComponent));
-
-               Deencapsulation.invoke(testSubject, "addComponentToCache", componentCache, id, fileName, component);
+               assertTrue(componentCache.isEmpty());
        }
 
        @Test
-       public void testWriteComponentInterface() {
+       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));
 
-               try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
-                       Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName, false);
-               } catch (IOException e) {
-                       e.printStackTrace();
-               }
 
+               try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
+                   List<Triple<String, String, Component>> output = Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName, false);
+
+                       assertNotNull(output);
+               }
        }
 
        @Test
@@ -716,7 +596,10 @@ public class CsarUtilsTest extends BeConfDependentTest {
                Mockito.when(artifactCassandraDao.getArtifact(Mockito.any(String.class)))
                                .thenReturn(Either.right(CassandraOperationStatus.GENERAL_ERROR));
 
-               Deencapsulation.invoke(testSubject, "getEntryData", cassandraId, childComponent);
+               Either<byte[], ActionStatus> output = Deencapsulation.invoke(testSubject, "getEntryData", cassandraId, childComponent);
+
+               assertNotNull(output);
+               assertTrue(output.isRight());
        }
 
        @Test
@@ -726,18 +609,26 @@ public class CsarUtilsTest extends BeConfDependentTest {
                Mockito.when(
                                sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(Mockito.any(String.class), Mockito.any(String.class)))
                                .thenReturn(Either.left(filesData));
-               Deencapsulation.invoke(testSubject, "getLatestSchemaFilesFromCassandra");
+
+               Either<byte[], ResponseFormat> output = Deencapsulation.invoke(testSubject, "getLatestSchemaFilesFromCassandra");
+
+               assertNotNull(output);
+               assertTrue(output.isRight());
        }
 
        @Test
        public void testExtractVfcsArtifactsFromCsar() {
-               String key = "Artifacts/org.openecomp.resource.some/path/to/resource";
+               String key = "Artifacts/org.openecomp.resource.some/Deployment/to/resource";
                byte[] data = "value".getBytes();
 
                Map<String, byte[]> csar = new HashMap<>();
                csar.put(key, data);
 
-               CsarUtils.extractVfcsArtifactsFromCsar(csar);
+               Map<String, List<ArtifactDefinition>> output = CsarUtils.extractVfcsArtifactsFromCsar(csar);
+
+               assertNotNull(output);
+               assertTrue(output.containsKey("org.openecomp.resource.some"));
+               assertEquals(1, output.get("org.openecomp.resource.some").size());
        }
 
        @Test
@@ -748,6 +639,8 @@ public class CsarUtilsTest extends BeConfDependentTest {
                artifacts.put("key", new ArrayList<>());
 
                Deencapsulation.invoke(testSubject, "addExtractedVfcArtifact", extractedVfcArtifact, artifacts);
+
+               assertEquals(1, artifacts.get("key").size());
        }
 
        @Test
@@ -758,6 +651,10 @@ public class CsarUtilsTest extends BeConfDependentTest {
                artifacts.put("key1", new ArrayList<>());
 
                Deencapsulation.invoke(testSubject, "addExtractedVfcArtifact", extractedVfcArtifact, artifacts);
+
+               assertEquals(0, artifacts.get("key1").size());
+               assertEquals(1, artifacts.get("key").size());
+               assertEquals(2, artifacts.size());
        }
 
        @Test
@@ -767,12 +664,23 @@ public class CsarUtilsTest extends BeConfDependentTest {
                map.put(path, "value".getBytes());
                Entry<String, byte[]> entry = map.entrySet().iterator().next();
 
-               Deencapsulation.invoke(testSubject, "extractVfcArtifact", entry, new HashMap<>());
+               Optional<ImmutablePair<String, ArtifactDefinition>> output =
+                       Deencapsulation.invoke(testSubject, "extractVfcArtifact", entry, new HashMap<>());
+
+               if(output.isPresent()) {
+                       assertEquals("to", output.get().left);
+               } else {
+                       fail("`output` is empty!");
+               }
        }
 
        @Test
        public void testDetectArtifactGroupTypeWithExceptionBeingCaught() {
-               Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", Map.class);
+               Either<ArtifactGroupTypeEnum, Boolean> output = Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", Map.class);
+
+               assertNotNull(output);
+               assertTrue(output.isRight());
+               assertFalse(output.right().value());
        }
 
        @Test
@@ -780,7 +688,11 @@ public class CsarUtilsTest extends BeConfDependentTest {
                Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
 
                collectedWarningMessages.put("Warning - unrecognized artifact group type {} was received.", new HashSet<>());
-               Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", collectedWarningMessages);
+               Either<ArtifactGroupTypeEnum, Boolean> output = Deencapsulation.invoke(testSubject, "detectArtifactGroupType", "type", collectedWarningMessages);
+
+               assertNotNull(output);
+               assertTrue(output.isRight());
+               assertFalse(output.right().value());
        }
 
        @Test
@@ -804,9 +716,9 @@ public class CsarUtilsTest extends BeConfDependentTest {
 
        @Test
        public void testNonMetaArtifactInfoGetArtifactType() {
-               NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
-
-               testSubject.getArtifactType();
+               final NonMetaArtifactInfo testSubject = createNonMetaArtifactInfoTestSubject();
+               assertThat("The artifact type should be as expected",
+                       testSubject.getArtifactType(), is(ArtifactTypeEnum.AAI_SERVICE_MODEL.getType()));
        }
 
        @Test
@@ -870,24 +782,6 @@ public class CsarUtilsTest extends BeConfDependentTest {
                CsarUtils.validateNonMetaArtifact("", new byte[0], new HashMap<>());
        }
 
-       @Test
-       public void testWriteArtifactDefinition() {
-               Component component = new Service();
-               List<ArtifactDefinition> artifactDefinitionList = new ArrayList<>();
-               String artifactPathAndFolder = "";
-
-               ArtifactDefinition artifact = new ArtifactDefinition();
-               artifact.setArtifactType(ArtifactTypeEnum.HEAT_ENV.getType());
-               artifactDefinitionList.add(artifact);
-
-               try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out);) {
-                       Deencapsulation.invoke(testSubject, "writeArtifactDefinition", component, zip, artifactDefinitionList,
-                                       artifactPathAndFolder, false);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
        @Test
        public void testCollectComponentCsarDefinitionWhenComponentIsServiceAndGetToscaElementIsLeft() {
                Component component = new Service();
@@ -914,8 +808,10 @@ public class CsarUtilsTest extends BeConfDependentTest {
                Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
                                Either.right(StorageOperationStatus.BAD_REQUEST));
 
-               Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
+               Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
 
+               assertNotNull(output);
+               assertTrue(output.isRight());
        }
 
        @Test
@@ -950,7 +846,10 @@ public class CsarUtilsTest extends BeConfDependentTest {
                Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
                                Either.left(fetchedComponent), Either.right(StorageOperationStatus.BAD_REQUEST));
 
-               Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
+               Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
+
+               assertNotNull(output);
+               assertTrue(output.isRight());
        }
 
        @Test
@@ -987,7 +886,10 @@ public class CsarUtilsTest extends BeConfDependentTest {
                Mockito.when(toscaOperationFacade.getToscaElement(Mockito.any(String.class))).thenReturn(Either.left(component),
                                Either.left(fetchedComponent));
 
-               Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
+               Either<Object, ResponseFormat> output = Deencapsulation.invoke(testSubject, "collectComponentCsarDefinition", component);
+
+               assertNotNull(output);
+               assertTrue(output.isLeft());
        }
 
        @Test
@@ -1033,4 +935,49 @@ public class CsarUtilsTest extends BeConfDependentTest {
                assertTrue(eitherNonMetaArtifact.isRight());
                assertTrue(!collectedWarningMessages.isEmpty());
        }
+
+       @Test(expected = IOException.class)
+       public void testAddSchemaFilesFromCassandraAddingDuplicatedEntry() throws IOException {
+               final String rootPath = System.getProperty("user.dir");
+               final Path path = Paths.get(rootPath + "/src/test/resources/sdc.zip");
+               try {
+                       final byte[] data = Files.readAllBytes(path);
+                       try (final ByteArrayOutputStream out = new ByteArrayOutputStream();
+                               final ZipOutputStream zip = new ZipOutputStream(out);) {
+                               Deencapsulation.invoke(testSubject, "addSchemaFilesFromCassandra",
+                                       zip, data, nodesFromPackage);
+                               zip.putNextEntry(new ZipEntry("Definitions/nodes.yml"));
+                               zip.finish();
+                       }
+               } catch (final IOException e) {
+                       Assert.assertTrue("duplicate entry: Definitions/nodes.yml".equals(e.getMessage()));
+                       throw new IOException("Could not add Schema Files From Cassandra", e);
+               }
+       }
+
+       @Test
+       public void testFindNonRootNodesFromPackage() {
+               final Resource resource = new Resource();
+               resource.setDerivedList(nodesFromPackage);
+               final Component component = resource;
+               final List<Triple<String, String, Component>> dependencies = new ArrayList<>();
+               final Triple<String, String, Component> triple = Triple.of("fileName", "cassandraId", component);
+               dependencies.add(triple);
+               final List<String> expectedResult = Arrays.asList("tosca.nodes.Container.Application");
+               final List<String> result = Deencapsulation.invoke(testSubject,
+                       "findNonRootNodesFromPackage", dependencies);
+               assertTrue(CollectionUtils.isNotEmpty(result));
+               assertEquals(expectedResult, result);
+       }
+
+    private byte[] getFileResource(final String filePath) throws IOException {
+        try (final InputStream inputStream = getFileResourceAsInputStream(filePath)) {
+            return IOUtils.toByteArray(inputStream);
+        }
+    }
+
+    private InputStream getFileResourceAsInputStream(final String filePath) {
+        return Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
+    }
+
 }