1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package complex.ooxml;
24 
25 import com.sun.star.lang.XComponent;
26 import com.sun.star.lang.XMultiServiceFactory;
27 import com.sun.star.uno.UnoRuntime;
28 import complexlib.ComplexTestCase;
29 import java.io.File;
30 import org.junit.After;
31 import org.junit.AfterClass;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.openoffice.test.Argument;
36 import org.openoffice.test.OfficeConnection;
37 import static org.junit.Assert.*;
38 
39 /*
40  * To change this template, choose Tools | Templates
41  * and open the template in the editor.
42  */
43 
44 /**
45  *
46  * @author hb137859
47  */
48 public class LoadDocuments {
test1()49     @Test public void test1() {
50         String testDocumentsPath = Argument.get("tdoc");
51         System.out.println("Test documents in:" + testDocumentsPath);
52 
53         File dir = new File(testDocumentsPath);
54         String [] files = dir.list();
55 
56         try {
57             if (files != null) {
58                 for (int i = 0; i < files.length; ++i) {
59                     System.out.println(files[i]);
60                     String url = TestDocument.getUrl(files[i]);
61                     System.out.println(url);
62 
63                     XComponent xDoc = util.DesktopTools.loadDoc(getMSF(), url, null);
64                     System.out.println("loaded.");
65                     util.DesktopTools.closeDoc(xDoc);
66                     System.out.println("done.");
67                 }
68             } else {
69                 fail("Files not found");
70             }
71         }
72         catch (Exception e) {
73             System.out.println(e);
74             fail("failed");
75         }
76     }
77 
getMSF()78     private XMultiServiceFactory getMSF()
79     {
80         final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
81         return xMSF1;
82     }
83 
84     // setup and close connections
setUpConnection()85     @BeforeClass public static void setUpConnection() throws Exception
86     {
87         System.out.println("setUpConnection()");
88         connection.setUp();
89     }
90 
tearDownConnection()91     @AfterClass public static void tearDownConnection()
92             throws InterruptedException, com.sun.star.uno.Exception
93     {
94         System.out.println("tearDownConnection()");
95         connection.tearDown();
96     }
97     private static final OfficeConnection connection = new OfficeConnection();
98 }
99