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 package complex.dbaccess; 24 25 import com.sun.star.beans.PropertyState; 26 import com.sun.star.beans.PropertyValue; 27 import com.sun.star.container.XEnumeration; 28 import com.sun.star.container.XEnumerationAccess; 29 import com.sun.star.frame.FrameSearchFlag; 30 import com.sun.star.frame.XComponentLoader; 31 import com.sun.star.frame.XController; 32 import com.sun.star.frame.XDispatch; 33 import com.sun.star.frame.XDispatchProvider; 34 import com.sun.star.frame.XFrame; 35 import com.sun.star.frame.XModel; 36 import com.sun.star.lang.XComponent; 37 import com.sun.star.sdb.CommandType; 38 import com.sun.star.uno.Exception; 39 import com.sun.star.uno.UnoRuntime; 40 import com.sun.star.util.URL; 41 import com.sun.star.util.XURLTransformer; 42 import com.sun.star.view.XSelectionSupplier; 43 import java.io.IOException; 44 45 46 // ---------- junit imports ----------------- 47 import org.junit.After; 48 // import org.junit.AfterClass; 49 import org.junit.Before; 50 // import org.junit.BeforeClass; 51 import org.junit.Test; 52 // import org.openoffice.test.OfficeConnection; 53 import static org.junit.Assert.*; 54 // ------------------------------------------ 55 56 57 /** complex test case for Base's application UI 58 */ 59 public class Beamer extends TestCase 60 { 61 62 private XModel docModel; 63 Beamer()64 public Beamer() 65 { 66 super(); 67 } 68 69 // -------------------------------------------------------------------------------------------------------- 70 @Before 71 @Override before()72 public void before() throws Exception, java.lang.Exception 73 { 74 // load it into a frame 75 final Object object = getMSF().createInstance("com.sun.star.frame.Desktop"); 76 final XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, object); 77 final XComponent loadedComponent = xComponentLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, new PropertyValue[0]); 78 // get the controller, which provides access to various UI operations 79 docModel = UnoRuntime.queryInterface(XModel.class, loadedComponent); 80 } 81 82 // -------------------------------------------------------------------------------------------------------- 83 @After 84 @Override after()85 public void after() 86 { 87 } 88 89 // -------------------------------------------------------------------------------------------------------- 90 @Test testBeamer()91 public void testBeamer() throws Exception, IOException, java.lang.Exception 92 { 93 final XController controller = docModel.getCurrentController(); 94 final XFrame frame = controller.getFrame(); 95 final XDispatchProvider dispatchP = UnoRuntime.queryInterface(XDispatchProvider.class, frame); 96 URL command = new URL(); 97 command.Complete = ".uno:ViewDataSourceBrowser"; 98 99 Object instance = getMSF().createInstance("com.sun.star.util.URLTransformer"); 100 XURLTransformer atrans = UnoRuntime.queryInterface(XURLTransformer.class, instance); 101 com.sun.star.util.URL[] aURLA = new com.sun.star.util.URL[1]; 102 aURLA[0] = command; 103 atrans.parseStrict(aURLA); 104 command = aURLA[0]; 105 106 final XDispatch dispatch = dispatchP.queryDispatch(command, "_self", FrameSearchFlag.AUTO); 107 assertNotNull(dispatch); 108 dispatch.dispatch(command, new PropertyValue[0]); 109 110 final PropertyValue[] props = new PropertyValue[] 111 { 112 new PropertyValue("DataSourceName", 0, "Bibliography", PropertyState.DIRECT_VALUE), 113 new PropertyValue("CommandType", 0, Integer.valueOf(CommandType.TABLE), PropertyState.DIRECT_VALUE), 114 new PropertyValue("Command", 0, "biblio", PropertyState.DIRECT_VALUE) 115 }; 116 117 final XFrame beamer = frame.findFrame("_beamer", 0); 118 assertNotNull(beamer); 119 final XEnumerationAccess evtBc = UnoRuntime.queryInterface(XEnumerationAccess.class, getMSF().createInstance("com.sun.star.frame.GlobalEventBroadcaster")); 120 XEnumeration enumeration = evtBc.createEnumeration(); 121 int count = -1; 122 while (enumeration.hasMoreElements()) 123 { 124 enumeration.nextElement(); 125 ++count; 126 } 127 final XSelectionSupplier selSup = UnoRuntime.queryInterface(XSelectionSupplier.class, beamer.getController()); 128 selSup.select(props); 129 final com.sun.star.util.XCloseable close = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, frame); 130 close.close(false); 131 132 enumeration = evtBc.createEnumeration(); 133 int count2 = 0; 134 while (enumeration.hasMoreElements()) 135 { 136 enumeration.nextElement(); 137 ++count2; 138 } 139 140 assertTrue("count1 = " + count + " count2 = " + count2, count == count2); 141 } 142 } 143