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.dbaccess;
24 
25 import com.sun.star.sdb.XSingleSelectQueryComposer;
26 import connectivity.tools.CRMDatabase;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 
30 // ---------- junit imports -----------------
31 import org.junit.After;
32 import org.junit.Before;
33 import static org.junit.Assert.*;
34 // ------------------------------------------
35 
36 public abstract class CRMBasedTestCase extends TestCase
37 {
38     protected   CRMDatabase m_database;
39 
40     // --------------------------------------------------------------------------------------------------------
createTestCase()41     protected void createTestCase()
42     {
43         try
44         {
45             m_database = new CRMDatabase( getMSF(), false );
46         }
47         catch ( Exception e )
48         {
49             e.printStackTrace( System.err );
50             fail( "caught an exception (" + e.getMessage() + ") while creating the test case");
51         }
52     }
53 
54     // --------------------------------------------------------------------------------------------------------
55     @Before
56     @Override
before()57     public void before()
58     {
59         createTestCase();
60     }
61 
62     // --------------------------------------------------------------------------------------------------------
63     @After
64     @Override
after()65     public void after()
66     {
67         try
68         {
69             if ( m_database != null )
70             {
71                 m_database.saveAndClose();
72             }
73         }
74         catch ( Exception ex )
75         {
76             Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, null, ex );
77         }
78     }
79 
80     // --------------------------------------------------------------------------------------------------------
81     /** creates a SingleSelectQueryComposer for our connection
82      */
createQueryComposer()83     protected final XSingleSelectQueryComposer createQueryComposer() throws com.sun.star.uno.Exception
84     {
85         return m_database.getConnection().createSingleSelectQueryComposer();
86     }
87 }
88