Remove all references to artifactgenerator config
[aai/babel.git] / src / test / java / org / onap / aai / babel / xml / generator / model / TestModel.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.aai.babel.xml.generator.model;
23
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.CoreMatchers.nullValue;
26 import static org.junit.Assert.assertThat;
27
28 import java.io.IOException;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.aai.babel.util.ArtifactTestUtils;
32
33 /**
34  * Direct tests of the Model abstract class (to improve code coverage). Not all methods are tested here. Some are
35  * covered by the tests of derived classes.
36  */
37 public class TestModel {
38
39     /**
40      * Load the Widget mapping configuration.
41      *
42      * @throws IOException
43      *             if the mappings configuration cannot be loaded
44      */
45     @BeforeClass
46     public static void setup() throws IOException {
47         new ArtifactTestUtils().loadWidgetMappings();
48     }
49
50     @Test
51     public void testGetModels() {
52         assertThat(Model.getModelFor(null), is(nullValue()));
53         assertThat(Model.getModelFor(""), is(nullValue()));
54         assertThat(Model.getModelFor("any.unknown.type"), is(nullValue()));
55
56         assertMapping("org.openecomp.resource.vfc", WidgetType.valueOf("VSERVER"));
57         assertMapping("org.openecomp.resource.cp", WidgetType.valueOf("LINT"));
58         assertMapping("org.openecomp.cp", WidgetType.valueOf("LINT"));
59         assertMapping("org.openecomp.cp.some.suffix", WidgetType.valueOf("LINT"));
60         assertMapping("org.openecomp.resource.vl", WidgetType.valueOf("L3_NET"));
61         assertMapping("org.openecomp.resource.vf", WidgetType.valueOf("VF"));
62         assertMapping("org.openecomp.groups.vfmodule", WidgetType.valueOf("VFMODULE"));
63         assertMapping("org.openecomp.groups.VfModule", WidgetType.valueOf("VFMODULE"));
64         assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", WidgetType.valueOf("VOLUME"));
65         assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration",
66                 WidgetType.valueOf("CONFIGURATION"));
67         assertMapping("any.string", "Configuration", WidgetType.valueOf("CONFIGURATION"));
68         assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", WidgetType.valueOf("CR"));
69         assertMapping("any.string", "CR", WidgetType.valueOf("CR"));
70
71         assertMapping("org.openecomp.resource.vfc", "an.unknown.type", WidgetType.valueOf("VSERVER"));
72     }
73
74     /**
75      * Test that there is no exception if processing a Model that has no metadata properties.
76      */
77     @Test
78     public void testNullIdentProperties() {
79         createTestModel().populateModelIdentificationInformation(null);
80     }
81
82     /**
83      * Test that an exception occurs if calling code passes an unsupported Widget Type value to the base implementation
84      * of the hasWidgetType() method.
85      */
86     @Test(expected = IllegalArgumentException.class)
87     public void testUnknownWidgetType() {
88         createTestModel().hasWidgetType(null);
89     }
90
91     /**
92      * Create any Model with a valid WidgetType, for method testing.
93      *
94      * @return a valid Model for testing purposes
95      */
96     private Model createTestModel() {
97         return new Resource(WidgetType.valueOf("VSERVER"), false);
98     }
99
100     /**
101      * Assert that the TOSCA type String is mapped to the expected Widget Type.
102      *
103      * @param toscaType
104      *            the TOSCA type or prefix
105      * @param widgetType
106      *            the type of Widget expected from the mappings
107      */
108     private void assertMapping(String toscaType, WidgetType widgetType) {
109         assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType));
110     }
111
112     /**
113      * Assert that the TOSCA metadata type is mapped to the expected Widget Type.
114      *
115      * @param toscaType
116      *            the name (or name prefix) of the TOSCA type
117      * @param metadataType
118      *            the type specified in the TOSCA metadata
119      * @param widgetType
120      *            the type of Widget expected from the mappings
121      */
122     private void assertMapping(String toscaType, String metadataType, WidgetType widgetType) {
123         assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));
124     }
125
126 }