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>
+ * 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.
+ *
+ * parent Resource model
* @param resourceNodeTemplates
* @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) {
boolean foundProvidingService = false;
for (NodeTemplate resourceNodeTemplate : resourceNodeTemplates) {
}
if (resourceModel.hasWidgetType("ALLOTTED_RESOURCE") && !foundProvidingService) {
}
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>")));
/**
* Initialize the Generator with an invalid mappings file path.
/**
* Initialize the Generator with an invalid mappings file path.
* @throws IOException
* if the file content could not be read successfully
*/
* @throws IOException
* if the file content could not be read successfully
*/
/**
* Initialize the Generator with no Widget Mappings content.
/**
* 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 {
* @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.
}
/**
* Initialize the Generator with invalid Widget Mappings content.
* @throws IOException
* if the file content could not be read successfully
*/
* @throws IOException
* if the file content could not be read successfully
*/
/**
* Process an Allotted Resource that does not have a Providing Service.
/**
* 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);
List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage"));
new ArtifactGeneratorToscaParser(null)
.processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList);
/**
* Add a CR (a type of Resource which is not a Providing Service) to a Resource Model.
/**
* 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"));
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);
// 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);
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
* @throws IOException
* if a WidgetMapping is invalid
*/
* @throws IOException
* if a WidgetMapping is invalid
*/
/**
* Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
/**
* Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
* @throws IOException
* if a WidgetMapping is invalid
*/
* @throws IOException
* if a WidgetMapping is invalid
*/
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
* @throws IOException
* if a WidgetMapping is invalid
*/
* @throws IOException
* if a WidgetMapping is invalid
*/
/**
* Process a dummy Group object for a Service Resource.
/**
* 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
* @throws XmlArtifactGenerationException
* if there is no configuration defined for a member Widget of an instance group
* @throws IOException