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._fwk;
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.uno.XInterface;
36 
37 /**
38 * Test for object that implements the following interfaces :
39 * <ul>
40 *  <li><code>com::sun::star::frame::XDispatchProvider</code></li>
41 *  <li><code>com::sun::star::lang::XInitialization</code></li>
42 * </ul><p>
43 * @see com.sun.star.frame.XDispatchProvider
44 * @see com.sun.star.lang.XInitialization
45 * @see ifc.frame._XDispatchProvider
46 * @see ifc.lang._XInitialization
47 */
48 public class JobHandler extends TestCase {
49 
50     /**
51     * Creating a Testenvironment for the interfaces to be tested.
52     */
createTestEnvironment( TestParameters Param, PrintWriter log )53     public TestEnvironment createTestEnvironment( TestParameters Param,
54         PrintWriter log ) throws StatusException {
55         boolean serviceRegistered = false;
56 
57         try {
58             Object obj = ((XMultiServiceFactory)Param.getMSF()).createInstance("test.Job");
59             serviceRegistered = obj != null;
60         } catch(com.sun.star.uno.Exception e) {}
61 
62         log.println("Service test.Job is "
63             + (serviceRegistered ? "already" : "not yet")  + " registered.");
64         if (! serviceRegistered){
65             String message = "You have to register 'test.Job' before office is stared.\n";
66             message += "Please run '$OFFICEPATH/program/pkgchk $DOCPTH/qadevlibs/JobExecutor.jar'";
67             throw new StatusException(message, new Exception());
68         }
69 
70         XInterface oObj = null;
71 
72         try {
73             oObj = (XInterface)((XMultiServiceFactory)Param.getMSF()).createInstance(
74                 "com.sun.star.comp.framework.jobs.JobDispatch");
75         } catch(com.sun.star.uno.Exception e) {
76             e.printStackTrace(log);
77             throw new StatusException(
78                 Status.failed("Couldn't create instance"));
79         }
80 
81         TestEnvironment tEnv = new TestEnvironment( oObj );
82 
83         tEnv.addObjRelation("XDispatchProvider.URL", "vnd.sun.star.job:alias=TestJob");
84         return tEnv;
85     } // finish method getTestEnvironment
86 
87 }
88