1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._dbaccess;
25 
26 import java.io.PrintWriter;
27 
28 import lib.Status;
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.sdbc.SQLException;
36 import com.sun.star.task.XInteractionContinuation;
37 import com.sun.star.task.XInteractionRequest;
38 import com.sun.star.uno.XInterface;
39 
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.sdb.InteractionHandler</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 *  <li> <code>com::sun::star::task::XInteractionHandler</code></li>
46 * </ul>
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurently.
49 * @see com.sun.star.task.XInteractionHandler
50 * @see com.sun.star.sdb.InteractionHandler
51 * @see ifc.task._XInteractionHandler
52 */
53 public class OInteractionHandler extends TestCase {
54 
55 
56     private static class TestRequest implements XInteractionRequest {
getRequest()57         public Object getRequest() {
58             return new SQLException("Test exception") ;
59         }
60 
getContinuations()61         public XInteractionContinuation[] getContinuations() {
62             return new XInteractionContinuation[0] ;
63         }
64     }
65 
66 
67     /**
68     * Creating a Testenvironment for the interfaces to be tested.
69     * Creates an instance of the service
70     * <code>com.sun.star.sdb.InteractionHandler</code>.
71     *     Object relations created :
72     * <ul>
73     *  <li> <code>'XInteractionHandler.Request'</code> for
74     *      {@link ifc.task._XInteractionHandler} : this realtion
75     *    is <code>com.sun.star.task.XInteractionRequest</code>
76     *    interface implementation which depends on the component
77     *    tested. In this case it emulates SQL error by returning
78     *    <code>SQLException</code> object. </li>
79     * </ul>
80     */
createTestEnvironment( TestParameters Param, PrintWriter log )81     public TestEnvironment createTestEnvironment( TestParameters Param,
82                                                   PrintWriter log )
83                                                     throws StatusException {
84         XInterface oObj = null;
85         Object oInterface = null;
86 
87         try {
88             oInterface = ((XMultiServiceFactory)Param.getMSF()).createInstance(
89                             "com.sun.star.sdb.InteractionHandler" );
90 
91         }
92         catch( com.sun.star.uno.Exception e ) {
93             log.println("Service not available" );
94             throw new StatusException("Service not available", e) ;
95         }
96 
97         if (oInterface == null) {
98             log.println("Service wasn't created") ;
99             throw new StatusException(Status.failed("Service wasn't created")) ;
100         }
101 
102           oObj = (XInterface) oInterface;
103 
104         log.println( "    creating a new environment for object" );
105         TestEnvironment tEnv = new TestEnvironment( oObj );
106 
107         tEnv.addObjRelation("XInteractionHandler.Request", new TestRequest()) ;
108 
109         return tEnv;
110     } // finish method getTestEnvironment
111 
112 }
113 
114