xref: /AOO41X/main/qadevOOo/tests/java/ifc/form/submission/_XSubmission.java (revision ef39d40d3f5e66cf3f035b3e93783012b340500d)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.form.submission;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.form.submission.XSubmission;
26cdf0e10cSrcweir import com.sun.star.form.submission.XSubmissionVetoListener;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import lib.MultiMethodTest;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir public class _XSubmission extends MultiMethodTest {
32cdf0e10cSrcweir     public XSubmission oObj = null;
33cdf0e10cSrcweir     public boolean HandlerWasCalled = false;
34cdf0e10cSrcweir 
_addSubmissionVetoListener()35cdf0e10cSrcweir     public void _addSubmissionVetoListener() {
36cdf0e10cSrcweir         log.println(
37cdf0e10cSrcweir             "submitting with VetoListener ... exception should appear");
38cdf0e10cSrcweir 
39cdf0e10cSrcweir         boolean res = true;
40cdf0e10cSrcweir         XSubmissionVetoListener aListener = new MyListener();
41cdf0e10cSrcweir 
42cdf0e10cSrcweir         try {
43cdf0e10cSrcweir             oObj.addSubmissionVetoListener(aListener);
44cdf0e10cSrcweir             oObj.submit();
45cdf0e10cSrcweir             res = false;
46cdf0e10cSrcweir             log.println(
47cdf0e10cSrcweir                 "the expected exception wasn't thrown ... FAILED");
48cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
49cdf0e10cSrcweir             log.println(
50cdf0e10cSrcweir                 "Expected exception was thrown while calling submit() "
51cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
52cdf0e10cSrcweir             res = false;
53cdf0e10cSrcweir         } catch (com.sun.star.lang.NoSupportException e) {
54cdf0e10cSrcweir             log.println(
55cdf0e10cSrcweir                 "NoSupportExpected exception was thrown while calling submit() "
56cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
57cdf0e10cSrcweir             res = false;
58cdf0e10cSrcweir         } catch (com.sun.star.util.VetoException e) {
59cdf0e10cSrcweir             log.println(
60cdf0e10cSrcweir                 "VetoException was thrown while calling submit() "
61cdf0e10cSrcweir                 + e.getMessage() + "OK");
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         try {
65cdf0e10cSrcweir             oObj.removeSubmissionVetoListener(aListener);
66cdf0e10cSrcweir         } catch (com.sun.star.lang.NoSupportException e) {
67cdf0e10cSrcweir             log.println(
68cdf0e10cSrcweir                 "NoSupportExpected exception was thrown while removing the listener) "
69cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
70cdf0e10cSrcweir             res = false;
71cdf0e10cSrcweir         }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir         tRes.tested("addSubmissionVetoListener()", res);
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir 
_removeSubmissionVetoListener()76cdf0e10cSrcweir     public void _removeSubmissionVetoListener() {
77cdf0e10cSrcweir         log.println(
78cdf0e10cSrcweir             "submitting with VetoListener ... exception should appear");
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         boolean res = true;
81cdf0e10cSrcweir         XSubmissionVetoListener aListener = new MyListener();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         try {
84cdf0e10cSrcweir             oObj.addSubmissionVetoListener(aListener);
85cdf0e10cSrcweir             oObj.submit();
86cdf0e10cSrcweir             res = false;
87cdf0e10cSrcweir             log.println(
88cdf0e10cSrcweir                 "the expected exception wasn't thrown ... FAILED");
89cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
90cdf0e10cSrcweir             log.println(
91cdf0e10cSrcweir                 "WrappedTargetException exception was thrown while calling submit() "
92cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
93cdf0e10cSrcweir             res = false;
94cdf0e10cSrcweir         } catch (com.sun.star.lang.NoSupportException e) {
95cdf0e10cSrcweir             log.println(
96cdf0e10cSrcweir                 "NoSupportExpected exception was thrown while calling submit() "
97cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
98cdf0e10cSrcweir             res = false;
99cdf0e10cSrcweir         } catch (com.sun.star.util.VetoException e) {
100cdf0e10cSrcweir             log.println(
101cdf0e10cSrcweir                 "VetoException was thrown while calling submit() "
102cdf0e10cSrcweir                 + e.getMessage() + "OK");
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         log.println("removing the listener");
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         try {
108cdf0e10cSrcweir             oObj.removeSubmissionVetoListener(aListener);
109cdf0e10cSrcweir         } catch (com.sun.star.lang.NoSupportException e) {
110cdf0e10cSrcweir             log.println(
111cdf0e10cSrcweir                 "NoSupportExpected exception was thrown while removing the listener) "
112cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
113cdf0e10cSrcweir             res = false;
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         log.println("Sleeping 2s");
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         try {
119cdf0e10cSrcweir             Thread.sleep(2000);
120cdf0e10cSrcweir         } catch (InterruptedException e) {
121cdf0e10cSrcweir             // sleeping didn't work
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         log.println("... done");
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         log.println(
127cdf0e10cSrcweir             "submitting after VetoListener has been removed... no exception should appear");
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         try {
130cdf0e10cSrcweir             oObj.submit();
131cdf0e10cSrcweir             log.println("No Exception ... OK");
132cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
133cdf0e10cSrcweir             log.println(
134cdf0e10cSrcweir                 "WrappedTargetException was thrown while calling submit() "
135cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
136cdf0e10cSrcweir             res = false;
137cdf0e10cSrcweir         } catch (com.sun.star.util.VetoException e) {
138cdf0e10cSrcweir             log.println(
139cdf0e10cSrcweir                 "VetoException was thrown while calling submit() "
140cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
141cdf0e10cSrcweir             res = false;
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         tRes.tested("removeSubmissionVetoListener()", res);
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     /** Calls submit and returns true if no exception was thrown
148cdf0e10cSrcweir      *  then adds a SubmissionVetoListener and checks if the
149cdf0e10cSrcweir      *  exception is thrown in case of a veto of this listener.
150cdf0e10cSrcweir      */
_submit()151cdf0e10cSrcweir     public void _submit() {
152cdf0e10cSrcweir         boolean res = true;
153cdf0e10cSrcweir         log.println(
154cdf0e10cSrcweir             "submitting without VetoListener ... no exception should appear");
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         try {
157cdf0e10cSrcweir             oObj.submit();
158cdf0e10cSrcweir             log.println("No Exception ... OK");
159cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
160cdf0e10cSrcweir             log.println(
161cdf0e10cSrcweir                 "Exception was thrown while calling submit() "
162cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
163cdf0e10cSrcweir             res = false;
164cdf0e10cSrcweir         } catch (com.sun.star.util.VetoException e) {
165cdf0e10cSrcweir             log.println(
166cdf0e10cSrcweir                 "VetoException was thrown while calling submit() "
167cdf0e10cSrcweir                 + e.getMessage() + "FAILED");
168cdf0e10cSrcweir             res = false;
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         tRes.tested("submit()", res);
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     public class MyListener implements XSubmissionVetoListener {
disposing( com.sun.star.lang.EventObject eventObject)175cdf0e10cSrcweir         public void disposing(
176cdf0e10cSrcweir             com.sun.star.lang.EventObject eventObject) {
177cdf0e10cSrcweir         }
178cdf0e10cSrcweir 
submitting( com.sun.star.lang.EventObject eventObject)179cdf0e10cSrcweir         public void submitting(
180cdf0e10cSrcweir             com.sun.star.lang.EventObject eventObject)
181cdf0e10cSrcweir                 throws com.sun.star.util.VetoException {
182cdf0e10cSrcweir             log.println("MyVetoListener was called");
183cdf0e10cSrcweir             throw new com.sun.star.util.VetoException(
184cdf0e10cSrcweir                 "submission isn't allowed ...");
185cdf0e10cSrcweir         }
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir }
189