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.frame; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir import util.utils; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.beans.Property; 30cdf0e10cSrcweir import com.sun.star.frame.XDocumentTemplates; 31cdf0e10cSrcweir import com.sun.star.frame.XStorable; 32cdf0e10cSrcweir import com.sun.star.sdbc.XResultSet; 33cdf0e10cSrcweir import com.sun.star.sdbc.XRow; 34cdf0e10cSrcweir import com.sun.star.ucb.Command; 35cdf0e10cSrcweir import com.sun.star.ucb.OpenCommandArgument2; 36cdf0e10cSrcweir import com.sun.star.ucb.XCommandProcessor; 37cdf0e10cSrcweir import com.sun.star.ucb.XContent; 38cdf0e10cSrcweir import com.sun.star.ucb.XContentAccess; 39cdf0e10cSrcweir import com.sun.star.ucb.XDynamicResultSet; 40cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 41cdf0e10cSrcweir import com.sun.star.uno.Type; 42cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 43cdf0e10cSrcweir /** 44cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XDesktop</code> 45cdf0e10cSrcweir * interface methods: 46cdf0e10cSrcweir * <ul> 47cdf0e10cSrcweir * <li><code> getContent() </code></li> 48cdf0e10cSrcweir * <li><code> storeTemplate() </code></li> 49cdf0e10cSrcweir * <li><code> addTemplate() </code></li> 50cdf0e10cSrcweir * <li><code> removeTemplate() </code></li> 51cdf0e10cSrcweir * <li><code> renameTemplate() </code></li> 52cdf0e10cSrcweir * <li><code> addGroup() </code></li> 53cdf0e10cSrcweir * <li><code> removeGroup() </code></li> 54cdf0e10cSrcweir * <li><code> renameGroup() </code></li> 55cdf0e10cSrcweir * <li><code> update() </code></li> 56cdf0e10cSrcweir * </ul><p> 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir public class _XDocumentTemplates extends MultiMethodTest { 59cdf0e10cSrcweir public XDocumentTemplates oObj = null; // oObj filled by MultiMethodTest 60cdf0e10cSrcweir protected XContent content = null; 61cdf0e10cSrcweir /** 62cdf0e10cSrcweir * Test calls the method and prints contents list to log.<p> 63cdf0e10cSrcweir * Has <b> OK </b> status if the XContent isn't empty. 64cdf0e10cSrcweir */ 65cdf0e10cSrcweir public void _getContent() { 66cdf0e10cSrcweir content = oObj.getContent(); 67cdf0e10cSrcweir log.println("Content list:" + getContentList(content)); 68cdf0e10cSrcweir tRes.tested("getContent()", content != null); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir /** 72cdf0e10cSrcweir * Test calls the method and checks that new group was added. <p> 73cdf0e10cSrcweir * Has <b> OK </b> status if method returns true and new group was added. 74cdf0e10cSrcweir */ 75cdf0e10cSrcweir public void _addGroup() { 76cdf0e10cSrcweir requiredMethod("getContent()"); 77cdf0e10cSrcweir if (getSubContent(content, "XDocumentTemplatesTemp") != null ) { 78cdf0e10cSrcweir oObj.removeGroup("XDocumentTemplatesTemp"); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir if (getSubContent(content, "XDocumentTemplates") != null ) { 81cdf0e10cSrcweir oObj.removeGroup("XDocumentTemplates"); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir boolean res = oObj.addGroup("XDocumentTemplatesTemp"); 84cdf0e10cSrcweir log.println("Method returned: " + res); 85cdf0e10cSrcweir res &= getSubContent(content, "XDocumentTemplatesTemp") != null; 86cdf0e10cSrcweir tRes.tested("addGroup()", res); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir XContent groupContent = null; 90cdf0e10cSrcweir /** 91cdf0e10cSrcweir * Test calls the method and checks that content has no group with old name 92cdf0e10cSrcweir * and that content has group with new name. <p> 93cdf0e10cSrcweir * Has <b> OK </b> status if method returns true, content has no group with 94cdf0e10cSrcweir * old name and content has group with new name.<p> 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir public void _renameGroup() { 97cdf0e10cSrcweir requiredMethod("addGroup()"); 98cdf0e10cSrcweir boolean res = oObj.renameGroup("XDocumentTemplatesTemp", 99cdf0e10cSrcweir "XDocumentTemplates"); 100cdf0e10cSrcweir log.println("Method returned: " + res); 101cdf0e10cSrcweir groupContent = getSubContent(content, "XDocumentTemplates"); 102cdf0e10cSrcweir res &= getSubContent(content, "XDocumentTemplatesTemp") == null; 103cdf0e10cSrcweir res &= groupContent != null; 104cdf0e10cSrcweir tRes.tested("renameGroup()", res); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir /** 108cdf0e10cSrcweir * Test calls the method and checks that group content has new template. <p> 109cdf0e10cSrcweir * Has <b> OK </b> status if method returns true and group content has new 110cdf0e10cSrcweir * template.<p> 111cdf0e10cSrcweir */ 112cdf0e10cSrcweir public void _addTemplate() { 113cdf0e10cSrcweir requiredMethod("renameGroup()"); 114cdf0e10cSrcweir String testDoc = utils.getFullTestURL("report.stw"); 115cdf0e10cSrcweir log.println("Adding template from " + testDoc); 116cdf0e10cSrcweir boolean res = oObj.addTemplate("XDocumentTemplates", 117cdf0e10cSrcweir "ANewTemplateTemp",testDoc); 118cdf0e10cSrcweir log.println("Method returned: " + res); 119cdf0e10cSrcweir res &= getSubContent(groupContent, "ANewTemplateTemp") != null; 120cdf0e10cSrcweir tRes.tested("addTemplate()", res); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir /** 124cdf0e10cSrcweir * Test calls the method and checks that group content has no template with 125cdf0e10cSrcweir * old name and that group content has template with new name. <p> 126cdf0e10cSrcweir * Has <b> OK </b> status if method returns true, group content has no 127cdf0e10cSrcweir * template with old name and group content has template with new name.<p> 128cdf0e10cSrcweir */ 129cdf0e10cSrcweir public void _renameTemplate() { 130cdf0e10cSrcweir requiredMethod("addTemplate()"); 131cdf0e10cSrcweir boolean res = oObj.renameTemplate("XDocumentTemplates", 132cdf0e10cSrcweir "ANewTemplateTemp", 133cdf0e10cSrcweir "ANewTemplate"); 134cdf0e10cSrcweir log.println("Method returned: " + res); 135cdf0e10cSrcweir res &= getSubContent(groupContent, "ANewTemplateTemp") == null; 136cdf0e10cSrcweir res &= getSubContent(groupContent, "ANewTemplate") != null; 137cdf0e10cSrcweir 138cdf0e10cSrcweir tRes.tested("renameTemplate()", res); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir /** 142cdf0e10cSrcweir * Test calls the method and checks that group content has new template. <p> 143cdf0e10cSrcweir * Has <b> OK </b> status if method returns true and new template was created.<p> 144cdf0e10cSrcweir */ 145cdf0e10cSrcweir public void _storeTemplate() { 146cdf0e10cSrcweir requiredMethod("renameGroup()"); 147cdf0e10cSrcweir XStorable store = (XStorable) tEnv.getObjRelation("Store"); 148cdf0e10cSrcweir boolean res = oObj.storeTemplate("XDocumentTemplates", 149cdf0e10cSrcweir "NewStoreTemplate", 150cdf0e10cSrcweir store); 151cdf0e10cSrcweir log.println("Method returned: " + res); 152cdf0e10cSrcweir res &= getSubContent(groupContent, "NewStoreTemplate") != null; 153cdf0e10cSrcweir tRes.tested("storeTemplate()", res); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir /** 157cdf0e10cSrcweir * Test calls the method and checks that group content has no deleted template. <p> 158cdf0e10cSrcweir * Has <b> OK </b> status if method returns true and group content has no 159cdf0e10cSrcweir * deleted template.<p> 160cdf0e10cSrcweir */ 161cdf0e10cSrcweir public void _removeTemplate() { 162cdf0e10cSrcweir requiredMethod("renameTemplate()"); 163cdf0e10cSrcweir boolean res = oObj.removeTemplate("XDocumentTemplates", "ANewTemplate"); 164cdf0e10cSrcweir log.println("Method returned: " + res); 165cdf0e10cSrcweir res &= getSubContent(groupContent, "ANewTemplate") == null; 166cdf0e10cSrcweir tRes.tested("removeTemplate()", res); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir /** 170cdf0e10cSrcweir * Test calls the method and checks that content has no deleted group. <p> 171cdf0e10cSrcweir * Has <b> OK </b> status if method returns true and content has no deleted 172cdf0e10cSrcweir * group.<p> 173cdf0e10cSrcweir */ 174cdf0e10cSrcweir public void _removeGroup() { 175cdf0e10cSrcweir requiredMethod("renameGroup()"); 176cdf0e10cSrcweir executeMethod("renameTemplate()"); 177cdf0e10cSrcweir boolean res = oObj.removeGroup("XDocumentTemplates"); 178cdf0e10cSrcweir log.println("Method returned: " + res); 179cdf0e10cSrcweir res &= getSubContent(content, "XDocumentTemplates") == null; 180cdf0e10cSrcweir tRes.tested("removeGroup()", res); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir /** 184cdf0e10cSrcweir * Test calls the method. <p> 185cdf0e10cSrcweir * Has <b> OK </b> status if no exception occurs.<p> 186cdf0e10cSrcweir */ 187cdf0e10cSrcweir public void _update() { 188cdf0e10cSrcweir oObj.update(); 189cdf0e10cSrcweir tRes.tested("update()",true); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir /** 193cdf0e10cSrcweir * Returns the string representation of content passed as parameter. 194cdf0e10cSrcweir */ 195cdf0e10cSrcweir protected String getContentList(XContent content) { 196cdf0e10cSrcweir XResultSet statRes = getStatResultSet(content); 197cdf0e10cSrcweir String ret = ""; 198cdf0e10cSrcweir try { 199cdf0e10cSrcweir statRes.first(); 200cdf0e10cSrcweir XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, statRes); 201cdf0e10cSrcweir while(! statRes.isAfterLast()) { 202cdf0e10cSrcweir ret += "\n " + row.getString(1); 203cdf0e10cSrcweir statRes.next(); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e) { 206cdf0e10cSrcweir log.println("Exception occured:" + e); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir return ret; 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir protected XResultSet getStatResultSet(XContent content) { 213cdf0e10cSrcweir XResultSet statResSet = null; 214cdf0e10cSrcweir try { 215cdf0e10cSrcweir statResSet = getDynaResultSet(content).getStaticResultSet(); 216cdf0e10cSrcweir } catch(com.sun.star.ucb.ListenerAlreadySetException e) { 217cdf0e10cSrcweir log.println("Exception occured:" + e); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir return statResSet; 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir protected XDynamicResultSet getDynaResultSet(XContent content) { 223cdf0e10cSrcweir Command command = new Command(); 224cdf0e10cSrcweir OpenCommandArgument2 comArg = new OpenCommandArgument2(); 225cdf0e10cSrcweir Property[] comProps = new Property[1]; 226cdf0e10cSrcweir comArg.Mode = com.sun.star.ucb.OpenMode.ALL; 227cdf0e10cSrcweir comProps[0] = new Property(); 228cdf0e10cSrcweir comProps[0].Name = "Title"; 229cdf0e10cSrcweir comArg.Properties = comProps; 230cdf0e10cSrcweir 231cdf0e10cSrcweir command.Name = "open"; 232cdf0e10cSrcweir command.Handle = -1; 233cdf0e10cSrcweir command.Argument = comArg; 234cdf0e10cSrcweir 235cdf0e10cSrcweir XCommandProcessor comProc = (XCommandProcessor) 236cdf0e10cSrcweir UnoRuntime.queryInterface(XCommandProcessor.class, content); 237cdf0e10cSrcweir 238cdf0e10cSrcweir XDynamicResultSet DynResSet = null; 239cdf0e10cSrcweir try { 240cdf0e10cSrcweir DynResSet = (XDynamicResultSet) AnyConverter.toObject( 241cdf0e10cSrcweir new Type(XDynamicResultSet.class),comProc.execute(command, 0, null)); 242cdf0e10cSrcweir } catch(com.sun.star.ucb.CommandAbortedException e) { 243cdf0e10cSrcweir log.println("Couldn't execute command:" + e); 244cdf0e10cSrcweir } catch(com.sun.star.uno.Exception e) { 245cdf0e10cSrcweir log.println("Couldn't execute command:" + e); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir return DynResSet; 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir protected XContent getSubContent(XContent content, String subName) { 252cdf0e10cSrcweir XResultSet statRes = getStatResultSet(content); 253cdf0e10cSrcweir XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, statRes); 254cdf0e10cSrcweir XContentAccess contAcc = (XContentAccess) 255cdf0e10cSrcweir UnoRuntime.queryInterface(XContentAccess.class, statRes); 256cdf0e10cSrcweir XContent subContent = null; 257cdf0e10cSrcweir try { 258cdf0e10cSrcweir statRes.first(); 259cdf0e10cSrcweir while(!statRes.isAfterLast()) { 260cdf0e10cSrcweir if ( subName.equals(row.getString(1)) ) { 261cdf0e10cSrcweir subContent = contAcc.queryContent(); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir statRes.next(); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir } catch(com.sun.star.sdbc.SQLException e) { 266cdf0e10cSrcweir log.println("Exception occured:" + e); 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir return subContent; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273