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=========================================================
21 package org.onap.aai.babel.xml.generator.model;
23 import static org.hamcrest.CoreMatchers.instanceOf;
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.FileNotFoundException;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.util.Properties;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
35 import org.onap.aai.babel.xml.generator.model.Widget.Type;
36 import org.onap.aai.babel.xml.generator.types.ModelType;
39 * Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
40 * covered by the tests of derived classes.
42 public class TestModel {
44 private Service serviceModel = new Service();
45 private Resource resourceModel = new VirtualFunction();
46 private Widget widgetModel = new OamNetwork();
47 private Model anonymousModel;
50 System.setProperty("APP_HOME", ".");
54 public void setup() throws FileNotFoundException, IOException {
55 InputStream in = TestModel.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
56 Properties properties = new Properties();
59 WidgetConfigurationUtil.setConfig(properties);
61 anonymousModel = new Model() {
63 public boolean addResource(Resource resource) {
68 public boolean addWidget(Widget resource) {
73 public Type getWidgetType() {
80 public void testGetModels() {
81 assertThat(Model.getModelFor(null), is(nullValue()));
82 assertThat(Model.getModelFor(""), is(nullValue()));
83 assertThat(Model.getModelFor("any.unknown.type"), is(nullValue()));
85 assertThat(Model.getModelFor("org.openecomp.resource.vf.allottedResource"), instanceOf(AllotedResource.class));
86 assertThat(Model.getModelFor("org.openecomp.resource.vfc.AllottedResource"),
87 instanceOf(ProvidingService.class));
88 assertThat(Model.getModelFor("org.openecomp.resource.vfc"), instanceOf(VServerWidget.class));
89 assertThat(Model.getModelFor("org.openecomp.resource.cp"), instanceOf(LIntfWidget.class));
90 assertThat(Model.getModelFor("org.openecomp.cp"), instanceOf(LIntfWidget.class));
91 assertThat(Model.getModelFor("org.openecomp.cp.some.suffix"), instanceOf(LIntfWidget.class));
92 assertThat(Model.getModelFor("org.openecomp.resource.vl"), instanceOf(L3Network.class));
93 assertThat(Model.getModelFor("org.openecomp.resource.vf"), instanceOf(VirtualFunction.class));
94 assertThat(Model.getModelFor("org.openecomp.groups.vfmodule"), instanceOf(VfModule.class));
95 assertThat(Model.getModelFor("org.openecomp.groups.VfModule"), instanceOf(VfModule.class));
96 assertThat(Model.getModelFor("org.openecomp.resource.vfc.nodes.heat.cinder"), instanceOf(VolumeWidget.class));
97 assertThat(Model.getModelFor("org.openecomp.nodes.PortMirroringConfiguration"),
98 instanceOf(Configuration.class));
102 public void testGetCardinality() {
103 resourceModel.getCardinality();
107 public void testGetModelType() {
108 assertThat(serviceModel.getModelType(), is(ModelType.SERVICE));
109 assertThat(resourceModel.getModelType(), is(ModelType.RESOURCE));
110 assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
111 assertThat(anonymousModel.getModelType(), is(nullValue()));
115 public void testGetModelNameVersionId() {
116 assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
119 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
120 public void testGetModelNameVersionIdIsUnsupported() {
121 assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));