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.tempfile; 24 25 import com.sun.star.lang.XMultiServiceFactory; 26 import com.sun.star.ucb.XSimpleFileAccess; 27 import com.sun.star.uno.UnoRuntime; 28 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.OfficeConnection; 35 import static org.junit.Assert.*; 36 37 /* Document. 38 */ 39 40 public class TempFileUnitTest { 41 private XMultiServiceFactory m_xMSF = null; 42 private XSimpleFileAccess m_xSFA = null; 43 before()44 @Before public void before() { 45 m_xMSF = getMSF(); 46 if ( m_xMSF == null ) { 47 fail ( "Cannot create service factory!" ); 48 } 49 try 50 { 51 Object oSFA = m_xMSF.createInstance( "com.sun.star.ucb.SimpleFileAccess" ); 52 m_xSFA = UnoRuntime.queryInterface( XSimpleFileAccess.class, oSFA ); 53 } 54 catch ( Exception e ) 55 { 56 fail ( "Cannot get simple file access! Exception: " + e); 57 } 58 if ( m_xSFA == null ) { 59 fail ( "Cannot get simple file access!" ); 60 } 61 } 62 after()63 @After public void after() { 64 m_xMSF = null; 65 m_xSFA = null; 66 } 67 ExecuteTest01()68 @Test public void ExecuteTest01() { 69 TempFileTest aTest = new Test01( m_xMSF, m_xSFA ); 70 assertTrue( "Test01 failed!", aTest.test() ); 71 } 72 ExecuteTest02()73 @Test public void ExecuteTest02() { 74 TempFileTest aTest = new Test02( m_xMSF, m_xSFA ); 75 assertTrue( "Test02 failed!", aTest.test() ); 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 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 97 private static final OfficeConnection connection = new OfficeConnection(); 98 }; 99 100