bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _jdbc / JDBCDriver.java
blob750120670ec6680c776dae1eb3c5b530daabd5be
1 /*
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 .
19 package mod._jdbc;
21 import java.io.PrintWriter;
23 import lib.Status;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.DBTools;
30 import com.sun.star.beans.PropertyValue;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.uno.XInterface;
35 /**
36 * Here <code>com.sun.star.sdbc.Driver</code> service is tested.<p>
37 * Test allows to run object tests in several threads concurently.
38 * @see com.sun.star.sdbc.Driver
39 * @see com.sun.star.sdbc.XDriver
40 * @see ifc.sdbc._XDriver
42 public class JDBCDriver extends TestCase {
43 /**
44 * Creates an instance of the service
45 * <code>com.sun.star.sdbc.Driver</code>. <p>
46 * Object relations created :
47 * <ul>
48 * <li> <code>'XDriver.URL'</code> for {@link ifc.sdbc._XDriver}:
49 * is the URL of the database to which to connect.
50 * The URL is obtained from the parameter <code>jdbc.url</code></li>
51 * <li> <code>'XDriver.UNSUITABLE_URL'</code> for {@link ifc.sdbc._XDriver}:
52 * the wrong kind of URL to connect using given driver.
53 * The URL is obtained from the parameter <code>flat.url</code></li>
54 * <li> <code>'XDriver.INFO'</code> for {@link ifc.sdbc._XDriver}:
55 * a list of arbitrary string tag/value pairs as connection arguments.
56 * The values for list are obtained from the parameter
57 * <code>jdbc.user</code> and <code>jdbc.password</code>.</li>
58 * </ul>
60 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
62 XInterface oObj = null;
64 try {
65 oObj = (XInterface)((XMultiServiceFactory)Param.getMSF()).createInstance(
66 "com.sun.star.comp.sdbc.JDBCDriver");
67 } catch (com.sun.star.uno.Exception e) {
68 e.printStackTrace(log);
69 throw new StatusException(Status.failed("Couldn't create object"));
72 log.println("creating a new environment for JDBCDriver object");
73 TestEnvironment tEnv = new TestEnvironment(oObj);
75 //adding relation for sdbc.XDriver
76 String jdbcURL = (String) Param.get("jdbc.url");
77 if (jdbcURL == null) {
78 throw new StatusException(Status.failed(
79 "Couldn't get 'jdbc.url' from ini-file"));
81 tEnv.addObjRelation("XDriver.URL", "jdbc:" + jdbcURL);
83 String user = (String) Param.get("jdbc.user");
84 String password = (String) Param.get("jdbc.password");
85 if (user == null || password == null) {
86 throw new StatusException(Status.failed(
87 "Couldn't get 'jdbc.user' or 'jdbc.password' from ini-file"));
89 PropertyValue[] info = new PropertyValue[4];
90 info[0] = new PropertyValue();
91 info[0].Name = "JavaDriverClass";
92 info[0].Value = DBTools.TST_JDBC_DRIVER;
93 info[1] = new PropertyValue();
94 info[1].Name = "user";
95 info[1].Value = user;
96 info[2] = new PropertyValue();
97 info[2].Name = "password";
98 info[2].Value = password;
99 info[3] = new PropertyValue();
100 info[3].Name = "isPasswordRequired";
101 info[3].Value = new Boolean(true);
103 tEnv.addObjRelation("XDriver.INFO", info);
105 String flatUrl = (String) Param.get("flat.url");
106 if (flatUrl == null) {
107 throw new StatusException(Status.failed(
108 "Couldn't get 'flat.url' from ini-file"));
110 tEnv.addObjRelation("XDriver.UNSUITABLE_URL", "sdbc:flat:" + flatUrl);
112 return tEnv;