1*76b6b121SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*76b6b121SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*76b6b121SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*76b6b121SAndrew Rist * distributed with this work for additional information 6*76b6b121SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*76b6b121SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*76b6b121SAndrew Rist * "License"); you may not use this file except in compliance 9*76b6b121SAndrew Rist * with the License. You may obtain a copy of the License at 10*76b6b121SAndrew Rist * 11*76b6b121SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*76b6b121SAndrew Rist * 13*76b6b121SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*76b6b121SAndrew Rist * software distributed under the License is distributed on an 15*76b6b121SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*76b6b121SAndrew Rist * KIND, either express or implied. See the License for the 17*76b6b121SAndrew Rist * specific language governing permissions and limitations 18*76b6b121SAndrew Rist * under the License. 19*76b6b121SAndrew Rist * 20*76b6b121SAndrew Rist *************************************************************/ 21*76b6b121SAndrew Rist 22*76b6b121SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package complex.ModuleManager; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.beans.*; 27cdf0e10cSrcweir import com.sun.star.frame.*; 28cdf0e10cSrcweir import com.sun.star.lang.*; 29cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 31cdf0e10cSrcweir import com.sun.star.util.*; 32cdf0e10cSrcweir import com.sun.star.container.*; 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir // ---------- junit imports ----------------- 37cdf0e10cSrcweir import org.junit.After; 38cdf0e10cSrcweir import org.junit.AfterClass; 39cdf0e10cSrcweir import org.junit.Before; 40cdf0e10cSrcweir import org.junit.BeforeClass; 41cdf0e10cSrcweir import org.junit.Test; 42cdf0e10cSrcweir import org.openoffice.test.OfficeConnection; 43cdf0e10cSrcweir import static org.junit.Assert.*; 44cdf0e10cSrcweir // ------------------------------------------ 45cdf0e10cSrcweir 46cdf0e10cSrcweir //----------------------------------------------- 47cdf0e10cSrcweir /** @short todo document me 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir public class CheckXModuleManager 50cdf0e10cSrcweir { 51cdf0e10cSrcweir //------------------------------------------- 52cdf0e10cSrcweir // some const 53cdf0e10cSrcweir 54cdf0e10cSrcweir //------------------------------------------- 55cdf0e10cSrcweir // member 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** points to the global uno service manager. */ 58cdf0e10cSrcweir private XMultiServiceFactory m_xSmgr = null; 59cdf0e10cSrcweir 60cdf0e10cSrcweir /** the module manager for testing. */ 61cdf0e10cSrcweir private XModuleManager m_xMM = null; 62cdf0e10cSrcweir 63cdf0e10cSrcweir /** a special frame used to load documents there. */ 64cdf0e10cSrcweir private XComponentLoader m_xLoader = null; 65cdf0e10cSrcweir 66cdf0e10cSrcweir //------------------------------------------- 67cdf0e10cSrcweir // test environment 68cdf0e10cSrcweir 69cdf0e10cSrcweir //------------------------------------------- 70cdf0e10cSrcweir /** @short A function to tell the framework, 71cdf0e10cSrcweir which test functions are available. 72cdf0e10cSrcweir 73cdf0e10cSrcweir @return All test methods. 74cdf0e10cSrcweir @todo Think about selection of tests from outside ... 75cdf0e10cSrcweir */ 76cdf0e10cSrcweir // public String[] getTestMethodNames() 77cdf0e10cSrcweir // { 78cdf0e10cSrcweir // return new String[] 79cdf0e10cSrcweir // { 80cdf0e10cSrcweir // "checkModuleIdentification" , 81cdf0e10cSrcweir // "checkModuleConfigurationReadable" , 82cdf0e10cSrcweir // "checkModuleConfigurationWriteable", 83cdf0e10cSrcweir // "checkModuleConfigurationQueries" 84cdf0e10cSrcweir // }; 85cdf0e10cSrcweir // } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //------------------------------------------- 88cdf0e10cSrcweir /** @short Create the environment for following tests. 89cdf0e10cSrcweir 90cdf0e10cSrcweir @descr Use either a component loader from desktop or 91cdf0e10cSrcweir from frame 92cdf0e10cSrcweir */ before()93cdf0e10cSrcweir @Before public void before() 94cdf0e10cSrcweir throws java.lang.Exception 95cdf0e10cSrcweir { 96cdf0e10cSrcweir // get uno service manager from global test environment 97cdf0e10cSrcweir m_xSmgr = getMSF(); 98cdf0e10cSrcweir 99cdf0e10cSrcweir // create module manager 100cdf0e10cSrcweir m_xMM = UnoRuntime.queryInterface(XModuleManager.class, m_xSmgr.createInstance("com.sun.star.frame.ModuleManager")); 101cdf0e10cSrcweir 102cdf0e10cSrcweir // create desktop instance to create a special frame to load documents there. 103cdf0e10cSrcweir XFrame xDesktop = UnoRuntime.queryInterface(XFrame.class, m_xSmgr.createInstance("com.sun.star.frame.Desktop")); 104cdf0e10cSrcweir 105cdf0e10cSrcweir m_xLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop.findFrame("_blank", 0)); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir //------------------------------------------- 109cdf0e10cSrcweir /** @short close the environment. 110cdf0e10cSrcweir */ after()111cdf0e10cSrcweir @After public void after() 112cdf0e10cSrcweir throws java.lang.Exception 113cdf0e10cSrcweir { 114cdf0e10cSrcweir XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, m_xLoader); 115cdf0e10cSrcweir xClose.close(false); 116cdf0e10cSrcweir 117cdf0e10cSrcweir m_xLoader = null; 118cdf0e10cSrcweir m_xMM = null; 119cdf0e10cSrcweir m_xSmgr = null; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir //------------------------------------------- 123cdf0e10cSrcweir /** @todo document me 124cdf0e10cSrcweir */ checkModuleIdentification()125cdf0e10cSrcweir @Test public void checkModuleIdentification() 126cdf0e10cSrcweir throws java.lang.Exception 127cdf0e10cSrcweir { 128cdf0e10cSrcweir impl_identifyModulesBasedOnDocs("com.sun.star.text.TextDocument" ); 129cdf0e10cSrcweir impl_identifyModulesBasedOnDocs("com.sun.star.text.WebDocument" ); 130cdf0e10cSrcweir impl_identifyModulesBasedOnDocs("com.sun.star.text.GlobalDocument" ); 131cdf0e10cSrcweir impl_identifyModulesBasedOnDocs("com.sun.star.formula.FormulaProperties" ); 132cdf0e10cSrcweir impl_identifyModulesBasedOnDocs("com.sun.star.sheet.SpreadsheetDocument" ); 133cdf0e10cSrcweir impl_identifyModulesBasedOnDocs("com.sun.star.drawing.DrawingDocument" ); 134cdf0e10cSrcweir impl_identifyModulesBasedOnDocs("com.sun.star.presentation.PresentationDocument"); 135cdf0e10cSrcweir impl_identifyModulesBasedOnDocs("com.sun.star.sdb.OfficeDatabaseDocument" ); 136cdf0e10cSrcweir // TODO: fails 137cdf0e10cSrcweir // impl_identifyModulesBasedOnDocs("com.sun.star.chart.ChartDocument" ); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir //------------------------------------------- 141cdf0e10cSrcweir /** @todo document me 142cdf0e10cSrcweir */ checkModuleConfigurationReadable()143cdf0e10cSrcweir @Test public void checkModuleConfigurationReadable() 144cdf0e10cSrcweir throws java.lang.Exception 145cdf0e10cSrcweir { 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir //------------------------------------------- 149cdf0e10cSrcweir /** @todo document me 150cdf0e10cSrcweir */ checkModuleConfigurationWriteable()151cdf0e10cSrcweir @Test public void checkModuleConfigurationWriteable() 152cdf0e10cSrcweir throws java.lang.Exception 153cdf0e10cSrcweir { 154cdf0e10cSrcweir // modules supporting real documents 155cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.text.TextDocument" ); 156cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.text.WebDocument" ); 157cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.text.GlobalDocument" ); 158cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.formula.FormulaProperties" ); 159cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.sheet.SpreadsheetDocument" ); 160cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.drawing.DrawingDocument" ); 161cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.presentation.PresentationDocument"); 162cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.OfficeDatabaseDocument" ); 163cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.chart.ChartDocument" ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir // other modules 166cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.FormDesign" ); 167cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.TextReportDesign" ); 168cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.RelationDesign" ); 169cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.QueryDesign" ); 170cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.TableDesign" ); 171cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.sdb.DataSourceBrowser"); 172cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.frame.Bibliography" ); 173cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.script.BasicIDE" ); 174cdf0e10cSrcweir impl_checkReadOnlyPropsOfModule("com.sun.star.frame.StartModule" ); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir //------------------------------------------- 178cdf0e10cSrcweir /** @todo document me 179cdf0e10cSrcweir */ checkModuleConfigurationQueries()180cdf0e10cSrcweir @Test public void checkModuleConfigurationQueries() 181cdf0e10cSrcweir throws java.lang.Exception 182cdf0e10cSrcweir { 183cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.text.TextDocument" ); 184cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.text.WebDocument" ); 185cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.text.GlobalDocument" ); 186cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.formula.FormulaProperties" ); 187cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.sheet.SpreadsheetDocument" ); 188cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.drawing.DrawingDocument" ); 189cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.presentation.PresentationDocument"); 190cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.sdb.OfficeDatabaseDocument" ); 191cdf0e10cSrcweir impl_searchModulesByDocumentService("com.sun.star.chart.ChartDocument" ); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir //------------------------------------------- 195cdf0e10cSrcweir /** @todo document me 196cdf0e10cSrcweir */ impl_searchModulesByDocumentService(String sDocumentService)197cdf0e10cSrcweir private void impl_searchModulesByDocumentService(String sDocumentService) 198cdf0e10cSrcweir throws java.lang.Exception 199cdf0e10cSrcweir { 200cdf0e10cSrcweir System.out.println("search modules matching document service '"+sDocumentService+"' ..."); 201cdf0e10cSrcweir 202cdf0e10cSrcweir NamedValue[] lProps = new NamedValue[1]; 203cdf0e10cSrcweir lProps[0] = new NamedValue(); 204cdf0e10cSrcweir lProps[0].Name = "ooSetupFactoryDocumentService"; 205cdf0e10cSrcweir lProps[0].Value = sDocumentService; 206cdf0e10cSrcweir 207cdf0e10cSrcweir XContainerQuery xMM = UnoRuntime.queryInterface(XContainerQuery.class, m_xMM); 208cdf0e10cSrcweir XEnumeration xResult = xMM.createSubSetEnumerationByProperties(lProps); 209cdf0e10cSrcweir while(xResult.hasMoreElements()) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir PropertyValue[] lModuleProps = (PropertyValue[])AnyConverter.toArray(xResult.nextElement()); 212cdf0e10cSrcweir int c = lModuleProps.length; 213cdf0e10cSrcweir int i = 0; 214cdf0e10cSrcweir String sFoundModule = ""; 215cdf0e10cSrcweir String sFoundDocService = ""; 216cdf0e10cSrcweir for (i=0; i<c; ++i) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir if (lModuleProps[i].Name.equals("ooSetupFactoryModuleIdentifier")) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir sFoundModule = AnyConverter.toString(lModuleProps[i].Value); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir if (lModuleProps[i].Name.equals("ooSetupFactoryDocumentService")) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir sFoundDocService = AnyConverter.toString(lModuleProps[i].Value); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir if (sFoundModule.length() < 1) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir fail("Miss module identifier in result set. Returned data are incomplete."); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir if ( ! sFoundDocService.equals(sDocumentService)) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir fail("Query returned wrong module '" + sFoundModule + "' with DocumentService='" + sFoundDocService + "'."); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir System.out.println("Found module '"+sFoundModule+"'."); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir //------------------------------------------- 243cdf0e10cSrcweir /** @todo document me 244cdf0e10cSrcweir */ impl_identifyModulesBasedOnDocs(String sModule)245cdf0e10cSrcweir private void impl_identifyModulesBasedOnDocs(String sModule) 246cdf0e10cSrcweir throws java.lang.Exception 247cdf0e10cSrcweir { 248cdf0e10cSrcweir System.out.println("check identification of module '"+sModule+"' ..."); 249cdf0e10cSrcweir 250cdf0e10cSrcweir XNameAccess xMM = UnoRuntime.queryInterface(XNameAccess.class, m_xMM); 251cdf0e10cSrcweir PropertyValue[] lModuleProps = (PropertyValue[])AnyConverter.toArray(xMM.getByName(sModule)); 252cdf0e10cSrcweir int c = lModuleProps.length; 253cdf0e10cSrcweir int i = 0; 254cdf0e10cSrcweir String sFactoryURL = ""; 255cdf0e10cSrcweir 256cdf0e10cSrcweir for (i=0; i<c; ++i) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir if (lModuleProps[i].Name.equals("ooSetupFactoryEmptyDocumentURL")) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir sFactoryURL = AnyConverter.toString(lModuleProps[i].Value); 261cdf0e10cSrcweir break; 262cdf0e10cSrcweir } 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir PropertyValue[] lArgs = new PropertyValue[1]; 266cdf0e10cSrcweir lArgs[0] = new PropertyValue(); 267cdf0e10cSrcweir lArgs[0].Name = "Hidden"; 268cdf0e10cSrcweir lArgs[0].Value = Boolean.TRUE; 269cdf0e10cSrcweir 270cdf0e10cSrcweir XComponent xModel = m_xLoader.loadComponentFromURL(sFactoryURL, "_self", 0, lArgs); 271cdf0e10cSrcweir XFrame xFrame = UnoRuntime.queryInterface(XFrame.class, m_xLoader); 272cdf0e10cSrcweir XController xController = xFrame.getController(); 273cdf0e10cSrcweir 274cdf0e10cSrcweir String sModuleFrame = m_xMM.identify(xFrame ); 275cdf0e10cSrcweir String sModuleController = m_xMM.identify(xController); 276cdf0e10cSrcweir String sModuleModel = m_xMM.identify(xModel ); 277cdf0e10cSrcweir 278cdf0e10cSrcweir if ( ! sModuleFrame.equals(sModule)) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir fail("Identification of module '" + sModule + "' failed if frame was used as entry point."); 281cdf0e10cSrcweir } 282cdf0e10cSrcweir if ( ! sModuleController.equals(sModule)) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir fail("Identification of module '" + sModule + "' failed if controller was used as entry point."); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir if ( ! sModuleModel.equals(sModule)) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir fail("Identification of module '" + sModule + "' failed if model was used as entry point."); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir //------------------------------------------- 293cdf0e10cSrcweir /** @todo document me 294cdf0e10cSrcweir */ impl_checkReadOnlyPropsOfModule(String sModule)295cdf0e10cSrcweir private void impl_checkReadOnlyPropsOfModule(String sModule) 296cdf0e10cSrcweir throws java.lang.Exception 297cdf0e10cSrcweir { 298cdf0e10cSrcweir XNameReplace xWrite = UnoRuntime.queryInterface(XNameReplace.class, m_xMM); 299cdf0e10cSrcweir 300cdf0e10cSrcweir impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryDocumentService" , "test"); 301cdf0e10cSrcweir impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryActualFilter" , "test"); 302cdf0e10cSrcweir impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryActualTemplateFilter", "test"); 303cdf0e10cSrcweir impl_checkReadOnlyPropOfModule(xWrite, sModule, "ooSetupFactoryEmptyDocumentURL" , "test"); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir //------------------------------------------- 307cdf0e10cSrcweir /** @todo document me 308cdf0e10cSrcweir */ impl_checkReadOnlyPropOfModule(XNameReplace xMM , String sModule , String sPropName , Object aPropValue )309cdf0e10cSrcweir private void impl_checkReadOnlyPropOfModule(XNameReplace xMM , 310cdf0e10cSrcweir String sModule , 311cdf0e10cSrcweir String sPropName , 312cdf0e10cSrcweir Object aPropValue ) 313cdf0e10cSrcweir throws java.lang.Exception 314cdf0e10cSrcweir { 315cdf0e10cSrcweir PropertyValue[] lChanges = new PropertyValue[1]; 316cdf0e10cSrcweir lChanges[0] = new PropertyValue(); 317cdf0e10cSrcweir lChanges[0].Name = sPropName; 318cdf0e10cSrcweir lChanges[0].Value = aPropValue; 319cdf0e10cSrcweir 320cdf0e10cSrcweir // Note: Exception is expected ! 321cdf0e10cSrcweir System.out.println("check readonly state of module '"+sModule+"' for property '"+sPropName+"' ..."); 322cdf0e10cSrcweir try 323cdf0e10cSrcweir { 324cdf0e10cSrcweir xMM.replaceByName(sModule, lChanges); 325cdf0e10cSrcweir fail("Was able to write READONLY property '"+sPropName+"' of module '"+sModule+"' configuration."); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir catch(Throwable ex) 328cdf0e10cSrcweir {} 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir 332cdf0e10cSrcweir getMSF()333cdf0e10cSrcweir private XMultiServiceFactory getMSF() 334cdf0e10cSrcweir { 335cdf0e10cSrcweir final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); 336cdf0e10cSrcweir return xMSF1; 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir // setup and close connections setUpConnection()340cdf0e10cSrcweir @BeforeClass public static void setUpConnection() throws Exception { 341cdf0e10cSrcweir System.out.println("setUpConnection()"); 342cdf0e10cSrcweir connection.setUp(); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir tearDownConnection()345cdf0e10cSrcweir @AfterClass public static void tearDownConnection() 346cdf0e10cSrcweir throws InterruptedException, com.sun.star.uno.Exception 347cdf0e10cSrcweir { 348cdf0e10cSrcweir System.out.println("tearDownConnection()"); 349cdf0e10cSrcweir connection.tearDown(); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir private static final OfficeConnection connection = new OfficeConnection(); 353cdf0e10cSrcweir 354cdf0e10cSrcweir } 355