1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._dbaccess;
29 
30 import java.io.PrintWriter;
31 
32 import lib.Status;
33 import lib.StatusException;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.sdbc.SQLException;
40 import com.sun.star.task.XInteractionContinuation;
41 import com.sun.star.task.XInteractionRequest;
42 import com.sun.star.uno.XInterface;
43 
44 /**
45 * Test for object which is represented by service
46 * <code>com.sun.star.sdb.InteractionHandler</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 *  <li> <code>com::sun::star::task::XInteractionHandler</code></li>
50 * </ul>
51 * This object test <b> is NOT </b> designed to be run in several
52 * threads concurently.
53 * @see com.sun.star.task.XInteractionHandler
54 * @see com.sun.star.sdb.InteractionHandler
55 * @see ifc.task._XInteractionHandler
56 */
57 public class OInteractionHandler extends TestCase {
58 
59 
60     private static class TestRequest implements XInteractionRequest {
61         public Object getRequest() {
62             return new SQLException("Test exception") ;
63         }
64 
65         public XInteractionContinuation[] getContinuations() {
66             return new XInteractionContinuation[0] ;
67         }
68     }
69 
70 
71     /**
72     * Creating a Testenvironment for the interfaces to be tested.
73     * Creates an instance of the service
74     * <code>com.sun.star.sdb.InteractionHandler</code>.
75     *     Object relations created :
76     * <ul>
77     *  <li> <code>'XInteractionHandler.Request'</code> for
78     *      {@link ifc.task._XInteractionHandler} : this realtion
79     *    is <code>com.sun.star.task.XInteractionRequest</code>
80     *    interface implementation which depends on the component
81     *    tested. In this case it emulates SQL error by returning
82     *    <code>SQLException</code> object. </li>
83     * </ul>
84     */
85     public TestEnvironment createTestEnvironment( TestParameters Param,
86                                                   PrintWriter log )
87                                                     throws StatusException {
88         XInterface oObj = null;
89         Object oInterface = null;
90 
91         try {
92             oInterface = ((XMultiServiceFactory)Param.getMSF()).createInstance(
93                             "com.sun.star.sdb.InteractionHandler" );
94 
95         }
96         catch( com.sun.star.uno.Exception e ) {
97             log.println("Service not available" );
98             throw new StatusException("Service not available", e) ;
99         }
100 
101         if (oInterface == null) {
102             log.println("Service wasn't created") ;
103             throw new StatusException(Status.failed("Service wasn't created")) ;
104         }
105 
106           oObj = (XInterface) oInterface;
107 
108         log.println( "    creating a new environment for object" );
109         TestEnvironment tEnv = new TestEnvironment( oObj );
110 
111         tEnv.addObjRelation("XInteractionHandler.Request", new TestRequest()) ;
112 
113         return tEnv;
114     } // finish method getTestEnvironment
115 
116 }
117 
118