* ============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.
package org.onap.aai.babel.xml.generator.model;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Collections;
-import java.util.Properties;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.onap.aai.babel.util.ArtifactTestUtils;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
import org.onap.aai.babel.xml.generator.types.ModelType;
/**
*/
public class TestWidget {
- static {
- System.setProperty("APP_HOME", ".");
- }
-
/**
- * Load the Widget to UUID mappings from the Artifact Generator properties.
+ * Load the Widget mappings configuration.
*
- * @throws FileNotFoundException
- * if the properties file is missing
* @throws IOException
- * if the properties file is not loaded
+ * if the mappings configuration cannot be loaded
*/
- @BeforeClass
- public static void setup() throws FileNotFoundException, IOException {
- final Properties properties = new Properties();
- try (InputStream in = TestWidget.class.getClassLoader().getResourceAsStream("artifact-generator.properties")) {
- properties.load(in);
- }
- WidgetConfigurationUtil.setConfig(properties);
+ @BeforeAll
+ public static void setup() throws IOException {
+ new ArtifactTestUtils().loadWidgetMappings();
}
@Test
- public void testGetWidgets() {
- assertThat(Widget.getWidget(Type.SERVICE), instanceOf(ServiceWidget.class));
- assertThat(Widget.getWidget(Type.VF), instanceOf(VfWidget.class));
- assertThat(Widget.getWidget(Type.VFC), instanceOf(VfcWidget.class));
- assertThat(Widget.getWidget(Type.VSERVER), instanceOf(VServerWidget.class));
- assertThat(Widget.getWidget(Type.VOLUME), instanceOf(VolumeWidget.class));
- assertThat(Widget.getWidget(Type.FLAVOR), instanceOf(FlavorWidget.class));
- assertThat(Widget.getWidget(Type.TENANT), instanceOf(TenantWidget.class));
- assertThat(Widget.getWidget(Type.VOLUME_GROUP), instanceOf(VolumeGroupWidget.class));
- assertThat(Widget.getWidget(Type.LINT), instanceOf(LIntfWidget.class));
- assertThat(Widget.getWidget(Type.L3_NET), instanceOf(L3NetworkWidget.class));
- assertThat(Widget.getWidget(Type.VFMODULE), instanceOf(VfModuleWidget.class));
- assertThat(Widget.getWidget(Type.IMAGE), instanceOf(ImageWidget.class));
- assertThat(Widget.getWidget(Type.OAM_NETWORK), instanceOf(OamNetwork.class));
- assertThat(Widget.getWidget(Type.ALLOTTED_RESOURCE), instanceOf(AllotedResourceWidget.class));
- assertThat(Widget.getWidget(Type.TUNNEL_XCONNECT), instanceOf(TunnelXconnectWidget.class));
- assertThat(Widget.getWidget(Type.CONFIGURATION), instanceOf(ConfigurationWidget.class));
+ public void testGetWidgets() throws XmlArtifactGenerationException {
+ Widget widget = Widget.createWidget("SERVICE");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("service-instance"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("VF");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("generic-vnf"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("VFC");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vnfc"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("VSERVER");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vserver"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("VOLUME");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("volume"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("FLAVOR");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("flavor"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.createWidget("TENANT");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("tenant"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.createWidget("VOLUME_GROUP");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("volume-group"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("LINT");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("l-interface"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("L3_NET");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("l3-network"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("VFMODULE");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vf-module"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("IMAGE");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("image"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.createWidget("OAM_NETWORK");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("oam-network"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("ALLOTTED_RESOURCE");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("allotted-resource"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("TUNNEL_XCONNECT");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("tunnel-xconnect"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.createWidget("CONFIGURATION");
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("configuration"));
+ assertThat(widget.getDeleteFlag(), is(true));
}
@Test
- public void testWidgetMethods() {
- Widget widget = new ServiceWidget();
+ public void testWidgetMethods() throws XmlArtifactGenerationException {
+ Widget widget = Widget.createWidget("SERVICE");
assertThat(widget.getType(), is(ModelType.WIDGET));
- assertThat(widget.getWidgetId(), is("82194af1-3c2c-485a-8f44-420e22a9eaa4"));
- assertThat(widget.addWidget(new TenantWidget()), is(true));
+ assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
+ 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");
- widget = new VolumeGroupWidget(); // just for variety
- assertThat(widget.getWidgetType(), is(nullValue()));
+ // 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 = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
- public void testAddResourceIsUnsupported() {
- new OamNetwork().addResource(null);
+ @Test
+ public void testGetUnknownWidget() throws XmlArtifactGenerationException {
+ assertThrows(IllegalArgumentException.class, () -> {
+ 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
+ public void testGetDynamicWidget() throws XmlArtifactGenerationException {
+ assertThrows(XmlArtifactGenerationException.class, () -> {
+ Widget.createWidget(new WidgetType(null));
+ });
+ }
+
+ @Test
+ public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException {
+ assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> {
+ Widget.createWidget("OAM_NETWORK").addResource(null);
+ });
+ }
+
+ // Call Widget methods which are not supported, purely for code coverage.
+
+ @Test
+ public void testGetModelNameVersionIdIsUnsupported() throws XmlArtifactGenerationException {
+ assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> {
+ Widget widgetModel = Widget.createWidget("OAM_NETWORK");
+ widgetModel.getModelNameVersionId();
+ });
+ }
+
+ @Test
+ public void testGetModelTypeNameIsUnsupported() throws XmlArtifactGenerationException {
+ assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> {
+ Widget widgetModel = Widget.createWidget("OAM_NETWORK");
+ widgetModel.getModelTypeName();
+ });
+ }
+
+ @Test
+ public void testGetModelIdIsUnsupported() throws XmlArtifactGenerationException {
+ assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> {
+ Widget widgetModel = Widget.createWidget("OAM_NETWORK");
+ widgetModel.getModelId();
+ });
+ }
+
}