1a740f2aaSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3a740f2aaSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4a740f2aaSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5a740f2aaSAndrew Rist  * distributed with this work for additional information
6a740f2aaSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7a740f2aaSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8a740f2aaSAndrew Rist  * "License"); you may not use this file except in compliance
9a740f2aaSAndrew Rist  * with the License.  You may obtain a copy of the License at
10a740f2aaSAndrew Rist  *
11a740f2aaSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12a740f2aaSAndrew Rist  *
13a740f2aaSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14a740f2aaSAndrew Rist  * software distributed under the License is distributed on an
15a740f2aaSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16a740f2aaSAndrew Rist  * KIND, either express or implied.  See the License for the
17a740f2aaSAndrew Rist  * specific language governing permissions and limitations
18a740f2aaSAndrew Rist  * under the License.
19a740f2aaSAndrew Rist  *
20a740f2aaSAndrew Rist  *************************************************************/
21a740f2aaSAndrew Rist 
22a740f2aaSAndrew Rist 
23cdf0e10cSrcweir package complex.ofopxmlstorages;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
26cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
27cdf0e10cSrcweir import com.sun.star.connection.XConnector;
28cdf0e10cSrcweir import com.sun.star.connection.XConnection;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver;
31cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
32cdf0e10cSrcweir import com.sun.star.uno.XInterface;
33cdf0e10cSrcweir import com.sun.star.uno.XNamingService;
34cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir import com.sun.star.container.*;
37cdf0e10cSrcweir import com.sun.star.beans.*;
38cdf0e10cSrcweir import com.sun.star.lang.*;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir import complex.ofopxmlstorages.*;
41*60509b5aSDamjan Jovanovic import share.LogWriter;
42*60509b5aSDamjan Jovanovic import stats.SimpleLogWriter;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir import util.utils;
45cdf0e10cSrcweir import java.util.*;
46cdf0e10cSrcweir import java.io.*;
47cdf0e10cSrcweir 
48*60509b5aSDamjan Jovanovic import org.junit.AfterClass;
49*60509b5aSDamjan Jovanovic import org.junit.Before;
50*60509b5aSDamjan Jovanovic import org.junit.BeforeClass;
51*60509b5aSDamjan Jovanovic import org.junit.Test;
52*60509b5aSDamjan Jovanovic import org.openoffice.test.OfficeConnection;
53*60509b5aSDamjan Jovanovic import static org.junit.Assert.*;
54*60509b5aSDamjan Jovanovic 
55cdf0e10cSrcweir /* This unit test for storage objects is designed to
56cdf0e10cSrcweir  * test most important statements from storage service
57cdf0e10cSrcweir  * specification.
58cdf0e10cSrcweir  *
59cdf0e10cSrcweir  * Regression tests are added to extend the tested
60cdf0e10cSrcweir  * functionalities.
61cdf0e10cSrcweir  */
62*60509b5aSDamjan Jovanovic public class StorageUnitTest
63cdf0e10cSrcweir {
64*60509b5aSDamjan Jovanovic     private static final OfficeConnection connection = new OfficeConnection();
65*60509b5aSDamjan Jovanovic     private static final LogWriter log = new SimpleLogWriter();
66cdf0e10cSrcweir 	private XMultiServiceFactory m_xMSF = null;
67cdf0e10cSrcweir 	private XSingleServiceFactory m_xStorageFactory = null;
68cdf0e10cSrcweir 
69*60509b5aSDamjan Jovanovic     @BeforeClass
setUpConnection()70*60509b5aSDamjan Jovanovic     public static void setUpConnection()
71*60509b5aSDamjan Jovanovic         throws Exception
72*60509b5aSDamjan Jovanovic     {
73*60509b5aSDamjan Jovanovic         connection.setUp();
74*60509b5aSDamjan Jovanovic         log.initialize(null, true);
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77*60509b5aSDamjan Jovanovic     @AfterClass
tearDownConnection()78*60509b5aSDamjan Jovanovic     public static void tearDownConnection()
79*60509b5aSDamjan Jovanovic         throws InterruptedException, com.sun.star.uno.Exception
80*60509b5aSDamjan Jovanovic     {
81*60509b5aSDamjan Jovanovic         connection.tearDown();
82cdf0e10cSrcweir     }
83cdf0e10cSrcweir 
84*60509b5aSDamjan Jovanovic     @Before
before()85cdf0e10cSrcweir     public void before()
86cdf0e10cSrcweir 	{
87*60509b5aSDamjan Jovanovic         m_xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
88cdf0e10cSrcweir 		if ( m_xMSF == null )
89cdf0e10cSrcweir 		{
90*60509b5aSDamjan Jovanovic 			fail( "Can't create service factory!" );
91cdf0e10cSrcweir 			return;
92cdf0e10cSrcweir 		}
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 		try {
95cdf0e10cSrcweir 			Object oStorageFactory = m_xMSF.createInstance( "com.sun.star.embed.StorageFactory" );
96cdf0e10cSrcweir 			m_xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class,
97cdf0e10cSrcweir 																				oStorageFactory );
98cdf0e10cSrcweir 		}
99cdf0e10cSrcweir 		catch( Exception e )
100cdf0e10cSrcweir 		{
101*60509b5aSDamjan Jovanovic 			fail( "Can't create storage factory!" );
102cdf0e10cSrcweir 			return;
103cdf0e10cSrcweir 		}
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		if ( m_xStorageFactory == null )
106cdf0e10cSrcweir 		{
107*60509b5aSDamjan Jovanovic 			fail( "Can't create service factory!" );
108cdf0e10cSrcweir 			return;
109cdf0e10cSrcweir 		}
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112*60509b5aSDamjan Jovanovic 
113*60509b5aSDamjan Jovanovic     @Test
ExecuteTest01()114cdf0e10cSrcweir 	public void ExecuteTest01()
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir 		StorageTest aTest = new Test01( m_xMSF, m_xStorageFactory, log );
117*60509b5aSDamjan Jovanovic 		assertTrue( "Test01 failed!", aTest.test() );
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 
120*60509b5aSDamjan Jovanovic     @Test
ExecuteTest02()121cdf0e10cSrcweir 	public void ExecuteTest02()
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir 		StorageTest aTest = new Test02( m_xMSF, m_xStorageFactory, log );
124*60509b5aSDamjan Jovanovic 		assertTrue( "Test02 failed!", aTest.test() );
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir 
127*60509b5aSDamjan Jovanovic     @Test
ExecuteTest03()128cdf0e10cSrcweir 	public void ExecuteTest03()
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir 		StorageTest aTest = new Test03( m_xMSF, m_xStorageFactory, log );
131*60509b5aSDamjan Jovanovic 		assertTrue( "Test03 failed!", aTest.test() );
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir 
134*60509b5aSDamjan Jovanovic     @Test
ExecuteTest04()135cdf0e10cSrcweir 	public void ExecuteTest04()
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		StorageTest aTest = new Test04( m_xMSF, m_xStorageFactory, log );
138*60509b5aSDamjan Jovanovic 		assertTrue( "Test04 failed!", aTest.test() );
139cdf0e10cSrcweir 	}
140cdf0e10cSrcweir 
141*60509b5aSDamjan Jovanovic     @Test
ExecuteTest05()142cdf0e10cSrcweir 	public void ExecuteTest05()
143cdf0e10cSrcweir 	{
144cdf0e10cSrcweir 		StorageTest aTest = new Test05( m_xMSF, m_xStorageFactory, log );
145*60509b5aSDamjan Jovanovic 		assertTrue( "Test05 failed!", aTest.test() );
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir 
148*60509b5aSDamjan Jovanovic     @Test
ExecuteTest06()149cdf0e10cSrcweir 	public void ExecuteTest06()
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		StorageTest aTest = new Test06( m_xMSF, m_xStorageFactory, log );
152*60509b5aSDamjan Jovanovic 		assertTrue( "Test06 failed!", aTest.test() );
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 
155*60509b5aSDamjan Jovanovic     @Test
ExecuteTest07()156cdf0e10cSrcweir 	public void ExecuteTest07()
157cdf0e10cSrcweir 	{
158cdf0e10cSrcweir 		StorageTest aTest = new Test07( m_xMSF, m_xStorageFactory, log );
159*60509b5aSDamjan Jovanovic 		assertTrue( "Test07 failed!", aTest.test() );
160cdf0e10cSrcweir 	}
161cdf0e10cSrcweir 
162*60509b5aSDamjan Jovanovic     @Test
ExecuteTest08()163cdf0e10cSrcweir 	public void ExecuteTest08()
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		StorageTest aTest = new Test08( m_xMSF, m_xStorageFactory, log );
166*60509b5aSDamjan Jovanovic 		assertTrue( "Test08 failed!", aTest.test() );
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170