summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-03-07 16:17:06 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-03-07 16:47:20 +0000
commit5a6fd49a6aca3a567464527335b107746e28f3bd (patch)
treec4c77e4684cfb9de1300d62a44d3772699d60d4d /src
parentf03e49cdf5c8d54733416ab244826b9429c9c86c (diff)
Re-implement model type value for Resource Mapping
Refactor the Model/Service/Resource/Widget hierarchy to improve code readability. Replace the configurable Boolean value for a Resource's model type with a value from the existing ModelType enum. Obtain the A&AI XML Model name (always resource or service) directly from the Model class and not from the configured model type for the Resource. Change-Id: I1487d919392b34e4bf1314da8cd2805a9fbf96a3 Issue-ID: AAI-2212 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java33
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java14
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java8
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java17
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java5
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java36
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java42
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Service.java21
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java31
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java30
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java35
11 files changed, 105 insertions, 167 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 ce1c352..6e37587 100644
--- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
+++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -44,6 +44,7 @@ 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.Widget;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.toscaparser.api.Group;
@@ -93,24 +94,6 @@ public class ArtifactGeneratorToscaParser {
}
/**
- * Get or create the artifact description.
- *
- * @param model
- * the artifact model
- * @return the artifact model's description
- */
- public static String getArtifactDescription(Model model) {
- switch (model.getModelType()) {
- case SERVICE:
- return "AAI Service Model";
- case RESOURCE:
- return "AAI Resource Model";
- default:
- return model.getModelDescription();
- }
- }
-
- /**
* Initializes the Widget to UUID mapping configuration.
*
* @throws IOException
@@ -223,7 +206,7 @@ public class ArtifactGeneratorToscaParser {
* if the relation is a widget and there is no configuration defined for the relation's widget type
*/
public void addRelatedModel(final Model model, final Resource relation) throws XmlArtifactGenerationException {
- if (relation.isResource()) {
+ if (relation.getModelType() == ModelType.RESOURCE) {
model.addResource(relation);
} else {
model.addWidget(Widget.getWidget(relation.getWidgetType()));
@@ -350,7 +333,7 @@ public class ArtifactGeneratorToscaParser {
memberModel.getClass().getSuperclass().getSimpleName(), memberModel.getClass(), nodeTypeName));
addRelatedModel(groupModel, memberModel);
- if (memberModel.isResource()) {
+ if (memberModel.getModelType() == ModelType.RESOURCE) {
resources.add(memberModel);
}
}
@@ -398,10 +381,10 @@ public class ArtifactGeneratorToscaParser {
if (resource.getWidgetType() == Type.L3_NET) {
// An l3-network inside a vf-module is treated as a Widget
- resource.setIsResource(false);
+ resource.setModelType(ModelType.WIDGET);
}
- if (!resource.isResource()) {
+ if (resource.getModelType() == ModelType.WIDGET) {
Widget widget = Widget.getWidget(resource.getWidgetType());
widget.addKey(member.getName());
// Add the widget element encountered to the Group model
@@ -442,7 +425,7 @@ public class ArtifactGeneratorToscaParser {
if (foundProvidingService) {
processProvidingService(resourceModel, resourceNode, nodeProperties);
- } else if (resourceNode != null && resourceNode.isResource()
+ } else if (resourceNode != null && resourceNode.getModelType() == ModelType.RESOURCE
&& resourceNode.getWidgetType() != Widget.Type.L3_NET) {
if (metaData != null) {
resourceNode.populateModelIdentificationInformation(metaData.getAllProperties());
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 75c5073..8742de3 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
@@ -46,6 +46,7 @@ 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;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
@@ -211,7 +212,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
}
parser.addRelatedModel(serviceModel, model);
- if (model.isResource()) {
+ if (model.getModelType() == ModelType.RESOURCE) {
generateResourceModel(csarHelper, resources, parser, nodeTemplate);
}
} else {
@@ -303,7 +304,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
private String getArtifactLabel(Model model) {
StringBuilder artifactName = new StringBuilder(ArtifactType.AAI.name());
artifactName.append("-");
- artifactName.append(model.getModelType().name().toLowerCase());
+ artifactName.append(model.getModelTypeName());
artifactName.append("-");
artifactName.append(hashCodeUuId(model.getModelNameVersionId()));
return (artifactName.toString()).replaceAll("[^a-zA-Z0-9 +]+", "-");
@@ -324,7 +325,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
artifactName.append(truncatedArtifactName);
artifactName.append("-");
- artifactName.append(model.getModelType().name().toLowerCase());
+ artifactName.append(model.getModelTypeName());
artifactName.append("-");
artifactName.append(model.getModelVersion());
@@ -342,7 +343,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* AAI model as string
* @return Generated {@link Artifact} model for the resource
*/
- private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
+ private Artifact getResourceArtifact(Resource resourceModel, String aaiResourceModel) {
final String resourceArtifactLabel = getArtifactLabel(resourceModel);
MDC.put(MDC_PARAM_MODEL_INFO, resourceModel.getModelName() + "," + resourceArtifactLabel);
final byte[] bytes = aaiResourceModel.getBytes();
@@ -351,7 +352,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
GeneratorUtil.checkSum(bytes), GeneratorUtil.encode(bytes));
artifact.setName(getArtifactName(resourceModel));
artifact.setLabel(resourceArtifactLabel);
- artifact.setDescription(ArtifactGeneratorToscaParser.getArtifactDescription(resourceModel));
+ artifact.setDescription("AAI Resource Model");
return artifact;
}
@@ -381,8 +382,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
String serviceArtifactLabel = getArtifactLabel(serviceModel);
artifact.setName(serviceArtifactName);
artifact.setLabel(serviceArtifactLabel);
- String description = ArtifactGeneratorToscaParser.getArtifactDescription(serviceModel);
- artifact.setDescription(description);
+ artifact.setDescription("AAI Service Model");
return artifact;
}
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 42cc29e..5c6488c 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
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -75,7 +75,7 @@ public class AaiModelGeneratorImpl implements AaiModelGenerator {
modelVer.setModelElements(new ModelElements());
ModelElements modelElements = modelVer.getModelElements();
// Populate basic model details
- aaiServiceModel.setModelType(service.getModelType().name().toLowerCase()); // Using enum name as model type
+ aaiServiceModel.setModelType(service.getModelTypeName());
List<ModelElement> modelElementList = modelElements.getModelElement();
// Add service base widget model element
@@ -134,7 +134,7 @@ public class AaiModelGeneratorImpl implements AaiModelGenerator {
modelVer.setModelVersionId(resource.getModelNameVersionId());
modelVer.setModelElements(new ModelElements());
ModelElements modelElements = modelVer.getModelElements();
- aaiResourceModel.setModelType(resource.getModelType().name().toLowerCase()); // Using enum name as model type
+ aaiResourceModel.setModelType(resource.getModelTypeName());
List<ModelElement> modelElementList = modelElements.getModelElement();
// Add resource base widget model element
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 7b3d4f2..b340cd9 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
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -21,6 +21,8 @@
package org.onap.aai.babel.xml.generator.data;
+import com.google.common.base.Enums;
+import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -31,6 +33,7 @@ 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;
+import org.onap.aai.babel.xml.generator.types.ModelType;
public class WidgetConfigurationUtil {
@@ -86,13 +89,15 @@ public class WidgetConfigurationUtil {
}
}
- public static void setWidgetMappings(List<WidgetMapping> mappings) {
+ public static void setWidgetMappings(List<WidgetMapping> mappings) throws IOException {
for (WidgetMapping mapping : mappings) {
- if (mapping.prefix == null || mapping.widget == null) {
- throw new IllegalArgumentException("Incomplete widget mapping specified: " + mapping);
+ ModelType modelType = Optional.ofNullable(mapping.type).map(String::toUpperCase)
+ .map(s -> Enums.getIfPresent(ModelType.class, s).orNull()).orElse(null);
+ if (mapping.prefix == null || mapping.widget == null || modelType == null) {
+ throw new IOException("Invalid widget mapping specified: " + mapping);
}
Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag);
- resource.setIsResource(mapping.type.equalsIgnoreCase("resource"));
+ resource.setModelType(modelType);
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 95ba7c1..2b298da 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
@@ -21,15 +21,12 @@
package org.onap.aai.babel.xml.generator.data;
-import java.util.Map;
-
public class WidgetMapping {
String prefix;
String type = "resource"; // Default type is Resource (not Widget)
String widget;
boolean deleteFlag = true;
- Map<String, Object> properties;
public void setType(String type) {
this.type = type;
@@ -42,6 +39,6 @@ public class WidgetMapping {
@Override
public String toString() {
return "WidgetMapping [prefix=" + prefix + ", type=" + type + ", widget=" + widget + ", deleteFlag="
- + deleteFlag + ", properties=" + properties + "]";
+ + deleteFlag + "]";
}
}
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 3f081df..c67d67f 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
@@ -30,9 +30,7 @@ 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;
-import org.onap.aai.babel.xml.generator.types.ModelType;
public abstract class Model {
@@ -158,15 +156,15 @@ public abstract class Model {
}
}
- public abstract boolean addResource(Resource resource);
-
public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException;
public abstract Widget.Type getWidgetType();
- public abstract Map<String, Object> getProperties();
+ public abstract String getModelTypeName();
- public abstract boolean isResource();
+ public boolean addResource(Resource resource) {
+ return resources.add(resource);
+ }
/**
* Gets delete flag.
@@ -182,7 +180,6 @@ public abstract class Model {
}
public String getModelId() {
- checkSupported();
return modelId;
}
@@ -195,28 +192,10 @@ public abstract class Model {
}
public String getModelNameVersionId() {
- checkSupported();
return modelNameVersionId;
}
/**
- * Gets model type.
- *
- * @return the model type
- */
- public ModelType getModelType() {
- if (this instanceof Service) {
- return ModelType.SERVICE;
- } else if (this instanceof Resource) {
- return ModelType.RESOURCE;
- } else if (this instanceof Widget) {
- return ModelType.WIDGET;
- } else {
- return null;
- }
- }
-
- /**
* Gets widget version id.
*
* @return the widget version id
@@ -266,10 +245,9 @@ public abstract class Model {
return widgets;
}
- private void checkSupported() {
- if (this instanceof Widget) {
- throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
- }
+ @Override
+ public String toString() {
+ return "Model [type=" + getModelTypeName() + ", name=" + getModelName() + "]";
}
}
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 e993c88..911bf32 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
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2017-2019 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,12 +26,13 @@ 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;
+import org.onap.aai.babel.xml.generator.types.ModelType;
public class Resource extends Model {
-
+
private Type type;
private boolean deleteFlag;
- private boolean isResource = true;
+ private ModelType modelType = ModelType.RESOURCE;
private Map<String, Object> properties = Collections.emptyMap();
Widget vserver = null;
@@ -63,35 +64,26 @@ public class Resource extends Model {
return deleteFlag;
}
-
-
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
- @Override
public Map<String, Object> getProperties() {
return properties;
}
-
- public void setIsResource(boolean isResource) {
- this.isResource = isResource;
+
+ public void setModelType(ModelType type) {
+ this.modelType = type;
}
-
- @Override
- public boolean isResource() {
- return isResource;
+
+ public ModelType getModelType() {
+ return modelType;
}
-
+
public void setMembers(List<String> members) {
this.members = members;
}
- @Override
- public boolean addResource(Resource resource) {
- return resources.add(resource);
- }
-
/**
* Adds a Widget.
*
@@ -121,14 +113,20 @@ public class Resource extends Model {
return widgets.add(widget);
}
}
-
+
public Type getWidgetType() {
return type;
}
+
+ public String getModelTypeName() {
+ return "resource";
+ }
@Override
public String toString() {
- return "Widget type " + getWidgetType() + ", isResource=" + isResource() + ", deleteFlag=" + deleteFlag;
+ return "Resource [widget type=" + getWidgetType() + ", deleteFlag=" + deleteFlag + ", modelType=" + modelType
+ + ", properties=" + properties + ", vserver=" + vserver + ", addlintf=" + addlintf + ", addvolume="
+ + addvolume + ", members=" + members + "]";
}
private void addVolumeWidget(Widget widget) {
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 8a9e428..6c96e96 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
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2019 European Software Marketing Ltd.
+ * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 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.
@@ -21,18 +21,11 @@
package org.onap.aai.babel.xml.generator.model;
-import java.util.Collections;
-import java.util.Map;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
public class Service extends Model {
@Override
- public boolean addResource(Resource resource) {
- return resources.add(resource);
- }
-
- @Override
public boolean addWidget(Widget widget) {
return widgets.add(widget);
}
@@ -42,13 +35,7 @@ public class Service extends Model {
return Type.SERVICE;
}
- @Override
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
- }
-
- @Override
- public boolean isResource() {
- return false;
+ public String getModelTypeName() {
+ return "service";
}
}
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 44beb65..2decc8c 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
@@ -24,7 +24,6 @@ package org.onap.aai.babel.xml.generator.model;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
@@ -58,7 +57,7 @@ public class Widget extends Model {
* Copy Constructor.
*
* @param baseWidget
- * @throws XmlArtifactGenerationException
+ * @throws XmlArtifactGenerationException
*/
public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag());
@@ -76,7 +75,7 @@ public class Widget extends Model {
* @param type
* the type
* @return a new widget of the specified type
- * @throws XmlArtifactGenerationException
+ * @throws XmlArtifactGenerationException
* if there is no configuration defined for the specified type
*/
public static Widget getWidget(Type type) throws XmlArtifactGenerationException {
@@ -87,11 +86,6 @@ public class Widget extends Model {
return widget;
}
- @Override
- public boolean isResource() {
- return false;
- }
-
public String getId() {
String id = WidgetConfigurationUtil.getConfig()
.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
@@ -188,11 +182,6 @@ public class Widget extends Model {
}
@Override
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
- }
-
- @Override
public String toString() {
return getName() + " Widget keys=" + keys + ", resources=" + resources + ", widgets=" + widgets;
}
@@ -201,4 +190,20 @@ public class Widget extends Model {
public boolean getDeleteFlag() {
return deleteFlag;
}
+
+ @Override
+ public String getModelTypeName() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
+ @Override
+ public String getModelId() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
+ @Override
+ public String getModelNameVersionId() {
+ throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
}
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 2de10b9..acc4a35 100644
--- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
+++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
@@ -122,25 +122,41 @@ public class TestArtifactGeneratorToscaParser {
}
/**
- * Initialise the Artifact Generator Widget Mapping config with incomplete data (no type).
+ * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
+ *
+ * @throws IOException
*/
- @Test(expected = IllegalArgumentException.class)
- public void testToscaMappingWithoutType() {
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithoutType() throws IOException {
WidgetMapping invalidMapping = new WidgetMapping();
invalidMapping.setType(null);
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
}
/**
- * Initialise the Artifact Generator Widget Mapping config with incomplete data (no widget name).
+ * Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
+ *
+ * @throws IOException
*/
- @Test(expected = IllegalArgumentException.class)
- public void testToscaMappingWithoutWidget() {
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithInvalidType() throws IOException {
+ WidgetMapping invalidMapping = new WidgetMapping();
+ invalidMapping.setType("invalid");
+ WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+ }
+
+ /**
+ * Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
+ *
+ * @throws IOException
+ */
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithoutWidget() throws IOException {
WidgetMapping invalidMapping = new WidgetMapping();
invalidMapping.setWidget(null);
WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
}
-
+
/**
* Process a dummy Group object for a Service Resource.
*
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 c564a93..f2b78a1 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
@@ -26,16 +26,11 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
import org.onap.aai.babel.util.ArtifactTestUtils;
import org.onap.aai.babel.xml.generator.model.Widget.Type;
-import org.onap.aai.babel.xml.generator.types.ModelType;
/**
* Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
@@ -43,9 +38,6 @@ import org.onap.aai.babel.xml.generator.types.ModelType;
*/
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 Widget(Type.OAM_NETWORK, "oam-network", true);
private Model anonymousModel;
@@ -73,11 +65,6 @@ public class TestModel {
anonymousModel = new Model() {
@Override
- public boolean addResource(Resource resource) {
- return false;
- }
-
- @Override
public boolean addWidget(Widget resource) {
return false;
}
@@ -88,13 +75,8 @@ public class TestModel {
}
@Override
- public Map<String, Object> getProperties() {
- return Collections.emptyMap();
- }
-
- @Override
- public boolean isResource() {
- return false;
+ public String getModelTypeName() {
+ return null;
}
};
}
@@ -149,16 +131,6 @@ public class TestModel {
}
@Test
- public void testGetModelType() {
- assertThat(serviceModel.getModelType(), is(ModelType.SERVICE));
- for (Resource resourceModel : resourceModels) {
- assertThat(resourceModel.getModelType(), is(ModelType.RESOURCE));
- }
- assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
- assertThat(anonymousModel.getModelType(), is(nullValue()));
- }
-
- @Test
public void testGetModelNameVersionId() {
assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
}
@@ -166,9 +138,6 @@ public class TestModel {
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
public void testGetModelNameVersionIdIsUnsupported() {
assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
- assertThat(resourceModels.get(0).getModelType(), is(ModelType.RESOURCE));
- assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
- assertThat(anonymousModel.getModelType(), is(nullValue()));
}
}