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 mappings configuration.
45 * if the mappings configuration cannot be loaded
48 public static void setup() throws IOException {
49 new ArtifactTestUtils().loadWidgetMappings();
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));
59 widget = Widget.createWidget("VF");
60 assertThat(widget.getType(), is(ModelType.WIDGET));
61 assertThat(widget.getName(), is("generic-vnf"));
62 assertThat(widget.getDeleteFlag(), is(true));
64 widget = Widget.createWidget("VFC");
65 assertThat(widget.getType(), is(ModelType.WIDGET));
66 assertThat(widget.getName(), is("vnfc"));
67 assertThat(widget.getDeleteFlag(), is(true));
69 widget = Widget.createWidget("VSERVER");
70 assertThat(widget.getType(), is(ModelType.WIDGET));
71 assertThat(widget.getName(), is("vserver"));
72 assertThat(widget.getDeleteFlag(), is(true));
74 widget = Widget.createWidget("VOLUME");
75 assertThat(widget.getType(), is(ModelType.WIDGET));
76 assertThat(widget.getName(), is("volume"));
77 assertThat(widget.getDeleteFlag(), is(true));
79 widget = Widget.createWidget("FLAVOR");
80 assertThat(widget.getType(), is(ModelType.WIDGET));
81 assertThat(widget.getName(), is("flavor"));
82 assertThat(widget.getDeleteFlag(), is(false));
84 widget = Widget.createWidget("TENANT");
85 assertThat(widget.getType(), is(ModelType.WIDGET));
86 assertThat(widget.getName(), is("tenant"));
87 assertThat(widget.getDeleteFlag(), is(false));
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));
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));
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));
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));
109 widget = Widget.createWidget("IMAGE");
110 assertThat(widget.getType(), is(ModelType.WIDGET));
111 assertThat(widget.getName(), is("image"));
112 assertThat(widget.getDeleteFlag(), is(false));
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));
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));
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));
129 widget = Widget.createWidget("CONFIGURATION");
130 assertThat(widget.getType(), is(ModelType.WIDGET));
131 assertThat(widget.getName(), is("configuration"));
132 assertThat(widget.getDeleteFlag(), is(true));
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));
146 * Call equals() method for code coverage.
148 * @throws XmlArtifactGenerationException
149 * if there is no configuration defined for the test Widget Type
152 public void testEquals() throws XmlArtifactGenerationException {
153 Widget widgetModel = Widget.createWidget("OAM_NETWORK");
155 // equals() is reflexive
156 assertThat(widgetModel.equals(widgetModel), is(true));
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));
163 assertThat(widgetModel.equals(null), is(false));
164 assertThat(widgetModel.equals(Widget.createWidget("VSERVER")), is(false));
167 @Test(expected = IllegalArgumentException.class)
168 public void testGetUnknownWidget() throws XmlArtifactGenerationException {
169 WidgetType.valueOf("invalid-widget-name");
173 * Try to get the Widget object for an unsupported (non-configured) type.
175 * @throws XmlArtifactGenerationException
176 * if there is no configuration defined for the specified Widget type
178 @Test(expected = XmlArtifactGenerationException.class)
179 public void testGetDynamicWidget() throws XmlArtifactGenerationException {
180 Widget.createWidget(new WidgetType(null));
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);
188 // Call Widget methods which are not supported, purely for code coverage.
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()));
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()));
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()));