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 package ifc.form.submission;
24 
25 import com.sun.star.form.submission.XSubmission;
26 import com.sun.star.form.submission.XSubmissionVetoListener;
27 
28 import lib.MultiMethodTest;
29 
30 
31 public class _XSubmission extends MultiMethodTest {
32     public XSubmission oObj = null;
33     public boolean HandlerWasCalled = false;
34 
_addSubmissionVetoListener()35     public void _addSubmissionVetoListener() {
36         log.println(
37             "submitting with VetoListener ... exception should appear");
38 
39         boolean res = true;
40         XSubmissionVetoListener aListener = new MyListener();
41 
42         try {
43             oObj.addSubmissionVetoListener(aListener);
44             oObj.submit();
45             res = false;
46             log.println(
47                 "the expected exception wasn't thrown ... FAILED");
48         } catch (com.sun.star.lang.WrappedTargetException e) {
49             log.println(
50                 "Expected exception was thrown while calling submit() "
51                 + e.getMessage() + "FAILED");
52             res = false;
53         } catch (com.sun.star.lang.NoSupportException e) {
54             log.println(
55                 "NoSupportExpected exception was thrown while calling submit() "
56                 + e.getMessage() + "FAILED");
57             res = false;
58         } catch (com.sun.star.util.VetoException e) {
59             log.println(
60                 "VetoException was thrown while calling submit() "
61                 + e.getMessage() + "OK");
62         }
63 
64         try {
65             oObj.removeSubmissionVetoListener(aListener);
66         } catch (com.sun.star.lang.NoSupportException e) {
67             log.println(
68                 "NoSupportExpected exception was thrown while removing the listener) "
69                 + e.getMessage() + "FAILED");
70             res = false;
71         }
72 
73         tRes.tested("addSubmissionVetoListener()", res);
74     }
75 
_removeSubmissionVetoListener()76     public void _removeSubmissionVetoListener() {
77         log.println(
78             "submitting with VetoListener ... exception should appear");
79 
80         boolean res = true;
81         XSubmissionVetoListener aListener = new MyListener();
82 
83         try {
84             oObj.addSubmissionVetoListener(aListener);
85             oObj.submit();
86             res = false;
87             log.println(
88                 "the expected exception wasn't thrown ... FAILED");
89         } catch (com.sun.star.lang.WrappedTargetException e) {
90             log.println(
91                 "WrappedTargetException exception was thrown while calling submit() "
92                 + e.getMessage() + "FAILED");
93             res = false;
94         } catch (com.sun.star.lang.NoSupportException e) {
95             log.println(
96                 "NoSupportExpected exception was thrown while calling submit() "
97                 + e.getMessage() + "FAILED");
98             res = false;
99         } catch (com.sun.star.util.VetoException e) {
100             log.println(
101                 "VetoException was thrown while calling submit() "
102                 + e.getMessage() + "OK");
103         }
104 
105         log.println("removing the listener");
106 
107         try {
108             oObj.removeSubmissionVetoListener(aListener);
109         } catch (com.sun.star.lang.NoSupportException e) {
110             log.println(
111                 "NoSupportExpected exception was thrown while removing the listener) "
112                 + e.getMessage() + "FAILED");
113             res = false;
114         }
115 
116         log.println("Sleeping 2s");
117 
118         try {
119             Thread.sleep(2000);
120         } catch (InterruptedException e) {
121             // sleeping didn't work
122         }
123 
124         log.println("... done");
125 
126         log.println(
127             "submitting after VetoListener has been removed... no exception should appear");
128 
129         try {
130             oObj.submit();
131             log.println("No Exception ... OK");
132         } catch (com.sun.star.lang.WrappedTargetException e) {
133             log.println(
134                 "WrappedTargetException was thrown while calling submit() "
135                 + e.getMessage() + "FAILED");
136             res = false;
137         } catch (com.sun.star.util.VetoException e) {
138             log.println(
139                 "VetoException was thrown while calling submit() "
140                 + e.getMessage() + "FAILED");
141             res = false;
142         }
143 
144         tRes.tested("removeSubmissionVetoListener()", res);
145     }
146 
147     /** Calls submit and returns true if no exception was thrown
148      *  then adds a SubmissionVetoListener and checks if the
149      *  exception is thrown in case of a veto of this listener.
150      */
_submit()151     public void _submit() {
152         boolean res = true;
153         log.println(
154             "submitting without VetoListener ... no exception should appear");
155 
156         try {
157             oObj.submit();
158             log.println("No Exception ... OK");
159         } catch (com.sun.star.lang.WrappedTargetException e) {
160             log.println(
161                 "Exception was thrown while calling submit() "
162                 + e.getMessage() + "FAILED");
163             res = false;
164         } catch (com.sun.star.util.VetoException e) {
165             log.println(
166                 "VetoException was thrown while calling submit() "
167                 + e.getMessage() + "FAILED");
168             res = false;
169         }
170 
171         tRes.tested("submit()", res);
172     }
173 
174     public class MyListener implements XSubmissionVetoListener {
disposing( com.sun.star.lang.EventObject eventObject)175         public void disposing(
176             com.sun.star.lang.EventObject eventObject) {
177         }
178 
submitting( com.sun.star.lang.EventObject eventObject)179         public void submitting(
180             com.sun.star.lang.EventObject eventObject)
181                 throws com.sun.star.util.VetoException {
182             log.println("MyVetoListener was called");
183             throw new com.sun.star.util.VetoException(
184                 "submission isn't allowed ...");
185         }
186     }
187 
188 }
189