X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Futil%2FArtifactTestUtils.java;h=066911ec6daae553ffb858ca416d057733dfa0b7;hb=bfde3ef00beb3c6f31cebfd12e90b9b9cdcc492e;hp=fa0b78458b69163b95eafd4cf5a18ca060a79985;hpb=0408ea82dc1a55b4f30e7062eb91e76b94091392;p=aai%2Fbabel.git diff --git a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java index fa0b784..066911e 100644 --- a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java +++ b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 European Software Marketing Ltd. + * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.util; import static org.hamcrest.CoreMatchers.equalTo; @@ -27,6 +28,7 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; import java.io.IOException; +import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; @@ -36,30 +38,50 @@ import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; import org.custommonkey.xmlunit.Diff; +import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser; import org.onap.aai.babel.xml.generator.data.Artifact; import org.xml.sax.SAXException; /** - * This class provides some utilities to assist with running tests. + * This class provides some utilities to assist with running local unit tests. */ public class ArtifactTestUtils { + public static final String CSAR_INPUTS_FOLDER = "compressedArtifacts/"; private static final String JSON_REQUESTS_FOLDER = "jsonFiles/"; private static final String JSON_RESPONSES_FOLDER = "response/"; - private static final String CSAR_INPUTS_FOLDER = "compressedArtifacts/"; + + /** + * Initialize System Properties for test configuration files. + */ + public void setGeneratorSystemProperties() { + System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE, + getResourcePath(Resources.TOSCA_MAPPING_CONFIG)); + } + + /** + * Load the Widget type mappings (resource). + * + * @throws IOException + * if the configuration file is not loaded + */ + public void loadWidgetMappings() throws IOException { + ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(getResourcePath(Resources.TOSCA_MAPPING_CONFIG)); + } /** * Specific test method for the YAML Extractor test. * * @param toscaFiles - * files extracted by the YamlExtractor + * files extracted by the YamlExtractor * @param ymlPayloadsToLoad - * the expected YAML files + * the expected YAML files * @throws IOException - * if an I/O exception occurs + * if an I/O exception occurs */ public void performYmlAsserts(List toscaFiles, List ymlPayloadsToLoad) throws IOException { assertThat("An incorrect number of YAML files have been extracted", toscaFiles.size(), @@ -83,14 +105,14 @@ public class ArtifactTestUtils { * Compare two XML strings to see if they have the same content. * * @param string1 - * XML content + * XML content * @param string2 - * XML content + * XML content * @return true if XML content is similar * @throws IOException - * if an I/O exception occurs + * if an I/O exception occurs * @throws SAXException - * if the XML parsing fails + * if the XML parsing fails */ public boolean compareXmlStrings(String string1, String string2) throws SAXException, IOException { return new Diff(string1, string2).similar(); @@ -120,6 +142,23 @@ public class ArtifactTestUtils { return Files.lines(Paths.get(getResource(resourceFile).toURI())).collect(Collectors.joining()); } + /** + * Create Properties from the content of the named resource (e.g. a file on the classpath). + * + * @param resourceName + * the resource name + * @return Properties loaded from the named resource + * @throws IOException + * if an error occurred when reading from the named resource + */ + public Properties getResourceAsProperties(String resourceName) throws IOException { + final Properties properties = new Properties(); + InputStream in = ArtifactTestUtils.class.getClassLoader().getResourceAsStream(resourceName); + properties.load(in); + in.close(); + return properties; + } + public String getResourcePath(String resourceName) { return getResource(resourceName).getPath(); }