added assert statements in Test classes
[appc.git] / appc-directed-graph / dg-loader / provider / src / test / java / org / onap / sdnc / dg / loader / DGLoaderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.sdnc.dg.loader;
25
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28 import java.io.File;
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;
34
35 public class DGLoaderTest {
36
37     @Test
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) {
47             jsonPath = args[0];
48             xmlPath = args[1];
49         }
50
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());
57     }
58
59     @Test
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());
68     }
69
70     @Test
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);
77     }
78
79     @Test
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);
86     }
87
88     @Test
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);
95     }
96
97     @Test
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);
104
105     }
106
107     @Test
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);
114
115     }
116
117     @Test
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);
123         assertTrue(true);
124     }
125
126     @Test(expected = Exception.class)
127     public void testDGActivateConstructorThrowsException() throws Exception {
128         String somePath = "";
129         DGXMLActivator dgXMLActivator = new DGXMLActivator(somePath);
130     }
131
132     @Test(expected = Exception.class)
133     public void testDGXMLLoadConstructorThrowsException() throws Exception {
134         String somePath = "";
135         DGXMLLoader dgXMLLoader = new DGXMLLoader(somePath);
136     }
137 }