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 java.io.File; 29 import org.junit.After; 30 import org.junit.AfterClass; 31 import org.junit.Before; 32 import org.junit.BeforeClass; 33 import org.junit.Test; 34 import org.openoffice.test.Argument; 35 import org.openoffice.test.OfficeConnection; 36 import static org.junit.Assert.*; 37 38 /* 39 * To change this template, choose Tools | Templates 40 * and open the template in the editor. 41 */ 42 43 /** 44 * 45 * @author hb137859 46 */ 47 public class LoadDocuments { test1()48 @Test public void test1() { 49 String testDocumentsPath = Argument.get("tdoc"); 50 System.out.println("Test documents in:" + testDocumentsPath); 51 52 File dir = new File(testDocumentsPath); 53 String [] files = dir.list(); 54 55 try { 56 if (files != null) { 57 for (int i = 0; i < files.length; ++i) { 58 System.out.println(files[i]); 59 String url = TestDocument.getUrl(files[i]); 60 System.out.println(url); 61 62 XComponent xDoc = util.DesktopTools.loadDoc(getMSF(), url, null); 63 System.out.println("loaded."); 64 util.DesktopTools.closeDoc(xDoc); 65 System.out.println("done."); 66 } 67 } else { 68 fail("Files not found"); 69 } 70 } 71 catch (Exception e) { 72 System.out.println(e); 73 fail("failed"); 74 } 75 } 76 getMSF()77 private XMultiServiceFactory getMSF() 78 { 79 final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 80 return xMSF1; 81 } 82 83 // setup and close connections setUpConnection()84 @BeforeClass public static void setUpConnection() throws Exception 85 { 86 System.out.println("setUpConnection()"); 87 connection.setUp(); 88 } 89 tearDownConnection()90 @AfterClass public static void tearDownConnection() 91 throws InterruptedException, com.sun.star.uno.Exception 92 { 93 System.out.println("tearDownConnection()"); 94 connection.tearDown(); 95 } 96 private static final OfficeConnection connection = new OfficeConnection(); 97 } 98