1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 
19 package ifc.sdbc;
20 
21 import lib.MultiMethodTest;
22 import lib.StatusException;
23 
24 import com.sun.star.sdbc.XConnection;
25 import com.sun.star.sdbc.XIsolatedConnection;
26 import com.sun.star.task.XInteractionHandler;
27 
28 /**
29  * Testing <code>com.sun.star.sdb.XCompletedConnection</code>
30  * interface methods :
31  * <ul>
32  *  <li><code> getIsolatedConnectionWithCompletion()</code></li>
33  *  <li><code> getIsolatedConnection()</code></li>
34  * </ul> <p>
35 *    The following object relations required :
36 * <ul>
37 * <li> <code>'XCompletedConnection.Handler'</code> : passed as parameter
38 * to <code>connectWithCompletion</code> method. </li>
39 * </ul>
40 * @see com.sun.star.sdb.XIsolatedConnection
41 * @see com.sun.star.task.XInteractionHandler
42 * @see com.sun.star.sdbc.XConnection
43 */
44 public class _XIsolatedConnection extends MultiMethodTest {
45 
46     // oObj filled by MultiMethodTest
47     public XIsolatedConnection oObj = null ;
48 
49     /**
50     * Test call the method with handler passed as object relation.
51     * Then value returned is checked.<p>
52     * Has OK status if not null value returned. <&nbsp>
53     * FAILED if exception occurred, null value returned or object
54     * relation was not found.
55     */
_getIsolatedConnectionWithCompletion()56     public void _getIsolatedConnectionWithCompletion() throws StatusException {
57         XInteractionHandler handler = (XInteractionHandler)
58             tEnv.getObjRelation("XCompletedConnection.Handler") ;
59 
60         if (handler == null) {
61             log.println("Required object relation not found !") ;
62             tRes.tested("getIsolatedConnectionWithCompletion()", false) ;
63             return ;
64         }
65 
66         XConnection con = null ;
67         try {
68             con = oObj.getIsolatedConnectionWithCompletion(handler) ;
69         } catch (com.sun.star.sdbc.SQLException e) {
70             throw new StatusException("Exception while method calling", e) ;
71         }
72 
73         tRes.tested("getIsolatedConnectionWithCompletion()", con != null) ;
74     }
75 
76     /**
77     * Test call the method with handler passed as object relation.
78     * Then value returned is checked.<p>
79     * Has OK status if not null value returned. <&nbsp>
80     * FAILED if exception occurred, null value returned or object
81     * relation was not found.
82     */
_getIsolatedConnection()83     public void _getIsolatedConnection() throws StatusException {
84         String[] userSettings = (String[])
85                         tEnv.getObjRelation("UserAndPassword") ;
86 
87         String user = null;
88         String pwd = null;
89 
90         if (userSettings[0] != null)
91             user = userSettings[0].equals("")?"<empty>":userSettings[0];
92         else
93             user = "<null>";
94         if (userSettings[1] != null)
95             pwd = userSettings[1].equals("")?"<empty>":userSettings[1];
96         else
97             pwd = "<null>";
98 
99         log.println("Testing \"getIsolatedConnection('user', 'password')\"\n" +
100                     "with user = '" + user + "'; password = '" + pwd + "'");
101         XConnection con = null ;
102         try {
103             con = oObj.getIsolatedConnection(user, pwd) ;
104         } catch (com.sun.star.sdbc.SQLException e) {
105             throw new StatusException("Exception while method calling", e) ;
106         }
107 
108         tRes.tested("getIsolatedConnection()", con != null) ;
109     }
110 }  // finish class _XIsolatedConnection
111 
112