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.text;
25 
26 import lib.MultiPropertyTest;
27 
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.sdbc.XConnection;
30 import com.sun.star.sdbc.XResultSet;
31 import com.sun.star.uno.UnoRuntime;
32 
33 public class _MailMerge extends MultiPropertyTest {
34 
35     /**
36      * Custom tester for properties which contains URLs.
37      * Switches between two valid folders
38      */
39     protected PropertyTester URLTester = new PropertyTester() {
40         protected Object getNewValue(String propName, Object oldValue) {
41             if (oldValue.equals(util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF())))
42                 return util.utils.getFullTestURL(""); else
43                 return util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF());
44         }
45     } ;
46 
47     /**
48      * Custom tester for properties which contains document URLs.
49      * Switches between two document URLs.
50      */
51     protected PropertyTester DocumentURLTester = new PropertyTester() {
52         protected Object getNewValue(String propName, Object oldValue) {
53             if (oldValue.equals(util.utils.getFullTestURL("MailMerge.sxw")))
54                 return util.utils.getFullTestURL("sForm.sxw"); else
55                 return util.utils.getFullTestURL("MailMerge.sxw");
56         }
57     } ;
58     /**
59      * Tested with custom property tester.
60      */
_ResultSet()61     public void _ResultSet() {
62         String propName = "ResultSet";
63         try{
64 
65             log.println("try to get value from property...");
66             XResultSet oldValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,oObj.getPropertyValue(propName));
67 
68             log.println("try to get value from object relation...");
69             XResultSet newValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,tEnv.getObjRelation("MailMerge.XResultSet"));
70 
71             log.println("set property to a new value...");
72             oObj.setPropertyValue(propName, newValue);
73 
74             log.println("get the new value...");
75             XResultSet getValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,oObj.getPropertyValue(propName));
76 
77             tRes.tested(propName, this.compare(newValue, getValue));
78         } catch (com.sun.star.beans.PropertyVetoException e){
79             log.println("could not set property '"+ propName +"' to a new value!");
80             tRes.tested(propName, false);
81         } catch (com.sun.star.lang.IllegalArgumentException e){
82             log.println("could not set property '"+ propName +"' to a new value!");
83             tRes.tested(propName, false);
84         } catch (com.sun.star.beans.UnknownPropertyException e){
85             if (this.isOptional(propName)){
86                     // skipping optional property test
87                     log.println("Property '" + propName
88                             + "' is optional and not supported");
89                     tRes.tested(propName,true);
90 
91             } else {
92                 log.println("could not get property '"+ propName +"' from XPropertySet!");
93                 tRes.tested(propName, false);
94             }
95         } catch (com.sun.star.lang.WrappedTargetException e){
96             log.println("could not get property '"+ propName +"' from XPropertySet!");
97             tRes.tested(propName, false);
98         }
99     }
100 
101     /**
102      * Tested with custom property tester.
103      */
104 
_ActiveConnection()105     public void _ActiveConnection() {
106         String propName = "ActiveConnection";
107         try{
108 
109             log.println("try to get value from property...");
110             XConnection oldValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,oObj.getPropertyValue(propName));
111 
112             log.println("try to get value from object relation...");
113             XConnection newValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,tEnv.getObjRelation("MailMerge.XConnection"));
114 
115             log.println("set property to a new value...");
116             oObj.setPropertyValue(propName, newValue);
117 
118             log.println("get the new value...");
119             XConnection getValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,oObj.getPropertyValue(propName));
120 
121             tRes.tested(propName, this.compare(newValue, getValue));
122         } catch (com.sun.star.beans.PropertyVetoException e){
123             log.println("could not set property '"+ propName +"' to a new value! " + e.toString());
124             tRes.tested(propName, false);
125         } catch (com.sun.star.lang.IllegalArgumentException e){
126             log.println("could not set property '"+ propName +"' to a new value! " + e.toString());
127             tRes.tested(propName, false);
128         } catch (com.sun.star.beans.UnknownPropertyException e){
129             if (this.isOptional(propName)){
130                     // skipping optional property test
131                     log.println("Property '" + propName
132                             + "' is optional and not supported");
133                     tRes.tested(propName,true);
134 
135             } else {
136                 log.println("could not get property '"+ propName +"' from XPropertySet!");
137                 tRes.tested(propName, false);
138             }
139         } catch (com.sun.star.lang.WrappedTargetException e){
140             log.println("could not get property '"+ propName +"' from XPropertySet!");
141             tRes.tested(propName, false);
142         }
143     }
144 
145     /**
146      * Tested with custom property tester.
147      */
_DocumentURL()148     public void _DocumentURL() {
149         log.println("Testing with custom Property tester") ;
150         testProperty("DocumentURL", DocumentURLTester) ;
151     }
152 
153     /**
154      * Tested with custom property tester.
155      */
_OutputURL()156     public void _OutputURL() {
157         log.println("Testing with custom Property tester") ;
158         testProperty("OutputURL", URLTester) ;
159     }
160 
161     /**
162     * Forces environment recreation.
163     */
after()164     protected void after() {
165         disposeEnvironment();
166     }
167 
168 
169 } //finish class _MailMerge
170 
171