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