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.openecomp.sdnc.dg.loader;
27 import static org.junit.Assert.*;
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.Properties;
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.*;
48 public class DGLoaderTest {
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){
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());
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());
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);
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);
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);
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);
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);
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);
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);
148 public void testDGLoadNActivateloadDGXMLDir() throws Exception {
149 String xmlPath = "src/test/resources/xml";
150 DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
151 Whitebox.invokeMethod(dgXMLLoadNActivate,"loadDGXMLDir",xmlPath);
155 public void testDGLoadNActivateloadDGXMLDirThrowsException() throws Exception {
156 String xmlPath = "src/test/resources/someDir";
157 DGXMLLoadNActivate dgXMLLoadNActivate = new MockDGXMLLoadNActivate();
158 Whitebox.invokeMethod(dgXMLLoadNActivate,"loadDGXMLDir",xmlPath);
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);
170 @Test (expected=Exception.class)
171 public void testDGActivateConstructorThrowsException() throws Exception {
173 DGXMLActivate dgXMLActivate = new DGXMLActivate(somePath);
176 @Test (expected=Exception.class)
177 public void testDGXMLLoadConstructorThrowsException() throws Exception {
179 DGXMLLoad dgXMLLoad = new DGXMLLoad(somePath);
182 @Test (expected=Exception.class)
183 public void testDGLoadNActivateConstructorThrowsException() throws Exception {
185 DGXMLLoadNActivate dgXMLLoadNActivate = new DGXMLLoadNActivate(somePath);