2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 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.Arrays;
30 import java.util.Collections;
31 import java.util.List;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
36 import org.onap.aai.babel.util.ArtifactTestUtils;
37 import org.onap.aai.babel.xml.generator.model.Widget.Type;
38 import org.onap.aai.babel.xml.generator.types.ModelType;
41 * Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
42 * covered by the tests of derived classes.
44 public class TestModel {
46 private Service serviceModel = new Service();
47 private List<Resource> resourceModels =
48 Arrays.asList(new Resource(Type.CR, true), new Resource(Type.INSTANCE_GROUP, true));
49 private Widget widgetModel = new OamNetwork();
50 private Model anonymousModel;
53 System.setProperty("APP_HOME", ".");
57 * Initialise the Artifact Generator with filtering and mapping configuration. Also Load the Widget to UUID mappings
58 * from the Artifact Generator properties.
61 * if the Artifact Generator properties file is not loaded
64 public void setup() throws IOException {
65 ArtifactTestUtils utils = new ArtifactTestUtils();
66 utils.setGeneratorSystemProperties();
68 ArtifactGeneratorToscaParser.initGroupFilterConfiguration();
69 utils.loadWidgetToUuidMappings();
71 anonymousModel = new Model() {
73 public boolean addResource(Resource resource) {
78 public boolean addWidget(Widget resource) {
83 public Type getWidgetType() {
88 public Map<String, Object> getProperties() {
89 return Collections.emptyMap();
93 public boolean isResource() {
100 public void testGetModels() {
101 assertThat(Model.getModelFor(null), is(nullValue()));
102 assertThat(Model.getModelFor(""), is(nullValue()));
103 assertThat(Model.getModelFor("any.unknown.type"), is(nullValue()));
105 assertMapping("org.openecomp.resource.vfc", Type.VSERVER);
106 assertMapping("org.openecomp.resource.cp", Type.LINT);
107 assertMapping("org.openecomp.cp", Type.LINT);
108 assertMapping("org.openecomp.cp.some.suffix", Type.LINT);
109 assertMapping("org.openecomp.resource.vl", Type.L3_NET);
110 assertMapping("org.openecomp.resource.vf", Type.VF);
111 assertMapping("org.openecomp.groups.vfmodule", Type.VFMODULE);
112 assertMapping("org.openecomp.groups.VfModule", Type.VFMODULE);
113 assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", Type.VOLUME);
114 assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration", Type.CONFIGURATION);
115 assertMapping("any.string", "Configuration", Type.CONFIGURATION);
116 assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", Type.CR);
117 assertMapping("any.string", "CR", Type.CR);
119 assertMapping("org.openecomp.resource.vfc", "an.unknown.type", Type.VSERVER);
123 * Assert that the TOSCA type String is mapped to the expected Widget Type.
126 * the TOSCA type or prefix
128 * the type of Widget expected from the mappings
130 private void assertMapping(String toscaType, Type widgetType) {
131 assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType));
135 * Assert that the TOSCA metadata type is mapped to the expected Widget Type.
138 * the name (or name prefix) of the TOSCA type
139 * @param metadataType
140 * the type specified in the TOSCA metadata
142 * the type of Widget expected from the mappings
144 private void assertMapping(String toscaType, String metadataType, Type widgetType) {
145 assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));
149 public void testGetModelType() {
150 assertThat(serviceModel.getModelType(), is(ModelType.SERVICE));
151 for (Resource resourceModel : resourceModels) {
152 assertThat(resourceModel.getModelType(), is(ModelType.RESOURCE));
154 assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
155 assertThat(anonymousModel.getModelType(), is(nullValue()));
159 public void testGetModelNameVersionId() {
160 assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
163 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
164 public void testGetModelNameVersionIdIsUnsupported() {
165 assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
166 assertThat(resourceModels.get(0).getModelType(), is(ModelType.RESOURCE));
167 assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
168 assertThat(anonymousModel.getModelType(), is(nullValue()));