* ============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 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.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;
*/
public class TestWidget {
- static {
- System.setProperty("APP_HOME", ".");
- }
-
/**
- * Load the Widget to UUID mappings from the Artifact Generator properties.
+ * Load the Widget Configuration, including the type mappings and the UUID mappings.
*
- * @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);
+ public static void setup() throws IOException {
+ ArtifactTestUtils util = new ArtifactTestUtils();
+ util.loadWidgetToUuidMappings();
+ util.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.getWidget(Type.SERVICE);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("service-instance"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.VF);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("generic-vnf"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(Type.VFC);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vnfc"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.VSERVER);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vserver"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.VOLUME);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("volume"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.FLAVOR);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("flavor"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(Type.TENANT);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("tenant"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(Type.VOLUME_GROUP);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("volume-group"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.LINT);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("l-interface"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.L3_NET);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("l3-network"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.VFMODULE);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("vf-module"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.IMAGE);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("image"));
+ assertThat(widget.getDeleteFlag(), is(false));
+
+ widget = Widget.getWidget(Type.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);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("allotted-resource"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.TUNNEL_XCONNECT);
+ assertThat(widget.getType(), is(ModelType.WIDGET));
+ assertThat(widget.getName(), is("tunnel-xconnect"));
+ assertThat(widget.getDeleteFlag(), is(true));
+
+ widget = Widget.getWidget(Type.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 = new Widget(Type.SERVICE, "service-instance", true);
assertThat(widget.getType(), is(ModelType.WIDGET));
assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
- assertThat(widget.addWidget(new TenantWidget()), is(true));
+ assertThat(widget.addWidget(Widget.getWidget(Type.TENANT)), is(true));
assertThat(widget.memberOf(null), is(false));
assertThat(widget.memberOf(Collections.emptyList()), is(false));
-
- widget = new VolumeGroupWidget(); // just for variety
- assertThat(widget.getWidgetType(), is(nullValue()));
}
@Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
- public void testAddResourceIsUnsupported() {
- new OamNetwork().addResource(null);
+ public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException {
+ Widget.getWidget(Type.OAM_NETWORK).addResource(null);
}
}