From e8bb310641941ddbb073df33d92cfbe6f6029029 Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Mon, 11 Mar 2019 15:17:15 +0000 Subject: Reimplement Widget.Type enum class Replace this with a WidgetType dynamic enumeration, which may be extended at runtime. Load the Widget Types from the mapping configuration (JSON file). Issue-ID: AAI-2229 Change-Id: I5d1bc4291b4446f6d744821bf1d74b1f117b901f Signed-off-by: mark.j.leonard --- .../parser/TestArtifactGeneratorToscaParser.java | 29 ++++--- .../aai/babel/xml/generator/model/TestModel.java | 91 ++++++---------------- .../babel/xml/generator/model/TestVfModule.java | 44 +++++------ .../aai/babel/xml/generator/model/TestWidget.java | 87 ++++++++++++++++----- 4 files changed, 132 insertions(+), 119 deletions(-) (limited to 'src/test') 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 acc4a35..50f0aa9 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.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. @@ -38,7 +38,7 @@ 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; -import org.onap.aai.babel.xml.generator.model.Widget.Type; +import org.onap.aai.babel.xml.generator.model.WidgetType; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -106,8 +106,8 @@ public class TestArtifactGeneratorToscaParser { @Test(expected = IllegalArgumentException.class) public void testMissingProvidingService() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage")); - new ArtifactGeneratorToscaParser(null).processResourceModels(new Resource(Type.ALLOTTED_RESOURCE, true), - nodeTemplateList); + new ArtifactGeneratorToscaParser(null) + .processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList); } /** @@ -117,7 +117,7 @@ public class TestArtifactGeneratorToscaParser { public void testAddResourceNotProvidingService() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR")); // Create any Resource to which the CR can be added - final Resource dummyResource = new Resource(Type.ALLOTTED_RESOURCE, true); + final Resource dummyResource = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true); new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList); } @@ -125,6 +125,7 @@ public class TestArtifactGeneratorToscaParser { * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type). * * @throws IOException + * if a WidgetMapping is invalid */ @Test(expected = IOException.class) public void testToscaMappingWithoutType() throws IOException { @@ -137,6 +138,7 @@ public class TestArtifactGeneratorToscaParser { * Initialize the Artifact Generator Widget Mapping config with invalid data (type value). * * @throws IOException + * if a WidgetMapping is invalid */ @Test(expected = IOException.class) public void testToscaMappingWithInvalidType() throws IOException { @@ -144,11 +146,12 @@ public class TestArtifactGeneratorToscaParser { invalidMapping.setType("invalid"); WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); } - + /** * Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name). * * @throws IOException + * if a WidgetMapping is invalid */ @Test(expected = IOException.class) public void testToscaMappingWithoutWidget() throws IOException { @@ -156,15 +159,19 @@ public class TestArtifactGeneratorToscaParser { invalidMapping.setWidget(null); WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); } - + /** * Process a dummy Group object for a Service Resource. * * @throws XmlArtifactGenerationException * if there is no configuration defined for a member Widget of an instance group + * @throws IOException + * if the widget mappings cannot be loaded */ @Test - public void testInstanceGroups() throws XmlArtifactGenerationException { + public void testInstanceGroups() throws XmlArtifactGenerationException, IOException { + new ArtifactTestUtils().loadWidgetMappings(); + final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup"; WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType)); @@ -181,8 +188,8 @@ public class TestArtifactGeneratorToscaParser { Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate)).thenReturn(groups); ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper); - List resources = - parser.processInstanceGroups(new Resource(Type.INSTANCE_GROUP, true), serviceNodeTemplate); + Resource groupResource = new Resource(WidgetType.valueOf("INSTANCE_GROUP"), true); + List resources = parser.processInstanceGroups(groupResource, serviceNodeTemplate); assertThat(resources.size(), is(1)); Resource resource = resources.get(0); 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 f2b78a1..ed4f5c1 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,11 +26,9 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; import java.io.IOException; -import org.junit.Before; +import org.junit.BeforeClass; 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; /** * Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are @@ -38,47 +36,17 @@ import org.onap.aai.babel.xml.generator.model.Widget.Type; */ public class TestModel { - private Widget widgetModel = new Widget(Type.OAM_NETWORK, "oam-network", true); - private Model anonymousModel; - /** - * Initialize the Artifact Generator with filtering and mapping configuration. Also load the Widget to UUID mappings - * from the Artifact Generator properties. + * Load the Widget Configuration, including the type mappings and the UUID mappings. * * @throws IOException * if the mappings configuration cannot be loaded */ - @Before - public void setup() throws IOException { - ArtifactTestUtils utils = new ArtifactTestUtils(); - utils.setGeneratorSystemProperties(); - - String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE); - if (configLocation == null) { - throw new IllegalArgumentException( - String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND, - ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE)); - } - - ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation); - utils.loadWidgetToUuidMappings(); - - anonymousModel = new Model() { - @Override - public boolean addWidget(Widget resource) { - return false; - } - - @Override - public Type getWidgetType() { - return null; - } - - @Override - public String getModelTypeName() { - return null; - } - }; + @BeforeClass + public static void setup() throws IOException { + ArtifactTestUtils util = new ArtifactTestUtils(); + util.loadWidgetToUuidMappings(); + util.loadWidgetMappings(); } @Test @@ -87,21 +55,22 @@ public class TestModel { assertThat(Model.getModelFor(""), is(nullValue())); assertThat(Model.getModelFor("any.unknown.type"), is(nullValue())); - assertMapping("org.openecomp.resource.vfc", Type.VSERVER); - assertMapping("org.openecomp.resource.cp", Type.LINT); - assertMapping("org.openecomp.cp", Type.LINT); - assertMapping("org.openecomp.cp.some.suffix", Type.LINT); - assertMapping("org.openecomp.resource.vl", Type.L3_NET); - assertMapping("org.openecomp.resource.vf", Type.VF); - assertMapping("org.openecomp.groups.vfmodule", Type.VFMODULE); - assertMapping("org.openecomp.groups.VfModule", Type.VFMODULE); - assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", Type.VOLUME); - assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration", Type.CONFIGURATION); - assertMapping("any.string", "Configuration", Type.CONFIGURATION); - assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", Type.CR); - assertMapping("any.string", "CR", Type.CR); - - assertMapping("org.openecomp.resource.vfc", "an.unknown.type", Type.VSERVER); + assertMapping("org.openecomp.resource.vfc", WidgetType.valueOf("VSERVER")); + assertMapping("org.openecomp.resource.cp", WidgetType.valueOf("LINT")); + assertMapping("org.openecomp.cp", WidgetType.valueOf("LINT")); + assertMapping("org.openecomp.cp.some.suffix", WidgetType.valueOf("LINT")); + assertMapping("org.openecomp.resource.vl", WidgetType.valueOf("L3_NET")); + assertMapping("org.openecomp.resource.vf", WidgetType.valueOf("VF")); + assertMapping("org.openecomp.groups.vfmodule", WidgetType.valueOf("VFMODULE")); + assertMapping("org.openecomp.groups.VfModule", WidgetType.valueOf("VFMODULE")); + assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", WidgetType.valueOf("VOLUME")); + assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration", + WidgetType.valueOf("CONFIGURATION")); + assertMapping("any.string", "Configuration", WidgetType.valueOf("CONFIGURATION")); + assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", WidgetType.valueOf("CR")); + assertMapping("any.string", "CR", WidgetType.valueOf("CR")); + + assertMapping("org.openecomp.resource.vfc", "an.unknown.type", WidgetType.valueOf("VSERVER")); } /** @@ -112,7 +81,7 @@ public class TestModel { * @param widgetType * the type of Widget expected from the mappings */ - private void assertMapping(String toscaType, Type widgetType) { + private void assertMapping(String toscaType, WidgetType widgetType) { assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType)); } @@ -126,18 +95,8 @@ public class TestModel { * @param widgetType * the type of Widget expected from the mappings */ - private void assertMapping(String toscaType, String metadataType, Type widgetType) { + private void assertMapping(String toscaType, String metadataType, WidgetType widgetType) { assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType)); } - @Test - public void testGetModelNameVersionId() { - assertThat(anonymousModel.getModelNameVersionId(), is(nullValue())); - } - - @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class) - public void testGetModelNameVersionIdIsUnsupported() { - assertThat(widgetModel.getModelNameVersionId(), is(nullValue())); - } - } 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 f712ba5..14f3798 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 @@ -34,7 +34,6 @@ 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; /** * Direct tests of the VFMODULE Resource and Widget functionality to improve code coverage. @@ -86,12 +85,12 @@ public class TestVfModule { @Test public void testAddVServerWidgetToVf() throws XmlArtifactGenerationException { - assertAddWidget(createNewVfModule(), Type.VSERVER); + assertAddWidget(createNewVfModule(), WidgetType.valueOf("VSERVER")); } @Test public void testAddServiceWidgetToVf() throws XmlArtifactGenerationException { - assertAddWidget(createNewVfModule(), Type.SERVICE); + assertAddWidget(createNewVfModule(), WidgetType.valueOf("SERVICE")); } /** @@ -104,7 +103,7 @@ public class TestVfModule { @Test public void testNonMemberWidgetToVf() throws XmlArtifactGenerationException { Resource vfModule = createNewVfModule(); - assertThat(vfModule.addWidget(createNewWidget(Type.SERVICE)), is(false)); + assertThat(vfModule.addWidget(createNewWidget(WidgetType.valueOf("SERVICE"))), is(false)); assertNumberOfWidgets(vfModule, 0); } @@ -117,7 +116,7 @@ public class TestVfModule { @Test public void testAddOamNetworkWidgetToVf() throws XmlArtifactGenerationException { Resource vfModule = createNewVfModule(); - assertThat(createNewWidgetForModule(vfModule, Type.OAM_NETWORK), is(false)); + assertThat(createNewWidgetForModule(vfModule, WidgetType.valueOf("OAM_NETWORK")), is(false)); assertNumberOfWidgets(vfModule, 0); } @@ -137,7 +136,7 @@ public class TestVfModule { Resource vfModule = createNewVfModule(); // Adding a Volume widget has no effect until a vserver widget is added. - assertAddWidget(vfModule, Type.VOLUME); + assertAddWidget(vfModule, WidgetType.valueOf("VOLUME")); assertNumberOfWidgets(vfModule, 0); final int vserverBaseWidgetCount = createVserverForVf(vfModule); @@ -146,11 +145,11 @@ public class TestVfModule { assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 1); // Adding another instance of a vserver widget fails. - assertFailToAddWidget(vfModule, Type.VSERVER); + assertFailToAddWidget(vfModule, WidgetType.valueOf("VSERVER")); assertNumberOfWidgets(vfModule, 1); // Adding another Volume widget is always treated as successful. - assertAddWidget(vfModule, Type.VOLUME); + assertAddWidget(vfModule, WidgetType.valueOf("VOLUME")); // Assert that no additional Widgets are actually present. assertNumberOfWidgets(vfModule, 1); assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 1); @@ -172,7 +171,7 @@ public class TestVfModule { Resource vfModule = createNewVfModule(); // Adding an L-Interface widget has no effect until a vserver widget is added. - assertFailToAddWidget(vfModule, Type.LINT); + assertFailToAddWidget(vfModule, WidgetType.valueOf("LINT")); assertNumberOfWidgets(vfModule, 0); final int vserverBaseWidgetCount = createVserverForVf(vfModule); @@ -181,11 +180,11 @@ public class TestVfModule { assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 1); // Adding another instance of a vserver widget fails. - assertFailToAddWidget(vfModule, Type.VSERVER); + assertFailToAddWidget(vfModule, WidgetType.valueOf("VSERVER")); assertNumberOfWidgets(vfModule, 1); // Adding an L-Interface widget is always treated as successful when a vserver exists. - assertAddWidget(vfModule, Type.LINT); + assertAddWidget(vfModule, WidgetType.valueOf("LINT")); // Assert that no additional Widgets are actually present. assertNumberOfWidgets(vfModule, 1); assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 1); @@ -208,11 +207,11 @@ public class TestVfModule { Resource vfModule = createNewVfModule(); // Adding a Volume widget has no effect until a vserver widget is added. - assertAddWidget(vfModule, Type.VOLUME); + assertAddWidget(vfModule, WidgetType.valueOf("VOLUME")); assertNumberOfWidgets(vfModule, 0); // Adding an L-Interface widget has no effect until a vserver widget is added. - assertFailToAddWidget(vfModule, Type.LINT); + assertFailToAddWidget(vfModule, WidgetType.valueOf("LINT")); assertNumberOfWidgets(vfModule, 0); final int vserverBaseWidgetCount = createVserverForVf(vfModule); @@ -221,12 +220,12 @@ public class TestVfModule { assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 2); // Adding another instance of a vserver widget fails. - assertFailToAddWidget(vfModule, Type.VSERVER); + assertFailToAddWidget(vfModule, WidgetType.valueOf("VSERVER")); assertNumberOfWidgets(vfModule, 1); // Add new instances (with no effect). - assertAddWidget(vfModule, Type.VOLUME); - assertAddWidget(vfModule, Type.LINT); + assertAddWidget(vfModule, WidgetType.valueOf("VOLUME")); + assertAddWidget(vfModule, WidgetType.valueOf("LINT")); // Assert that no additional Widgets are in fact present. assertNumberOfWidgets(vfModule, 1); assertNumberOfWidgets(vfModule.vserver, vserverBaseWidgetCount + 2); @@ -245,7 +244,7 @@ public class TestVfModule { * @throws XmlArtifactGenerationException * if the Widget mapping configuration is missing */ - private Widget createNewWidget(Type widgetType) throws XmlArtifactGenerationException { + private Widget createNewWidget(WidgetType widgetType) throws XmlArtifactGenerationException { return Widget.getWidget(widgetType); } @@ -255,7 +254,7 @@ public class TestVfModule { * @return new VF Module resource */ private Resource createNewVfModule() { - Resource vfModule = new Resource(Type.VFMODULE, true); + Resource vfModule = new Resource(WidgetType.valueOf("VFMODULE"), true); assertNumberOfWidgets(vfModule, 0); return vfModule; } @@ -282,7 +281,7 @@ public class TestVfModule { * @throws XmlArtifactGenerationException * if the Widget mapping configuration is missing */ - private void assertAddWidget(Resource vfModule, Type widgetType) throws XmlArtifactGenerationException { + private void assertAddWidget(Resource vfModule, WidgetType widgetType) throws XmlArtifactGenerationException { assertThat(createNewWidgetForModule(vfModule, widgetType), is(true)); } @@ -296,7 +295,7 @@ public class TestVfModule { * @throws XmlArtifactGenerationException * if the Widget mapping configuration is missing */ - private void assertFailToAddWidget(Resource vfModule, Type widgetType) throws XmlArtifactGenerationException { + private void assertFailToAddWidget(Resource vfModule, WidgetType widgetType) throws XmlArtifactGenerationException { assertThat(createNewWidgetForModule(vfModule, widgetType), is(false)); } @@ -311,7 +310,8 @@ public class TestVfModule { * @throws XmlArtifactGenerationException * if the Widget mapping configuration is missing */ - private boolean createNewWidgetForModule(Resource vfModule, Type widgetType) throws XmlArtifactGenerationException { + private boolean createNewWidgetForModule(Resource vfModule, WidgetType widgetType) + throws XmlArtifactGenerationException { Widget widget = createNewWidget(widgetType); setWidgetAsMember(vfModule, widget); return vfModule.addWidget(widget); @@ -343,7 +343,7 @@ public class TestVfModule { * if the Widget mapping configuration is missing */ private int createVserverForVf(Resource vfModule) throws XmlArtifactGenerationException { - Widget vserverWidget = createNewWidget(Type.VSERVER); + Widget vserverWidget = createNewWidget(WidgetType.valueOf("VSERVER")); assertNumberOfWidgets(vfModule, 0); final int initialWidgetCount = addVserverToVf(vfModule, vserverWidget); assertNumberOfWidgets(vfModule, 1); 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 8c2338c..4f28131 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 @@ -22,6 +22,7 @@ package org.onap.aai.babel.xml.generator.model; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; import java.io.IOException; @@ -30,7 +31,6 @@ 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; /** @@ -53,82 +53,82 @@ public class TestWidget { @Test public void testGetWidgets() throws XmlArtifactGenerationException { - Widget widget = Widget.getWidget(Type.SERVICE); + Widget widget = Widget.getWidget(WidgetType.valueOf("SERVICE")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("service-instance")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.VF); + widget = Widget.getWidget(WidgetType.valueOf("VF")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("generic-vnf")); assertThat(widget.getDeleteFlag(), is(false)); - widget = Widget.getWidget(Type.VFC); + widget = Widget.getWidget(WidgetType.valueOf("VFC")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("vnfc")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.VSERVER); + widget = Widget.getWidget(WidgetType.valueOf("VSERVER")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("vserver")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.VOLUME); + widget = Widget.getWidget(WidgetType.valueOf("VOLUME")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("volume")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.FLAVOR); + widget = Widget.getWidget(WidgetType.valueOf("FLAVOR")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("flavor")); assertThat(widget.getDeleteFlag(), is(false)); - widget = Widget.getWidget(Type.TENANT); + widget = Widget.getWidget(WidgetType.valueOf("TENANT")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("tenant")); assertThat(widget.getDeleteFlag(), is(false)); - widget = Widget.getWidget(Type.VOLUME_GROUP); + widget = Widget.getWidget(WidgetType.valueOf("VOLUME_GROUP")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("volume-group")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.LINT); + widget = Widget.getWidget(WidgetType.valueOf("LINT")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("l-interface")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.L3_NET); + widget = Widget.getWidget(WidgetType.valueOf("L3_NET")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("l3-network")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.VFMODULE); + widget = Widget.getWidget(WidgetType.valueOf("VFMODULE")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("vf-module")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.IMAGE); + widget = Widget.getWidget(WidgetType.valueOf("IMAGE")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("image")); assertThat(widget.getDeleteFlag(), is(false)); - widget = Widget.getWidget(Type.OAM_NETWORK); + widget = Widget.getWidget(WidgetType.valueOf("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); + widget = Widget.getWidget(WidgetType.valueOf("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); + widget = Widget.getWidget(WidgetType.valueOf("TUNNEL_XCONNECT")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("tunnel-xconnect")); assertThat(widget.getDeleteFlag(), is(true)); - widget = Widget.getWidget(Type.CONFIGURATION); + widget = Widget.getWidget(WidgetType.valueOf("CONFIGURATION")); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getName(), is("configuration")); assertThat(widget.getDeleteFlag(), is(true)); @@ -136,16 +136,63 @@ public class TestWidget { @Test public void testWidgetMethods() throws XmlArtifactGenerationException { - Widget widget = new Widget(Type.SERVICE, "service-instance", true); + Widget widget = new Widget(WidgetType.valueOf("SERVICE"), "service-instance", true); assertThat(widget.getType(), is(ModelType.WIDGET)); assertThat(widget.getWidgetId(), is("service-instance-invariant-id")); - assertThat(widget.addWidget(Widget.getWidget(Type.TENANT)), is(true)); + assertThat(widget.addWidget(Widget.getWidget(WidgetType.valueOf("TENANT"))), is(true)); assertThat(widget.memberOf(null), is(false)); assertThat(widget.memberOf(Collections.emptyList()), is(false)); } + @Test(expected = IllegalArgumentException.class) + public void testGetUnknownWidget() throws XmlArtifactGenerationException { + WidgetType.valueOf("invalid-widget-name"); + } + + /** + * 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)); + } + @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class) public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException { - Widget.getWidget(Type.OAM_NETWORK).addResource(null); + Widget.getWidget(WidgetType.valueOf("OAM_NETWORK")).addResource(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetVersionIdForUknownWidget() { + new Widget(new WidgetType("test"), null, false).getId(); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetInvariantIdForUknownWidget() { + new Widget(new WidgetType("test"), null, false).getWidgetId(); + } + + // 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); + 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); + 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); + assertThat(widgetModel.getModelId(), is(nullValue())); + } + } -- cgit 1.2.3-korg