From 5c5d34c913a2d8451061b44a8ee2fec19354316c Mon Sep 17 00:00:00 2001 From: ayalaben Date: Wed, 3 Jan 2018 08:38:27 +0200 Subject: Unit Tests Change-Id: I39ee00e80475aa93b0f99a350b56754c31c6e9b6 Issue-ID: SDC-860 Signed-off-by: ayalaben --- .../utilities/file/FileContentHandlerTest.java | 7 +++- .../dao/ServiceModelDaoFactoryTest.java | 49 ++++++++++------------ 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java index be0686ef5a..2210932669 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java @@ -1,5 +1,6 @@ package org.openecomp.core.utilities.file; +import org.testng.Assert; import org.testng.annotations.Test; import java.io.IOException; @@ -26,7 +27,8 @@ public class FileContentHandlerTest { final byte[] content = new byte[size]; Arrays.fill(content, (byte) 44); contentHandler.addFile(FILE_NAME, content); - assertEquals(contentHandler.processFileContent(FILE_NAME, optional -> { + + byte[] actualContent = contentHandler.processFileContent(FILE_NAME, optional -> { try { byte[] buffer = new byte[size]; @@ -37,7 +39,8 @@ public class FileContentHandlerTest { throw new RuntimeException("Unexpected error", e); } - }), content); + }); + Assert.assertTrue(Arrays.equals(actualContent, content)); } @Test diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java index 418da9a770..74bdeef16e 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java @@ -28,7 +28,6 @@ import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; import com.amdocs.zusammen.commons.health.data.HealthInfo; import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.SessionContext; -import com.amdocs.zusammen.datatypes.UserInfo; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; import com.amdocs.zusammen.datatypes.item.Item; @@ -49,6 +48,8 @@ import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.YamlUtil; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.ByteArrayInputStream; @@ -65,10 +66,15 @@ public class ServiceModelDaoFactoryTest { private static final String baseServiceTemplateName = "baseYaml.yaml"; private static String artifact001; - static { + @BeforeMethod + public void setUp(){ SessionContextProviderFactory.getInstance().createInterface().create("test"); } + @AfterMethod + public void tearDaown(){ + SessionContextProviderFactory.getInstance().createInterface().close(); + } @Test public void storeServiceModelTest() { @@ -85,14 +91,6 @@ public class ServiceModelDaoFactoryTest { serviceModelDaoZusammen.storeServiceModel(vspId, version, model); } - private SessionContext getSessionContext() { - SessionContext context = new SessionContext(); - context.setUser(new UserInfo("USER_A")); - context.setTenant("asdc"); - return context; - } - - @Test public void getServiceModelTest() { @@ -133,14 +131,13 @@ public class ServiceModelDaoFactoryTest { serviceModelElementInfo); zusammenAdaptor.addElement(element); - Object model = + ToscaServiceModel model = serviceModelDaoZusammen.getServiceModel(vspId, version); Assert.assertNotNull(model); - Assert.assertTrue(model instanceof ToscaServiceModel); - if (model instanceof ToscaServiceModel) { - setArtifact((ToscaServiceModel) model); - } + setArtifact(model); + Assert.assertEquals(artifact001,"dataFileName"); + } private static void setArtifact(ToscaServiceModel model) { @@ -173,15 +170,15 @@ public class ServiceModelDaoFactoryTest { Map artifacts = new HashMap<>(); artifacts.put("art1", "this is art1".getBytes()); artifacts.put("art2", ("this is art2 desc:" + CommonMethods.nextUuId()).getBytes()); - artifacts.put("art2", ("this is art3 desc:" + CommonMethods.nextUuId()).getBytes()); - artifacts.put("art2", ("this is art4 desc:" + CommonMethods.nextUuId()).getBytes()); + artifacts.put("art3", ("this is art3 desc:" + CommonMethods.nextUuId()).getBytes()); + artifacts.put("art4", ("this is art4 desc:" + CommonMethods.nextUuId()).getBytes()); FileContentHandler fileContentHandler = new FileContentHandler(); fileContentHandler.putAll(artifacts); return fileContentHandler; } - public ServiceTemplate getServiceTemplate() { + private ServiceTemplate getServiceTemplate() { ServiceTemplate serviceTemplate = new ServiceTemplate(); serviceTemplate.setTosca_definitions_version("version 1.0"); serviceTemplate.setDescription(CommonMethods.nextUuId()); @@ -191,18 +188,18 @@ public class ServiceModelDaoFactoryTest { private class ZusammenAdaptorMock implements ZusammenAdaptor { private ItemVersion itemVersion; - private Map elementInfoMap = new HashMap(); + private Map elementInfoMap = new HashMap<>(); private Collection elements = new ArrayList<>(); - public void setItemVersion(ItemVersion itemVersion) { + private void setItemVersion(ItemVersion itemVersion) { this.itemVersion = itemVersion; } - public void addElementInfo(String key, ElementInfo elementInfo) { + private void addElementInfo(String key, ElementInfo elementInfo) { elementInfoMap.put(key, elementInfo); } - public void addElement(Element element) { + private void addElement(Element element) { elements.add(element); } @@ -225,14 +222,14 @@ public class ServiceModelDaoFactoryTest { @Override public Optional getElement(SessionContext context, ElementContext elementContext, String elementId) { - return null; + return Optional.empty(); } @Override public Optional getElementByName(SessionContext context, ElementContext elementContext, Id parentElementId, String elementName) { - return null; + return Optional.empty(); } @Override @@ -372,7 +369,7 @@ public class ServiceModelDaoFactoryTest { public Optional getElementInfo(SessionContext context, ElementContext elementContext, Id elementId) { - return null; + return Optional.empty(); } @Override @@ -396,7 +393,7 @@ public class ServiceModelDaoFactoryTest { public Optional getElementConflict(SessionContext context, ElementContext elementContext, Id id) { - return null; + return Optional.empty(); } @Override -- cgit 1.2.3-korg