diff options
author | 2018-04-21 16:18:37 +0530 | |
---|---|---|
committer | 2018-04-26 17:47:29 +0530 | |
commit | 3de22e1c6c2711072ce996335e7250445a39d320 (patch) | |
tree | c7a528bee3166b3262eef9977b0f87923df0e99f /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org | |
parent | d71a8de8c7b688eabb250e524dc4f6000b3233b6 (diff) |
Reducing onboarding backend maven build time
Reducing onboarding backend maven build time
Change-Id: Id0178cbf010e46f741f4bff11e14b0801f14d4b8
Issue-ID: SDC-1189
Signed-off-by: GAUTAMS <gautams@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org')
1 files changed, 109 insertions, 115 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseFullTranslationTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseFullTranslationTest.java index 2387390df9..801f2c67a0 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseFullTranslationTest.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseFullTranslationTest.java @@ -18,11 +18,22 @@ package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslati import static org.junit.Assert.assertEquals; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import org.apache.commons.collections4.MapUtils; import org.junit.Assert; import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.rules.TestName; import org.openecomp.core.translator.api.HeatToToscaTranslator; import org.openecomp.core.translator.datatypes.TranslatorOutput; import org.openecomp.core.translator.factory.HeatToToscaTranslatorFactory; @@ -39,133 +50,116 @@ import org.openecomp.sdc.translator.TestUtils; import org.togglz.testing.TestFeatureManager; import org.togglz.testing.TestFeatureManagerProvider; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - public class BaseFullTranslationTest { - public static final String IN_POSTFIX = "/in"; - public static final String OUT_POSTFIX = "/out"; - - @Rule - public TestName name = new TestName(); - - protected static TestFeatureManager manager; - private static File tempDir = new File(System.getProperty("java.io.tmpdir")); - - @BeforeClass - public static void enableToggleableFeatures(){ - manager = new TestFeatureManager(ToggleableFeature.class); - manager.enableAll(); - TestFeatureManagerProvider.setFeatureManager(manager); - } - - - public static void disableToggleableFeatures() { - manager.disableAll(); - manager = null; - TestFeatureManagerProvider.setFeatureManager(null); - } - - protected void testTranslationWithInit(String path) throws IOException { - byte[] translatedZipFile = initTranslatorAndTranslate(path); - testTranslation(path, translatedZipFile); - } - - protected byte[] initTranslatorAndTranslate(String path) throws IOException { - HeatToToscaTranslator heatToToscaTranslator = HeatToToscaTranslatorFactory.getInstance().createInterface(); - return translateZipFile(path, heatToToscaTranslator); - } - - protected void testTranslation(String basePath, byte[] translatedZipFile) throws IOException { - - URL url = BaseFullTranslationTest.class.getResource(basePath + OUT_POSTFIX); - Set<String> expectedResultFileNameSet = new HashSet<>(); - Map<String, byte[]> expectedResultMap = new HashMap<>(); - - String path = url.getPath(); - File pathFile = new File(path); - File[] files = pathFile.listFiles(); - Assert.assertNotNull("manifest files is empty", files); - for (File expectedFile : files) { - expectedResultFileNameSet.add(expectedFile.getName()); - try (FileInputStream input = new FileInputStream(expectedFile)) { - expectedResultMap.put(expectedFile.getName(), FileUtils.toByteArray(input)); - } + public static final String IN_POSTFIX = "/in"; + public static final String OUT_POSTFIX = "/out"; + + + protected static TestFeatureManager manager; + + @BeforeClass + public static void enableToggleableFeatures() { + manager = new TestFeatureManager(ToggleableFeature.class); + manager.enableAll(); + TestFeatureManagerProvider.setFeatureManager(manager); } - try (ByteArrayInputStream fis = new ByteArrayInputStream(translatedZipFile);BufferedInputStream bis = new BufferedInputStream(fis); - ZipInputStream zis = new ZipInputStream(bis)) { - ZipEntry entry; - String name; - String expected; - String actual; - while ((entry = zis.getNextEntry()) != null) { + public static void disableToggleableFeatures() { + manager.disableAll(); + manager = null; + TestFeatureManagerProvider.setFeatureManager(null); + } - name = entry.getName() - .substring(entry.getName().lastIndexOf(File.separator) + 1, entry.getName().length()); - if (expectedResultFileNameSet.contains(name)) { - expected = new String(expectedResultMap.get(name)).trim().replace("\r", ""); - actual = new String(FileUtils.toByteArray(zis)).trim().replace("\r", ""); - assertEquals("difference in file: " + name, expected, actual); + protected void testTranslationWithInit(String path) throws IOException { + byte[] translatedZipFile = initTranslatorAndTranslate(path); + testTranslation(path, translatedZipFile); + } - expectedResultFileNameSet.remove(name); - } - } - if (expectedResultFileNameSet.isEmpty()) { - expectedResultFileNameSet.forEach(System.out::println); - } + protected byte[] initTranslatorAndTranslate(String path) throws IOException { + HeatToToscaTranslator heatToToscaTranslator = HeatToToscaTranslatorFactory.getInstance().createInterface(); + return translateZipFile(path, heatToToscaTranslator); } - assertEquals(0, expectedResultFileNameSet.size()); - } - - private byte[] translateZipFile(String basePath, HeatToToscaTranslator heatToToscaTranslator) throws IOException { - URL inputFilesUrl = this.getClass().getResource(basePath + IN_POSTFIX); - String path = inputFilesUrl.getPath(); - TestUtils.addFilesToTranslator(heatToToscaTranslator, path); - TranslatorOutput translatorOutput = heatToToscaTranslator.translate(); - Assert.assertNotNull(translatorOutput); - if (MapUtils.isNotEmpty(translatorOutput.getErrorMessages()) && MapUtils.isNotEmpty( - MessageContainerUtil - .getMessageByLevel(ErrorLevel.ERROR, translatorOutput.getErrorMessages()))) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage( - "Error in validation " + getErrorAsString(translatorOutput.getErrorMessages())) - .withId("Validation Error").withCategory(ErrorCategory.APPLICATION).build()); + + protected void testTranslation(String basePath, byte[] translatedZipFile) throws IOException { + + URL url = BaseFullTranslationTest.class.getResource(basePath + OUT_POSTFIX); + Set<String> expectedResultFileNameSet = new HashSet<>(); + Map<String, byte[]> expectedResultMap = new HashMap<>(); + + String path = url.getPath(); + File pathFile = new File(path); + File[] files = pathFile.listFiles(); + Assert.assertNotNull("manifest files is empty", files); + for (File expectedFile : files) { + expectedResultFileNameSet.add(expectedFile.getName()); + try (FileInputStream input = new FileInputStream(expectedFile)) { + expectedResultMap.put(expectedFile.getName(), FileUtils.toByteArray(input)); + } + } + + try (ByteArrayInputStream fis = new ByteArrayInputStream(translatedZipFile); + BufferedInputStream bis = new BufferedInputStream(fis); ZipInputStream zis = new ZipInputStream(bis)) { + ZipEntry entry; + String name; + String expected; + String actual; + + while ((entry = zis.getNextEntry()) != null) { + + name = entry.getName() + .substring(entry.getName().lastIndexOf(File.separator) + 1, entry.getName().length()); + if (expectedResultFileNameSet.contains(name)) { + expected = new String(expectedResultMap.get(name)).trim().replace("\r", ""); + actual = new String(FileUtils.toByteArray(zis)).trim().replace("\r", ""); + assertEquals("difference in file: " + name, expected, actual); + + expectedResultFileNameSet.remove(name); + } + } + if (expectedResultFileNameSet.isEmpty()) { + expectedResultFileNameSet.forEach(System.out::println); + } + } + assertEquals(0, expectedResultFileNameSet.size()); } - byte[] data = new ToscaFileOutputServiceCsarImpl().createOutputFile(translatorOutput.getToscaServiceModel(), null); + private byte[] translateZipFile(String basePath, HeatToToscaTranslator heatToToscaTranslator) throws IOException { + URL inputFilesUrl = this.getClass().getResource(basePath + IN_POSTFIX); + String path = inputFilesUrl.getPath(); + TestUtils.addFilesToTranslator(heatToToscaTranslator, path); + TranslatorOutput translatorOutput = heatToToscaTranslator.translate(); + Assert.assertNotNull(translatorOutput); + if (MapUtils.isNotEmpty(translatorOutput.getErrorMessages()) && MapUtils.isNotEmpty( + MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, translatorOutput.getErrorMessages()))) { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage( + "Error in validation " + getErrorAsString(translatorOutput.getErrorMessages())) + .withId("Validation Error") + .withCategory(ErrorCategory.APPLICATION).build()); + } - return data; - } + byte[] data = + new ToscaFileOutputServiceCsarImpl().createOutputFile(translatorOutput.getToscaServiceModel(), null); - private String getErrorAsString(Map<String, List<ErrorMessage>> errorMessages) { - StringBuilder sb = new StringBuilder(); - errorMessages.entrySet().forEach( - entry -> sb.append("File:").append(entry.getKey()).append(System.lineSeparator()) - .append(getErrorList(entry.getValue()))); + return data; + } - return sb.toString(); - } + private String getErrorAsString(Map<String, List<ErrorMessage>> errorMessages) { + StringBuilder sb = new StringBuilder(); + errorMessages.entrySet().forEach( + entry -> sb.append("File:").append(entry.getKey()).append(System.lineSeparator()) + .append(getErrorList(entry.getValue()))); - private String getErrorList(List<ErrorMessage> errors) { - StringBuilder sb = new StringBuilder(); - errors.forEach( - error -> sb.append(error.getMessage()).append("[").append(error.getLevel()).append("]") - .append(System.lineSeparator())); - return sb.toString(); - } + return sb.toString(); + } + + private String getErrorList(List<ErrorMessage> errors) { + StringBuilder sb = new StringBuilder(); + errors.forEach(error -> sb.append(error.getMessage()).append("[").append(error.getLevel()).append("]") + .append(System.lineSeparator())); + return sb.toString(); + } } |