aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-01-28 11:42:54 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-01-30 14:05:06 +0000
commit7fcc74469c941c1834cd02b54ff5ca88a53bf83b (patch)
tree3d9c130fb098cb996d2c8db4a8b9f57501c393b6 /src/test/java/org/onap
parent6833fb0a9a3f8c26688ad5c323eb266827b707c2 (diff)
Load type mappings from a group configuration file
Change the filter-types.properties file: re-implement to use JSON content. Remove the System Property that defines the location of the file and add this to the Spring application properties. Initialise the type-to-model mappings using the key=value pairs from this JSON content. Refactor existing Junit tests to remove duplicated resource loading code. Change-Id: Idb2e962fe5cae39b70cc8cf16053d0a253f4fac0 Issue-ID: AAI-2121 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java9
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestToscaParser.java31
-rw-r--r--src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java21
-rw-r--r--src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java18
-rw-r--r--src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java51
-rw-r--r--src/test/java/org/onap/aai/babel/util/Resources.java31
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java29
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java90
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java19
9 files changed, 167 insertions, 132 deletions
diff --git a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
index b7957f7..52dd462 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
@@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Properties;
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
@@ -76,9 +75,7 @@ public class TestArtifactGeneratorToscaParser {
@Test
public void testInstanceGroups() {
final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup";
- Properties props = new Properties();
- props.put("AAI.instance-group-types", instanceGroupType);
- WidgetConfigurationUtil.setFilterConfig(props);
+ WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType));
ISdcCsarHelper helper = Mockito.mock(ISdcCsarHelper.class);
SubstitutionMappings sm = Mockito.mock(SubstitutionMappings.class);
@@ -105,9 +102,9 @@ public class TestArtifactGeneratorToscaParser {
* sdc-tosca parser.
*
* @param name
- * name of the NodeTemplate
+ * name of the NodeTemplate
* @param type
- * type of the NodeTemplate
+ * type of the NodeTemplate
* @return a new NodeTemplate object
*/
private NodeTemplate buildNodeTemplate(String name, String type) {
diff --git a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java b/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
index 3bab915..f8d8478 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestToscaParser.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 © 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.
@@ -24,13 +24,10 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
@@ -40,10 +37,9 @@ import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator;
import org.onap.aai.babel.xml.generator.data.AdditionalParams;
import org.onap.aai.babel.xml.generator.data.Artifact;
import org.onap.aai.babel.xml.generator.data.GenerationData;
-import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
/**
- * Direct tests of the Model to improve code coverage.
+ * Direct tests of the {@link AaiArtifactGenerator} to improve code coverage.
*/
public class TestToscaParser {
@@ -53,22 +49,9 @@ public class TestToscaParser {
}
}
- private static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
- private static final String FILTER_TYPES_CONFIG = "filter-types.properties";
-
@Before
- public void setup() throws FileNotFoundException, IOException {
- System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
- new ArtifactTestUtils().getResourcePath(ARTIFACT_GENERATOR_CONFIG));
-
- System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE,
- new ArtifactTestUtils().getResourcePath(FILTER_TYPES_CONFIG));
-
- InputStream in = TestToscaParser.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
- Properties properties = new Properties();
- properties.load(in);
- in.close();
- WidgetConfigurationUtil.setConfig(properties);
+ public void setup() {
+ new ArtifactTestUtils().setGeneratorSystemProperties();
}
@Test
@@ -78,8 +61,8 @@ public class TestToscaParser {
additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), "1.0");
AaiArtifactGenerator generator = new AaiArtifactGenerator();
- GenerationData data = generator.generateArtifact(CsarTest.VNF_VENDOR_CSAR.getContent(), ymlFiles,
- additionalParams);
+ GenerationData data =
+ generator.generateArtifact(CsarTest.VNF_VENDOR_CSAR.getContent(), ymlFiles, additionalParams);
assertThat(data.getErrorData().size(), is(equalTo(0)));
assertThat(data.getResultData().size(), is(equalTo(2)));
diff --git a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
index 1d39f6d..1ead8e6 100644
--- a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
+++ b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.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 © 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.
@@ -54,9 +54,6 @@ import org.xml.sax.SAXException;
*/
public class CsarToXmlConverterTest {
- private static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
- private static final String FILTER_TYPES_CONFIG = "filter-types.properties";
-
private static final String INCORRECT_CSAR_NAME = "the_name_of_the_csar_file.csar";
private static final String SERVICE_VERSION = "1.0";
@@ -74,12 +71,7 @@ public class CsarToXmlConverterTest {
@Before
public void setup() {
- System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
- new ArtifactTestUtils().getResourcePath(ARTIFACT_GENERATOR_CONFIG));
-
- System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE,
- new ArtifactTestUtils().getResourcePath(FILTER_TYPES_CONFIG));
-
+ new ArtifactTestUtils().setGeneratorSystemProperties();
converter = new CsarToXmlConverter();
}
@@ -118,9 +110,9 @@ public class CsarToXmlConverterTest {
* Test that an Exception is thrown when the Artifact Generator properties are not present.
*
* @throws CsarConverterException
- * if there is an error either extracting the YAML files or generating XML artifacts
+ * if there is an error either extracting the YAML files or generating XML artifacts
* @throws IOException
- * if an I/O exception occurs loading the test CSAR file
+ * if an I/O exception occurs loading the test CSAR file
* @throws IOException
* @throws XmlArtifactGenerationException
* @throws CsarConverterException
@@ -147,7 +139,8 @@ public class CsarToXmlConverterTest {
public void generateXmlFromCsarFilterTypesSystemPropertyNotSet()
throws IOException, XmlArtifactGenerationException, CsarConverterException {
exception.expect(CsarConverterException.class);
- exception.expectMessage("Cannot generate artifacts. System property groupfilter.config not configured");
+ exception.expectMessage("Cannot generate artifacts. System property "
+ + ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE + " not configured");
// Unset the required system property
System.clearProperty(ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE);
diff --git a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java
index 78e02f4..d87f3c3 100644
--- a/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.java
+++ b/src/test/java/org/onap/aai/babel/service/TestGenerateArtifactsServiceImpl.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 © 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.
@@ -18,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.service;
import static org.hamcrest.Matchers.is;
@@ -42,7 +43,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.onap.aai.auth.AAIMicroServiceAuth;
-import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
import org.onap.aai.babel.service.data.BabelRequest;
import org.onap.aai.babel.testdata.CsarTest;
import org.onap.aai.babel.util.ArtifactTestUtils;
@@ -55,7 +55,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "classpath:/babel-beans.xml" })
+@ContextConfiguration(locations = {"classpath:/babel-beans.xml"})
public class TestGenerateArtifactsServiceImpl {
static {
@@ -65,18 +65,14 @@ public class TestGenerateArtifactsServiceImpl {
System.setProperty("CONFIG_HOME", "src/test/resources");
}
- private static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
- private static final String FILTER_TYPES_CONFIG = "filter-types.properties";
@Inject
private AAIMicroServiceAuth auth;
@BeforeClass
public static void setup() {
- System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
- new ArtifactTestUtils().getResourcePath(ARTIFACT_GENERATOR_CONFIG));
- System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE,
- new ArtifactTestUtils().getResourcePath(FILTER_TYPES_CONFIG));
+ new ArtifactTestUtils().setGeneratorSystemProperties();
+
}
@Test
@@ -199,7 +195,7 @@ public class TestGenerateArtifactsServiceImpl {
Mockito.when(mockCertificate.getSubjectX500Principal())
.thenReturn(new X500Principal("CN=test, OU=qa, O=Test Ltd, L=London, ST=London, C=GB"));
- servletRequest.setAttribute("javax.servlet.request.X509Certificate", new X509Certificate[] { mockCertificate });
+ servletRequest.setAttribute("javax.servlet.request.X509Certificate", new X509Certificate[] {mockCertificate});
servletRequest.setAttribute("javax.servlet.request.cipher_suite", "");
GenerateArtifactsServiceImpl service = new GenerateArtifactsServiceImpl(auth);
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..6608c00 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 © 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.
@@ -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,14 +38,17 @@ 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.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 {
@@ -51,15 +56,33 @@ 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
+ * 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<Artifact> toscaFiles, List<String> ymlPayloadsToLoad) throws IOException {
assertThat("An incorrect number of YAML files have been extracted", toscaFiles.size(),
@@ -83,14 +106,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 +143,14 @@ public class ArtifactTestUtils {
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();
}
diff --git a/src/test/java/org/onap/aai/babel/util/Resources.java b/src/test/java/org/onap/aai/babel/util/Resources.java
new file mode 100644
index 0000000..199b3cd
--- /dev/null
+++ b/src/test/java/org/onap/aai/babel/util/Resources.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * 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.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.babel.util;
+
+/**
+ * Common Test resources.
+ */
+public class Resources {
+
+ public static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
+ public static final String FILTER_TYPES_CONFIG = "tosca-mappings.json";
+
+}
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java
index 9b5700d..912a505 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.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 © 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.
@@ -26,15 +26,13 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
-import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
-import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
+import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
+import org.onap.aai.babel.util.ArtifactTestUtils;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.onap.aai.babel.xml.generator.types.ModelType;
@@ -54,20 +52,19 @@ public class TestModel {
}
/**
- * Load the Widget to UUID mappings from the Artifact Generator properties.
+ * Initialise the Artifact Generator with filtering and mapping configuration. Also Load the Widget to UUID mappings
+ * from the Artifact Generator properties.
*
- * @throws FileNotFoundException
- * if the properties file is missing
* @throws IOException
- * if the properties file is not loaded
+ * if the Artifact Generator properties file is not loaded
*/
@Before
- public void setup() throws FileNotFoundException, IOException {
- InputStream in = TestModel.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
- Properties properties = new Properties();
- properties.load(in);
- in.close();
- WidgetConfigurationUtil.setConfig(properties);
+ public void setup() throws IOException {
+ ArtifactTestUtils utils = new ArtifactTestUtils();
+ utils.setGeneratorSystemProperties();
+
+ ArtifactGeneratorToscaParser.initGroupFilterConfiguration();
+ utils.loadWidgetToUuidMappings();
anonymousModel = new Model() {
@Override
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java
index e9c8c1b..1a5986b 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.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 © 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.
@@ -26,16 +26,13 @@ import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.Assert.assertThat;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
+import org.onap.aai.babel.util.ArtifactTestUtils;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
/**
@@ -47,33 +44,39 @@ public class TestVfModule {
System.setProperty("APP_HOME", ".");
}
- /**
- * Load the Widget to UUID mappings from the Artifact Generator properties.
- *
- * @throws FileNotFoundException if the properties file is missing
- * @throws IOException if the properties file is not loaded
- */
@BeforeClass
- public static void setup() throws FileNotFoundException, IOException {
- InputStream in = TestVfModule.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
- Properties properties = new Properties();
- properties.load(in);
- in.close();
- WidgetConfigurationUtil.setConfig(properties);
+ public static void setup() throws IOException {
+ new ArtifactTestUtils().loadWidgetToUuidMappings();
}
/**
- * Call equals() and hashCode() methods for code coverage.
+ * Call hashCode() method for code coverage.
*/
@Test
- public void testEqualsHashCode() {
+ public void testHashCode() {
VfModule vfModule = createNewVfModule();
populateIdentInfo(vfModule);
assertThat(vfModule.hashCode(), is(notNullValue()));
- assertThat(vfModule.equals(vfModule), is(true));
- // Tests that the overridden equals() method correctly returns false for a different type of Object
- // This is necessary to achieve complete code coverage
- assertThat(vfModule.equals("string"), is(false)); // NOSONAR
+ }
+
+ /**
+ * Call equals() method for code coverage.
+ */
+ @Test
+ public void testEquals() {
+ VfModule vfModuleA = createNewVfModule();
+ populateIdentInfo(vfModuleA);
+
+ // equals() is reflexive
+ assertThat(vfModuleA.equals(vfModuleA), is(true));
+
+ // equals() is symmetric
+ VfModule vfModuleB = createNewVfModule();
+ populateIdentInfo(vfModuleB);
+ assertThat(vfModuleA.equals(vfModuleB), is(true));
+ assertThat(vfModuleB.equals(vfModuleA), is(true));
+
+ assertThat(vfModuleA.equals(null), is(false));
}
@Test
@@ -216,7 +219,8 @@ public class TestVfModule {
/**
* Use the static Factory method to create a new Widget.
*
- * @param widgetType type of Widget to create
+ * @param widgetType
+ * type of Widget to create
* @return a new Widget
*/
private Widget createNewWidget(Type widgetType) {
@@ -237,7 +241,8 @@ public class TestVfModule {
/**
* Set up some dummy Model Identification properties.
*
- * @param vfModule to be populated
+ * @param vfModule
+ * to be populated
*/
private void populateIdentInfo(VfModule vfModule) {
Map<String, String> modelIdentInfo = new HashMap<>();
@@ -248,8 +253,10 @@ public class TestVfModule {
/**
* Create a new Widget and assert that it is successfully added to the VF Module.
*
- * @param vfModule the VF Module to update
- * @param widgetType the type of Widget to create and add
+ * @param vfModule
+ * the VF Module to update
+ * @param widgetType
+ * the type of Widget to create and add
*/
private void assertAddWidget(VfModule vfModule, Type widgetType) {
assertThat(createNewWidgetForModule(vfModule, widgetType), is(true));
@@ -258,8 +265,10 @@ public class TestVfModule {
/**
* Create a new Widget and assert that it cannot be added to the VF Module.
*
- * @param vfModule the VF Module
- * @param widgetType the type of Widget to create and attempt to add
+ * @param vfModule
+ * the VF Module
+ * @param widgetType
+ * the type of Widget to create and attempt to add
*/
private void assertFailToAddWidget(VfModule vfModule, Type widgetType) {
assertThat(createNewWidgetForModule(vfModule, widgetType), is(false));
@@ -268,8 +277,10 @@ public class TestVfModule {
/**
* Create a new widget, make it a member of the VF Module, then try to add it.
*
- * @param vfModule the VF Module to update
- * @param widgetType the type of Widget to create and attempt to add
+ * @param vfModule
+ * the VF Module to update
+ * @param widgetType
+ * the type of Widget to create and attempt to add
* @return whether or not the Widget was added to the module
*/
private boolean createNewWidgetForModule(VfModule vfModule, Type widgetType) {
@@ -283,8 +294,10 @@ public class TestVfModule {
* to its set of keys, and by then setting the VF Module's members to a Singleton List comprised of this ID. These
* updates allow the Widget to be successfully added to the VF Module. (Non-member Widgets cannot be added.)
*
- * @param vfModule the module for which members are overwritten
- * @param widget the widget to be set as the member
+ * @param vfModule
+ * the module for which members are overwritten
+ * @param widget
+ * the widget to be set as the member
*/
private void setWidgetAsMember(VfModule vfModule, Widget widget) {
String id = widget.getId();
@@ -295,7 +308,8 @@ public class TestVfModule {
/**
* Create a vserver widget and add it to the specified VF Module.
*
- * @param vfModule the VF Module to update
+ * @param vfModule
+ * the VF Module to update
* @return the number of Widgets present in the vserver on creation
*/
private int createVserverForVf(VfModule vfModule) {
@@ -309,8 +323,10 @@ public class TestVfModule {
/**
* Add the specified vserver to the specified VF Module.
*
- * @param vfModule the VF Module to update
- * @param vserverWidget the Widget to add
+ * @param vfModule
+ * the VF Module to update
+ * @param vserverWidget
+ * the Widget to add
* @return initial widget count for the vserver Widget
*/
private int addVserverToVf(VfModule vfModule, VServerWidget vserverWidget) {
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java
index 212c221..d7fe4af 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.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 © 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.
@@ -26,14 +26,11 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Collections;
-import java.util.Properties;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
+import org.onap.aai.babel.util.ArtifactTestUtils;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.onap.aai.babel.xml.generator.types.ModelType;
@@ -49,18 +46,12 @@ public class TestWidget {
/**
* Load the Widget to UUID mappings from the Artifact Generator properties.
*
- * @throws FileNotFoundException
- * if the properties file is missing
* @throws IOException
* if the properties file is not loaded
*/
@BeforeClass
- public static void setup() throws FileNotFoundException, IOException {
- final Properties properties = new Properties();
- try (InputStream in = TestWidget.class.getClassLoader().getResourceAsStream("artifact-generator.properties")) {
- properties.load(in);
- }
- WidgetConfigurationUtil.setConfig(properties);
+ public static void setup() throws IOException {
+ new ArtifactTestUtils().loadWidgetToUuidMappings();
}
@Test