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