2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.onap.aai.babel.xml.generator.model;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.CoreMatchers.notNullValue;
25 import static org.junit.Assert.assertThat;
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;
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;
40 * Direct tests of the Model class VfModule so as to improve code coverage
42 public class TestVfModule {
45 if (System.getProperty("APP_HOME") == null) {
46 System.setProperty("APP_HOME", ".");
51 public void setup() throws FileNotFoundException, IOException {
52 InputStream in = TestVfModule.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
53 Properties properties = new Properties();
56 WidgetConfigurationUtil.setConfig(properties);
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
73 public void testNonMemberWidgetToVF() {
74 VfModule vf = new VfModule();
75 Widget widget = Widget.getWidget(Type.SERVICE);
76 vf.setMembers(Collections.singletonList(widget.getId()));
81 public void testAddServiceWidgetToVF() {
82 VfModule vf = new VfModule();
83 addWidgetToModule(vf, Type.SERVICE);
87 public void testAddVServerWidgetToVF() {
88 VfModule vf = new VfModule();
89 addWidgetToModule(vf, Type.VSERVER);
93 public void testAddLIntfWidgetToVF() {
94 VfModule vf = new VfModule();
95 addWidgetToModule(vf, Type.LINT);
96 addWidgetToModule(vf, Type.VSERVER);
97 addWidgetToModule(vf, Type.LINT);
101 public void testAddVolumeWidgetToVF() {
102 VfModule vf = new VfModule();
103 addWidgetToModule(vf, Type.VOLUME);
104 addWidgetToModule(vf, Type.VSERVER);
105 addWidgetToModule(vf, Type.VOLUME);
109 public void testAddOAMNetworkWidgetToVF() {
110 VfModule vf = new VfModule();
111 addWidgetToModule(vf, Type.OAM_NETWORK);
114 private void addWidgetToModule(VfModule vfModule, Type widgeType) {
115 Widget widget = Widget.getWidget(widgeType);
116 String id = widget.getId();
118 vfModule.setMembers(Collections.singletonList(id));
119 vfModule.addWidget(widget);