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.hamcrest.MatcherAssert.assertThat;
27 import static org.junit.jupiter.api.Assertions.assertThrows;
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;
38 * Direct tests of the Widget class for code coverage.
40 public class TestWidget {
43 * Load the Widget mappings configuration.
46 * if the mappings configuration cannot be loaded
49 public static void setup() throws IOException {
50 new ArtifactTestUtils().loadWidgetMappings();
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));
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));
65 widget = Widget.createWidget("VFC");
66 assertThat(widget.getType(), is(ModelType.WIDGET));
67 assertThat(widget.getName(), is("vnfc"));
68 assertThat(widget.getDeleteFlag(), is(true));
70 widget = Widget.createWidget("VSERVER");
71 assertThat(widget.getType(), is(ModelType.WIDGET));
72 assertThat(widget.getName(), is("vserver"));
73 assertThat(widget.getDeleteFlag(), is(true));
75 widget = Widget.createWidget("VOLUME");
76 assertThat(widget.getType(), is(ModelType.WIDGET));
77 assertThat(widget.getName(), is("volume"));
78 assertThat(widget.getDeleteFlag(), is(true));
80 widget = Widget.createWidget("FLAVOR");
81 assertThat(widget.getType(), is(ModelType.WIDGET));
82 assertThat(widget.getName(), is("flavor"));
83 assertThat(widget.getDeleteFlag(), is(false));
85 widget = Widget.createWidget("TENANT");
86 assertThat(widget.getType(), is(ModelType.WIDGET));
87 assertThat(widget.getName(), is("tenant"));
88 assertThat(widget.getDeleteFlag(), is(false));
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));
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));
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));
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));
110 widget = Widget.createWidget("IMAGE");
111 assertThat(widget.getType(), is(ModelType.WIDGET));
112 assertThat(widget.getName(), is("image"));
113 assertThat(widget.getDeleteFlag(), is(false));
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));
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));
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));
130 widget = Widget.createWidget("CONFIGURATION");
131 assertThat(widget.getType(), is(ModelType.WIDGET));
132 assertThat(widget.getName(), is("configuration"));
133 assertThat(widget.getDeleteFlag(), is(true));
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));
147 * Call equals() method for code coverage.
149 * @throws XmlArtifactGenerationException
150 * if there is no configuration defined for the test Widget Type
153 public void testEquals() throws XmlArtifactGenerationException {
154 Widget widgetModel = Widget.createWidget("OAM_NETWORK");
156 // equals() is reflexive
157 assertThat(widgetModel.equals(widgetModel), is(true));
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));
164 assertThat(widgetModel.equals(null), is(false));
165 assertThat(widgetModel.equals(Widget.createWidget("VSERVER")), is(false));
169 public void testGetUnknownWidget() throws XmlArtifactGenerationException {
170 assertThrows(IllegalArgumentException.class, () -> {
171 WidgetType.valueOf("invalid-widget-name");
176 * Try to get the Widget object for an unsupported (non-configured) type.
178 * @throws XmlArtifactGenerationException
179 * if there is no configuration defined for the specified Widget type
182 public void testGetDynamicWidget() throws XmlArtifactGenerationException {
183 assertThrows(XmlArtifactGenerationException.class, () -> {
184 Widget.createWidget(new WidgetType(null));
189 public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException {
190 assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> {
191 Widget.createWidget("OAM_NETWORK").addResource(null);
195 // Call Widget methods which are not supported, purely for code coverage.
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();
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();
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();