aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java25
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java22
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java11
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java4
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java4
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java38
-rw-r--r--src/test/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverterTest.java9
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java3
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java37
-rw-r--r--src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java78
10 files changed, 153 insertions, 78 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 684324a..9b66e58 100644
--- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
+++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
@@ -209,7 +209,7 @@ public class ArtifactGeneratorToscaParser {
if (relation.getModelType() == ModelType.RESOURCE) {
model.addResource(relation);
} else {
- model.addWidget(Widget.getWidget(relation.getWidgetType()));
+ model.addWidget(Widget.createWidget(relation.getWidgetType()));
}
}
@@ -228,10 +228,11 @@ public class ArtifactGeneratorToscaParser {
* @param model
* @param serviceNode
* @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support the widget type of a VF Module
*/
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
+ // Get the customization UUID for each VF node and use it to get its Groups
String uuid = csarHelper.getNodeTemplateCustomizationUuid(serviceNode);
List<Group> serviceGroups = csarHelper.getVfModulesByVf(uuid);
@@ -341,6 +342,15 @@ public class ArtifactGeneratorToscaParser {
return resources;
}
+ /**
+ * @param resources
+ * @param vfModel
+ * @param groupDefinition
+ * @param serviceNode
+ * @param groupModel
+ * @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support the widget type of a VF Module
+ */
private void processVfModule(List<Resource> resources, Model vfModel, Group groupDefinition,
NodeTemplate serviceNode, Resource groupModel) throws XmlArtifactGenerationException {
groupModel.populateModelIdentificationInformation(
@@ -355,6 +365,12 @@ public class ArtifactGeneratorToscaParser {
}
}
+ /**
+ * @param groupModel
+ * @param members
+ * @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support the widget type of a member
+ */
private void processVfModuleGroup(Resource groupModel, List<NodeTemplate> members)
throws XmlArtifactGenerationException {
if (members != null && !members.isEmpty()) {
@@ -371,8 +387,11 @@ public class ArtifactGeneratorToscaParser {
* Process the Widget members of a VF Module Group
*
* @param group
+ * the group resource model
* @param member
+ * the group member to process
* @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support the widget type of the member
*/
private void processGroupMembers(Resource group, NodeTemplate member) throws XmlArtifactGenerationException {
Resource resource = Model.getModelFor(member.getType());
@@ -385,7 +404,7 @@ public class ArtifactGeneratorToscaParser {
}
if (resource.getModelType() == ModelType.WIDGET) {
- Widget widget = Widget.getWidget(resource.getWidgetType());
+ Widget widget = Widget.createWidget(resource.getWidgetType());
widget.addKey(member.getName());
// Add the widget element encountered to the Group model
group.addWidget(widget);
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 7415702..2b8b128 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
@@ -124,6 +124,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* interface to the TOSCA parser
* @return the generated Artifacts (containing XML models)
* @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support processed widget type(s)
*/
public GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper)
throws XmlArtifactGenerationException {
@@ -182,6 +183,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* @param serviceModel
* @return the generated Models
* @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support processed widget type(s)
*/
private List<Resource> generateResourceModels(ISdcCsarHelper csarHelper, List<NodeTemplate> serviceNodeTemplates,
Service serviceModel) throws XmlArtifactGenerationException {
@@ -201,6 +203,16 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
return resources;
}
+ /**
+ * @param csarHelper
+ * @param serviceModel
+ * @param resources
+ * @param serviceGroups
+ * @param parser
+ * @param nodeTemplate
+ * @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support processed widget type(s)
+ */
private void generateModelFromNodeTemplate(ISdcCsarHelper csarHelper, Service serviceModel,
List<Resource> resources, final List<Group> serviceGroups, ArtifactGeneratorToscaParser parser,
NodeTemplate nodeTemplate) throws XmlArtifactGenerationException {
@@ -250,6 +262,14 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
return model;
}
+ /**
+ * @param csarHelper
+ * @param resources
+ * @param parser
+ * @param nodeTemplate
+ * @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support processed widget type(s)
+ */
private void generateResourceModel(ISdcCsarHelper csarHelper, List<Resource> resources,
ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) throws XmlArtifactGenerationException {
Resource resourceModel = getModelFor(parser, nodeTemplate);
@@ -268,7 +288,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
}
if (parser.hasSubCategoryTunnelXConnect(serviceMetadata) && parser.hasAllottedResource(serviceMetadata)) {
- resourceModel.addWidget(Widget.getWidget(WidgetType.valueOf("TUNNEL_XCONNECT")));
+ resourceModel.addWidget(Widget.createWidget("TUNNEL_XCONNECT"));
}
resources.addAll(parser.processInstanceGroups(resourceModel, nodeTemplate));
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 1e41f60..baecada 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
@@ -74,6 +74,15 @@ public class WidgetConfigurationUtil {
return resource;
}
+ /**
+ * Create a new Widget object according to the supplied Widget Type.
+ *
+ * @param widgetType
+ * a String identifying the type of Widget to create
+ * @return a new Widget object from the defined widget type, or else null
+ * @throws XmlArtifactGenerationException
+ * if there is an internal error creating the Widget because of the defined widget mappings
+ */
public static Widget createWidgetFromType(String widgetType) throws XmlArtifactGenerationException {
Optional<Widget> widget = Optional.ofNullable(typeToWidget.get(widgetType));
if (widget.isPresent()) {
@@ -96,7 +105,7 @@ public class WidgetConfigurationUtil {
WidgetType.validateElements();
}
- public static void setWidgetMappings(List<WidgetMapping> mappings) throws IOException {
+ public static void setWidgetMappings(List<WidgetMapping> mappings) throws IOException {
for (WidgetMapping mapping : mappings) {
ModelType modelType = Optional.ofNullable(mapping.type).map(String::toUpperCase)
.map(s -> Enums.getIfPresent(ModelType.class, s).orNull()).orElse(null);
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 b2020cd..84b5489 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
@@ -215,7 +215,7 @@ public abstract class Model {
* @throws XmlArtifactGenerationException
*/
public String getWidgetId() throws XmlArtifactGenerationException {
- return Widget.getWidget(getWidgetType()).getId();
+ return Widget.createWidget(getWidgetType()).getId();
}
/**
@@ -225,7 +225,7 @@ public abstract class Model {
* @throws XmlArtifactGenerationException
*/
public String getWidgetInvariantId() throws XmlArtifactGenerationException {
- return Widget.getWidget(getWidgetType()).getWidgetId();
+ return Widget.createWidget(getWidgetType()).getWidgetId();
}
/**
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 77679ac..04c69bb 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
@@ -165,10 +165,10 @@ public class Resource extends Model {
private void addVserverWidget(Widget widget) throws XmlArtifactGenerationException {
vserver = widget;
if (addlintf) {
- vserver.addWidget(Widget.getWidget(WidgetType.valueOf("LINT")));
+ vserver.addWidget(Widget.createWidget("LINT"));
}
if (addvolume) {
- vserver.addWidget(Widget.getWidget(WidgetType.valueOf("VOLUME")));
+ vserver.addWidget(Widget.createWidget("VOLUME"));
}
}
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 732ec4d..78a1e8a 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
@@ -51,37 +51,51 @@ public class Widget extends Model {
/**
* Copy Constructor.
- *
+ *
* @param baseWidget
* @throws XmlArtifactGenerationException
+ * if there is no widget mapping defined for any of the VSERVER child types
*/
public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag());
- if (type == WidgetType.valueOf("VSERVER")) {
- widgets.add(getWidget(WidgetType.valueOf("FLAVOR")));
- widgets.add(getWidget(WidgetType.valueOf("IMAGE")));
- widgets.add(getWidget(WidgetType.valueOf("TENANT")));
- widgets.add(getWidget(WidgetType.valueOf("VFC")));
+ if (this.hasWidgetType("VSERVER")) {
+ widgets.add(createWidget("FLAVOR"));
+ widgets.add(createWidget("IMAGE"));
+ widgets.add(createWidget("TENANT"));
+ widgets.add(createWidget("VFC"));
}
}
/**
- * Gets widget.
+ * Creates a new widget of the specified type.
*
- * @param typeString
- *
+ * @param type
+ * String value of the Widget Type
* @return a new widget of the specified type
* @throws XmlArtifactGenerationException
- * if there is no configuration defined for the specified type
+ * if the configured widget mappings do not support the specified type
*/
- public static Widget getWidget(WidgetType type) throws XmlArtifactGenerationException {
- Widget widget = WidgetConfigurationUtil.createWidgetFromType(type.toString());
+ public static Widget createWidget(String type) throws XmlArtifactGenerationException {
+ Widget widget = WidgetConfigurationUtil.createWidgetFromType(type);
if (widget == null) {
throw new XmlArtifactGenerationException("No widget type is defined for " + type);
}
return widget;
}
+ /**
+ * Creates a new widget of the specified type.
+ *
+ * @param type
+ * the Widget Type
+ * @return a new widget of the specified type
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for the specified type
+ */
+ public static Widget createWidget(WidgetType type) throws XmlArtifactGenerationException {
+ return createWidget(type.toString());
+ }
+
public String getId() {
String id = WidgetConfigurationUtil.getConfig()
.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
diff --git a/src/test/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverterTest.java b/src/test/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverterTest.java
index b251401..e4ece96 100644
--- a/src/test/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverterTest.java
+++ b/src/test/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverterTest.java
@@ -2,9 +2,9 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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.
* You may obtain a copy of the License at
@@ -18,12 +18,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.babel.csar.vnfcatalog;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java b/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java
index d95291b..2668e1e 100644
--- a/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java
+++ b/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java
@@ -78,8 +78,11 @@ public class TestAaiArtifactGenerator {
* in the WidgetType dynamic enumeration.
*
* @throws SdcToscaParserException
+ * if the test CSAR file is invalid
* @throws IOException
+ * if the widget mappings config cannot be loaded
* @throws XmlArtifactGenerationException
+ * if the configured widget mappings do not support processed widget type(s)
*/
@Test(expected = IllegalArgumentException.class)
public void testParserWithIncompleteMappings()
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 14f3798..38931fb 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
@@ -96,20 +96,20 @@ public class TestVfModule {
/**
* 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
* if the Widget mapping configuration is missing
*/
@Test
public void testNonMemberWidgetToVf() throws XmlArtifactGenerationException {
Resource vfModule = createNewVfModule();
- assertThat(vfModule.addWidget(createNewWidget(WidgetType.valueOf("SERVICE"))), is(false));
+ assertThat(vfModule.addWidget(Widget.createWidget("SERVICE")), is(false));
assertNumberOfWidgets(vfModule, 0);
}
/**
* OAM Network is specifically excluded from a VF Module.
- *
+ *
* @throws XmlArtifactGenerationException
* if the Widget mapping configuration is missing
*/
@@ -122,12 +122,12 @@ public class TestVfModule {
/**
* Add a Volume Widget to a VF Module via a vserver Widget.
- *
+ *
* <li>Create a VF Module</li>
* <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
* if the Widget mapping configuration is missing
*/
@@ -157,12 +157,12 @@ public class TestVfModule {
/**
* Add an L-Interface Widget to a VF Module via a vserver Widget.
- *
+ *
* <li>Create a VF Module</li>
* <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
* if the Widget mapping configuration is missing
*/
@@ -192,13 +192,13 @@ public class TestVfModule {
/**
* Add a Volume and an L-Interface Widget to a VF Module via a vserver Widget.
- *
+ *
* <li>Create a VF Module</li>
* <li>Add a Volume Widget</li>
* <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
* if the Widget mapping configuration is missing
*/
@@ -236,19 +236,6 @@ public class TestVfModule {
}
/**
- * Use the static Factory method to create a new Widget.
- *
- * @param widgetType
- * type of Widget to create
- * @return a new Widget
- * @throws XmlArtifactGenerationException
- * if the Widget mapping configuration is missing
- */
- private Widget createNewWidget(WidgetType widgetType) throws XmlArtifactGenerationException {
- return Widget.getWidget(widgetType);
- }
-
- /**
* Create a new VF Module that contains zero widgets and has no members.
*
* @return new VF Module resource
@@ -312,7 +299,7 @@ public class TestVfModule {
*/
private boolean createNewWidgetForModule(Resource vfModule, WidgetType widgetType)
throws XmlArtifactGenerationException {
- Widget widget = createNewWidget(widgetType);
+ Widget widget = Widget.createWidget(widgetType);
setWidgetAsMember(vfModule, widget);
return vfModule.addWidget(widget);
}
@@ -343,7 +330,7 @@ public class TestVfModule {
* if the Widget mapping configuration is missing
*/
private int createVserverForVf(Resource vfModule) throws XmlArtifactGenerationException {
- Widget vserverWidget = createNewWidget(WidgetType.valueOf("VSERVER"));
+ Widget vserverWidget = Widget.createWidget("VSERVER");
assertNumberOfWidgets(vfModule, 0);
final int initialWidgetCount = addVserverToVf(vfModule, vserverWidget);
assertNumberOfWidgets(vfModule, 1);
@@ -352,7 +339,7 @@ public class TestVfModule {
/**
* Add the specified vserver to the specified VF Module.
- *
+ *
* @param vfModule
* the VF Module to update
* @param vserverWidget
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 4f28131..2b64bfb 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
@@ -53,82 +53,82 @@ public class TestWidget {
@Test
public void testGetWidgets() throws XmlArtifactGenerationException {
- Widget widget = Widget.getWidget(WidgetType.valueOf("SERVICE"));
+ Widget widget = Widget.createWidget("SERVICE");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("service-instance"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("VF"));
+ widget = Widget.createWidget("VF");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("generic-vnf"));
assertThat(widget.getDeleteFlag(), is(false));
- widget = Widget.getWidget(WidgetType.valueOf("VFC"));
+ widget = Widget.createWidget("VFC");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("vnfc"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("VSERVER"));
+ widget = Widget.createWidget("VSERVER");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("vserver"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("VOLUME"));
+ widget = Widget.createWidget("VOLUME");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("volume"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("FLAVOR"));
+ widget = Widget.createWidget("FLAVOR");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("flavor"));
assertThat(widget.getDeleteFlag(), is(false));
- widget = Widget.getWidget(WidgetType.valueOf("TENANT"));
+ widget = Widget.createWidget("TENANT");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("tenant"));
assertThat(widget.getDeleteFlag(), is(false));
- widget = Widget.getWidget(WidgetType.valueOf("VOLUME_GROUP"));
+ widget = Widget.createWidget("VOLUME_GROUP");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("volume-group"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("LINT"));
+ widget = Widget.createWidget("LINT");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("l-interface"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("L3_NET"));
+ widget = Widget.createWidget("L3_NET");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("l3-network"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("VFMODULE"));
+ widget = Widget.createWidget("VFMODULE");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("vf-module"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("IMAGE"));
+ widget = Widget.createWidget("IMAGE");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("image"));
assertThat(widget.getDeleteFlag(), is(false));
- widget = Widget.getWidget(WidgetType.valueOf("OAM_NETWORK"));
+ widget = Widget.createWidget("OAM_NETWORK");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("oam-network"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("ALLOTTED_RESOURCE"));
+ widget = Widget.createWidget("ALLOTTED_RESOURCE");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("allotted-resource"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("TUNNEL_XCONNECT"));
+ widget = Widget.createWidget("TUNNEL_XCONNECT");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("tunnel-xconnect"));
assertThat(widget.getDeleteFlag(), is(true));
- widget = Widget.getWidget(WidgetType.valueOf("CONFIGURATION"));
+ widget = Widget.createWidget("CONFIGURATION");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getName(), is("configuration"));
assertThat(widget.getDeleteFlag(), is(true));
@@ -136,14 +136,36 @@ public class TestWidget {
@Test
public void testWidgetMethods() throws XmlArtifactGenerationException {
- Widget widget = new Widget(WidgetType.valueOf("SERVICE"), "service-instance", true);
+ Widget widget = Widget.createWidget("SERVICE");
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
- assertThat(widget.addWidget(Widget.getWidget(WidgetType.valueOf("TENANT"))), is(true));
+ assertThat(widget.addWidget(Widget.createWidget("TENANT")), is(true));
assertThat(widget.memberOf(null), is(false));
assertThat(widget.memberOf(Collections.emptyList()), is(false));
}
+ /**
+ * Call equals() method for code coverage.
+ *
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for the test Widget Type
+ */
+ @Test
+ public void testEquals() throws XmlArtifactGenerationException {
+ Widget widgetModel = Widget.createWidget("OAM_NETWORK");
+
+ // equals() is reflexive
+ assertThat(widgetModel.equals(widgetModel), is(true));
+
+ // equals() is symmetric
+ Widget widgetModelB = Widget.createWidget("OAM_NETWORK");
+ assertThat(widgetModel.equals(widgetModelB), is(true));
+ assertThat(widgetModelB.equals(widgetModel), is(true));
+
+ assertThat(widgetModel.equals(null), is(false));
+ assertThat(widgetModel.equals(Widget.createWidget("VSERVER")), is(false));
+ }
+
@Test(expected = IllegalArgumentException.class)
public void testGetUnknownWidget() throws XmlArtifactGenerationException {
WidgetType.valueOf("invalid-widget-name");
@@ -151,18 +173,18 @@ public class TestWidget {
/**
* Try to get the Widget object for an unsupported (non-configured) type.
- *
+ *
* @throws XmlArtifactGenerationException
* if there is no configuration defined for the specified Widget type
*/
@Test(expected = XmlArtifactGenerationException.class)
public void testGetDynamicWidget() throws XmlArtifactGenerationException {
- Widget.getWidget(new WidgetType(null));
+ Widget.createWidget(new WidgetType(null));
}
-
+
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException {
- Widget.getWidget(WidgetType.valueOf("OAM_NETWORK")).addResource(null);
+ Widget.createWidget("OAM_NETWORK").addResource(null);
}
@Test(expected = IllegalArgumentException.class)
@@ -178,20 +200,20 @@ public class TestWidget {
// Call Widget methods which are not supported, purely for code coverage.
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
- public void testGetModelNameVersionIdIsUnsupported() {
- Widget widgetModel = new Widget(WidgetType.valueOf("OAM_NETWORK"), "oam-network", true);
+ public void testGetModelNameVersionIdIsUnsupported() throws XmlArtifactGenerationException {
+ Widget widgetModel = Widget.createWidget("OAM_NETWORK");
assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
}
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
- public void testGetModelTypeNameIsUnsupported() {
- Widget widgetModel = new Widget(WidgetType.valueOf("OAM_NETWORK"), "oam-network", true);
+ public void testGetModelTypeNameIsUnsupported() throws XmlArtifactGenerationException {
+ Widget widgetModel = Widget.createWidget("OAM_NETWORK");
assertThat(widgetModel.getModelTypeName(), is(nullValue()));
}
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
- public void testGetModelIdIsUnsupported() {
- Widget widgetModel = new Widget(WidgetType.valueOf("OAM_NETWORK"), "oam-network", true);
+ public void testGetModelIdIsUnsupported() throws XmlArtifactGenerationException {
+ Widget widgetModel = Widget.createWidget("OAM_NETWORK");
assertThat(widgetModel.getModelId(), is(nullValue()));
}