2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.sdnc.dg.loader;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import java.util.ArrayList;
31 import java.util.List;
32 import org.apache.commons.io.FileUtils;
33 import org.junit.Test;
34 import org.powermock.reflect.Whitebox;
36 public class DGLoaderTest {
39 public void testXMLGenerator() throws Exception {
40 DGXMLGenerator application = new DGXMLGenerator();
41 String jsonPath = null;
42 String xmlPath = null;
43 String propertyPath = "somePath";
44 // Generate, GenerateLoad, GenerateLoadActivate
45 String[] args = new String[] {"src/test/resources/json", "src/test/resources/xml"};
46 // logger.info("DGXML Conversion Started with arguments :"+ args[0] +":"+ args[1]);
47 if (args != null && args.length >= 2) {
52 application.generateXMLFromJSON(jsonPath, xmlPath, propertyPath);
53 File dir = new File("src/test/resources/xml");
54 String extensions[] = new String[] {"xml", "XML"};
55 List<File> files = new ArrayList<File>();
56 files = (List<File>) FileUtils.listFiles(dir, extensions, true);
57 assertNotNull(files.get(0));
58 assertNotNull(files.get(0).getName());
62 public void testXMLGeneratorMain() throws Exception {
63 String[] args = new String[] {"src/test/resources/json", "src/test/resources/xml"};
64 DGXMLGenerator.main(args);
65 File dir = new File("src/test/resources/xml");
66 String extensions[] = new String[] {"xml", "XML"};
67 List<File> files = new ArrayList<File>();
68 files = (List<File>) FileUtils.listFiles(dir, extensions, true);
69 assertNotNull(files.get(0));
70 assertNotNull(files.get(0).getName());
74 public void testDGLoader() throws Exception {
75 String propertyPath = "src/test/resources/dummy.properties";
76 String xmlPath = "src/test/resources/xml/Appc_UniTest.xml";
77 DGXMLLoad dgXMLLoad = new MockDGXMLLoad();
78 dgXMLLoad.loadDGXMLFile(xmlPath);
82 public void testDGLoaderWithDir() throws Exception {
83 String propertyPath = "src/test/resources/dummy.properties";
84 String xmlPath = "src/test/resources/xml";
85 DGXMLLoad dgXMLLoad = new MockDGXMLLoad();
86 Whitebox.invokeMethod(dgXMLLoad, "loadDGXMLDir", xmlPath);
90 public void testDGLoaderWithDirThrowsException() throws Exception {
91 String propertyPath = "src/test/resources/dummy.properties";
92 String xmlPath = "src/test/resources/xml/xml";
93 DGXMLLoad dgXMLLoad = new MockDGXMLLoad();
94 Whitebox.invokeMethod(dgXMLLoad, "loadDGXMLDir", xmlPath);
98 public void testDGActivate() throws Exception {
99 String propertyPath = "src/test/resources/dummy.properties";
100 String activateFilePath = "src/test/resources/dg_activate_test";
101 DGXMLActivate dgXMLActivate = new MockDGXMLActivate();
102 dgXMLActivate.activateDg(activateFilePath);
107 public void testDGActivateThrowsException() throws Exception {
108 String propertyPath = "src/test/resources/dummy.properties";
109 String activateFilePath = "src/test/resources/someFile";
110 DGXMLActivate dgXMLActivate = new MockDGXMLActivate();
111 dgXMLActivate.activateDg(activateFilePath);
116 public void testDGLoadNActivate() throws Exception {
117 String propertyPath = "src/test/resources/dummy.properties";
118 String activateFilePath = "src/test/resources/dg_activate_test";
119 String xmlPath = "src/test/resources/xml/Appc_UniTest.xml";
120 DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
121 dgXMLLoadNActivate.loadDGXMLFile(xmlPath);
122 dgXMLLoadNActivate.activateDg(activateFilePath);
126 public void testDGLoadNActivateThrowsException() throws Exception {
127 String propertyPath = "src/test/resources/dummy.properties";
128 String activateFilePath = "src/test/resources/someFile";
129 String xmlPath = "src/test/resources/xml/Appc_UniTest.xml";
130 DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
131 dgXMLLoadNActivate.loadDGXMLFile(xmlPath);
132 dgXMLLoadNActivate.activateDg(activateFilePath);
136 public void testDGLoadNActivateloadDGXMLDir() throws Exception {
137 String xmlPath = "src/test/resources/xml";
138 DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
139 Whitebox.invokeMethod(dgXMLLoadNActivate, "loadDGXMLDir", xmlPath);
143 public void testDGLoadNActivateloadDGXMLDirThrowsException() throws Exception {
144 String xmlPath = "src/test/resources/someDir";
145 DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
146 Whitebox.invokeMethod(dgXMLLoadNActivate, "loadDGXMLDir", xmlPath);
150 public void testDGLoaderActivator() throws Exception {
151 String xmlPath = "src/test/resources/xml";
152 DGLoaderActivator dgLoaderActivator = new DGLoaderActivator();
153 dgLoaderActivator.start(null);
154 dgLoaderActivator.stop(null);
158 @Test(expected = Exception.class)
159 public void testDGActivateConstructorThrowsException() throws Exception {
160 String somePath = "";
161 DGXMLActivate dgXMLActivate = new DGXMLActivate(somePath);
164 @Test(expected = Exception.class)
165 public void testDGXMLLoadConstructorThrowsException() throws Exception {
166 String somePath = "";
167 DGXMLLoad dgXMLLoad = new DGXMLLoad(somePath);
170 @Test(expected = Exception.class)
171 public void testDGLoadNActivateConstructorThrowsException() throws Exception {
172 String somePath = "";
173 DGXMLLoadNActivate dgXMLLoadNActivate = new DGXMLLoadNActivate(somePath);