1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.text; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiPropertyTest; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 33*cdf0e10cSrcweir import com.sun.star.sdbc.XConnection; 34*cdf0e10cSrcweir import com.sun.star.sdbc.XResultSet; 35*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir public class _MailMerge extends MultiPropertyTest { 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir /** 40*cdf0e10cSrcweir * Custom tester for properties which contains URLs. 41*cdf0e10cSrcweir * Switches between two valid folders 42*cdf0e10cSrcweir */ 43*cdf0e10cSrcweir protected PropertyTester URLTester = new PropertyTester() { 44*cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) { 45*cdf0e10cSrcweir if (oldValue.equals(util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()))) 46*cdf0e10cSrcweir return util.utils.getFullTestURL(""); else 47*cdf0e10cSrcweir return util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()); 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir } ; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /** 52*cdf0e10cSrcweir * Custom tester for properties which contains document URLs. 53*cdf0e10cSrcweir * Switches between two document URLs. 54*cdf0e10cSrcweir */ 55*cdf0e10cSrcweir protected PropertyTester DocumentURLTester = new PropertyTester() { 56*cdf0e10cSrcweir protected Object getNewValue(String propName, Object oldValue) { 57*cdf0e10cSrcweir if (oldValue.equals(util.utils.getFullTestURL("MailMerge.sxw"))) 58*cdf0e10cSrcweir return util.utils.getFullTestURL("sForm.sxw"); else 59*cdf0e10cSrcweir return util.utils.getFullTestURL("MailMerge.sxw"); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir } ; 62*cdf0e10cSrcweir /** 63*cdf0e10cSrcweir * Tested with custom property tester. 64*cdf0e10cSrcweir */ 65*cdf0e10cSrcweir public void _ResultSet() { 66*cdf0e10cSrcweir String propName = "ResultSet"; 67*cdf0e10cSrcweir try{ 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir log.println("try to get value from property..."); 70*cdf0e10cSrcweir XResultSet oldValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,oObj.getPropertyValue(propName)); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir log.println("try to get value from object relation..."); 73*cdf0e10cSrcweir XResultSet newValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,tEnv.getObjRelation("MailMerge.XResultSet")); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir log.println("set property to a new value..."); 76*cdf0e10cSrcweir oObj.setPropertyValue(propName, newValue); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir log.println("get the new value..."); 79*cdf0e10cSrcweir XResultSet getValue = (XResultSet) UnoRuntime.queryInterface(XResultSet.class,oObj.getPropertyValue(propName)); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir tRes.tested(propName, this.compare(newValue, getValue)); 82*cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException e){ 83*cdf0e10cSrcweir log.println("could not set property '"+ propName +"' to a new value!"); 84*cdf0e10cSrcweir tRes.tested(propName, false); 85*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e){ 86*cdf0e10cSrcweir log.println("could not set property '"+ propName +"' to a new value!"); 87*cdf0e10cSrcweir tRes.tested(propName, false); 88*cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e){ 89*cdf0e10cSrcweir if (this.isOptional(propName)){ 90*cdf0e10cSrcweir // skipping optional property test 91*cdf0e10cSrcweir log.println("Property '" + propName 92*cdf0e10cSrcweir + "' is optional and not supported"); 93*cdf0e10cSrcweir tRes.tested(propName,true); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir } else { 96*cdf0e10cSrcweir log.println("could not get property '"+ propName +"' from XPropertySet!"); 97*cdf0e10cSrcweir tRes.tested(propName, false); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e){ 100*cdf0e10cSrcweir log.println("could not get property '"+ propName +"' from XPropertySet!"); 101*cdf0e10cSrcweir tRes.tested(propName, false); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir /** 106*cdf0e10cSrcweir * Tested with custom property tester. 107*cdf0e10cSrcweir */ 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir public void _ActiveConnection() { 110*cdf0e10cSrcweir String propName = "ActiveConnection"; 111*cdf0e10cSrcweir try{ 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir log.println("try to get value from property..."); 114*cdf0e10cSrcweir XConnection oldValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,oObj.getPropertyValue(propName)); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir log.println("try to get value from object relation..."); 117*cdf0e10cSrcweir XConnection newValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,tEnv.getObjRelation("MailMerge.XConnection")); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir log.println("set property to a new value..."); 120*cdf0e10cSrcweir oObj.setPropertyValue(propName, newValue); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir log.println("get the new value..."); 123*cdf0e10cSrcweir XConnection getValue = (XConnection) UnoRuntime.queryInterface(XConnection.class,oObj.getPropertyValue(propName)); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir tRes.tested(propName, this.compare(newValue, getValue)); 126*cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException e){ 127*cdf0e10cSrcweir log.println("could not set property '"+ propName +"' to a new value! " + e.toString()); 128*cdf0e10cSrcweir tRes.tested(propName, false); 129*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e){ 130*cdf0e10cSrcweir log.println("could not set property '"+ propName +"' to a new value! " + e.toString()); 131*cdf0e10cSrcweir tRes.tested(propName, false); 132*cdf0e10cSrcweir } catch (com.sun.star.beans.UnknownPropertyException e){ 133*cdf0e10cSrcweir if (this.isOptional(propName)){ 134*cdf0e10cSrcweir // skipping optional property test 135*cdf0e10cSrcweir log.println("Property '" + propName 136*cdf0e10cSrcweir + "' is optional and not supported"); 137*cdf0e10cSrcweir tRes.tested(propName,true); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir } else { 140*cdf0e10cSrcweir log.println("could not get property '"+ propName +"' from XPropertySet!"); 141*cdf0e10cSrcweir tRes.tested(propName, false); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e){ 144*cdf0e10cSrcweir log.println("could not get property '"+ propName +"' from XPropertySet!"); 145*cdf0e10cSrcweir tRes.tested(propName, false); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir /** 150*cdf0e10cSrcweir * Tested with custom property tester. 151*cdf0e10cSrcweir */ 152*cdf0e10cSrcweir public void _DocumentURL() { 153*cdf0e10cSrcweir log.println("Testing with custom Property tester") ; 154*cdf0e10cSrcweir testProperty("DocumentURL", DocumentURLTester) ; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /** 158*cdf0e10cSrcweir * Tested with custom property tester. 159*cdf0e10cSrcweir */ 160*cdf0e10cSrcweir public void _OutputURL() { 161*cdf0e10cSrcweir log.println("Testing with custom Property tester") ; 162*cdf0e10cSrcweir testProperty("OutputURL", URLTester) ; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir /** 166*cdf0e10cSrcweir * Forces environment recreation. 167*cdf0e10cSrcweir */ 168*cdf0e10cSrcweir protected void after() { 169*cdf0e10cSrcweir disposeEnvironment(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir } //finish class _MailMerge 174*cdf0e10cSrcweir 175