ea83213fcc576818c8ece5d94cf8b42c1132a7d1
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.sdnc.dg.loader;
26
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29 import java.io.File;
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;
35
36 public class DGLoaderTest {
37
38     @Test
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) {
48             jsonPath = args[0];
49             xmlPath = args[1];
50         }
51
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());
59     }
60
61     @Test
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());
71     }
72
73     @Test
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);
79     }
80
81     @Test
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);
87     }
88
89     @Test
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);
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         DGXMLActivate dgXMLActivate = new MockDGXMLActivate();
102         dgXMLActivate.activateDg(activateFilePath);
103
104     }
105
106     @Test
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);
112
113     }
114
115     @Test
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);
123     }
124
125     @Test
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);
133     }
134
135     @Test
136     public void testDGLoadNActivateloadDGXMLDir() throws Exception {
137         String xmlPath = "src/test/resources/xml";
138         DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
139         Whitebox.invokeMethod(dgXMLLoadNActivate, "loadDGXMLDir", xmlPath);
140     }
141
142
143     public void testDGLoadNActivateloadDGXMLDirThrowsException() throws Exception {
144         String xmlPath = "src/test/resources/someDir";
145         DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
146         Whitebox.invokeMethod(dgXMLLoadNActivate, "loadDGXMLDir", xmlPath);
147     }
148
149     @Test
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);
155         assertTrue(true);
156     }
157
158     @Test(expected = Exception.class)
159     public void testDGActivateConstructorThrowsException() throws Exception {
160         String somePath = "";
161         DGXMLActivate dgXMLActivate = new DGXMLActivate(somePath);
162     }
163
164     @Test(expected = Exception.class)
165     public void testDGXMLLoadConstructorThrowsException() throws Exception {
166         String somePath = "";
167         DGXMLLoad dgXMLLoad = new DGXMLLoad(somePath);
168     }
169
170     @Test(expected = Exception.class)
171     public void testDGLoadNActivateConstructorThrowsException() throws Exception {
172         String somePath = "";
173         DGXMLLoadNActivate dgXMLLoadNActivate = new DGXMLLoadNActivate(somePath);
174     }
175
176 }