bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / ODatabaseContext.java
blob595dd7d3d6f70b57790d0c18fb4b9f51a6321aa3
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._dbaccess;
21 import com.sun.star.beans.PropertyValue;
22 import java.io.PrintWriter;
24 import lib.Status;
25 import lib.StatusException;
26 import lib.TestCase;
27 import lib.TestEnvironment;
28 import lib.TestParameters;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
34 import com.sun.star.uno.XNamingService;
35 import com.sun.star.frame.XStorable;
36 import com.sun.star.sdb.XDocumentDataSource;
37 import util.utils;
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.sdb.DatabaseContext</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
46 * <li> <code>com::sun::star::container::XNameAccess</code></li>
47 * <li> <code>com::sun::star::container::XElementAccess</code></li>
48 * <li> <code>com::sun::star::uno::XNamingService</code></li>
49 * </ul>
51 * @see com.sun.star.container.XNameAccess
52 * @see com.sun.star.container.XEnumerationAccess
53 * @see com.sun.star.container.XElementAccess
54 * @see com.sun.star.uno.XNamingService
55 * @see com.sun.star.sdb.DatabaseContext
56 * @see ifc.container._XNameAccess
57 * @see ifc.container._XEnumerationAccess
58 * @see ifc.container._XElementAccess
59 * @see ifc.uno._XNamingService
61 public class ODatabaseContext extends TestCase {
63 /**
64 * Does nothing.
66 protected void initialize ( TestParameters Param, PrintWriter log) {
70 /**
71 * Creating a Testenvironment for the interfaces to be tested.
72 * Creates service <code>com.sun.star.sdb.DatabaseContext</code>.
73 * Needed object relations :
74 * <ul>
75 * <li> <code>'XNamingService.RegisterObject'</code> for
76 * {@link ifc.uno._XNamingService} as an
77 * instance of <code>com.sun.star.sdb.DataSource</code>
78 * service. </li>
79 * </ul>
81 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
82 XInterface oObj = null;
83 Object oInterface = null;
84 XMultiServiceFactory xMSF = null ;
86 try {
87 xMSF = (XMultiServiceFactory)Param.getMSF();
88 oInterface = xMSF.createInstance( "com.sun.star.sdb.DatabaseContext" );
90 catch( com.sun.star.uno.Exception e ) {
91 log.println("Service not available" );
92 throw new StatusException("Service not available", e) ;
95 if (oInterface == null) {
96 log.println("Service wasn't created") ;
97 throw new StatusException(Status.failed("Service wasn't created")) ;
100 oObj = (XInterface) oInterface;
102 log.println( " creating a new environment for object" );
103 TestEnvironment tEnv = new TestEnvironment( oObj );
105 // adding obj relation for XNamingService
106 try {
107 xMSF = (XMultiServiceFactory)Param.getMSF();
108 oInterface = xMSF.createInstance( "com.sun.star.sdb.DataSource" );
110 XPropertySet xDSProps = UnoRuntime.queryInterface(XPropertySet.class, oInterface) ;
112 xDSProps.setPropertyValue("URL", "sdbc:dbase:file:///.") ;
114 XDocumentDataSource xDDS = UnoRuntime.queryInterface(XDocumentDataSource.class, oInterface);
115 XStorable store = UnoRuntime.queryInterface(XStorable.class,
116 xDDS.getDatabaseDocument ());
117 String aFile = utils.getOfficeTemp ((XMultiServiceFactory) Param.getMSF ())+"DatabaseContext.odb";
118 log.println("store to '" + aFile + "'");
119 store.storeAsURL(aFile,new PropertyValue[]{});
121 tEnv.addObjRelation("XNamingService.RegisterObject", oInterface) ;
123 tEnv.addObjRelation("INSTANCE", oInterface);
125 tEnv.addObjRelation("XContainer.Container",
126 UnoRuntime.queryInterface(
127 XNamingService.class, oObj));
129 } catch (com.sun.star.uno.Exception e) {
130 throw new StatusException("Can't create object relation", e) ;
131 } catch (NullPointerException e) {
132 throw new StatusException("Can't create object relation", e) ;
135 return tEnv;
136 } // finish method getTestEnvironment