1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ODBCDriver.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
36 import lib
.StatusException
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
41 import com
.sun
.star
.beans
.PropertyValue
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.uno
.XInterface
;
46 * Here <code>com.sun.star.sdbc.Driver</code> service is tested.<p>
47 * Test allows to run object tests in several threads concurently.
48 * @see com.sun.star.sdbc.Driver
49 * @see com.sun.star.sdbc.XDriver
50 * @see ifc.sdbc._XDriver
52 public class ODBCDriver
extends TestCase
{
54 * Creates an instance of the service
55 * <code>com.sun.star.sdbc.Driver</code>. <p>
56 * Object relations created :
58 * <li> <code>'XDriver.URL'</code> for {@link ifc.sdbc._XDriver}:
59 * is the URL of the database to which to connect.
60 * The URL is obtained from the parameter <code>odbc.url</code></li>
61 * <li> <code>'XDriver.UNSUITABLE_URL'</code> for {@link ifc.sdbc._XDriver}:
62 * the wrong kind of URL to connect using given driver.
63 * The URL is obtained from the parameter <code>jdbc.url</code></li>
64 * <li> <code>'XDriver.INFO'</code> for {@link ifc.sdbc._XDriver}:
65 * a list of arbitrary string tag/value pairs as connection arguments.
69 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
71 XInterface oObj
= null;
74 oObj
= (XInterface
)((XMultiServiceFactory
)Param
.getMSF()).createInstance(
75 "com.sun.star.comp.sdbc.ODBCDriver");
76 } catch (com
.sun
.star
.uno
.Exception e
) {
77 e
.printStackTrace(log
);
78 throw new StatusException(Status
.failed("Couldn't create object"));
81 log
.println("creating a new environment for ODBCDriver object");
82 TestEnvironment tEnv
= new TestEnvironment(oObj
);
84 //adding relation for sdbc.XDriver
85 String odbcURL
= (String
) Param
.get("odbc.url");
86 if (odbcURL
== null) {
87 throw new StatusException(Status
.failed(
88 "Couldn't get 'odbc.url' from ini-file"));
90 tEnv
.addObjRelation("XDriver.URL", "sdbc:odbc:" + odbcURL
);
92 PropertyValue
[] info
= new PropertyValue
[0];
93 tEnv
.addObjRelation("XDriver.INFO", info
);
95 String jdbcUrl
= (String
) Param
.get("jdbc.url");
96 if (jdbcUrl
== null) {
97 throw new StatusException(Status
.failed(
98 "Couldn't get 'jdbc.url' from ini-file"));
100 tEnv
.addObjRelation("XDriver.UNSUITABLE_URL", "jdbc:" + jdbcUrl
);