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