2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
24 import lib
.StatusException
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
30 import com
.sun
.star
.beans
.PropertyValue
;
31 import com
.sun
.star
.uno
.XInterface
;
35 * Here <code>com.sun.star.sdbc.Driver</code> service is tested.<p>
36 * Test allows to run object tests in several threads concurently.
37 * @see com.sun.star.sdbc.Driver
38 * @see com.sun.star.sdbc.XDriver
39 * @see ifc.sdbc._XDriver
41 public class JDBCDriver
extends TestCase
{
43 * Creates an instance of the service
44 * <code>com.sun.star.sdbc.Driver</code>. <p>
45 * Object relations created :
47 * <li> <code>'XDriver.URL'</code> for {@link ifc.sdbc._XDriver}:
48 * is the URL of the database to which to connect.
49 * The URL is obtained from the parameter <code>jdbc.url</code></li>
50 * <li> <code>'XDriver.UNSUITABLE_URL'</code> for {@link ifc.sdbc._XDriver}:
51 * the wrong kind of URL to connect using given driver.
52 * The URL is obtained from the parameter <code>flat.url</code></li>
53 * <li> <code>'XDriver.INFO'</code> for {@link ifc.sdbc._XDriver}:
54 * a list of arbitrary string tag/value pairs as connection arguments.
55 * The values for list are obtained from the parameter
56 * <code>jdbc.user</code> and <code>jdbc.password</code>.</li>
60 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
62 XInterface oObj
= null;
65 oObj
= (XInterface
)Param
.getMSF().createInstance(
66 "com.sun.star.comp.sdbc.JDBCDriver");
67 } catch (com
.sun
.star
.uno
.Exception e
) {
68 throw new StatusException(e
, Status
.failed("Couldn't create object"));
71 log
.println("creating a new environment for JDBCDriver object");
72 TestEnvironment tEnv
= new TestEnvironment(oObj
);
74 //adding relation for sdbc.XDriver
75 String jdbcURL
= (String
) Param
.get("jdbc.url");
76 if (jdbcURL
== null) {
77 throw new StatusException(Status
.failed(
78 "Couldn't get 'jdbc.url' from ini-file"));
80 tEnv
.addObjRelation("XDriver.URL", "jdbc:" + jdbcURL
);
82 String user
= (String
) Param
.get("jdbc.user");
83 String password
= (String
) Param
.get("jdbc.password");
84 if (user
== null || password
== null) {
85 throw new StatusException(Status
.failed(
86 "Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
88 PropertyValue
[] info
= new PropertyValue
[4];
89 info
[0] = new PropertyValue();
90 info
[0].Name
= "JavaDriverClass";
91 info
[0].Value
= DBTools
.TST_JDBC_DRIVER
;
92 info
[1] = new PropertyValue();
93 info
[1].Name
= "user";
95 info
[2] = new PropertyValue();
96 info
[2].Name
= "password";
97 info
[2].Value
= password
;
98 info
[3] = new PropertyValue();
99 info
[3].Name
= "isPasswordRequired";
100 info
[3].Value
= Boolean
.TRUE
;
102 tEnv
.addObjRelation("XDriver.INFO", info
);
104 String flatUrl
= (String
) Param
.get("flat.url");
105 if (flatUrl
== null) {
106 throw new StatusException(Status
.failed(
107 "Couldn't get 'flat.url' from ini-file"));
109 tEnv
.addObjRelation("XDriver.UNSUITABLE_URL", "sdbc:flat:" + flatUrl
);