2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.sdnc.dg.loader;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
29 import java.util.ArrayList;
30 import java.util.List;
31 import org.apache.commons.io.FileUtils;
32 import org.junit.Test;
33 import org.powermock.reflect.Whitebox;
35 public class DGLoaderTest {
38 public void testXMLGenerator() throws Exception {
39 DGXMLGenerator application = new DGXMLGenerator();
40 String jsonPath = null;
41 String xmlPath = null;
42 String propertyPath = "somePath";
43 // Generate, GenerateLoad, GenerateLoadActivate
44 String[] args = new String[] {"src/test/resources/json", "src/test/resources/xml"};
45 // logger.info("DGXML Conversion Started with arguments :"+ args[0] +":"+ args[1]);
46 if (args.length >= 2) {
51 application.generateXMLFromJSON(jsonPath, xmlPath, propertyPath);
52 File dir = new File("src/test/resources/xml");
53 String extensions[] = new String[] {"xml", "XML"};
54 List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
55 assertNotNull(files.get(0));
56 assertNotNull(files.get(0).getName());
60 public void testXMLGeneratorMain() throws Exception {
61 String[] args = new String[] {"src/test/resources/json", "src/test/resources/xml"};
62 DGXMLGenerator.main(args);
63 File dir = new File("src/test/resources/xml");
64 String extensions[] = new String[] {"xml", "XML"};
65 List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
66 assertNotNull(files.get(0));
67 assertNotNull(files.get(0).getName());
71 public void testDGLoader() throws Exception {
72 String propertyPath = "src/test/resources/dummy.properties";
73 String xmlPath = "src/test/resources/xml/Appc_UniTest.xml";
74 DGXMLLoader dgXMLLoad = new MockDGXMLLoader();
75 dgXMLLoad.loadDGXMLFile(xmlPath);
76 assertNotNull(propertyPath);
80 public void testDGLoaderWithDir() throws Exception {
81 String propertyPath = "src/test/resources/dummy.properties";
82 String xmlPath = "src/test/resources/xml";
83 DGXMLLoader dgXMLLoad = new MockDGXMLLoader();
84 Whitebox.invokeMethod(dgXMLLoad, "loadDGXMLDir", xmlPath);
85 assertNotNull(propertyPath);
89 public void testDGLoaderWithDirThrowsException() throws Exception {
90 String propertyPath = "src/test/resources/dummy.properties";
91 String xmlPath = "src/test/resources/xml/xml";
92 DGXMLLoader dgXMLLoader = new MockDGXMLLoader();
93 Whitebox.invokeMethod(dgXMLLoader, "loadDGXMLDir", xmlPath);
94 assertNotNull(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 DGXMLActivator dgXMLActivator = new MockDGXMLActivator();
102 dgXMLActivator.activateDg(activateFilePath);
103 assertNotNull(dgXMLActivator);
108 public void testDGActivateThrowsException() throws Exception {
109 String propertyPath = "src/test/resources/dummy.properties";
110 String activateFilePath = "src/test/resources/someFile";
111 DGXMLActivator dgXMLActivator = new MockDGXMLActivator();
112 dgXMLActivator.activateDg(activateFilePath);
113 assertNotNull(activateFilePath);
118 public void testDGLoaderActivator() throws Exception {
119 String xmlPath = "src/test/resources/xml";
120 DGLoaderActivator dgLoaderActivator = new DGLoaderActivator();
121 dgLoaderActivator.start(null);
122 dgLoaderActivator.stop(null);
126 @Test(expected = Exception.class)
127 public void testDGActivateConstructorThrowsException() throws Exception {
128 String somePath = "";
129 DGXMLActivator dgXMLActivator = new DGXMLActivator(somePath);
132 @Test(expected = Exception.class)
133 public void testDGXMLLoadConstructorThrowsException() throws Exception {
134 String somePath = "";
135 DGXMLLoader dgXMLLoader = new DGXMLLoader(somePath);