2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.babel.xml.generator.model;
24 import static org.hamcrest.CoreMatchers.instanceOf;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.CoreMatchers.nullValue;
27 import static org.junit.Assert.assertThat;
29 import java.io.FileNotFoundException;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.util.Collections;
33 import java.util.Properties;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
37 import org.onap.aai.babel.xml.generator.model.Widget.Type;
38 import org.onap.aai.babel.xml.generator.types.ModelType;
41 * Direct tests of the Widget class for code coverage.
43 public class TestWidget {
46 System.setProperty("APP_HOME", ".");
50 * Load the Widget to UUID mappings from the Artifact Generator properties.
52 * @throws FileNotFoundException
53 * if the properties file is missing
55 * if the properties file is not loaded
58 public static void setup() throws FileNotFoundException, IOException {
59 final Properties properties = new Properties();
60 try (InputStream in = TestWidget.class.getClassLoader().getResourceAsStream("artifact-generator.properties")) {
63 WidgetConfigurationUtil.setConfig(properties);
67 public void testGetWidgets() {
68 assertThat(Widget.getWidget(Type.SERVICE), instanceOf(ServiceWidget.class));
69 assertThat(Widget.getWidget(Type.VF), instanceOf(VfWidget.class));
70 assertThat(Widget.getWidget(Type.VFC), instanceOf(VfcWidget.class));
71 assertThat(Widget.getWidget(Type.VSERVER), instanceOf(VServerWidget.class));
72 assertThat(Widget.getWidget(Type.VOLUME), instanceOf(VolumeWidget.class));
73 assertThat(Widget.getWidget(Type.FLAVOR), instanceOf(FlavorWidget.class));
74 assertThat(Widget.getWidget(Type.TENANT), instanceOf(TenantWidget.class));
75 assertThat(Widget.getWidget(Type.VOLUME_GROUP), instanceOf(VolumeGroupWidget.class));
76 assertThat(Widget.getWidget(Type.LINT), instanceOf(LIntfWidget.class));
77 assertThat(Widget.getWidget(Type.L3_NET), instanceOf(L3NetworkWidget.class));
78 assertThat(Widget.getWidget(Type.VFMODULE), instanceOf(VfModuleWidget.class));
79 assertThat(Widget.getWidget(Type.IMAGE), instanceOf(ImageWidget.class));
80 assertThat(Widget.getWidget(Type.OAM_NETWORK), instanceOf(OamNetwork.class));
81 assertThat(Widget.getWidget(Type.ALLOTTED_RESOURCE), instanceOf(AllotedResourceWidget.class));
82 assertThat(Widget.getWidget(Type.TUNNEL_XCONNECT), instanceOf(TunnelXconnectWidget.class));
83 assertThat(Widget.getWidget(Type.CONFIGURATION), instanceOf(ConfigurationWidget.class));
87 public void testWidgetMethods() {
88 Widget widget = new ServiceWidget();
89 assertThat(widget.getType(), is(ModelType.WIDGET));
90 assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
91 assertThat(widget.addWidget(new TenantWidget()), is(true));
92 assertThat(widget.memberOf(null), is(false));
93 assertThat(widget.memberOf(Collections.emptyList()), is(false));
95 widget = new VolumeGroupWidget(); // just for variety
96 assertThat(widget.getWidgetType(), is(nullValue()));
99 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
100 public void testAddResourceIsUnsupported() {
101 new OamNetwork().addResource(null);