Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _odbc / ODBCDriver.java
blob6e6cd83039f4294c23e96eb82f0acc1e0bd79144
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._odbc;
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;
29 import com.sun.star.beans.PropertyValue;
30 import com.sun.star.uno.XInterface;
32 /**
33 * Here <code>com.sun.star.sdbc.Driver</code> service is tested.<p>
34 * Test allows to run object tests in several threads concurently.
35 * @see com.sun.star.sdbc.Driver
36 * @see com.sun.star.sdbc.XDriver
37 * @see ifc.sdbc._XDriver
39 public class ODBCDriver extends TestCase {
40 /**
41 * Creates an instance of the service
42 * <code>com.sun.star.sdbc.Driver</code>. <p>
43 * Object relations created :
44 * <ul>
45 * <li> <code>'XDriver.URL'</code> for {@link ifc.sdbc._XDriver}:
46 * is the URL of the database to which to connect.
47 * The URL is obtained from the parameter <code>odbc.url</code></li>
48 * <li> <code>'XDriver.UNSUITABLE_URL'</code> for {@link ifc.sdbc._XDriver}:
49 * the wrong kind of URL to connect using given driver.
50 * The URL is obtained from the parameter <code>jdbc.url</code></li>
51 * <li> <code>'XDriver.INFO'</code> for {@link ifc.sdbc._XDriver}:
52 * a list of arbitrary string tag/value pairs as connection arguments.
53 * </li>
54 * </ul>
56 @Override
57 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
59 XInterface oObj = null;
61 try {
62 oObj = (XInterface)Param.getMSF().createInstance(
63 "com.sun.star.comp.sdbc.ODBCDriver");
64 } catch (com.sun.star.uno.Exception e) {
65 throw new StatusException(e, Status.failed("Couldn't create object"));
68 log.println("creating a new environment for ODBCDriver object");
69 TestEnvironment tEnv = new TestEnvironment(oObj);
71 //adding relation for sdbc.XDriver
72 String odbcURL = (String) Param.get("odbc.url");
73 if (odbcURL == null) {
74 throw new StatusException(Status.failed(
75 "Couldn't get 'odbc.url' from ini-file"));
77 tEnv.addObjRelation("XDriver.URL", "sdbc:odbc:" + odbcURL);
79 PropertyValue[] info = new PropertyValue[0];
80 tEnv.addObjRelation("XDriver.INFO", info);
82 String jdbcUrl = (String) Param.get("jdbc.url");
83 if (jdbcUrl == null) {
84 throw new StatusException(Status.failed(
85 "Couldn't get 'jdbc.url' from ini-file"));
87 tEnv.addObjRelation("XDriver.UNSUITABLE_URL", "jdbc:" + jdbcUrl);
89 return tEnv;