1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.sheet;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.sheet.XDataPilotDescriptor;
31cdf0e10cSrcweir import com.sun.star.sheet.XDataPilotTables;
32cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet;
33cdf0e10cSrcweir import com.sun.star.table.CellAddress;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir * Testing <code>com.sun.star.sheet.XDataPilotTables</code>
37cdf0e10cSrcweir * interface methods :
38cdf0e10cSrcweir * <ul>
39cdf0e10cSrcweir *  <li><code> createDataPilotDescriptor()</code></li>
40cdf0e10cSrcweir *  <li><code> insertNewByName()</code></li>
41cdf0e10cSrcweir *  <li><code> removeByName()</code></li>
42cdf0e10cSrcweir * </ul> <p>
43cdf0e10cSrcweir * This test needs the following object relations :
44cdf0e10cSrcweir * <ul>
45cdf0e10cSrcweir *  <li> <code>'SHEET'</code> (of type <code>XSpreadsheet</code>):
46cdf0e10cSrcweir *   to have a spreadsheet document for document content checking</li>
47cdf0e10cSrcweir * <ul> <p>
48cdf0e10cSrcweir * @see com.sun.star.sheet.XDataPilotTables
49cdf0e10cSrcweir */
50cdf0e10cSrcweir public class _XDataPilotTables extends MultiMethodTest {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     public XDataPilotTables oObj = null;
53cdf0e10cSrcweir     XDataPilotDescriptor DPDscr = null;
54cdf0e10cSrcweir     String name = "XDataPilotTables";
55cdf0e10cSrcweir     CellAddress CA = new CellAddress((short)0, 9, 8);
56cdf0e10cSrcweir     XSpreadsheet oSheet = null;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     /**
59cdf0e10cSrcweir     * Retrieves object relations.
60cdf0e10cSrcweir     * @throws StatusException If one of relations not found.
61cdf0e10cSrcweir     */
62cdf0e10cSrcweir     protected void before() {
63cdf0e10cSrcweir         oSheet = (XSpreadsheet)tEnv.getObjRelation("SHEET");
64cdf0e10cSrcweir         if (oSheet == null) throw new StatusException(Status.failed
65cdf0e10cSrcweir             ("Relation 'SHEET' not found"));
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     /**
69cdf0e10cSrcweir     * Test calls the method, stores returned value and checks returned value.
70cdf0e10cSrcweir     * <p>Has <b> OK </b> status if returned value isn't null. <p>
71cdf0e10cSrcweir     */
72cdf0e10cSrcweir     public void _createDataPilotDescriptor(){
73cdf0e10cSrcweir         DPDscr = oObj.createDataPilotDescriptor();
74cdf0e10cSrcweir         tRes.tested("createDataPilotDescriptor()", DPDscr != null);
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     /**
78cdf0e10cSrcweir     * Test calls the method inserting new table with new name and then calls
79cdf0e10cSrcweir     * the method inserting table with existent name. <p>
80cdf0e10cSrcweir     * Has <b> OK </b> status if the cell content where table was inserted is
81cdf0e10cSrcweir     * equal to 'Filter' after first call and exception was thrown during
82cdf0e10cSrcweir     * second call. <p>
83cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
84cdf0e10cSrcweir     * <ul>
85cdf0e10cSrcweir     *  <li> <code> createDataPilotDescriptor() </code> : to have
86cdf0e10cSrcweir     *  <code>XDataPilotDescriptor</code> created by this method</li>
87cdf0e10cSrcweir     * </ul>
88cdf0e10cSrcweir     */
89cdf0e10cSrcweir     public void _insertNewByName(){
90cdf0e10cSrcweir         requiredMethod("createDataPilotDescriptor()");
91cdf0e10cSrcweir         boolean bResult = true;
92cdf0e10cSrcweir         log.println("Inserting new Table \"" + name + "\"");
93cdf0e10cSrcweir         try {
94cdf0e10cSrcweir             oObj.insertNewByName(name, CA, DPDscr);
95cdf0e10cSrcweir             bResult &= oSheet.getCellByPosition
96cdf0e10cSrcweir                 (CA.Column, CA.Row).getFormula().equals("Filter");
97cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
98cdf0e10cSrcweir             log.println("Exception occured! " + e);
99cdf0e10cSrcweir             bResult = false;
100cdf0e10cSrcweir         }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         log.println(bResult ? "OK" : "FAILED");
103cdf0e10cSrcweir         log.println("Trying to insert element with existent name");
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         try {
106cdf0e10cSrcweir             oObj.insertNewByName(name,new CellAddress((short)0, 7, 7), DPDscr);
107cdf0e10cSrcweir             log.println("No exception! - FAILED");
108cdf0e10cSrcweir             bResult = false;
109cdf0e10cSrcweir         } catch (com.sun.star.uno.RuntimeException e) {
110cdf0e10cSrcweir             log.println("Expected exception - OK " + e);
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         log.println("Inserting new table " + (bResult ? "OK" : "FAILED"));
114cdf0e10cSrcweir         tRes.tested("insertNewByName()", bResult);
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /**
118cdf0e10cSrcweir     * Test calls the method for existent table and for unexistent table. <p>
119cdf0e10cSrcweir     * Has <b> OK </b> status if the cell where table was removed from is empty
120cdf0e10cSrcweir     * after first call and exception was thrown during second call. <p>
121cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
122cdf0e10cSrcweir     * <ul>
123cdf0e10cSrcweir     *  <li> <code>insertNewByName()</code>: to have name of existent table</li>
124cdf0e10cSrcweir     * </ul>
125cdf0e10cSrcweir     */
126cdf0e10cSrcweir     public void _removeByName(){
127cdf0e10cSrcweir         requiredMethod("insertNewByName()");
128cdf0e10cSrcweir         boolean bResult = true;
129cdf0e10cSrcweir         log.println("Remove table with name " + name);
130cdf0e10cSrcweir         try {
131cdf0e10cSrcweir             oObj.removeByName(name);
132cdf0e10cSrcweir             bResult &= oSheet.getCellByPosition
133cdf0e10cSrcweir                 (CA.Column, CA.Row).getFormula().equals("");
134cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
135cdf0e10cSrcweir             log.println("Exception occured ! " + e);
136cdf0e10cSrcweir             bResult = false;
137cdf0e10cSrcweir         }
138cdf0e10cSrcweir         log.println(bResult ? "OK" : "FAILED");
139cdf0e10cSrcweir         log.println("Removing unexistent element");
140cdf0e10cSrcweir         try {
141cdf0e10cSrcweir             oObj.removeByName(name);
142cdf0e10cSrcweir             log.println("No exception! - FAILED");
143cdf0e10cSrcweir             bResult = false;
144cdf0e10cSrcweir         } catch (com.sun.star.uno.RuntimeException e) {
145cdf0e10cSrcweir             log.println("Expected exception - OK " + e);
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         log.println("Removing a table " + (bResult ? "OK" : "FAILED"));
149cdf0e10cSrcweir         tRes.tested("removeByName()", bResult);
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154