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.ofopxmlstorages;
24 
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.lang.XMultiComponentFactory;
27 import com.sun.star.connection.XConnector;
28 import com.sun.star.connection.XConnection;
29 
30 import com.sun.star.bridge.XUnoUrlResolver;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 import com.sun.star.uno.XNamingService;
34 import com.sun.star.uno.XComponentContext;
35 
36 import com.sun.star.container.*;
37 import com.sun.star.beans.*;
38 import com.sun.star.lang.*;
39 
40 import complex.ofopxmlstorages.*;
41 import share.LogWriter;
42 import stats.SimpleLogWriter;
43 
44 import util.utils;
45 import java.util.*;
46 import java.io.*;
47 
48 import org.junit.AfterClass;
49 import org.junit.Before;
50 import org.junit.BeforeClass;
51 import org.junit.Test;
52 import org.openoffice.test.OfficeConnection;
53 import static org.junit.Assert.*;
54 
55 /* This unit test for storage objects is designed to
56  * test most important statements from storage service
57  * specification.
58  *
59  * Regression tests are added to extend the tested
60  * functionalities.
61  */
62 public class StorageUnitTest
63 {
64     private static final OfficeConnection connection = new OfficeConnection();
65     private static final LogWriter log = new SimpleLogWriter();
66 	private XMultiServiceFactory m_xMSF = null;
67 	private XSingleServiceFactory m_xStorageFactory = null;
68 
69     @BeforeClass
setUpConnection()70     public static void setUpConnection()
71         throws Exception
72     {
73         connection.setUp();
74         log.initialize(null, true);
75     }
76 
77     @AfterClass
tearDownConnection()78     public static void tearDownConnection()
79         throws InterruptedException, com.sun.star.uno.Exception
80     {
81         connection.tearDown();
82     }
83 
84     @Before
before()85     public void before()
86 	{
87         m_xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
88 		if ( m_xMSF == null )
89 		{
90 			fail( "Can't create service factory!" );
91 			return;
92 		}
93 
94 		try {
95 			Object oStorageFactory = m_xMSF.createInstance( "com.sun.star.embed.StorageFactory" );
96 			m_xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class,
97 																				oStorageFactory );
98 		}
99 		catch( Exception e )
100 		{
101 			fail( "Can't create storage factory!" );
102 			return;
103 		}
104 
105 		if ( m_xStorageFactory == null )
106 		{
107 			fail( "Can't create service factory!" );
108 			return;
109 		}
110     }
111 
112 
113     @Test
ExecuteTest01()114 	public void ExecuteTest01()
115 	{
116 		StorageTest aTest = new Test01( m_xMSF, m_xStorageFactory, log );
117 		assertTrue( "Test01 failed!", aTest.test() );
118 	}
119 
120     @Test
ExecuteTest02()121 	public void ExecuteTest02()
122 	{
123 		StorageTest aTest = new Test02( m_xMSF, m_xStorageFactory, log );
124 		assertTrue( "Test02 failed!", aTest.test() );
125 	}
126 
127     @Test
ExecuteTest03()128 	public void ExecuteTest03()
129 	{
130 		StorageTest aTest = new Test03( m_xMSF, m_xStorageFactory, log );
131 		assertTrue( "Test03 failed!", aTest.test() );
132 	}
133 
134     @Test
ExecuteTest04()135 	public void ExecuteTest04()
136 	{
137 		StorageTest aTest = new Test04( m_xMSF, m_xStorageFactory, log );
138 		assertTrue( "Test04 failed!", aTest.test() );
139 	}
140 
141     @Test
ExecuteTest05()142 	public void ExecuteTest05()
143 	{
144 		StorageTest aTest = new Test05( m_xMSF, m_xStorageFactory, log );
145 		assertTrue( "Test05 failed!", aTest.test() );
146 	}
147 
148     @Test
ExecuteTest06()149 	public void ExecuteTest06()
150 	{
151 		StorageTest aTest = new Test06( m_xMSF, m_xStorageFactory, log );
152 		assertTrue( "Test06 failed!", aTest.test() );
153 	}
154 
155     @Test
ExecuteTest07()156 	public void ExecuteTest07()
157 	{
158 		StorageTest aTest = new Test07( m_xMSF, m_xStorageFactory, log );
159 		assertTrue( "Test07 failed!", aTest.test() );
160 	}
161 
162     @Test
ExecuteTest08()163 	public void ExecuteTest08()
164 	{
165 		StorageTest aTest = new Test08( m_xMSF, m_xStorageFactory, log );
166 		assertTrue( "Test08 failed!", aTest.test() );
167 	}
168 }
169 
170