Incorporate the ECOMP SDC Artefact Generator code
[aai/babel.git] / src / test / java / org / onap / aai / babel / xml / generator / model / TestVfModule.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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 package org.onap.aai.babel.xml.generator.model;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.CoreMatchers.notNullValue;
25 import static org.junit.Assert.assertThat;
26
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.Map;
33 import java.util.Properties;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
37 import org.onap.aai.babel.xml.generator.model.Widget.Type;
38
39 /**
40  * Direct tests of the Model class VfModule so as to improve code coverage
41  */
42 public class TestVfModule {
43
44     static {
45         if (System.getProperty("AJSC_HOME") == null) {
46             System.setProperty("AJSC_HOME", ".");
47         }
48     }
49
50     @Before
51     public void setup() throws FileNotFoundException, IOException {
52         InputStream in = TestVfModule.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
53         Properties properties = new Properties();
54         properties.load(in);
55         in.close();
56         WidgetConfigurationUtil.setConfig(properties);
57     }
58
59     @Test
60     public void testCreateVfModule() {
61         VfModule vf = new VfModule();
62         Map<String, String> modelIdentInfo = new HashMap<>();
63         modelIdentInfo.put("UUID", "dummy_uuid");
64         vf.populateModelIdentificationInformation(modelIdentInfo);
65         assertThat(vf.hashCode(), is(notNullValue()));
66         assertThat(vf.equals(vf), is(true));
67         // Tests that the overridden equals() method correctly returns false for a different type of Object
68         // This is necessary to achieve complete code coverage
69         assertThat(vf.equals("string"), is(false)); // NOSONAR
70     }
71
72     @Test
73     public void testNonMemberWidgetToVF() {
74         VfModule vf = new VfModule();
75         Widget widget = Widget.getWidget(Type.SERVICE);
76         vf.setMembers(Collections.singletonList(widget.getId()));
77         vf.addWidget(widget);
78     }
79
80     @Test
81     public void testAddServiceWidgetToVF() {
82         VfModule vf = new VfModule();
83         addWidgetToModule(vf, Type.SERVICE);
84     }
85
86     @Test
87     public void testAddVServerWidgetToVF() {
88         VfModule vf = new VfModule();
89         addWidgetToModule(vf, Type.VSERVER);
90     }
91
92     @Test
93     public void testAddLIntfWidgetToVF() {
94         VfModule vf = new VfModule();
95         addWidgetToModule(vf, Type.LINT);
96         addWidgetToModule(vf, Type.VSERVER);
97         addWidgetToModule(vf, Type.LINT);
98     }
99
100     @Test
101     public void testAddVolumeWidgetToVF() {
102         VfModule vf = new VfModule();
103         addWidgetToModule(vf, Type.VOLUME);
104         addWidgetToModule(vf, Type.VSERVER);
105         addWidgetToModule(vf, Type.VOLUME);
106     }
107
108     @Test
109     public void testAddOAMNetworkWidgetToVF() {
110         VfModule vf = new VfModule();
111         addWidgetToModule(vf, Type.OAM_NETWORK);
112     }
113
114     private void addWidgetToModule(VfModule vfModule, Type widgeType) {
115         Widget widget = Widget.getWidget(widgeType);
116         String id = widget.getId();
117         widget.addKey(id);
118         vfModule.setMembers(Collections.singletonList(id));
119         vfModule.addWidget(widget);
120     }
121 }