aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-03-28 17:28:41 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-03-28 17:45:59 +0000
commit5f1b6e4eb654639de6aaae9b7d862eb01b991f55 (patch)
tree0a88b2cee4c3532e9f9036038c5801967b245f77
parentc1824169b0cfa25101c1efa8118d6b0b085edd15 (diff)
Use checked Exception instead of RuntimeException
Replace IllegalArgumentException with XmlArtifactGenerationException in the ArtifactGeneratorToscaParser method processResourceModels(). Add comments to explain the processing. Change-Id: Icf401ae22ebe26d687fc58c33743582c9c9e576e Issue-ID: AAI-2281 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java15
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java36
2 files changed, 34 insertions, 17 deletions
diff --git a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
index 281ac63..0777e51 100644
--- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
+++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
@@ -237,10 +237,18 @@ public class ArtifactGeneratorToscaParser {
}
/**
+ * Add each of the resources to the specified resourceModel. If the resourceModel type is Allotted Resource then
+ * validate that one of the resources is a Providing Service.
+ *
* @param resourceModel
+ * parent Resource model
* @param resourceNodeTemplates
+ * the child node templates of the resourceModel
+ * @throws XmlArtifactGenerationException
+ * if the resourceModel is an ALLOTTED_RESOURCE with no Providing Service
*/
- public void processResourceModels(Model resourceModel, List<NodeTemplate> resourceNodeTemplates) {
+ public void processResourceModels(Resource resourceModel, List<NodeTemplate> resourceNodeTemplates)
+ throws XmlArtifactGenerationException {
boolean foundProvidingService = false;
for (NodeTemplate resourceNodeTemplate : resourceNodeTemplates) {
@@ -261,9 +269,8 @@ public class ArtifactGeneratorToscaParser {
}
if (resourceModel.hasWidgetType("ALLOTTED_RESOURCE") && !foundProvidingService) {
- final String modelInvariantId = resourceModel.getModelId();
- throw new IllegalArgumentException(String.format(GENERATOR_AAI_PROVIDING_SERVICE_MISSING,
- modelInvariantId == null ? "<null ID>" : modelInvariantId));
+ throw new XmlArtifactGenerationException(String.format(GENERATOR_AAI_PROVIDING_SERVICE_MISSING,
+ Optional.ofNullable(resourceModel.getModelId()).orElse("<null ID>")));
}
}
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 2416cc8..65ec4c3 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
@@ -59,7 +59,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Generator with an invalid mappings file path.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
@@ -70,19 +70,19 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Generator with no Widget Mappings content.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
@Test(expected = IOException.class)
public void testMissingMappingsContent() throws IOException {
- String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG);
- ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+ String emptyJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG);
+ ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(emptyJson);
}
/**
* Initialize the Generator with invalid Widget Mappings content.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
@@ -94,9 +94,12 @@ public class TestArtifactGeneratorToscaParser {
/**
* Process an Allotted Resource that does not have a Providing Service.
+ *
+ * @throws XmlArtifactGenerationException
+ * because the ALLOTTED_RESOURCE lacks a Providing Service
*/
- @Test(expected = IllegalArgumentException.class)
- public void testMissingProvidingService() {
+ @Test(expected = XmlArtifactGenerationException.class)
+ public void testMissingProvidingService() throws XmlArtifactGenerationException {
List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage"));
new ArtifactGeneratorToscaParser(null)
.processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList);
@@ -104,10 +107,17 @@ public class TestArtifactGeneratorToscaParser {
/**
* Add a CR (a type of Resource which is not a Providing Service) to a Resource Model.
+ *
+ * @throws XmlArtifactGenerationException
+ * because the ALLOTTED_RESOURCE lacks a Providing Service
+ * @throws IOException
+ * if the test mappings cannot be loaded
*/
- @Test(expected = IllegalArgumentException.class)
- public void testAddResourceNotProvidingService() {
+ @Test(expected = XmlArtifactGenerationException.class)
+ public void testAddResourceNotProvidingService() throws XmlArtifactGenerationException, IOException {
+ new ArtifactTestUtils().loadWidgetMappings();
List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR"));
+
// Create any Resource to which the CR can be added
final Resource dummyResource = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true);
new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList);
@@ -115,7 +125,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
@@ -128,7 +138,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
@@ -141,7 +151,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
@@ -177,7 +187,7 @@ public class TestArtifactGeneratorToscaParser {
/**
* 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