aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-03-25 18:12:48 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-03-25 18:12:48 +0000
commitf6107af893b29094f84fb2eea2b9dd8acc78dc53 (patch)
treef302b255449fc8bb7bbae52effac355bb76dbb44 /src/test/java
parentd2215b5d8b6c8976a9540a9e4706c7bebca80aa2 (diff)
Additional JUnit tests for Model classes
Increase code coverage for Model and Service Change-Id: I02430f470cfa6497535a372a0b18be8678279270 Issue-ID: AAI-2280 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java43
-rw-r--r--src/test/java/org/onap/aai/babel/service/TestCsarToXmlConverter.java (renamed from src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java)4
-rw-r--r--src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java8
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java (renamed from src/test/java/org/onap/aai/babel/parser/TestToscaParser.java)40
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java30
5 files changed, 105 insertions, 20 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 50f0aa9..7bc9fa8 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
@@ -37,8 +37,11 @@ import org.onap.aai.babel.util.Resources;
import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.data.WidgetMapping;
+import org.onap.aai.babel.xml.generator.model.Model;
import org.onap.aai.babel.xml.generator.model.Resource;
+import org.onap.aai.babel.xml.generator.model.Service;
import org.onap.aai.babel.xml.generator.model.WidgetType;
+import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.Group;
import org.onap.sdc.toscaparser.api.NodeTemplate;
@@ -55,7 +58,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Generator with an invalid artifact generator properties file path.
- *
+ *
* @throws IOException
* if an error occurs reading the configuration properties
*/
@@ -67,7 +70,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Generator with an invalid mappings file path.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
@@ -78,7 +81,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Generator with no Widget Mappings content.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
@@ -90,7 +93,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Generator with invalid Widget Mappings content.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
@@ -123,7 +126,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
@@ -136,7 +139,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
@@ -149,7 +152,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
@@ -161,8 +164,32 @@ public class TestArtifactGeneratorToscaParser {
}
/**
+ * Create a Resource with a Widget model type and add this to a Service. Note that there are no test CSAR files
+ * which require this functionality, but the code path exists to support it.
+ *
+ * @throws IOException
+ * if the widget mappings are not loaded
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for the test resource's widget type
+ */
+ @Test
+ public void testAddWidgetToService() throws IOException, XmlArtifactGenerationException {
+ ArtifactTestUtils testUtils = new ArtifactTestUtils();
+ testUtils.loadWidgetMappings();
+ testUtils.loadWidgetToUuidMappings();
+
+ Model serviceModel = new Service();
+ Resource resourceModel = new Resource(WidgetType.valueOf("VF"), false);
+ resourceModel.setModelType(ModelType.WIDGET);
+
+ ISdcCsarHelper helper = Mockito.mock(ISdcCsarHelper.class);
+ ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper);
+ parser.addRelatedModel(serviceModel, resourceModel);
+ }
+
+ /**
* Process a dummy Group object for a Service Resource.
- *
+ *
* @throws XmlArtifactGenerationException
* if there is no configuration defined for a member Widget of an instance group
* @throws IOException
diff --git a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java b/src/test/java/org/onap/aai/babel/service/TestCsarToXmlConverter.java
index 5001a09..244eccd 100644
--- a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
+++ b/src/test/java/org/onap/aai/babel/service/TestCsarToXmlConverter.java
@@ -52,7 +52,7 @@ import org.xml.sax.SAXException;
/**
* Tests {@link CsarToXmlConverter}.
*/
-public class CsarToXmlConverterTest {
+public class TestCsarToXmlConverter {
private static final String INCORRECT_CSAR_NAME = "the_name_of_the_csar_file.csar";
private static final String SERVICE_VERSION = "1.0";
@@ -189,7 +189,7 @@ public class CsarToXmlConverterTest {
/**
* A Matcher for comparing generated XML Strings with expected XML content.
- *
+ *
* @param expected
* the expected XML String
* @return a new Matcher for comparing XML Strings
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 df27c22..164c80b 100644
--- a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java
+++ b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java
@@ -52,9 +52,9 @@ import org.xml.sax.SAXException;
*/
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.
@@ -69,7 +69,7 @@ public class ArtifactTestUtils {
/**
* Load the Widget to UUID mappings from the Artifact Generator Properties (resource).
- *
+ *
* @throws IOException
* if the properties file is not loaded
*/
@@ -79,7 +79,7 @@ public class ArtifactTestUtils {
/**
* Load the Widget type mappings (resource).
- *
+ *
* @throws IOException
* if the configuration file is not loaded
*/
@@ -158,7 +158,7 @@ public class ArtifactTestUtils {
/**
* 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
diff --git a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java b/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java
index f300f7b..d95291b 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.babel.parser;
+package org.onap.aai.babel.xml.generator;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
@@ -31,21 +31,29 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
+import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
import org.onap.aai.babel.testdata.CsarTest;
import org.onap.aai.babel.util.ArtifactTestUtils;
import org.onap.aai.babel.util.Resources;
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.GenerationData;
+import org.onap.aai.babel.xml.generator.model.WidgetType;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
/**
* Direct tests of the {@link AaiArtifactGenerator} to improve code coverage.
*/
-public class TestToscaParser {
+public class TestAaiArtifactGenerator {
+
+ private ArtifactTestUtils testUtils;
@Before
public void setup() {
- new ArtifactTestUtils().setGeneratorSystemProperties();
+ testUtils = new ArtifactTestUtils();
+ testUtils.setGeneratorSystemProperties();
}
@Test
@@ -66,8 +74,32 @@ public class TestToscaParser {
}
/**
+ * Test that an Exception is thrown when a Widget Type (such as ALLOTTED_RESOURCE) required by Babel is not present
+ * in the WidgetType dynamic enumeration.
+ *
+ * @throws SdcToscaParserException
+ * @throws IOException
+ * @throws XmlArtifactGenerationException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testParserWithIncompleteMappings()
+ throws SdcToscaParserException, IOException, XmlArtifactGenerationException {
+ testUtils.loadWidgetMappings();
+ testUtils.loadWidgetToUuidMappings();
+
+ AaiArtifactGenerator artifactGenerator = new AaiArtifactGenerator();
+ WidgetType.clearElements(); // Remove all WidgetTypes so that the generator fails
+
+ ISdcCsarHelper csarHelper = SdcToscaParserFactory.getInstance()
+ .getSdcCsarHelper(TestAaiArtifactGenerator.class.getClassLoader()
+ .getResource(ArtifactTestUtils.CSAR_INPUTS_FOLDER + CsarTest.VNF_VENDOR_CSAR.getName())
+ .getFile().toString());
+ artifactGenerator.generateAllArtifacts("1.0", csarHelper);
+ }
+
+ /**
* Invoke the generator with a sample CSAR file.
- *
+ *
* @return the generated AAI Artifacts
* @throws InvalidArchiveException
* if the test CSAR file is invalid
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 ed4f5c1..f1a579e 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
@@ -74,8 +74,34 @@ public class TestModel {
}
/**
+ * Test that there is no exception if processing a Model that has no metadata properties.
+ */
+ @Test
+ public void testNullIdentProperties() {
+ createTestModel().populateModelIdentificationInformation(null);
+ }
+
+ /**
+ * Test that an exception occurs if calling code passes an unsupported Widget Type value to the base implementation
+ * of the hasWidgetType() method.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testUnknownWidgetType() {
+ createTestModel().hasWidgetType(null);
+ }
+
+ /**
+ * Create any Model with a valid WidgetType, for method testing.
+ *
+ * @return a valid Model for testing purposes
+ */
+ private Model createTestModel() {
+ return new Resource(WidgetType.valueOf("VSERVER"), false);
+ }
+
+ /**
* Assert that the TOSCA type String is mapped to the expected Widget Type.
- *
+ *
* @param toscaType
* the TOSCA type or prefix
* @param widgetType
@@ -87,7 +113,7 @@ public class TestModel {
/**
* Assert that the TOSCA metadata type is mapped to the expected Widget Type.
- *
+ *
* @param toscaType
* the name (or name prefix) of the TOSCA type
* @param metadataType