2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2019 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.IOException;
30 import java.util.Collections;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.aai.babel.util.ArtifactTestUtils;
34 import org.onap.aai.babel.xml.generator.model.Widget.Type;
35 import org.onap.aai.babel.xml.generator.types.ModelType;
38 * Direct tests of the Widget class for code coverage.
40 public class TestWidget {
43 System.setProperty("APP_HOME", ".");
47 * Load the Widget to UUID mappings from the Artifact Generator properties.
50 * if the properties file is not loaded
53 public static void setup() throws IOException {
54 new ArtifactTestUtils().loadWidgetToUuidMappings();
58 public void testGetWidgets() {
59 assertThat(Widget.getWidget(Type.SERVICE), instanceOf(ServiceWidget.class));
60 assertThat(Widget.getWidget(Type.VF), instanceOf(VfWidget.class));
61 assertThat(Widget.getWidget(Type.VFC), instanceOf(VfcWidget.class));
62 assertThat(Widget.getWidget(Type.VSERVER), instanceOf(VServerWidget.class));
63 assertThat(Widget.getWidget(Type.VOLUME), instanceOf(VolumeWidget.class));
64 assertThat(Widget.getWidget(Type.FLAVOR), instanceOf(FlavorWidget.class));
65 assertThat(Widget.getWidget(Type.TENANT), instanceOf(TenantWidget.class));
66 assertThat(Widget.getWidget(Type.VOLUME_GROUP), instanceOf(VolumeGroupWidget.class));
67 assertThat(Widget.getWidget(Type.LINT), instanceOf(LIntfWidget.class));
68 assertThat(Widget.getWidget(Type.L3_NET), instanceOf(L3NetworkWidget.class));
69 assertThat(Widget.getWidget(Type.VFMODULE), instanceOf(VfModuleWidget.class));
70 assertThat(Widget.getWidget(Type.IMAGE), instanceOf(ImageWidget.class));
71 assertThat(Widget.getWidget(Type.OAM_NETWORK), instanceOf(OamNetwork.class));
72 assertThat(Widget.getWidget(Type.ALLOTTED_RESOURCE), instanceOf(AllotedResourceWidget.class));
73 assertThat(Widget.getWidget(Type.TUNNEL_XCONNECT), instanceOf(TunnelXconnectWidget.class));
74 assertThat(Widget.getWidget(Type.CONFIGURATION), instanceOf(ConfigurationWidget.class));
78 public void testWidgetMethods() {
79 Widget widget = new ServiceWidget();
80 assertThat(widget.getType(), is(ModelType.WIDGET));
81 assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
82 assertThat(widget.addWidget(new TenantWidget()), is(true));
83 assertThat(widget.memberOf(null), is(false));
84 assertThat(widget.memberOf(Collections.emptyList()), is(false));
86 widget = new VolumeGroupWidget(); // just for variety
87 assertThat(widget.getWidgetType(), is(nullValue()));
90 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
91 public void testAddResourceIsUnsupported() {
92 new OamNetwork().addResource(null);