* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 European Software Marketing Ltd.
+ * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.util;
import static org.hamcrest.CoreMatchers.equalTo;
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;
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.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
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 {
private static final String JSON_RESPONSES_FOLDER = "response/";
private static final String CSAR_INPUTS_FOLDER = "compressedArtifacts/";
+ public void setGeneratorSystemProperties() {
+ System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
+ getResourcePath(Resources.ARTIFACT_GENERATOR_CONFIG));
+
+ System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE,
+ getResourcePath(Resources.FILTER_TYPES_CONFIG));
+ }
+
+ /**
+ * Load the Widget to UUID mappings from the Artifact Generator Properties (resource).
+ *
+ * @throws IOException
+ * if the properties file is not loaded
+ */
+ public void loadWidgetToUuidMappings() throws IOException {
+ WidgetConfigurationUtil.setConfig(getResourceAsProperties(Resources.ARTIFACT_GENERATOR_CONFIG));
+ }
+
+ /**
+ * Specific test method for the YAML Extractor test.
+ *
+ * @param toscaFiles
+ * files extracted by the YamlExtractor
+ * @param ymlPayloadsToLoad
+ * the expected YAML files
+ * @throws IOException
+ * if an I/O exception occurs
+ */
public void performYmlAsserts(List<Artifact> toscaFiles, List<String> ymlPayloadsToLoad) throws IOException {
assertThat("An incorrect number of YAML files have been extracted", toscaFiles.size(),
is(equalTo(ymlPayloadsToLoad.size())));
}
/**
- * Compare 2 XML strings to see if they have the same content
+ * Compare two XML strings to see if they have the same content.
*
* @param string1
+ * XML content
* @param string2
- * @return true if similar
+ * XML content
+ * @return true if XML content is similar
+ * @throws IOException
+ * if an I/O exception occurs
+ * @throws SAXException
+ * if the XML parsing fails
*/
- public boolean compareXmlStrings(String string1, String string2) {
- boolean similar = false;
-
- try {
- similar = new Diff(string1, string2).similar();
- } catch (SAXException | IOException e) { // NOSONAR
- similar = true;
- }
-
- return similar;
+ public boolean compareXmlStrings(String string1, String string2) throws SAXException, IOException {
+ return new Diff(string1, string2).similar();
}
public byte[] getCompressedArtifact(String resourceName) throws IOException {
return Files.lines(Paths.get(getResource(resourceFile).toURI())).collect(Collectors.joining());
}
+ 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();
}