2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.aai.babel.xml.generator.model;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.CoreMatchers.nullValue;
26 import static org.junit.Assert.assertThat;
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;
37 * Direct tests of the Widget class for code coverage.
39 public class TestWidget {
42 * Load the Widget Configuration, including the type mappings and the UUID mappings.
45 * if the mappings configuration cannot be loaded
48 public static void setup() throws IOException {
49 ArtifactTestUtils util = new ArtifactTestUtils();
50 util.loadWidgetToUuidMappings();
51 util.loadWidgetMappings();
55 public void testGetWidgets() throws XmlArtifactGenerationException {
56 Widget widget = Widget.createWidget("SERVICE");
57 assertThat(widget.getType(), is(ModelType.WIDGET));
58 assertThat(widget.getName(), is("service-instance"));
59 assertThat(widget.getDeleteFlag(), is(true));
61 widget = Widget.createWidget("VF");
62 assertThat(widget.getType(), is(ModelType.WIDGET));
63 assertThat(widget.getName(), is("generic-vnf"));
64 assertThat(widget.getDeleteFlag(), is(false));
66 widget = Widget.createWidget("VFC");
67 assertThat(widget.getType(), is(ModelType.WIDGET));
68 assertThat(widget.getName(), is("vnfc"));
69 assertThat(widget.getDeleteFlag(), is(true));
71 widget = Widget.createWidget("VSERVER");
72 assertThat(widget.getType(), is(ModelType.WIDGET));
73 assertThat(widget.getName(), is("vserver"));
74 assertThat(widget.getDeleteFlag(), is(true));
76 widget = Widget.createWidget("VOLUME");
77 assertThat(widget.getType(), is(ModelType.WIDGET));
78 assertThat(widget.getName(), is("volume"));
79 assertThat(widget.getDeleteFlag(), is(true));
81 widget = Widget.createWidget("FLAVOR");
82 assertThat(widget.getType(), is(ModelType.WIDGET));
83 assertThat(widget.getName(), is("flavor"));
84 assertThat(widget.getDeleteFlag(), is(false));
86 widget = Widget.createWidget("TENANT");
87 assertThat(widget.getType(), is(ModelType.WIDGET));
88 assertThat(widget.getName(), is("tenant"));
89 assertThat(widget.getDeleteFlag(), is(false));
91 widget = Widget.createWidget("VOLUME_GROUP");
92 assertThat(widget.getType(), is(ModelType.WIDGET));
93 assertThat(widget.getName(), is("volume-group"));
94 assertThat(widget.getDeleteFlag(), is(true));
96 widget = Widget.createWidget("LINT");
97 assertThat(widget.getType(), is(ModelType.WIDGET));
98 assertThat(widget.getName(), is("l-interface"));
99 assertThat(widget.getDeleteFlag(), is(true));
101 widget = Widget.createWidget("L3_NET");
102 assertThat(widget.getType(), is(ModelType.WIDGET));
103 assertThat(widget.getName(), is("l3-network"));
104 assertThat(widget.getDeleteFlag(), is(true));
106 widget = Widget.createWidget("VFMODULE");
107 assertThat(widget.getType(), is(ModelType.WIDGET));
108 assertThat(widget.getName(), is("vf-module"));
109 assertThat(widget.getDeleteFlag(), is(true));
111 widget = Widget.createWidget("IMAGE");
112 assertThat(widget.getType(), is(ModelType.WIDGET));
113 assertThat(widget.getName(), is("image"));
114 assertThat(widget.getDeleteFlag(), is(false));
116 widget = Widget.createWidget("OAM_NETWORK");
117 assertThat(widget.getType(), is(ModelType.WIDGET));
118 assertThat(widget.getName(), is("oam-network"));
119 assertThat(widget.getDeleteFlag(), is(true));
121 widget = Widget.createWidget("ALLOTTED_RESOURCE");
122 assertThat(widget.getType(), is(ModelType.WIDGET));
123 assertThat(widget.getName(), is("allotted-resource"));
124 assertThat(widget.getDeleteFlag(), is(true));
126 widget = Widget.createWidget("TUNNEL_XCONNECT");
127 assertThat(widget.getType(), is(ModelType.WIDGET));
128 assertThat(widget.getName(), is("tunnel-xconnect"));
129 assertThat(widget.getDeleteFlag(), is(true));
131 widget = Widget.createWidget("CONFIGURATION");
132 assertThat(widget.getType(), is(ModelType.WIDGET));
133 assertThat(widget.getName(), is("configuration"));
134 assertThat(widget.getDeleteFlag(), is(true));
138 public void testWidgetMethods() throws XmlArtifactGenerationException {
139 Widget widget = Widget.createWidget("SERVICE");
140 assertThat(widget.getType(), is(ModelType.WIDGET));
141 assertThat(widget.getWidgetId(), is("service-instance-invariant-id"));
142 assertThat(widget.addWidget(Widget.createWidget("TENANT")), is(true));
143 assertThat(widget.memberOf(null), is(false));
144 assertThat(widget.memberOf(Collections.emptyList()), is(false));
148 * Call equals() method for code coverage.
150 * @throws XmlArtifactGenerationException
151 * if there is no configuration defined for the test Widget Type
154 public void testEquals() throws XmlArtifactGenerationException {
155 Widget widgetModel = Widget.createWidget("OAM_NETWORK");
157 // equals() is reflexive
158 assertThat(widgetModel.equals(widgetModel), is(true));
160 // equals() is symmetric
161 Widget widgetModelB = Widget.createWidget("OAM_NETWORK");
162 assertThat(widgetModel.equals(widgetModelB), is(true));
163 assertThat(widgetModelB.equals(widgetModel), is(true));
165 assertThat(widgetModel.equals(null), is(false));
166 assertThat(widgetModel.equals(Widget.createWidget("VSERVER")), is(false));
169 @Test(expected = IllegalArgumentException.class)
170 public void testGetUnknownWidget() throws XmlArtifactGenerationException {
171 WidgetType.valueOf("invalid-widget-name");
175 * Try to get the Widget object for an unsupported (non-configured) type.
177 * @throws XmlArtifactGenerationException
178 * if there is no configuration defined for the specified Widget type
180 @Test(expected = XmlArtifactGenerationException.class)
181 public void testGetDynamicWidget() throws XmlArtifactGenerationException {
182 Widget.createWidget(new WidgetType(null));
185 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
186 public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException {
187 Widget.createWidget("OAM_NETWORK").addResource(null);
190 @Test(expected = IllegalArgumentException.class)
191 public void testGetVersionIdForUknownWidget() {
192 new Widget(new WidgetType("test"), null, false).getId();
195 @Test(expected = IllegalArgumentException.class)
196 public void testGetInvariantIdForUknownWidget() {
197 new Widget(new WidgetType("test"), null, false).getWidgetId();
200 // Call Widget methods which are not supported, purely for code coverage.
202 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
203 public void testGetModelNameVersionIdIsUnsupported() throws XmlArtifactGenerationException {
204 Widget widgetModel = Widget.createWidget("OAM_NETWORK");
205 assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
208 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
209 public void testGetModelTypeNameIsUnsupported() throws XmlArtifactGenerationException {
210 Widget widgetModel = Widget.createWidget("OAM_NETWORK");
211 assertThat(widgetModel.getModelTypeName(), is(nullValue()));
214 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
215 public void testGetModelIdIsUnsupported() throws XmlArtifactGenerationException {
216 Widget widgetModel = Widget.createWidget("OAM_NETWORK");
217 assertThat(widgetModel.getModelId(), is(nullValue()));