aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java86
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java59
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java6
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java7
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java10
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java4
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetType.java (renamed from src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java)14
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/CRWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ConfigurationWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroupWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java23
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java26
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Service.java8
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java44
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java92
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java25
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/Model.java53
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java45
-rw-r--r--src/main/resources/babel-logging-resources.properties5
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java51
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestToscaParser.java2
-rw-r--r--src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java2
-rw-r--r--src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java11
-rw-r--r--src/test/java/org/onap/aai/babel/util/Resources.java2
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java4
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java48
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java119
-rw-r--r--src/test/resources/empty-tosca-mappings.json0
-rw-r--r--src/test/resources/invalid-tosca-mappings.json1
-rw-r--r--src/test/resources/tosca-mappings.json92
45 files changed, 506 insertions, 888 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 3fb77be..c79c2ef 100644
--- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
+++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
@@ -22,10 +22,10 @@
package org.onap.aai.babel.parser;
import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
@@ -37,6 +37,7 @@ import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.GroupConfiguration;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.model.Model;
@@ -85,7 +86,7 @@ public class ArtifactGeneratorToscaParser {
* Constructs using csarHelper
*
* @param csarHelper
- * The csar helper
+ * The csar helper
*/
public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) {
this.csarHelper = csarHelper;
@@ -95,7 +96,7 @@ public class ArtifactGeneratorToscaParser {
* Get or create the artifact description.
*
* @param model
- * the artifact model
+ * the artifact model
* @return the artifact model's description
*/
public static String getArtifactDescription(Model model) {
@@ -110,7 +111,7 @@ public class ArtifactGeneratorToscaParser {
}
/**
- * Initialises the widget configuration.
+ * Initializes the Widget to UUID mapping configuration.
*
* @throws IOException
*/
@@ -133,26 +134,35 @@ public class ArtifactGeneratorToscaParser {
}
/**
- * Initialises the group filtering and TOSCA mapping configuration.
+ * Initializes the group filtering and TOSCA to Widget mapping configuration.
*
* @param configLocation
- * the pathname to the JSON config file
- * @throws FileNotFoundException
- * if the file cannot be opened for reading
+ * the pathname to the JSON mappings file
+ * @throws IOException
+ * if the file content could not be read successfully
*/
- public static void initToscaMappingsConfiguration(String configLocation) throws FileNotFoundException {
+ public static void initToscaMappingsConfiguration(String configLocation) throws IOException {
log.debug("Getting TOSCA Mappings Configuration");
File file = new File(configLocation);
if (!file.exists()) {
throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND, configLocation));
}
- BufferedReader bufferedReader = new BufferedReader(new FileReader(configLocation));
- GroupConfiguration config = new Gson().fromJson(bufferedReader, GroupConfiguration.class);
- if (config != null) {
- WidgetConfigurationUtil.setSupportedInstanceGroups(config.getInstanceGroupTypes());
- WidgetConfigurationUtil.setWidgetMappings(config.getWidgetMappings());
+ GroupConfiguration config;
+
+ try (BufferedReader bufferedReader = new BufferedReader(new FileReader(configLocation))) {
+ config = new Gson().fromJson(bufferedReader, GroupConfiguration.class);
+ } catch (JsonSyntaxException e) {
+ throw new IOException("Invalid Mappings Configuration " + configLocation, e);
}
+
+ if (config == null) {
+ throw new IOException("There is no content for the Mappings Configuration " + configLocation);
+ }
+
+ WidgetConfigurationUtil.setSupportedInstanceGroups(config.getInstanceGroupTypes());
+ WidgetConfigurationUtil.setWidgetTypes(config.getWidgetTypes());
+ WidgetConfigurationUtil.setWidgetMappings(config.getWidgetMappings());
}
/**
@@ -161,8 +171,10 @@ public class ArtifactGeneratorToscaParser {
* @param resourceModel
* @param serviceNodeTemplate
* @return resources for which XML Models should be generated
+ * @throws XmlArtifactGenerationException
*/
- public List<Resource> processInstanceGroups(Model resourceModel, NodeTemplate serviceNodeTemplate) {
+ public List<Resource> processInstanceGroups(Model resourceModel, NodeTemplate serviceNodeTemplate)
+ throws XmlArtifactGenerationException {
List<Resource> resources = new ArrayList<>();
if (serviceNodeTemplate.getSubMappingToscaTemplate() != null) {
List<Group> serviceGroups = csarHelper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate);
@@ -181,9 +193,9 @@ public class ArtifactGeneratorToscaParser {
* duplicate keys then the TOSCA Property value takes precedence.
*
* @param stringProps
- * initial Map of String property values (e.g. from the TOSCA YAML metadata section)
+ * initial Map of String property values (e.g. from the TOSCA YAML metadata section)
* @param toscaProps
- * Map of TOSCA Property Type Object values to merge in (or overwrite)
+ * Map of TOSCA Property Type Object values to merge in (or overwrite)
* @return a Map of the property values converted to String
*/
public Map<String, String> mergeProperties(Map<String, String> stringProps, Map<String, Property> toscaProps) {
@@ -202,8 +214,9 @@ public class ArtifactGeneratorToscaParser {
/**
* @param model
* @param relation
+ * @throws XmlArtifactGenerationException
*/
- public void addRelatedModel(final Model model, final Resource relation) {
+ public void addRelatedModel(final Model model, final Resource relation) throws XmlArtifactGenerationException {
if (relation.isResource()) {
model.addResource(relation);
} else {
@@ -225,8 +238,10 @@ public class ArtifactGeneratorToscaParser {
* @param resources
* @param model
* @param serviceNode
+ * @throws XmlArtifactGenerationException
*/
- public void processVfModules(List<Resource> resources, Model resourceModel, NodeTemplate serviceNode) {
+ public void processVfModules(List<Resource> resources, Model resourceModel, NodeTemplate serviceNode)
+ throws XmlArtifactGenerationException {
// Get the customisation UUID for each VF node and use it to get its Groups
String uuid = csarHelper.getNodeTemplateCustomizationUuid(serviceNode);
List<Group> serviceGroups = csarHelper.getVfModulesByVf(uuid);
@@ -275,17 +290,19 @@ public class ArtifactGeneratorToscaParser {
* Create an Instance Group Model and populate it with the supplied data.
*
* @param resourceModel
- * the Resource node template Model
+ * the Resource node template Model
* @param memberNodes
- * the Resources and Widgets belonging to the Group
+ * the Resources and Widgets belonging to the Group
* @param metaProperties
- * the metadata of the Group
+ * the metadata of the Group
* @param properties
- * the properties of the Group
+ * the properties of the Group
* @return the Instance Group and Member resource models
+ * @throws XmlArtifactGenerationException
*/
private List<Resource> processInstanceGroup(Model resourceModel, ArrayList<NodeTemplate> memberNodes,
- Map<String, String> metaProperties, Map<String, Property> properties) {
+ Map<String, String> metaProperties, Map<String, Property> properties)
+ throws XmlArtifactGenerationException {
Resource groupModel = createInstanceGroupModel(mergeProperties(metaProperties, properties));
resourceModel.addResource(groupModel);
List<Resource> resources = Stream.of(groupModel).collect(Collectors.toList());
@@ -301,9 +318,10 @@ public class ArtifactGeneratorToscaParser {
* @param memberNodes
* @param groupModel
* @return
+ * @throws XmlArtifactGenerationException
*/
private List<Resource> generateResourcesAndWidgets(final ArrayList<NodeTemplate> memberNodes,
- final Resource groupModel) {
+ final Resource groupModel) throws XmlArtifactGenerationException {
log.debug(String.format("Processing member nodes for Group %s (invariant UUID %s)", //
groupModel.getModelName(), groupModel.getModelId()));
@@ -332,7 +350,7 @@ public class ArtifactGeneratorToscaParser {
}
private void processVfModule(List<Resource> resources, Model vfModel, Group groupDefinition,
- NodeTemplate serviceNode, Resource groupModel) {
+ NodeTemplate serviceNode, Resource groupModel) throws XmlArtifactGenerationException {
groupModel.populateModelIdentificationInformation(
mergeProperties(groupDefinition.getMetadata().getAllProperties(), groupDefinition.getProperties()));
@@ -345,7 +363,8 @@ public class ArtifactGeneratorToscaParser {
}
}
- private void processVfModuleGroup(Resource groupModel, List<NodeTemplate> members) {
+ private void processVfModuleGroup(Resource groupModel, List<NodeTemplate> members)
+ throws XmlArtifactGenerationException {
if (members != null && !members.isEmpty()) {
// Get names of the members of the service group
List<String> memberNames = members.stream().map(NodeTemplate::getName).collect(Collectors.toList());
@@ -361,8 +380,9 @@ public class ArtifactGeneratorToscaParser {
*
* @param group
* @param member
+ * @throws XmlArtifactGenerationException
*/
- private void processGroupMembers(Resource group, NodeTemplate member) {
+ private void processGroupMembers(Resource group, NodeTemplate member) throws XmlArtifactGenerationException {
Resource resource = Model.getModelFor(member.getType());
log.debug(member.getType() + " mapped to " + resource);
@@ -384,7 +404,7 @@ public class ArtifactGeneratorToscaParser {
* Create a Map of property name against String property value from the input Map
*
* @param inputMap
- * The input Map
+ * The input Map
* @return Map of property name against String property value
*/
private Map<String, String> populateStringProperties(Map<String, Property> inputMap) {
@@ -397,13 +417,13 @@ public class ArtifactGeneratorToscaParser {
* is ProvidingService then return true, otherwise return false.
*
* @param resourceModel
- * parent Resource
+ * parent Resource
* @param metaData
- * for populating the Resource IDs
+ * for populating the Resource IDs
* @param resourceNode
- * any Model (will be ignored if not a Resource)
+ * any Model (will be ignored if not a Resource)
* @param nodeProperties
- * the node properties
+ * the node properties
* @return whether or not a ProvidingService was processed
*/
private boolean processModel(Model resourceModel, Metadata metaData, Resource resourceNode,
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
index 57e8a67..4415c47 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
@@ -33,6 +33,7 @@ import org.apache.commons.lang3.StringUtils;
import org.onap.aai.babel.logging.ApplicationMsgs;
import org.onap.aai.babel.logging.LogHelper;
import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
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.ArtifactType;
@@ -43,10 +44,11 @@ import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
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.TunnelXconnectWidget;
+import org.onap.aai.babel.xml.generator.model.Widget;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.toscaparser.api.Group;
import org.onap.sdc.toscaparser.api.NodeTemplate;
@@ -71,15 +73,6 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
@Override
public GenerationData generateArtifact(byte[] csarArchive, List<Artifact> input,
Map<String, String> additionalParams) {
- Path csarPath;
-
- try {
- csarPath = createTempFile(csarArchive);
- } catch (IOException e) {
- log.error(ApplicationMsgs.TEMP_FILE_ERROR, e);
- return createErrorData(e);
- }
-
String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
if (configLocation == null) {
throw new IllegalArgumentException(
@@ -90,10 +83,25 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
try {
ArtifactGeneratorToscaParser.initWidgetConfiguration();
ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
+ } catch (IOException e) {
+ log.error(ApplicationMsgs.LOAD_PROPERTIES, e);
+ return createErrorData(e);
+ }
+
+ Path csarPath;
+
+ try {
+ csarPath = createTempFile(csarArchive);
+ } catch (IOException e) {
+ log.error(ApplicationMsgs.TEMP_FILE_ERROR, e);
+ return createErrorData(e);
+ }
+
+ try {
ISdcCsarHelper csarHelper =
SdcToscaParserFactory.getInstance().getSdcCsarHelper(csarPath.toAbsolutePath().toString());
return generateAllArtifacts(validateServiceVersion(additionalParams), csarHelper);
- } catch (Exception e) {
+ } catch (SdcToscaParserException | XmlArtifactGenerationException e) {
log.error(ApplicationMsgs.INVALID_CSAR_FILE, e);
return createErrorData(e);
} finally {
@@ -112,10 +120,12 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
*
* @param serviceVersion
* @param csarHelper
- * interface to the TOSCA parser
+ * interface to the TOSCA parser
* @return the generated Artifacts (containing XML models)
+ * @throws XmlArtifactGenerationException
*/
- private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) {
+ private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper)
+ throws XmlArtifactGenerationException {
List<NodeTemplate> serviceNodeTemplates = csarHelper.getServiceNodeTemplates();
if (serviceNodeTemplates == null) {
throw new IllegalArgumentException(GENERATOR_AAI_ERROR_MISSING_SERVICE_TOSCA);
@@ -170,9 +180,10 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* @param serviceNodeTemplates
* @param serviceModel
* @return the generated Models
+ * @throws XmlArtifactGenerationException
*/
private List<Resource> generateResourceModels(ISdcCsarHelper csarHelper, List<NodeTemplate> serviceNodeTemplates,
- Service serviceModel) {
+ Service serviceModel) throws XmlArtifactGenerationException {
final List<Group> serviceGroups = csarHelper.getGroupsOfTopologyTemplate();
final ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(csarHelper);
@@ -191,7 +202,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
private void generateModelFromNodeTemplate(ISdcCsarHelper csarHelper, Service serviceModel,
List<Resource> resources, final List<Group> serviceGroups, ArtifactGeneratorToscaParser parser,
- NodeTemplate nodeTemplate) {
+ NodeTemplate nodeTemplate) throws XmlArtifactGenerationException {
Resource model = getModelFor(parser, nodeTemplate);
if (model != null) {
@@ -239,7 +250,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
}
private void generateResourceModel(ISdcCsarHelper csarHelper, List<Resource> resources,
- ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) {
+ ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) throws XmlArtifactGenerationException {
Resource resourceModel = getModelFor(parser, nodeTemplate);
if (resourceModel == null) {
log.info(ApplicationMsgs.DISTRIBUTION_EVENT, "Could not generate resource model");
@@ -256,7 +267,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
}
if (parser.hasSubCategoryTunnelXConnect(serviceMetadata) && parser.hasAllottedResource(serviceMetadata)) {
- resourceModel.addWidget(new TunnelXconnectWidget());
+ resourceModel.addWidget(Widget.getWidget(Type.TUNNEL_XCONNECT));
}
resources.addAll(parser.processInstanceGroups(resourceModel, nodeTemplate));
@@ -266,8 +277,10 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
/**
* @param generationData
* @param resource
+ * @throws XmlArtifactGenerationException
*/
- private void generateResourceArtifact(GenerationData generationData, Resource resource) {
+ private void generateResourceArtifact(GenerationData generationData, Resource resource)
+ throws XmlArtifactGenerationException {
if (!isContained(generationData, getArtifactName(resource))) {
log.info(ApplicationMsgs.DISTRIBUTION_EVENT, "Generating resource model");
generationData.add(getResourceArtifact(resource, modelGenerator.generateModelFor(resource)));
@@ -300,7 +313,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Method to generate the artifact name for an AAI model.
*
* @param model
- * AAI artifact model
+ * AAI artifact model
* @return Model artifact name
*/
private String getArtifactName(Model model) {
@@ -324,9 +337,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Create Resource artifact model from the AAI xml model string.
*
* @param resourceModel
- * Model of the resource artifact
+ * Model of the resource artifact
* @param aaiResourceModel
- * AAI model as string
+ * AAI model as string
* @return Generated {@link Artifact} model for the resource
*/
private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
@@ -356,9 +369,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Create Service artifact model from the AAI XML model.
*
* @param serviceModel
- * Model of the service artifact
+ * Model of the service artifact
* @param aaiServiceModel
- * AAI model as string
+ * AAI model as string
* @return Generated {@link Artifact} model for the service
*/
private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
index daf9d36..d3ddafd 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
@@ -18,14 +18,16 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.xml.generator.api;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Service;
public interface AaiModelGenerator {
- public String generateModelFor(Service service);
+ public String generateModelFor(Service service) throws XmlArtifactGenerationException;
- public String generateModelFor(Resource resource);
+ public String generateModelFor(Resource resource) throws XmlArtifactGenerationException;
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java
index 3bff7e7..42cc29e 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java
@@ -29,6 +29,7 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.onap.aai.babel.logging.ApplicationMsgs;
import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
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.Widget;
@@ -56,9 +57,10 @@ public class AaiModelGeneratorImpl implements AaiModelGenerator {
* @param service
* Java object model representing an AAI {@link Service} model
* @return XML representation of the service model in String format
+ * @throws XmlArtifactGenerationException
*/
@Override
- public String generateModelFor(Service service) {
+ public String generateModelFor(Service service) throws XmlArtifactGenerationException {
// Create a JAXB Model for AAI service model
Model aaiServiceModel = new Model();
log.debug("Generating Model for Service with ModelName: " + service.getModelName());
@@ -116,9 +118,10 @@ public class AaiModelGeneratorImpl implements AaiModelGenerator {
* @param resource
* Java object model representing an AAI {@link Resource} model
* @return XML representation of the resource model in String format
+ * @throws XmlArtifactGenerationException
*/
@Override
- public String generateModelFor(Resource resource) {
+ public String generateModelFor(Resource resource) throws XmlArtifactGenerationException {
// Create a JAXB Model for AAI Resource model
Model aaiResourceModel = new Model();
log.debug("Generating Model for Resource with ModelName: " + resource.getModelName());
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java
index bbc7164..9d6409b 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java
@@ -31,6 +31,11 @@ public class GroupConfiguration {
private List<String> instanceGroupTypes;
/**
+ * Set of Widget Types.
+ */
+ private List<WidgetType> widgetTypes;
+
+ /**
* Mapping from TOSCA type to Widget directly.
*/
private List<WidgetMapping> widgetMappings;
@@ -39,7 +44,12 @@ public class GroupConfiguration {
return instanceGroupTypes;
}
+ public List<WidgetType> getWidgetTypes() {
+ return widgetTypes;
+ }
+
public List<WidgetMapping> getWidgetMappings() {
return widgetMappings;
}
+
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java
index 5298f08..7b3d4f2 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java
@@ -27,17 +27,20 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Widget;
+import org.onap.aai.babel.xml.generator.model.Widget.Type;
public class WidgetConfigurationUtil {
private static Properties config;
private static List<String> instanceGroups = Collections.emptyList();
- private static Map<String, Resource> typeToWidget = new HashMap<>();
+ private static Map<String, Resource> typeToResource = new HashMap<>();
+ private static Map<String, Widget> typeToWidget = new HashMap<>();
/*
- * Private constructor to prevent instantiation
+ * Private constructor to prevent instantiation.
*/
private WidgetConfigurationUtil() {
throw new UnsupportedOperationException("This static class should not be instantiated!");
@@ -60,7 +63,27 @@ public class WidgetConfigurationUtil {
}
public static Optional<Resource> createModelFromType(String typePrefix) {
- return Optional.ofNullable(typeToWidget.get(typePrefix));
+ return Optional.ofNullable(typeToResource.get(typePrefix));
+ }
+
+ public static Widget createWidgetFromType(Type type) throws XmlArtifactGenerationException {
+ Optional<Widget> widget = Optional.ofNullable(typeToWidget.get(type.toString()));
+ if (widget.isPresent()) {
+ // Make a copy of the Widget found in the mappings table.
+ return new Widget(widget.get());
+ }
+ return null;
+ }
+
+ public static void setWidgetTypes(List<WidgetType> types) {
+ for (WidgetType type : types) {
+ if (type.type == null || type.name == null) {
+ throw new IllegalArgumentException("Incomplete widget type specified: " + type);
+ }
+ Type widgetType = Widget.Type.valueOf(type.type);
+ Widget widget = new Widget(widgetType, type.name, type.deleteFlag);
+ typeToWidget.put(type.type, widget);
+ }
}
public static void setWidgetMappings(List<WidgetMapping> mappings) {
@@ -70,7 +93,7 @@ public class WidgetConfigurationUtil {
}
Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag);
resource.setIsResource(mapping.type.equalsIgnoreCase("resource"));
- typeToWidget.put(mapping.prefix, resource);
+ typeToResource.put(mapping.prefix, resource);
}
}
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java
index dd46626..95ba7c1 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java
@@ -25,9 +25,9 @@ import java.util.Map;
public class WidgetMapping {
- String prefix = null;
+ String prefix;
String type = "resource"; // Default type is Resource (not Widget)
- String widget = null;
+ String widget;
boolean deleteFlag = true;
Map<String, Object> properties;
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetType.java
index a0f84c7..7691f0f 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetType.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,7 +18,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.babel.xml.generator.model;
-public class ResourceWidget extends Widget {
+package org.onap.aai.babel.xml.generator.data;
+
+public class WidgetType {
+
+ String type;
+ String name;
+ boolean deleteFlag = false;
+
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java
deleted file mode 100644
index 740ca62..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.ALLOTTED_RESOURCE,
- cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "allotted-resource")
-public class AllotedResourceWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/CRWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/CRWidget.java
deleted file mode 100644
index f0962ad..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/CRWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.CR, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "cr")
-public class CRWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ConfigurationWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ConfigurationWidget.java
deleted file mode 100644
index 7822926..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/ConfigurationWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.CONFIGURATION, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "configuration")
-public class ConfigurationWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java
deleted file mode 100644
index 26dde9b..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.FLAVOR, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
-@ModelWidget(type = ModelType.WIDGET, name = "flavor")
-public class FlavorWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java
deleted file mode 100644
index 60656b2..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.IMAGE, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
-@ModelWidget(type = ModelType.WIDGET, name = "image")
-public class ImageWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroupWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroupWidget.java
deleted file mode 100644
index dabce34..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroupWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.INSTANCE_GROUP, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "instance-group")
-public class InstanceGroupWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java
deleted file mode 100644
index f737b82..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.L3_NET, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "l3-network")
-public class L3NetworkWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java
deleted file mode 100644
index fb07ef6..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.LINT, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "l-interface")
-public class LIntfWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
index d4da6df..3c407bd 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
@@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
@@ -158,7 +159,7 @@ public abstract class Model {
public abstract boolean addResource(Resource resource);
- public abstract boolean addWidget(Widget resource);
+ public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException;
public abstract Widget.Type getWidgetType();
@@ -172,9 +173,7 @@ public abstract class Model {
* @return the delete flag
*/
public boolean getDeleteFlag() {
- org.onap.aai.babel.xml.generator.types.Model model =
- this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
- return model.dataDeleteFlag();
+ return true;
}
public String getModelDescription() {
@@ -220,24 +219,22 @@ public abstract class Model {
* Gets widget version id.
*
* @return the widget version id
+ * @throws XmlArtifactGenerationException
*/
- public String getWidgetId() {
- org.onap.aai.babel.xml.generator.types.Model model =
- this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
- return Widget.getWidget(model.widget()).getId();
+ public String getWidgetId() throws XmlArtifactGenerationException {
+ return Widget.getWidget(getWidgetType()).getId();
}
/**
* Gets invariant id.
*
* @return the invariant id
+ * @throws XmlArtifactGenerationException
*/
- public String getWidgetInvariantId() {
- org.onap.aai.babel.xml.generator.types.Model model =
- this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
- return Widget.getWidget(model.widget()).getWidgetId();
+ public String getWidgetInvariantId() throws XmlArtifactGenerationException {
+ return Widget.getWidget(getWidgetType()).getWidgetId();
}
-
+
/**
* Populate model identification information.
*
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java b/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java
deleted file mode 100644
index e9076a9..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.L3_NET, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "oam-network")
-public class OamNetwork extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
index d655ca6..e993c88 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
@@ -24,6 +24,7 @@ package org.onap.aai.babel.xml.generator.model;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
public class Resource extends Model {
@@ -62,15 +63,7 @@ public class Resource extends Model {
return deleteFlag;
}
- @Override
- public String getWidgetInvariantId() {
- return Widget.getWidget(getWidgetType()).getWidgetId();
- }
- @Override
- public String getWidgetId() {
- return Widget.getWidget(getWidgetType()).getId();
- }
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
@@ -105,20 +98,21 @@ public class Resource extends Model {
* @param widget
* the widget
* @return the boolean
+ * @throws XmlArtifactGenerationException
*/
@Override
- public boolean addWidget(Widget widget) {
+ public boolean addWidget(Widget widget) throws XmlArtifactGenerationException {
if (type == Type.VFMODULE) {
if (widget.memberOf(members)) {
- if (vserver == null && widget instanceof VServerWidget) {
+ if (vserver == null && widget.getWidgetType() == Type.VSERVER) {
addVserverWidget(widget);
- } else if (widget instanceof LIntfWidget) {
+ } else if (widget.getWidgetType() == Type.LINT) {
return addLIntfWidget(widget);
- } else if (widget instanceof VolumeWidget) {
+ } else if (widget.getWidgetType() == Type.VOLUME) {
addVolumeWidget(widget);
return true;
}
- if (!(widget instanceof OamNetwork)) {
+ if (widget.getWidgetType() != Type.OAM_NETWORK) {
return widgets.add(widget);
}
}
@@ -159,13 +153,13 @@ public class Resource extends Model {
}
}
- private void addVserverWidget(Widget widget) {
+ private void addVserverWidget(Widget widget) throws XmlArtifactGenerationException {
vserver = widget;
if (addlintf) {
- vserver.addWidget(new LIntfWidget());
+ vserver.addWidget(Widget.getWidget(Type.LINT));
}
if (addvolume) {
- vserver.addWidget(new VolumeWidget());
+ vserver.addWidget(Widget.getWidget(Type.VOLUME));
}
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
index 0815a61..fe8ba04 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
@@ -22,10 +22,8 @@ package org.onap.aai.babel.xml.generator.model;
import java.util.Collections;
import java.util.Map;
-import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.model.Widget.Type;
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.SERVICE, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
public class Service extends Model {
@Override
@@ -40,9 +38,9 @@ public class Service extends Model {
@Override
public Widget.Type getWidgetType() {
- return null;
+ return Type.SERVICE;
}
-
+
@Override
public Map<String, Object> getProperties() {
return Collections.emptyMap();
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java
deleted file mode 100644
index 7c2229d..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@ModelWidget(type = ModelType.WIDGET, name = "service-instance")
-public class ServiceWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java
deleted file mode 100644
index a0a4392..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.TENANT, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
-@ModelWidget(type = ModelType.WIDGET, name = "tenant")
-public class TenantWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java
deleted file mode 100644
index 548cd6f..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.TUNNEL_XCONNECT, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "tunnel-xconnect")
-public class TunnelXconnectWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java
deleted file mode 100644
index dabeecd..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.VSERVER, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "vserver")
-public class VServerWidget extends Widget {
-
- /** Instantiates a new vserver widget. */
- public VServerWidget() {
- addWidget(new FlavorWidget());
- addWidget(new ImageWidget());
- addWidget(new TenantWidget());
- addWidget(new VfcWidget());
- }
-
- @Override
- public boolean addWidget(Widget widget) {
- return widgets.add(widget);
- }
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java
deleted file mode 100644
index cc27ca9..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VFMODULE, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "vf-module")
-public class VfModuleWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java
deleted file mode 100644
index 614244e..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VF, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "generic-vnf")
-public class VfWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java
deleted file mode 100644
index abfa49f..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VFC, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "vnfc")
-public class VfcWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java
deleted file mode 100644
index 3a0aa37..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VOLUME_GROUP, cardinality = Cardinality.UNBOUNDED,
- dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "volume-group")
-public class VolumeGroupWidget extends Widget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java
deleted file mode 100644
index d18a723..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.model;
-
-import org.onap.aai.babel.xml.generator.types.Cardinality;
-import org.onap.aai.babel.xml.generator.types.Model;
-import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-
-@Model(widget = Widget.Type.VOLUME, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
-@ModelWidget(type = ModelType.WIDGET, name = "volume")
-public class VolumeWidget extends ResourceWidget {
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
index be84526..e66b06c 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
@@ -20,24 +20,19 @@
*/
package org.onap.aai.babel.xml.generator.model;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Collections;
-import java.util.EnumMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import org.onap.aai.babel.logging.ApplicationMsgs;
-import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.data.ArtifactType;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
import org.onap.aai.babel.xml.generator.types.ModelType;
-import org.onap.aai.babel.xml.generator.types.ModelWidget;
-import org.onap.aai.cl.api.Logger;
-public abstract class Widget extends Model {
+public class Widget extends Model {
public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
"Cannot generate artifacts. Widget configuration not found for %s";
@@ -46,30 +41,32 @@ public abstract class Widget extends Model {
SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE, OAM_NETWORK, ALLOTTED_RESOURCE, TUNNEL_XCONNECT, CONFIGURATION, CR, INSTANCE_GROUP;
}
- private static Logger log = LogHelper.INSTANCE;
-
private Set<String> keys = new HashSet<>();
- private static EnumMap<Widget.Type, Class<? extends Widget>> typeToWidget = new EnumMap<>(Widget.Type.class);
- static {
- typeToWidget.put(Type.SERVICE, ServiceWidget.class);
- typeToWidget.put(Type.VF, VfWidget.class);
- typeToWidget.put(Type.VFC, VfcWidget.class);
- typeToWidget.put(Type.VSERVER, VServerWidget.class);
- typeToWidget.put(Type.VOLUME, VolumeWidget.class);
- typeToWidget.put(Type.FLAVOR, FlavorWidget.class);
- typeToWidget.put(Type.TENANT, TenantWidget.class);
- typeToWidget.put(Type.VOLUME_GROUP, VolumeGroupWidget.class);
- typeToWidget.put(Type.LINT, LIntfWidget.class);
- typeToWidget.put(Type.L3_NET, L3NetworkWidget.class);
- typeToWidget.put(Type.VFMODULE, VfModuleWidget.class);
- typeToWidget.put(Type.IMAGE, ImageWidget.class);
- typeToWidget.put(Type.OAM_NETWORK, OamNetwork.class);
- typeToWidget.put(Type.ALLOTTED_RESOURCE, AllotedResourceWidget.class);
- typeToWidget.put(Type.TUNNEL_XCONNECT, TunnelXconnectWidget.class);
- typeToWidget.put(Type.CONFIGURATION, ConfigurationWidget.class);
- typeToWidget.put(Type.CR, CRWidget.class);
- typeToWidget.put(Type.INSTANCE_GROUP, InstanceGroupWidget.class);
+ protected String name;
+ protected Type type;
+ protected boolean deleteFlag = false;
+
+ public Widget(Type widgetType, String name, boolean deleteFlag) {
+ type = widgetType;
+ this.name = name;
+ this.deleteFlag = deleteFlag;
+ }
+
+ /**
+ * Copy Constructor
+ *
+ * @param baseWidget
+ * @throws XmlArtifactGenerationException
+ */
+ public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
+ this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag());
+ if (type == Type.VSERVER) {
+ widgets.add(getWidget(Type.FLAVOR));
+ widgets.add(getWidget(Type.IMAGE));
+ widgets.add(getWidget(Type.TENANT));
+ widgets.add(getWidget(Type.VFC));
+ }
}
/**
@@ -77,18 +74,13 @@ public abstract class Widget extends Model {
*
* @param type
* the type
- * @return the widget
+ * @return a new widget of the specified type
+ * @throws XmlArtifactGenerationException
*/
- public static Widget getWidget(Type type) {
- Widget widget = null;
- Class<? extends Widget> clazz = typeToWidget.get(type);
- if (clazz != null) {
- try {
- widget = clazz.getConstructor().newInstance();
- } catch (InstantiationException | java.lang.IllegalAccessException | IllegalArgumentException
- | InvocationTargetException | NoSuchMethodException | SecurityException e) {
- log.error(ApplicationMsgs.INVALID_CSAR_FILE, e);
- }
+ public static Widget getWidget(Type type) throws XmlArtifactGenerationException {
+ Widget widget = WidgetConfigurationUtil.createWidgetFromType(type);
+ if (widget == null) {
+ throw new XmlArtifactGenerationException("No widget type is defined for " + type);
}
return widget;
}
@@ -109,12 +101,11 @@ public abstract class Widget extends Model {
}
public ModelType getType() {
- ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
- return widgetModel.type();
+ return ModelType.WIDGET;
}
public String getName() {
- return this.getClass().getAnnotation(ModelWidget.class).name();
+ return name;
}
/**
@@ -140,7 +131,7 @@ public abstract class Widget extends Model {
@Override
public Type getWidgetType() {
- return null;
+ return type;
}
/**
@@ -188,6 +179,9 @@ public abstract class Widget extends Model {
@Override
public boolean addWidget(Widget widget) {
+ if (getWidgetType() == Type.VSERVER) {
+ return widgets.add(widget);
+ }
return true;
}
@@ -195,4 +189,14 @@ public abstract class Widget extends Model {
public Map<String, Object> getProperties() {
return Collections.emptyMap();
}
+
+ @Override
+ public String toString() {
+ return getName() + " Widget keys=" + keys + ", resources=" + resources + ", widgets=" + widgets;
+ }
+
+ @Override
+ public boolean getDeleteFlag() {
+ return deleteFlag;
+ }
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java b/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java
deleted file mode 100644
index 9cdb93b..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.types;
-
-public enum Cardinality {
- UNBOUNDED
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java
deleted file mode 100644
index f69c3ea..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.types;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.onap.aai.babel.xml.generator.model.Widget;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Model {
-
- /**
- * Widget widget . type.
- *
- * @return the widget . type
- */
- public Widget.Type widget();
-
- /**
- * Data delete flag boolean.
- *
- * @return the boolean
- */
- public boolean dataDeleteFlag();
-
- /**
- * Cardinality cardinality.
- *
- * @return the cardinality
- */
- public Cardinality cardinality();
-}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java
deleted file mode 100644
index 307524e..0000000
--- a/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.xml.generator.types;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ModelWidget {
-
- /**
- * Type model type.
- *
- * @return the model type
- */
- public ModelType type();
-
- /**
- * Name string.
- *
- * @return the string
- */
- public String name();
-}
diff --git a/src/main/resources/babel-logging-resources.properties b/src/main/resources/babel-logging-resources.properties
index 167c369..841bdaf 100644
--- a/src/main/resources/babel-logging-resources.properties
+++ b/src/main/resources/babel-logging-resources.properties
@@ -89,4 +89,9 @@ MISSING_SERVICE_METADATA=\
TEMP_FILE_ERROR=\
BABEL0012E|\
Error creating temporary CSAR file.|\
+
+LOAD_PROPERTIES=\
+ BABEL0013E|\
+ Error loading properties: {0}|Correct the file contents|\
+
\ No newline at end of file
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 a538373..4451a28 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
@@ -25,12 +25,16 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import org.junit.Test;
import org.mockito.Mockito;
+import org.onap.aai.babel.util.ArtifactTestUtils;
+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.Resource;
@@ -50,6 +54,49 @@ public class TestArtifactGeneratorToscaParser {
private static final String TEST_UUID = "1234";
/**
+ * Initialize the Generator with an invalid artifact generator properties file path.
+ *
+ * @throws IOException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testMissingPropertiesFile() throws IOException {
+ System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE, "non-existent.file");
+ ArtifactGeneratorToscaParser.initWidgetConfiguration();
+ }
+
+ /**
+ * Initialize the Generator with an invalid mappings file path.
+ *
+ * @throws IOException
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testMissingMappingsFile() throws IOException {
+ ArtifactGeneratorToscaParser.initToscaMappingsConfiguration("non-existent.file");
+ }
+
+ /**
+ * Initialize the Generator with no Widget Mappings content.
+ *
+ * @throws IOException
+ */
+ @Test(expected = IOException.class)
+ public void testMissingMappingsContent() throws IOException {
+ String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG);
+ ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+ }
+
+ /**
+ * Initialize the Generator with invalid Widget Mappings content.
+ *
+ * @throws IOException
+ */
+ @Test(expected = IOException.class)
+ public void testInvalidMappingsContent() throws IOException {
+ String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.INVALID_TOSCA_MAPPING_CONFIG);
+ ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+ }
+
+ /**
* Process an Allotted Resource that does not have a Providing Service.
*/
@Test(expected = IllegalArgumentException.class)
@@ -92,9 +139,11 @@ public class TestArtifactGeneratorToscaParser {
/**
* Process a dummy Group object for a Service Resource.
+ *
+ * @throws XmlArtifactGenerationException
*/
@Test
- public void testInstanceGroups() {
+ public void testInstanceGroups() throws XmlArtifactGenerationException {
final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup";
WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType));
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 348e1a1..f94328b 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java
@@ -65,7 +65,7 @@ public class TestToscaParser {
GenerationData data =
generator.generateArtifact(CsarTest.VNF_VENDOR_CSAR.getContent(), ymlFiles, additionalParams);
- assertThat("Number of errors produced", data.getErrorData().size(), is(equalTo(0)));
+ assertThat("Number of errors produced " + data.getErrorData(), data.getErrorData().size(), is(equalTo(0)));
assertThat("Number of resources generated", 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 4921490..fe30be4 100644
--- a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
+++ b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
@@ -116,7 +116,7 @@ public class CsarToXmlConverterTest {
*/
@Test
public void testArtifactGeneratorConfigMissing() throws CsarConverterException, IOException {
- exception.expect(CsarConverterException.class);
+ exception.expect(IllegalArgumentException.class);
exception.expectMessage("Cannot generate artifacts. System property artifactgenerator.config not configured");
// Unset the required system property
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 01f62cf..f5a5a94 100644
--- a/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java
+++ b/src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java
@@ -78,6 +78,17 @@ public class ArtifactTestUtils {
}
/**
+ * Load the Widget to UUID mappings from the Artifact Generator Properties (resource).
+ *
+ * @throws IOException
+ * if the properties file is not loaded
+ */
+ public void loadWidgetMappings() throws IOException {
+ ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(getResourcePath(Resources.TOSCA_MAPPING_CONFIG));
+ }
+
+
+ /**
* Specific test method for the YAML Extractor test.
*
* @param toscaFiles
diff --git a/src/test/java/org/onap/aai/babel/util/Resources.java b/src/test/java/org/onap/aai/babel/util/Resources.java
index bbd663d..a8cffdb 100644
--- a/src/test/java/org/onap/aai/babel/util/Resources.java
+++ b/src/test/java/org/onap/aai/babel/util/Resources.java
@@ -27,5 +27,7 @@ public class Resources {
public static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
public static final String TOSCA_MAPPING_CONFIG = "tosca-mappings.json";
+ public static final String EMPTY_TOSCA_MAPPING_CONFIG = "empty-tosca-mappings.json";
+ public static final String INVALID_TOSCA_MAPPING_CONFIG = "invalid-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 92b548a..4c5ff20 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
@@ -46,7 +46,7 @@ public class TestModel {
private Service serviceModel = new Service();
private List<Resource> resourceModels =
Arrays.asList(new Resource(Type.CR, true), new Resource(Type.INSTANCE_GROUP, true));
- private Widget widgetModel = new OamNetwork();
+ private Widget widgetModel = new Widget(Type.OAM_NETWORK, "oam-network", true);
private Model anonymousModel;
static {
@@ -54,7 +54,7 @@ public class TestModel {
}
/**
- * Initialise the Artifact Generator with filtering and mapping configuration. Also Load the Widget to UUID mappings
+ * Initialize the Artifact Generator with filtering and mapping configuration. Also Load the Widget to UUID mappings
* from the Artifact Generator properties.
*
* @throws IOException
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 451d2bb..4171023 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
@@ -33,6 +33,7 @@ import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.aai.babel.util.ArtifactTestUtils;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
/**
@@ -44,9 +45,15 @@ public class TestVfModule {
System.setProperty("APP_HOME", ".");
}
+ /**
+ * @throws IOException
+ * if a properties file is not loaded
+ */
@BeforeClass
public static void setup() throws IOException {
- new ArtifactTestUtils().loadWidgetToUuidMappings();
+ ArtifactTestUtils util = new ArtifactTestUtils();
+ util.loadWidgetToUuidMappings();
+ util.loadWidgetMappings();
}
/**
@@ -80,21 +87,22 @@ public class TestVfModule {
}
@Test
- public void testAddVServerWidgetToVf() {
+ public void testAddVServerWidgetToVf() throws XmlArtifactGenerationException {
assertAddWidget(createNewVfModule(), Type.VSERVER);
}
@Test
- public void testAddServiceWidgetToVf() {
+ public void testAddServiceWidgetToVf() throws XmlArtifactGenerationException {
assertAddWidget(createNewVfModule(), Type.SERVICE);
}
/**
* Add a new Widget to a VF Module, where the Widget is NOT set as a member. N.B. For the current VF Module
* implementation the actual Widget type is not important.
+ * @throws XmlArtifactGenerationException
*/
@Test
- public void testNonMemberWidgetToVf() {
+ public void testNonMemberWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
assertThat(vfModule.addWidget(createNewWidget(Type.SERVICE)), is(false));
assertNumberOfWidgets(vfModule, 0);
@@ -102,9 +110,10 @@ public class TestVfModule {
/**
* OAM Network is specifically excluded from a VF Module.
+ * @throws XmlArtifactGenerationException
*/
@Test
- public void testAddOamNetworkWidgetToVf() {
+ public void testAddOamNetworkWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
assertThat(createNewWidgetForModule(vfModule, Type.OAM_NETWORK), is(false));
assertNumberOfWidgets(vfModule, 0);
@@ -117,9 +126,10 @@ public class TestVfModule {
* <li>Add a Volume Widget</li>
* <li>Add a vserver Widget</li>
* <li>Check that the Volume Widget appears under the vserver</li>
+ * @throws XmlArtifactGenerationException
*/
@Test
- public void testAddVolumeWidgetToVf() {
+ public void testAddVolumeWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
// Adding a Volume widget has no effect until a vserver widget is added.
@@ -149,9 +159,10 @@ public class TestVfModule {
* <li>Add an L-Interface Widget</li>
* <li>Add a vserver Widget</li>
* <li>Check that the L-Interface Widget appears under the vserver</li>
+ * @throws XmlArtifactGenerationException
*/
@Test
- public void testAddLinterfaceWidgetToVf() {
+ public void testAddLinterfaceWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
// Adding an L-Interface widget has no effect until a vserver widget is added.
@@ -182,9 +193,10 @@ public class TestVfModule {
* <li>Add an L-Interface Widget</li>
* <li>Add a vserver Widget</li>
* <li>Check that both Widgets appear under the vserver</li>
+ * @throws XmlArtifactGenerationException
*/
@Test
- public void testAddVolumeAndLinterfaceWidgetToVf() {
+ public void testAddVolumeAndLinterfaceWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
// Adding a Volume widget has no effect until a vserver widget is added.
@@ -222,8 +234,9 @@ public class TestVfModule {
* @param widgetType
* type of Widget to create
* @return a new Widget
+ * @throws XmlArtifactGenerationException
*/
- private Widget createNewWidget(Type widgetType) {
+ private Widget createNewWidget(Type widgetType) throws XmlArtifactGenerationException {
return Widget.getWidget(widgetType);
}
@@ -257,8 +270,9 @@ public class TestVfModule {
* the VF Module to update
* @param widgetType
* the type of Widget to create and add
+ * @throws XmlArtifactGenerationException
*/
- private void assertAddWidget(Resource vfModule, Type widgetType) {
+ private void assertAddWidget(Resource vfModule, Type widgetType) throws XmlArtifactGenerationException {
assertThat(createNewWidgetForModule(vfModule, widgetType), is(true));
}
@@ -269,8 +283,9 @@ public class TestVfModule {
* the VF Module
* @param widgetType
* the type of Widget to create and attempt to add
+ * @throws XmlArtifactGenerationException
*/
- private void assertFailToAddWidget(Resource vfModule, Type widgetType) {
+ private void assertFailToAddWidget(Resource vfModule, Type widgetType) throws XmlArtifactGenerationException {
assertThat(createNewWidgetForModule(vfModule, widgetType), is(false));
}
@@ -282,8 +297,9 @@ public class TestVfModule {
* @param widgetType
* the type of Widget to create and attempt to add
* @return whether or not the Widget was added to the module
+ * @throws XmlArtifactGenerationException
*/
- private boolean createNewWidgetForModule(Resource vfModule, Type widgetType) {
+ private boolean createNewWidgetForModule(Resource vfModule, Type widgetType) throws XmlArtifactGenerationException {
Widget widget = createNewWidget(widgetType);
setWidgetAsMember(vfModule, widget);
return vfModule.addWidget(widget);
@@ -311,9 +327,10 @@ public class TestVfModule {
* @param vfModule
* the VF Module to update
* @return the number of Widgets present in the vserver on creation
+ * @throws XmlArtifactGenerationException
*/
- private int createVserverForVf(Resource vfModule) {
- VServerWidget vserverWidget = (VServerWidget) createNewWidget(Type.VSERVER);
+ private int createVserverForVf(Resource vfModule) throws XmlArtifactGenerationException {
+ Widget vserverWidget = createNewWidget(Type.VSERVER);
assertNumberOfWidgets(vfModule, 0);
final int initialWidgetCount = addVserverToVf(vfModule, vserverWidget);
assertNumberOfWidgets(vfModule, 1);
@@ -328,8 +345,9 @@ public class TestVfModule {
* @param vserverWidget
* the Widget to add
* @return initial widget count for the vserver Widget
+ * @throws XmlArtifactGenerationException
*/
- private int addVserverToVf(Resource vfModule, VServerWidget vserverWidget) {
+ private int addVserverToVf(Resource vfModule, Widget vserverWidget) throws XmlArtifactGenerationException {
// A vserver (initially) has Flavor, Image, Tenant and Vfc.
final int initialWidgetCount = 4;
assertNumberOfWidgets(vserverWidget, initialWidgetCount);
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 d7fe4af..da6e4d5 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
@@ -21,9 +21,7 @@
package org.onap.aai.babel.xml.generator.model;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import java.io.IOException;
@@ -31,11 +29,12 @@ import java.util.Collections;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.aai.babel.util.ArtifactTestUtils;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
import org.onap.aai.babel.xml.generator.types.ModelType;
/**
- * Direct tests of the Widget class for code coverage.
+ * Direct tests of the Widget class for code coverage.
*/
public class TestWidget {
@@ -51,44 +50,106 @@ public class TestWidget {
*/
@BeforeClass
public static void setup() throws IOException {
- new ArtifactTestUtils().loadWidgetToUuidMappings();
+ ArtifactTestUtils util = new ArtifactTestUtils();
+ util.loadWidgetToUuidMappings();
+ util.loadWidgetMappings();
}
@Test
- public void testGetWidgets() {
- assertThat(Widget.getWidget(Type.SERVICE), instanceOf(ServiceWidget.class));
- assertThat(Widget.getWidget(Type.VF), instanceOf(VfWidget.class));
- assertThat(Widget.getWidget(Type.VFC), instanceOf(VfcWidget.class));
- assertThat(Widget.getWidget(Type.VSERVER), instanceOf(VServerWidget.class));
- assertThat(Widget.getWidget(Type.VOLUME), instanceOf(VolumeWidget.class));
- assertThat(Widget.getWidget(Type.FLAVOR), instanceOf(FlavorWidget.class));
- assertThat(Widget.getWidget(Type.TENANT), instanceOf(TenantWidget.class));
- assertThat(Widget.getWidget(Type.VOLUME_GROUP), instanceOf(VolumeGroupWidget.class));
- assertThat(Widget.getWidget(Type.LINT), instanceOf(LIntfWidget.class));
- assertThat(Widget.getWidget(Type.L3_NET), instanceOf(L3NetworkWidget.class));
- assertThat(Widget.getWidget(Type.VFMODULE), instanceOf(VfModuleWidget.class));
- assertThat(Widget.getWidget(Type.IMAGE), instanceOf(ImageWidget.class));
- assertThat(Widget.getWidget(Type.OAM_NETWORK), instanceOf(OamNetwork.class));
- assertThat(Widget.getWidget(Type.ALLOTTED_RESOURCE), instanceOf(AllotedResourceWidget.class));
- assertThat(Widget.getWidget(Type.TUNNEL_XCONNECT), instanceOf(TunnelXconnectWidget.class));
- assertThat(Widget.getWidget(Type.CONFIGURATION), instanceOf(ConfigurationWidget.class));
+ public void testGetWidgets() throws XmlArtifactGenerationException {
+ Widget widget = Widget.getWidget(Type.SERVICE);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("service-instance"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.VF);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("generic-vnf"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(Type.VFC);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vnfc"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.VSERVER);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vserver"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.VOLUME);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("volume"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.FLAVOR);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("flavor"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(Type.TENANT);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("tenant"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(Type.VOLUME_GROUP);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("volume-group"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.LINT);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("l-interface"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.L3_NET);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("l3-network"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.VFMODULE);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vf-module"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.IMAGE);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("image"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(Type.OAM_NETWORK);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("oam-network"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.ALLOTTED_RESOURCE);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("allotted-resource"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.TUNNEL_XCONNECT);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("tunnel-xconnect"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.CONFIGURATION);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("configuration"));
+ assertThat(widget.getDeleteFlag(), is(true));
}
@Test
- public void testWidgetMethods() {
- Widget widget = new ServiceWidget();
+ public void testWidgetMethods() throws XmlArtifactGenerationException {
+ Widget widget = new Widget(Type.SERVICE, "service-instance", true);
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
- assertThat(widget.addWidget(new TenantWidget()), is(true));
+ assertThat(widget.addWidget(Widget.getWidget(Type.TENANT)), is(true));
assertThat(widget.memberOf(null), is(false));
assertThat(widget.memberOf(Collections.emptyList()), is(false));
-
- widget = new VolumeGroupWidget(); // just for variety
- assertThat(widget.getWidgetType(), is(nullValue()));
}
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
- public void testAddResourceIsUnsupported() {
- new OamNetwork().addResource(null);
+ public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException {
+ Widget.getWidget(Type.OAM_NETWORK).addResource(null);
}
}
diff --git a/src/test/resources/empty-tosca-mappings.json b/src/test/resources/empty-tosca-mappings.json
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/test/resources/empty-tosca-mappings.json
diff --git a/src/test/resources/invalid-tosca-mappings.json b/src/test/resources/invalid-tosca-mappings.json
new file mode 100644
index 0000000..bbd27bd
--- /dev/null
+++ b/src/test/resources/invalid-tosca-mappings.json
@@ -0,0 +1 @@
+test file that does not contain valid JSON content \ No newline at end of file
diff --git a/src/test/resources/tosca-mappings.json b/src/test/resources/tosca-mappings.json
index 0d306ea..c67b3e2 100644
--- a/src/test/resources/tosca-mappings.json
+++ b/src/test/resources/tosca-mappings.json
@@ -4,6 +4,98 @@
"org.openecomp.groups.VfcInstanceGroup",
"org.openecomp.groups.ResourceInstanceGroup"
],
+ "widgetTypes": [
+ {
+ "type": "SERVICE",
+ "name": "service-instance",
+ "deleteFlag": true
+ },
+ {
+ "type": "VF",
+ "name": "generic-vnf",
+ "deleteFlag": false
+ },
+ {
+ "type": "VFC",
+ "name": "vnfc",
+ "deleteFlag": true
+ },
+ {
+ "type": "VSERVER",
+ "name": "vserver",
+ "deleteFlag": true
+ },
+ {
+ "type": "VOLUME",
+ "name": "volume",
+ "deleteFlag": true
+ },
+ {
+ "type": "FLAVOR",
+ "name": "flavor",
+ "deleteFlag": false
+ },
+ {
+ "type": "TENANT",
+ "name": "tenant",
+ "deleteFlag": false
+ },
+ {
+ "type": "VOLUME_GROUP",
+ "name": "volume-group",
+ "deleteFlag": true
+ },
+ {
+ "type": "LINT",
+ "name": "l-interface",
+ "deleteFlag": true
+ },
+ {
+ "type": "L3_NET",
+ "name": "l3-network",
+ "deleteFlag": true
+ },
+ {
+ "type": "VFMODULE",
+ "name": "vf-module",
+ "deleteFlag": true
+ },
+ {
+ "type": "IMAGE",
+ "name": "image",
+ "deleteFlag": false
+ },
+ {
+ "type": "OAM_NETWORK",
+ "name": "oam-network",
+ "deleteFlag": true
+ },
+ {
+ "type": "ALLOTTED_RESOURCE",
+ "name": "allotted-resource",
+ "deleteFlag": true
+ },
+ {
+ "type": "TUNNEL_XCONNECT",
+ "name": "tunnel-xconnect",
+ "deleteFlag": true
+ },
+ {
+ "type": "CONFIGURATION",
+ "name": "configuration",
+ "deleteFlag": true
+ },
+ {
+ "type": "CR",
+ "name": "cr",
+ "deleteFlag": true
+ },
+ {
+ "type": "INSTANCE_GROUP",
+ "name": "instance-group",
+ "deleteFlag": true
+ }
+ ],
"widgetMappings": [
{
"prefix": "org.openecomp.resource.vfc",