212c221b755e97c11335779237273495f19b314f
[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
53      *             if the properties file is missing
54      * @throws IOException
55      *             if the properties file is not loaded
56      */
57     @BeforeClass
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")) {
61             properties.load(in);
62         }
63         WidgetConfigurationUtil.setConfig(properties);
64     }
65
66     @Test
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));
84     }
85
86     @Test
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));
94
95         widget = new VolumeGroupWidget(); // just for variety
96         assertThat(widget.getWidgetType(), is(nullValue()));
97     }
98
99     @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
100     public void testAddResourceIsUnsupported() {
101         new OamNetwork().addResource(null);
102     }
103 }