Create new tests for adding Widgets to VfModule
[aai/babel.git] / src / test / java / org / onap / aai / babel / xml / generator / model / TestWidget.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.aai.babel.xml.generator.model;
23
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;
28
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;
39
40 /**
41  * Direct tests of the Widget class for code coverage.
42  */
43 public class TestWidget {
44
45     static {
46         System.setProperty("APP_HOME", ".");
47     }
48
49     /**
50      * Load the Widget to UUID mappings from the Artifact Generator properties.
51      *
52      * @throws FileNotFoundException if the properties file is missing
53      * @throws IOException if the properties file is not loaded
54      */
55     @BeforeClass
56     public static void setup() throws FileNotFoundException, IOException {
57         final Properties properties = new Properties();
58         try (InputStream in = TestWidget.class.getClassLoader().getResourceAsStream("artifact-generator.properties")) {
59             properties.load(in);
60         }
61         WidgetConfigurationUtil.setConfig(properties);
62     }
63
64     @Test
65     public void testGetWidgets() {
66         assertThat(Widget.getWidget(Type.SERVICE), instanceOf(ServiceWidget.class));
67         assertThat(Widget.getWidget(Type.VF), instanceOf(VfWidget.class));
68         assertThat(Widget.getWidget(Type.VFC), instanceOf(VfcWidget.class));
69         assertThat(Widget.getWidget(Type.VSERVER), instanceOf(VServerWidget.class));
70         assertThat(Widget.getWidget(Type.VOLUME), instanceOf(VolumeWidget.class));
71         assertThat(Widget.getWidget(Type.FLAVOR), instanceOf(FlavorWidget.class));
72         assertThat(Widget.getWidget(Type.TENANT), instanceOf(TenantWidget.class));
73         assertThat(Widget.getWidget(Type.VOLUME_GROUP), instanceOf(VolumeGroupWidget.class));
74         assertThat(Widget.getWidget(Type.LINT), instanceOf(LIntfWidget.class));
75         assertThat(Widget.getWidget(Type.L3_NET), instanceOf(L3NetworkWidget.class));
76         assertThat(Widget.getWidget(Type.VFMODULE), instanceOf(VfModuleWidget.class));
77         assertThat(Widget.getWidget(Type.IMAGE), instanceOf(ImageWidget.class));
78         assertThat(Widget.getWidget(Type.OAM_NETWORK), instanceOf(OamNetwork.class));
79         assertThat(Widget.getWidget(Type.ALLOTTED_RESOURCE), instanceOf(AllotedResourceWidget.class));
80         assertThat(Widget.getWidget(Type.TUNNEL_XCONNECT), instanceOf(TunnelXconnectWidget.class));
81         assertThat(Widget.getWidget(Type.CONFIGURATION), instanceOf(ConfigurationWidget.class));
82     }
83
84     @Test
85     public void testWidgetMethods() {
86         Widget widget = new ServiceWidget();
87         assertThat(widget.getType(), is(ModelType.WIDGET));
88         assertThat(widget.getWidgetId(), is("82194af1-3c2c-485a-8f44-420e22a9eaa4"));
89         assertThat(widget.addWidget(new TenantWidget()), is(true));
90         assertThat(widget.memberOf(null), is(false));
91         assertThat(widget.memberOf(Collections.emptyList()), is(false));
92
93         widget = new VolumeGroupWidget(); // just for variety
94         assertThat(widget.getWidgetType(), is(nullValue()));
95     }
96
97     @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
98     public void testAddResourceIsUnsupported() {
99         new OamNetwork().addResource(null);
100     }
101 }