1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XImportable.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import lib
.MultiMethodTest
;
34 import com
.sun
.star
.beans
.PropertyValue
;
35 import com
.sun
.star
.table
.XCellRange
;
36 import com
.sun
.star
.uno
.Type
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.util
.XImportable
;
42 * checks the Interface XImportable
44 public class _XImportable
extends MultiMethodTest
{
45 public XImportable oObj
;
46 protected PropertyValue
[] descriptor
= null;
47 protected String
[] names
= new String
[] {
48 "DatabaseName", "SourceType", "SourceObject", "IsNative"
50 protected Type
[] types
= new Type
[] {
51 new Type(String
.class), new Type(com
.sun
.star
.sheet
.DataImportMode
.class),
52 new Type(String
.class), new Type(Boolean
.class)
56 * creates an ImportDescriptor, the gained PropertyValues can be found
57 * in com.sun.star.sheet.DatabaseImportDescriptor.<br>
58 * Returns OK state is all propertynames and types are the specified.
61 public void _createImportDescriptor() {
63 boolean locResult
= false;
65 descriptor
= oObj
.createImportDescriptor(true);
66 log
.print("Getting when calling createImportDescriptor(true) --");
69 //printPropertyValue(descriptor);
72 log
.print("Checking PropertyNames -- ");
73 locResult
= checkPropertyNames(descriptor
, names
);
74 log
.println("Worked: " + locResult
);
77 log
.print("Checking PropertyTypes -- ");
78 locResult
= checkPropertyTypes(descriptor
, types
);
79 log
.println("Worked: " + locResult
);
82 descriptor
= oObj
.createImportDescriptor(false);
83 log
.print("Getting when calling createImportDescriptor(false) -- ");
86 //printPropertyValue(descriptor);
89 log
.print("Checking PropertyNames -- ");
90 locResult
= checkPropertyNames(descriptor
, names
);
91 log
.println("Worked: " + locResult
);
94 log
.print("Checking PropertyTypes -- ");
95 locResult
= checkPropertyTypes(descriptor
, types
);
96 log
.println("Worked - " + locResult
);
99 tRes
.tested("createImportDescriptor()", res
);
102 public void _doImport() {
103 requiredMethod("createImportDescriptor()");
106 log
.print("Setting the ImportDescriptor (Bibliograpy, Table, biblio) -- ");
107 descriptor
[0].Value
= "Bibliography";
108 descriptor
[1].Value
= com
.sun
.star
.sheet
.DataImportMode
.TABLE
;
109 descriptor
[2].Value
= "biblio";
112 log
.print("Importing data (Bibliograpy, Table, biblio) -- ");
113 oObj
.doImport(descriptor
);
116 log
.println("Checking data");
117 res
&= checkA1("Identifier");
119 log
.print("Setting the ImportDescriptor (Bibliograpy, SQL, select Author from biblio) -- ");
120 descriptor
[0].Value
= "Bibliography";
121 descriptor
[1].Value
= com
.sun
.star
.sheet
.DataImportMode
.SQL
;
122 descriptor
[2].Value
= "select Author from biblio";
125 log
.print("Importing data (Bibliograpy, SQL, select Author from biblio) -- ");
126 oObj
.doImport(descriptor
);
129 log
.println("Checking data");
130 res
&= checkA1("Author");
132 tRes
.tested("doImport()",res
);
135 protected void printPropertyValue(PropertyValue
[] props
) {
136 for (int i
= 0; i
< props
.length
; i
++) {
137 log
.println("\tName: " + props
[i
].Name
);
138 log
.println("\tValue: " + props
[i
].Value
);
142 protected boolean checkPropertyNames(PropertyValue
[] props
, String
[] names
) {
145 for (int i
= 0; i
< props
.length
; i
++) {
146 boolean locResult
= props
[i
].Name
.equals(names
[i
]);
149 log
.println("PropertyName differs for index " + i
);
150 log
.println("\tGetting: " + props
[i
].Name
);
151 log
.println("\tExpected: " + names
[i
]);
160 protected boolean checkPropertyTypes(PropertyValue
[] props
, Type
[] types
) {
163 for (int i
= 0; i
< props
.length
; i
++) {
164 Type ValueType
= new Type(props
[i
].Value
.getClass());
165 boolean locResult
= ValueType
.equals(types
[i
]);
168 log
.println("PropertyType differs for " + props
[i
].Name
);
169 log
.println("\tGetting: " + ValueType
.getTypeName());
170 log
.println("\tExpected: " + types
[i
].getTypeName());
179 protected boolean checkA1(String expected
) {
180 XCellRange range
= (XCellRange
) UnoRuntime
.queryInterface(XCellRange
.class, tEnv
.getTestObject());
183 String a1
= range
.getCellByPosition(0,0).getFormula();
184 res
= a1
.equals(expected
);
186 log
.println("\tResult differs from expectation");
187 log
.println("\tGetting: "+a1
);
188 log
.println("\tExpected: "+expected
);
190 log
.println("successful");
192 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
193 log
.println("Couldn't get Cell to check");
199 * Dispose environment.
201 protected void after() {
202 disposeEnvironment();