Load type mappings from a group configuration file
[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-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
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.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;
36
37 /**
38  * Direct tests of the Widget class for code coverage.
39  */
40 public class TestWidget {
41
42     static {
43         System.setProperty("APP_HOME", ".");
44     }
45
46     /**
47      * Load the Widget to UUID mappings from the Artifact Generator properties.
48      *
49      * @throws IOException
50      *             if the properties file is not loaded
51      */
52     @BeforeClass
53     public static void setup() throws IOException {
54         new ArtifactTestUtils().loadWidgetToUuidMappings();
55     }
56
57     @Test
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));
75     }
76
77     @Test
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));
85
86         widget = new VolumeGroupWidget(); // just for variety
87         assertThat(widget.getWidgetType(), is(nullValue()));
88     }
89
90     @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
91     public void testAddResourceIsUnsupported() {
92         new OamNetwork().addResource(null);
93     }
94 }