bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _dbaccess / ODatabaseContext.java
blob2a1e4939a2503fb3aaaade842dc6d87c290ca7ad
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 @Override
67 protected void initialize ( TestParameters Param, PrintWriter log) {
71 /**
72 * Creating a Testenvironment for the interfaces to be tested.
73 * Creates service <code>com.sun.star.sdb.DatabaseContext</code>.
74 * Needed object relations :
75 * <ul>
76 * <li> <code>'XNamingService.RegisterObject'</code> for
77 * {@link ifc.uno._XNamingService} as an
78 * instance of <code>com.sun.star.sdb.DataSource</code>
79 * service. </li>
80 * </ul>
82 @Override
83 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
84 XInterface oObj = null;
85 Object oInterface = null;
86 XMultiServiceFactory xMSF = null ;
88 try {
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
108 try {
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) ;
137 return tEnv;
138 } // finish method getTestEnvironment