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._adabas;
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 
34 import com.sun.star.beans.PropertyValue;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.uno.XInterface;
37 
38 /**
39 * Here <code>com.sun.star.sdbc.Driver</code> service is tested.<p>
40 * Test allows to run object tests in several threads concurently.
41 * @see com.sun.star.sdbc.Driver
42 * @see com.sun.star.sdbc.XDriver
43 * @see com.sun.star.sdbcx.XCreateCatalog
44 * @see com.sun.star.sdbcx.XDropCatalog
45 * @see ifc.sdbc._XDriver
46 * @see ifc.sdbcx._XCreateCatalog
47 * @see ifc.sdbcx._XDropCatalog
48 */
49 public class ODriver extends TestCase {
50     /**
51      * Creates an instance of the service
52      * <code>com.sun.star.sdbc.Driver</code>. <p>
53      * Object relations created :
54      * <ul>
55      *  <li> <code>'XDriver.URL'</code> for {@link ifc.sdbc._XDriver}:
56      *      is the URL of the database to which to connect.
57      *      The URL is obtained from the parameter <code>adabas.url</code></li>
58      *  <li> <code>'XDriver.UNSUITABLE_URL'</code> for {@link ifc.sdbc._XDriver}:
59      *      the wrong kind of URL to connect using given driver.
60      *      The URL is obtained from the parameter <code>jdbc.url</code></li>
61      *  <li> <code>'XDriver.INFO'</code> for {@link ifc.sdbc._XDriver}:
62      *      a list of arbitrary string tag/value pairs as connection arguments.
63      *      The values for list are obtained from the parameter
64      *      <code>adabas.user</code> and <code>adabas.password</code>.</li>
65      * </ul>
66      */
createTestEnvironment(TestParameters Param, PrintWriter log)67     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
68 
69         XInterface oObj = null;
70 
71         try {
72             oObj = (XInterface)((XMultiServiceFactory)Param.getMSF()).
73                 createInstance("com.sun.star.comp.sdbcx.adabas.ODriver");
74         } catch (com.sun.star.uno.Exception e) {
75             e.printStackTrace(log);
76             throw new StatusException(Status.failed("Couldn't create object"));
77         }
78 
79         log.println("creating a new environment for object");
80         TestEnvironment tEnv = new TestEnvironment(oObj);
81 
82         //adding relation for sdbc.XDriver
83         String adabasURL = (String) Param.get("adabas.url");
84         if (adabasURL == null) {
85             throw new StatusException(Status.failed(
86                 "Couldn't get 'adabas.url' from ini-file"));
87         }
88         tEnv.addObjRelation("XDriver.URL", "sdbc:adabas:" + adabasURL);
89 
90 
91         String user = (String) Param.get("adabas.user");
92         if (user == null) {
93             throw new StatusException(Status.failed(
94                 "Couldn't get 'adabas.user' from ini-file"));
95         }
96         String password = (String) Param.get("adabas.password");
97         if (password == null) {
98             throw new StatusException(Status.failed(
99                 "Couldn't get 'adabas.password' from ini-file"));
100         }
101         PropertyValue[] info = new PropertyValue[2];
102         info[0] = new PropertyValue();
103         info[0].Name = "user"; info[0].Value = user;
104         info[1] = new PropertyValue();
105         info[1].Name = "password"; info[1].Value = password;
106         tEnv.addObjRelation("XDriver.INFO", info);
107 
108         String jdbcUrl = (String) Param.get("jdbc.url");
109         if (jdbcUrl == null) {
110             throw new StatusException(Status.failed(
111                 "Couldn't get 'jdbc.url' from ini-file"));
112         }
113         tEnv.addObjRelation("XDriver.UNSUITABLE_URL", "jdbc:" + jdbcUrl);
114 
115         return tEnv;
116     }
117 }
118