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 
24 package mod._dbpool;
25 
26 import java.io.PrintWriter;
27 
28 import lib.Status;
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 import util.DBTools;
34 
35 import com.sun.star.beans.PropertyValue;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.uno.XInterface;
38 
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.sdbc.ConnectionPool</code>. <p>
42 * Object implements the following interfaces :
43 * <ul>
44 *  <li> <code>com::sun::star::sdbc::XDriverManager</code></li>
45 * </ul>
46 * @see com.sun.star.sdbc.XDriverManager
47 * @see ifc.sdbc._XDriverManager
48 */
49 public class OConnectionPool extends TestCase {
createTestEnvironment(TestParameters Param, PrintWriter log)50     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
51 
52         XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
53         XInterface oObj = null;
54 
55         try {
56             oObj = (XInterface)
57                 xMSF.createInstance("com.sun.star.sdbc.ConnectionPool");
58         } catch(com.sun.star.uno.Exception e) {
59             throw new StatusException(
60                 Status.failed("Couldn't create instance"));
61         }
62 
63         log.println("creating a new environment for object");
64         TestEnvironment tEnv = new TestEnvironment( oObj );
65 
66         //adding relations for XDriverManager
67         String dbaseURL = (String) Param.get("dbase.url");
68         if (dbaseURL == null) {
69             throw new StatusException(
70                 Status.failed("Couldn't get parameter 'dbase.url'"));
71         }
72 
73         tEnv.addObjRelation("SDBC.URL", "sdbc:dbase:" + dbaseURL);
74 
75         String jdbcURL = (String) Param.get("jdbc.url");
76         if (jdbcURL == null) {
77             throw new StatusException(
78                 Status.failed("Couldn't get parameter 'jdbc.url'"));
79         }
80 
81         tEnv.addObjRelation("JDBC.URL", "jdbc:" + jdbcURL);
82 
83         String jdbcUser = (String) Param.get("jdbc.user");
84         if (jdbcUser == null) {
85             throw new StatusException(
86                 Status.failed("Couldn't get parameter 'jdbc.user'"));
87         }
88 
89         String jdbcPassword = (String) Param.get("jdbc.password");
90         if (jdbcPassword == null) {
91             throw new StatusException(
92                 Status.failed("Couldn't get parameter 'jdbc.password'"));
93         }
94 
95         PropertyValue[] jdbcInfo = new PropertyValue[3];
96         jdbcInfo[0] = new PropertyValue();
97         jdbcInfo[0].Name = "user";
98         jdbcInfo[0].Value = jdbcUser;
99         jdbcInfo[1] = new PropertyValue();
100         jdbcInfo[1].Name = "password";
101         jdbcInfo[1].Value = jdbcPassword;
102         jdbcInfo[2] = new PropertyValue();
103         jdbcInfo[2].Name = "JavaDriverClass";
104         jdbcInfo[2].Value = DBTools.TST_JDBC_DRIVER;
105 
106         tEnv.addObjRelation("JDBC.INFO", jdbcInfo);
107 
108         return tEnv;
109     }
110 }
111