fea884ca79646b3276ab26d7aa4381c3b5bc1b20
[appc.git] / appc-directed-graph / dg-loader / provider / src / test / java / org / openecomp / 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.openecomp.sdnc.dg.loader;
26
27 import static org.junit.Assert.*;
28
29 import java.io.File;
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.Properties;
33
34 import org.apache.commons.io.FileUtils;
35 import org.eclipse.osgi.framework.internal.core.BundleContextImpl;
36 import org.eclipse.osgi.framework.internal.core.BundleHost;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.mockito.Mockito;
40 import org.openecomp.sdnc.sli.ConfigurationException;
41 import org.openecomp.sdnc.sli.SvcLogicException;
42 import org.openecomp.sdnc.sli.SvcLogicStore;
43 import org.openecomp.sdnc.sli.SvcLogicStoreFactory;
44 import org.osgi.framework.BundleContext;
45 import org.powermock.reflect.Whitebox;
46 import org.powermock.*;
47
48 public class DGLoaderTest {
49     
50     @Test
51     public void testXMLGenerator() throws Exception {
52         DGXMLGenerator application = new DGXMLGenerator();
53         String jsonPath = null;
54         String xmlPath = null;
55         String propertyPath = "somePath";
56         // Generate, GenerateLoad, GenerateLoadActivate
57         String []args = new String[]{"src/test/resources/json","src/test/resources/xml"};
58         //logger.info("DGXML Conversion Started with arguments :"+ args[0] +":"+ args[1]);
59         if(args != null && args.length >= 2){
60             jsonPath = args[0];
61             xmlPath = args[1];
62         }
63     
64         application.generateXMLFromJSON(jsonPath, xmlPath, propertyPath);
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 testXMLGeneratorMain() throws Exception {
75         String []args = new String[]{"src/test/resources/json","src/test/resources/xml"};
76         DGXMLGenerator.main(args);
77         File dir=new File("src/test/resources/xml");
78         String extensions[]=new String[] {"xml","XML"};
79         List<File> files = new ArrayList<File>();
80         files=(List<File>) FileUtils.listFiles(dir, extensions, true);
81         assertNotNull(files.get(0));
82         assertNotNull(files.get(0).getName());
83     }
84         
85     @Test
86     public void testDGLoader() throws Exception {
87         String propertyPath = "src/test/resources/dummy.properties";
88         String xmlPath = "src/test/resources/xml/Appc_UniTest.xml";
89         DGXMLLoad dgXMLLoad = new MockDGXMLLoad();
90         dgXMLLoad.loadDGXMLFile(xmlPath);
91        }
92     
93     @Test
94     public void testDGLoaderWithDir() throws Exception {
95         String propertyPath = "src/test/resources/dummy.properties";
96         String xmlPath = "src/test/resources/xml";
97         DGXMLLoad dgXMLLoad = new MockDGXMLLoad();
98         Whitebox.invokeMethod(dgXMLLoad, "loadDGXMLDir",xmlPath);
99     }
100     
101     @Test
102     public void testDGLoaderWithDirThrowsException() throws Exception {
103         String propertyPath = "src/test/resources/dummy.properties";
104         String xmlPath = "src/test/resources/xml/xml";
105         DGXMLLoad dgXMLLoad = new MockDGXMLLoad();
106         Whitebox.invokeMethod(dgXMLLoad, "loadDGXMLDir",xmlPath);
107     }
108     
109     @Test
110     public void testDGActivate() throws Exception {
111         String propertyPath = "src/test/resources/dummy.properties";
112         String activateFilePath = "src/test/resources/dg_activate_test";
113         DGXMLActivate dgXMLActivate = new MockDGXMLActivate();
114         dgXMLActivate.activateDg(activateFilePath);
115
116     }
117     
118     @Test
119     public void testDGActivateThrowsException() throws Exception {
120         String propertyPath = "src/test/resources/dummy.properties";
121         String activateFilePath = "src/test/resources/someFile";
122         DGXMLActivate dgXMLActivate = new MockDGXMLActivate();
123         dgXMLActivate.activateDg(activateFilePath);
124
125     }
126     
127     @Test
128     public void testDGLoadNActivate() throws Exception {
129         String propertyPath = "src/test/resources/dummy.properties";
130         String activateFilePath = "src/test/resources/dg_activate_test";
131         String xmlPath = "src/test/resources/xml/Appc_UniTest.xml";
132         DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
133         dgXMLLoadNActivate.loadDGXMLFile(xmlPath);
134         dgXMLLoadNActivate.activateDg(activateFilePath);
135     }
136     
137     @Test
138     public void testDGLoadNActivateThrowsException() throws Exception {
139         String propertyPath = "src/test/resources/dummy.properties";
140         String activateFilePath = "src/test/resources/someFile";
141         String xmlPath = "src/test/resources/xml/Appc_UniTest.xml";
142         DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
143         dgXMLLoadNActivate.loadDGXMLFile(xmlPath);
144         dgXMLLoadNActivate.activateDg(activateFilePath);
145     }
146     
147     @Test
148     public void testDGLoadNActivateloadDGXMLDir() throws Exception {
149         String xmlPath = "src/test/resources/xml";
150         DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
151         Whitebox.invokeMethod(dgXMLLoadNActivate,"loadDGXMLDir",xmlPath);
152      }
153     
154     
155     public void testDGLoadNActivateloadDGXMLDirThrowsException() throws Exception {
156         String xmlPath = "src/test/resources/someDir";
157         DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
158         Whitebox.invokeMethod(dgXMLLoadNActivate,"loadDGXMLDir",xmlPath);
159      }
160     
161     @Test
162     public void testDGLoaderActivator() throws Exception {
163         String xmlPath = "src/test/resources/xml";
164         DGLoaderActivator dgLoaderActivator = new DGLoaderActivator();
165         dgLoaderActivator.start(null);
166         dgLoaderActivator.stop(null);
167         assertTrue(true);
168     }
169
170     @Test (expected=Exception.class)
171     public void testDGActivateConstructorThrowsException() throws Exception {
172         String somePath="";
173         DGXMLActivate dgXMLActivate = new DGXMLActivate(somePath);
174     }
175     
176     @Test (expected=Exception.class)
177     public void testDGXMLLoadConstructorThrowsException() throws Exception {
178         String somePath="";
179         DGXMLLoad dgXMLLoad = new DGXMLLoad(somePath);
180     }
181     
182     @Test (expected=Exception.class)
183     public void testDGLoadNActivateConstructorThrowsException() throws Exception {
184         String somePath="";
185         DGXMLLoadNActivate dgXMLLoadNActivate = new DGXMLLoadNActivate(somePath);
186     }
187     
188 }