Remove all references to artifactgenerator config
[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 (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Copyright (c) 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.is;
25 import static org.hamcrest.CoreMatchers.nullValue;
26 import static org.junit.Assert.assertThat;
27
28 import java.io.IOException;
29 import java.util.Collections;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.onap.aai.babel.util.ArtifactTestUtils;
33 import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
34 import org.onap.aai.babel.xml.generator.types.ModelType;
35
36 /**
37  * Direct tests of the Widget class for code coverage.
38  */
39 public class TestWidget {
40
41     /**
42      * Load the Widget mappings configuration.
43      *
44      * @throws IOException
45      *             if the mappings configuration cannot be loaded
46      */
47     @BeforeClass
48     public static void setup() throws IOException {
49         new ArtifactTestUtils().loadWidgetMappings();
50     }
51
52     @Test
53     public void testGetWidgets() throws XmlArtifactGenerationException {
54         Widget widget = Widget.createWidget("SERVICE");
55         assertThat(widget.getType(), is(ModelType.WIDGET));
56         assertThat(widget.getName(), is("service-instance"));
57         assertThat(widget.getDeleteFlag(), is(true));
58
59         widget = Widget.createWidget("VF");
60         assertThat(widget.getType(), is(ModelType.WIDGET));
61         assertThat(widget.getName(), is("generic-vnf"));
62         assertThat(widget.getDeleteFlag(), is(false));
63
64         widget = Widget.createWidget("VFC");
65         assertThat(widget.getType(), is(ModelType.WIDGET));
66         assertThat(widget.getName(), is("vnfc"));
67         assertThat(widget.getDeleteFlag(), is(true));
68
69         widget = Widget.createWidget("VSERVER");
70         assertThat(widget.getType(), is(ModelType.WIDGET));
71         assertThat(widget.getName(), is("vserver"));
72         assertThat(widget.getDeleteFlag(), is(true));
73
74         widget = Widget.createWidget("VOLUME");
75         assertThat(widget.getType(), is(ModelType.WIDGET));
76         assertThat(widget.getName(), is("volume"));
77         assertThat(widget.getDeleteFlag(), is(true));
78
79         widget = Widget.createWidget("FLAVOR");
80         assertThat(widget.getType(), is(ModelType.WIDGET));
81         assertThat(widget.getName(), is("flavor"));
82         assertThat(widget.getDeleteFlag(), is(false));
83
84         widget = Widget.createWidget("TENANT");
85         assertThat(widget.getType(), is(ModelType.WIDGET));
86         assertThat(widget.getName(), is("tenant"));
87         assertThat(widget.getDeleteFlag(), is(false));
88
89         widget = Widget.createWidget("VOLUME_GROUP");
90         assertThat(widget.getType(), is(ModelType.WIDGET));
91         assertThat(widget.getName(), is("volume-group"));
92         assertThat(widget.getDeleteFlag(), is(true));
93
94         widget = Widget.createWidget("LINT");
95         assertThat(widget.getType(), is(ModelType.WIDGET));
96         assertThat(widget.getName(), is("l-interface"));
97         assertThat(widget.getDeleteFlag(), is(true));
98
99         widget = Widget.createWidget("L3_NET");
100         assertThat(widget.getType(), is(ModelType.WIDGET));
101         assertThat(widget.getName(), is("l3-network"));
102         assertThat(widget.getDeleteFlag(), is(true));
103
104         widget = Widget.createWidget("VFMODULE");
105         assertThat(widget.getType(), is(ModelType.WIDGET));
106         assertThat(widget.getName(), is("vf-module"));
107         assertThat(widget.getDeleteFlag(), is(true));
108
109         widget = Widget.createWidget("IMAGE");
110         assertThat(widget.getType(), is(ModelType.WIDGET));
111         assertThat(widget.getName(), is("image"));
112         assertThat(widget.getDeleteFlag(), is(false));
113
114         widget = Widget.createWidget("OAM_NETWORK");
115         assertThat(widget.getType(), is(ModelType.WIDGET));
116         assertThat(widget.getName(), is("oam-network"));
117         assertThat(widget.getDeleteFlag(), is(true));
118
119         widget = Widget.createWidget("ALLOTTED_RESOURCE");
120         assertThat(widget.getType(), is(ModelType.WIDGET));
121         assertThat(widget.getName(), is("allotted-resource"));
122         assertThat(widget.getDeleteFlag(), is(true));
123
124         widget = Widget.createWidget("TUNNEL_XCONNECT");
125         assertThat(widget.getType(), is(ModelType.WIDGET));
126         assertThat(widget.getName(), is("tunnel-xconnect"));
127         assertThat(widget.getDeleteFlag(), is(true));
128
129         widget = Widget.createWidget("CONFIGURATION");
130         assertThat(widget.getType(), is(ModelType.WIDGET));
131         assertThat(widget.getName(), is("configuration"));
132         assertThat(widget.getDeleteFlag(), is(true));
133     }
134
135     @Test
136     public void testWidgetMethods() throws XmlArtifactGenerationException {
137         Widget widget = Widget.createWidget("SERVICE");
138         assertThat(widget.getType(), is(ModelType.WIDGET));
139         assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
140         assertThat(widget.addWidget(Widget.createWidget("TENANT")), is(true));
141         assertThat(widget.memberOf(null), is(false));
142         assertThat(widget.memberOf(Collections.emptyList()), is(false));
143     }
144
145     /**
146      * Call equals() method for code coverage.
147      *
148      * @throws XmlArtifactGenerationException
149      *             if there is no configuration defined for the test Widget Type
150      */
151     @Test
152     public void testEquals() throws XmlArtifactGenerationException {
153         Widget widgetModel = Widget.createWidget("OAM_NETWORK");
154
155         // equals() is reflexive
156         assertThat(widgetModel.equals(widgetModel), is(true));
157
158         // equals() is symmetric
159         Widget widgetModelB = Widget.createWidget("OAM_NETWORK");
160         assertThat(widgetModel.equals(widgetModelB), is(true));
161         assertThat(widgetModelB.equals(widgetModel), is(true));
162
163         assertThat(widgetModel.equals(null), is(false));
164         assertThat(widgetModel.equals(Widget.createWidget("VSERVER")), is(false));
165     }
166
167     @Test(expected = IllegalArgumentException.class)
168     public void testGetUnknownWidget() throws XmlArtifactGenerationException {
169         WidgetType.valueOf("invalid-widget-name");
170     }
171
172     /**
173      * Try to get the Widget object for an unsupported (non-configured) type.
174      *
175      * @throws XmlArtifactGenerationException
176      *             if there is no configuration defined for the specified Widget type
177      */
178     @Test(expected = XmlArtifactGenerationException.class)
179     public void testGetDynamicWidget() throws XmlArtifactGenerationException {
180         Widget.createWidget(new WidgetType(null));
181     }
182
183     @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
184     public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException {
185         Widget.createWidget("OAM_NETWORK").addResource(null);
186     }
187
188     // Call Widget methods which are not supported, purely for code coverage.
189
190     @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
191     public void testGetModelNameVersionIdIsUnsupported() throws XmlArtifactGenerationException {
192         Widget widgetModel = Widget.createWidget("OAM_NETWORK");
193         assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
194     }
195
196     @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
197     public void testGetModelTypeNameIsUnsupported() throws XmlArtifactGenerationException {
198         Widget widgetModel = Widget.createWidget("OAM_NETWORK");
199         assertThat(widgetModel.getModelTypeName(), is(nullValue()));
200     }
201
202     @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
203     public void testGetModelIdIsUnsupported() throws XmlArtifactGenerationException {
204         Widget widgetModel = Widget.createWidget("OAM_NETWORK");
205         assertThat(widgetModel.getModelId(), is(nullValue()));
206     }
207
208 }