summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-03-25 23:38:53 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-03-25 23:55:35 +0000
commit550216df935437b1380b6d4425fd422ea7c013f5 (patch)
tree784353c285833db6d99c602fe08aa192557abe1d /src/test/java
parentf6107af893b29094f84fb2eea2b9dd8acc78dc53 (diff)
Refactor Widget creation methods
Rename getWidget() to createWidget() to indicate that a new Object is created. Add a method to create a Widget from the String representation of its type. Change-Id: I430acf02ea67c7b730e28e79887f8fbdb18feb42 Issue-ID: AAI-2281 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test/java')
-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
4 files changed, 70 insertions, 57 deletions
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()));
}