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
;
25 import lib
.StatusException
;
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
;
40 * Test for object which is represented by service
41 * <code>com.sun.star.sdb.DatabaseContext</code>. <p>
43 * Object implements the following interfaces :
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>
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
{
67 protected void initialize ( TestParameters Param
, PrintWriter log
) {
72 * Creating a Testenvironment for the interfaces to be tested.
73 * Creates service <code>com.sun.star.sdb.DatabaseContext</code>.
74 * Needed object relations :
76 * <li> <code>'XNamingService.RegisterObject'</code> for
77 * {@link ifc.uno._XNamingService} as an
78 * instance of <code>com.sun.star.sdb.DataSource</code>
83 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
84 XInterface oObj
= null;
85 Object oInterface
= null;
86 XMultiServiceFactory xMSF
= null ;
89 xMSF
= Param
.getMSF();
90 oInterface
= xMSF
.createInstance( "com.sun.star.sdb.DatabaseContext" );
92 catch( com
.sun
.star
.uno
.Exception e
) {
93 log
.println("Service not available" );
94 throw new StatusException("Service not available", e
) ;
97 if (oInterface
== null) {
98 log
.println("Service wasn't created") ;
99 throw new StatusException(Status
.failed("Service wasn't created")) ;
102 oObj
= (XInterface
) oInterface
;
104 log
.println( " creating a new environment for object" );
105 TestEnvironment tEnv
= new TestEnvironment( oObj
);
107 // adding obj relation for XNamingService
109 xMSF
= Param
.getMSF();
110 oInterface
= xMSF
.createInstance( "com.sun.star.sdb.DataSource" );
112 XPropertySet xDSProps
= UnoRuntime
.queryInterface(XPropertySet
.class, oInterface
) ;
114 xDSProps
.setPropertyValue("URL", "sdbc:dbase:file:///.") ;
116 XDocumentDataSource xDDS
= UnoRuntime
.queryInterface(XDocumentDataSource
.class, oInterface
);
117 XStorable store
= UnoRuntime
.queryInterface(XStorable
.class,
118 xDDS
.getDatabaseDocument ());
119 String aFile
= utils
.getOfficeTemp (Param
.getMSF ())+"DatabaseContext.odb";
120 log
.println("store to '" + aFile
+ "'");
121 store
.storeAsURL(aFile
,new PropertyValue
[]{});
123 tEnv
.addObjRelation("XNamingService.RegisterObject", oInterface
) ;
125 tEnv
.addObjRelation("INSTANCE", oInterface
);
127 tEnv
.addObjRelation("XContainer.Container",
128 UnoRuntime
.queryInterface(
129 XNamingService
.class, oObj
));
131 } catch (com
.sun
.star
.uno
.Exception e
) {
132 throw new StatusException("Can't create object relation", e
) ;
133 } catch (NullPointerException e
) {
134 throw new StatusException("Can't create object relation", e
) ;
138 } // finish method getTestEnvironment