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 ifc.frame;
25 
26 
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.util.URL;
29 import lib.MultiMethodTest;
30 import lib.Status;
31 import lib.StatusException;
32 import com.sun.star.frame.XNotifyingDispatch;
33 import com.sun.star.frame.DispatchResultEvent;
34 
35 /**
36 * Testing <code>com.sun.star.frame.XNotifyingDispatch</code>
37 * interface methods :
38 * <ul>
39 *  <li><code> dispatchWithNotification()</code></li>
40 * </ul> <p>
41 * This test needs the following object relations :
42 * <ul>
43 *  <li> <code>'XDispatch.URL'</code> (of type <code>com.sun.star.util.URL
44 *   </code>): URL for passing to <code>dispatch()</code> method. </li>
45 *  <li> <code>[OPTIONAL] 'XNotifyingDispatchArgument'</code>
46 *    (of type  sequence<code>com::sun::star::beans::PropertyValue
47 *   </code>): argumets for <code>dispatchWithNotification()</code> method. </li>
48 * <ul> <p>
49 * @see com.sun.star.frame.XDispatch
50 * @see com.sun.star.frame.XNotifyingDispatch
51 * @see ifc.frmae._XDispatch
52 */
53 public class _XNotifyingDispatch extends MultiMethodTest {
54 
55     public XNotifyingDispatch oObj = null;
56 
57 
58     /**
59     * Listener implementation which sets flags on appropriate method calls
60     */
61     protected class TestNotificationListener implements
62             com.sun.star.frame.XDispatchResultListener {
63         public boolean disposingCalled = false ;
64         public boolean finishedDispatch = false ;
65         private java.io.PrintWriter log = null ;
66 
67         public TestNotificationListener(java.io.PrintWriter log) {
68             this.log = log ;
69         }
70 
71         public void disposing(com.sun.star.lang.EventObject e) {
72             disposingCalled = true ;
73             log.println("   disposing was called.") ;
74         }
75 
76         public void dispatchFinished( DispatchResultEvent e) {
77             finishedDispatch = true ;
78             log.println("   dispatchFinished was called.") ;
79         }
80 
81     }
82 
83     TestNotificationListener notificationListener = null;
84     PropertyValue[] arguments = null;
85     URL url = null ;
86 
87     /**
88     * Retrieves object relations and creates new listeners.
89     * @throws StatusException If one of relations not found.
90     */
91     public void before() {
92         notificationListener = new TestNotificationListener(log) ;
93         url = (URL) tEnv.getObjRelation("XDispatch.URL") ;
94 
95         if (url == null) throw new StatusException
96             (Status.failed("Relation not found.")) ;
97 
98         arguments = (PropertyValue[])
99                               tEnv.getObjRelation("XNotifyingDispatchArgument");
100     }
101 
102     /**
103     * Calls the method using URL and arguments from relation. <p>
104     * Has <b> OK </b> status if listener is called.
105     * The following method tests are to be completed successfully before :
106     */
107     public void _dispatchWithNotification() {
108 
109         boolean result = true ;
110 
111         oObj.dispatchWithNotification(url, arguments, notificationListener);
112 
113         try {
114             Thread.sleep(200);
115         }
116         catch(java.lang.InterruptedException e) {}
117 
118         log.println("Listener called: "+ notificationListener.finishedDispatch);
119 
120         result = notificationListener.finishedDispatch;
121 
122 
123         tRes.tested("dispatchWithNotification()", result) ;
124     }
125 
126 }
127 
128