2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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.instanceOf;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.CoreMatchers.nullValue;
27 import static org.junit.Assert.assertThat;
29 import java.io.FileNotFoundException;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.util.Arrays;
33 import java.util.List;
34 import java.util.Properties;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
38 import org.onap.aai.babel.xml.generator.model.Widget.Type;
39 import org.onap.aai.babel.xml.generator.types.ModelType;
42 * Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
43 * covered by the tests of derived classes.
45 public class TestModel {
47 private Service serviceModel = new Service();
48 private List<Resource> resourceModels = Arrays.asList(new VirtualFunction(), new InstanceGroup());
49 private Widget widgetModel = new OamNetwork();
50 private Model anonymousModel;
53 System.setProperty("APP_HOME", ".");
57 * Load the Widget to UUID mappings from the Artifact Generator properties.
59 * @throws FileNotFoundException
60 * if the properties file is missing
62 * if the properties file is not loaded
65 public void setup() throws FileNotFoundException, IOException {
66 InputStream in = TestModel.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
67 Properties properties = new Properties();
70 WidgetConfigurationUtil.setConfig(properties);
72 anonymousModel = new Model() {
74 public boolean addResource(Resource resource) {
79 public boolean addWidget(Widget resource) {
84 public Type getWidgetType() {
91 public void testGetModels() {
92 assertThat(Model.getModelFor(null), is(nullValue()));
93 assertThat(Model.getModelFor(""), is(nullValue()));
94 assertThat(Model.getModelFor("any.unknown.type"), is(nullValue()));
96 assertThat(Model.getModelFor("org.openecomp.resource.vf.allottedResource"), instanceOf(AllotedResource.class));
97 assertThat(Model.getModelFor("org.openecomp.resource.vf.allottedResource.with.sub.type"),
98 instanceOf(AllotedResource.class));
99 assertThat(Model.getModelFor("org.openecomp.resource.vfc.AllottedResource"),
100 instanceOf(ProvidingService.class));
101 assertThat(Model.getModelFor("org.openecomp.resource.vfc"), instanceOf(VServerWidget.class));
102 assertThat(Model.getModelFor("org.openecomp.resource.cp"), instanceOf(LIntfWidget.class));
103 assertThat(Model.getModelFor("org.openecomp.cp"), instanceOf(LIntfWidget.class));
104 assertThat(Model.getModelFor("org.openecomp.cp.some.suffix"), instanceOf(LIntfWidget.class));
105 assertThat(Model.getModelFor("org.openecomp.resource.vl"), instanceOf(L3Network.class));
106 assertThat(Model.getModelFor("org.openecomp.resource.vf"), instanceOf(VirtualFunction.class));
107 assertThat(Model.getModelFor("org.openecomp.groups.vfmodule"), instanceOf(VfModule.class));
108 assertThat(Model.getModelFor("org.openecomp.groups.VfModule"), instanceOf(VfModule.class));
109 assertThat(Model.getModelFor("org.openecomp.resource.vfc.nodes.heat.cinder"), instanceOf(VolumeWidget.class));
110 assertThat(Model.getModelFor("org.openecomp.nodes.PortMirroringConfiguration"),
111 instanceOf(Configuration.class));
112 assertThat(Model.getModelFor("org.openecomp.nodes.PortMirroringConfiguration", "Configuration"),
113 instanceOf(Configuration.class));
114 assertThat(Model.getModelFor("any.string", "Configuration"), instanceOf(Configuration.class));
115 assertThat(Model.getModelFor("org.openecomp.resource.cr.Kk1806Cr1", "CR"), instanceOf(CR.class));
116 assertThat(Model.getModelFor("any.string", "CR"), instanceOf(CR.class));
118 assertThat(Model.getModelFor("org.openecomp.resource.vfc", "an.unknown.type"), instanceOf(VServerWidget.class));
122 public void testGetCardinality() {
123 resourceModels.get(0).getCardinality();
127 public void testGetModelType() {
128 assertThat(serviceModel.getModelType(), is(ModelType.SERVICE));
129 for (Resource resourceModel : resourceModels) {
130 assertThat(resourceModel.getModelType(), is(ModelType.RESOURCE));
132 assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
133 assertThat(anonymousModel.getModelType(), is(nullValue()));
137 public void testGetModelNameVersionId() {
138 assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
141 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
142 public void testGetModelNameVersionIdIsUnsupported() {
143 assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
144 assertThat(resourceModels.get(0).getModelType(), is(ModelType.RESOURCE));
145 assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
146 assertThat(anonymousModel.getModelType(), is(nullValue()));