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 Widget(Type.OAM_NETWORK, "oam-network", true);
50 private Model anonymousModel;
53 System.setProperty("APP_HOME", ".");
57 * Initialize 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 String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
69 if (configLocation == null) {
70 throw new IllegalArgumentException(
71 String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND,
72 ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
75 ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
76 utils.loadWidgetToUuidMappings();
78 anonymousModel = new Model() {
80 public boolean addResource(Resource resource) {
85 public boolean addWidget(Widget resource) {
90 public Type getWidgetType() {
95 public Map<String, Object> getProperties() {
96 return Collections.emptyMap();
100 public boolean isResource() {
107 public void testGetModels() {
108 assertThat(Model.getModelFor(null), is(nullValue()));
109 assertThat(Model.getModelFor(""), is(nullValue()));
110 assertThat(Model.getModelFor("any.unknown.type"), is(nullValue()));
112 assertMapping("org.openecomp.resource.vfc", Type.VSERVER);
113 assertMapping("org.openecomp.resource.cp", Type.LINT);
114 assertMapping("org.openecomp.cp", Type.LINT);
115 assertMapping("org.openecomp.cp.some.suffix", Type.LINT);
116 assertMapping("org.openecomp.resource.vl", Type.L3_NET);
117 assertMapping("org.openecomp.resource.vf", Type.VF);
118 assertMapping("org.openecomp.groups.vfmodule", Type.VFMODULE);
119 assertMapping("org.openecomp.groups.VfModule", Type.VFMODULE);
120 assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", Type.VOLUME);
121 assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration", Type.CONFIGURATION);
122 assertMapping("any.string", "Configuration", Type.CONFIGURATION);
123 assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", Type.CR);
124 assertMapping("any.string", "CR", Type.CR);
126 assertMapping("org.openecomp.resource.vfc", "an.unknown.type", Type.VSERVER);
130 * Assert that the TOSCA type String is mapped to the expected Widget Type.
133 * the TOSCA type or prefix
135 * the type of Widget expected from the mappings
137 private void assertMapping(String toscaType, Type widgetType) {
138 assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType));
142 * Assert that the TOSCA metadata type is mapped to the expected Widget Type.
145 * the name (or name prefix) of the TOSCA type
146 * @param metadataType
147 * the type specified in the TOSCA metadata
149 * the type of Widget expected from the mappings
151 private void assertMapping(String toscaType, String metadataType, Type widgetType) {
152 assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));
156 public void testGetModelType() {
157 assertThat(serviceModel.getModelType(), is(ModelType.SERVICE));
158 for (Resource resourceModel : resourceModels) {
159 assertThat(resourceModel.getModelType(), is(ModelType.RESOURCE));
161 assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
162 assertThat(anonymousModel.getModelType(), is(nullValue()));
166 public void testGetModelNameVersionId() {
167 assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
170 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
171 public void testGetModelNameVersionIdIsUnsupported() {
172 assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));
173 assertThat(resourceModels.get(0).getModelType(), is(ModelType.RESOURCE));
174 assertThat(widgetModel.getModelType(), is(ModelType.WIDGET));
175 assertThat(anonymousModel.getModelType(), is(nullValue()));