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 org.junit.Before;
30 import org.junit.Test;
31 import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
32 import org.onap.aai.babel.util.ArtifactTestUtils;
33 import org.onap.aai.babel.xml.generator.model.Widget.Type;
36 * Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
37 * covered by the tests of derived classes.
39 public class TestModel {
41 private Widget widgetModel = new Widget(Type.OAM_NETWORK, "oam-network", true);
42 private Model anonymousModel;
45 * Initialize the Artifact Generator with filtering and mapping configuration. Also load the Widget to UUID mappings
46 * from the Artifact Generator properties.
49 * if the mappings configuration cannot be loaded
52 public void setup() throws IOException {
53 ArtifactTestUtils utils = new ArtifactTestUtils();
54 utils.setGeneratorSystemProperties();
56 String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
57 if (configLocation == null) {
58 throw new IllegalArgumentException(
59 String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND,
60 ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
63 ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
64 utils.loadWidgetToUuidMappings();
66 anonymousModel = new Model() {
68 public boolean addWidget(Widget resource) {
73 public Type getWidgetType() {
78 public String getModelTypeName() {
85 public void testGetModels() {
86 assertThat(Model.getModelFor(null), is(nullValue()));
87 assertThat(Model.getModelFor(""), is(nullValue()));
88 assertThat(Model.getModelFor("any.unknown.type"), is(nullValue()));
90 assertMapping("org.openecomp.resource.vfc", Type.VSERVER);
91 assertMapping("org.openecomp.resource.cp", Type.LINT);
92 assertMapping("org.openecomp.cp", Type.LINT);
93 assertMapping("org.openecomp.cp.some.suffix", Type.LINT);
94 assertMapping("org.openecomp.resource.vl", Type.L3_NET);
95 assertMapping("org.openecomp.resource.vf", Type.VF);
96 assertMapping("org.openecomp.groups.vfmodule", Type.VFMODULE);
97 assertMapping("org.openecomp.groups.VfModule", Type.VFMODULE);
98 assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", Type.VOLUME);
99 assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration", Type.CONFIGURATION);
100 assertMapping("any.string", "Configuration", Type.CONFIGURATION);
101 assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", Type.CR);
102 assertMapping("any.string", "CR", Type.CR);
104 assertMapping("org.openecomp.resource.vfc", "an.unknown.type", Type.VSERVER);
108 * Assert that the TOSCA type String is mapped to the expected Widget Type.
111 * the TOSCA type or prefix
113 * the type of Widget expected from the mappings
115 private void assertMapping(String toscaType, Type widgetType) {
116 assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType));
120 * Assert that the TOSCA metadata type is mapped to the expected Widget Type.
123 * the name (or name prefix) of the TOSCA type
124 * @param metadataType
125 * the type specified in the TOSCA metadata
127 * the type of Widget expected from the mappings
129 private void assertMapping(String toscaType, String metadataType, Type widgetType) {
130 assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));
134 public void testGetModelNameVersionId() {
135 assertThat(anonymousModel.getModelNameVersionId(), is(nullValue()));
138 @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class)
139 public void testGetModelNameVersionIdIsUnsupported() {
140 assertThat(widgetModel.getModelNameVersionId(), is(nullValue()));