xref: /trunk/test/testuno/source/fvt/mix/sc/sheet/InsertCalcSheetTest.java (revision 3309286857f19787ae62bd793a98b5af4edd2ad3)
1*47b4b2ceSCarl Marcum /**************************************************************
2*47b4b2ceSCarl Marcum  *
3*47b4b2ceSCarl Marcum  * Licensed to the Apache Software Foundation (ASF) under one
4*47b4b2ceSCarl Marcum  * or more contributor license agreements.  See the NOTICE file
5*47b4b2ceSCarl Marcum  * distributed with this work for additional information
6*47b4b2ceSCarl Marcum  * regarding copyright ownership.  The ASF licenses this file
7*47b4b2ceSCarl Marcum  * to you under the Apache License, Version 2.0 (the
8*47b4b2ceSCarl Marcum  * "License"); you may not use this file except in compliance
9*47b4b2ceSCarl Marcum  * with the License.  You may obtain a copy of the License at
10*47b4b2ceSCarl Marcum  *
11*47b4b2ceSCarl Marcum  *   http://www.apache.org/licenses/LICENSE-2.0
12*47b4b2ceSCarl Marcum  *
13*47b4b2ceSCarl Marcum  * Unless required by applicable law or agreed to in writing,
14*47b4b2ceSCarl Marcum  * software distributed under the License is distributed on an
15*47b4b2ceSCarl Marcum  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*47b4b2ceSCarl Marcum  * KIND, either express or implied.  See the License for the
17*47b4b2ceSCarl Marcum  * specific language governing permissions and limitations
18*47b4b2ceSCarl Marcum  * under the License.
19*47b4b2ceSCarl Marcum  *
20*47b4b2ceSCarl Marcum  *************************************************************/
21*47b4b2ceSCarl Marcum 
22*47b4b2ceSCarl Marcum package fvt.mix.sc.sheet;
23*47b4b2ceSCarl Marcum 
24*47b4b2ceSCarl Marcum import static org.junit.Assert.*;
25*47b4b2ceSCarl Marcum 
26*47b4b2ceSCarl Marcum import org.junit.After;
27*47b4b2ceSCarl Marcum import org.junit.AfterClass;
28*47b4b2ceSCarl Marcum import org.junit.Before;
29*47b4b2ceSCarl Marcum import org.junit.BeforeClass;
30*47b4b2ceSCarl Marcum import org.junit.Rule;
31*47b4b2ceSCarl Marcum import org.junit.Test;
32*47b4b2ceSCarl Marcum 
33*47b4b2ceSCarl Marcum import org.openoffice.test.common.Logger;
34*47b4b2ceSCarl Marcum import org.openoffice.test.common.Testspace;
35*47b4b2ceSCarl Marcum import org.openoffice.test.uno.UnoApp;
36*47b4b2ceSCarl Marcum 
37*47b4b2ceSCarl Marcum import com.sun.star.beans.XPropertySet;
38*47b4b2ceSCarl Marcum import com.sun.star.container.XIndexAccess;
39*47b4b2ceSCarl Marcum import com.sun.star.frame.XDesktop;
40*47b4b2ceSCarl Marcum import com.sun.star.lang.XComponent;
41*47b4b2ceSCarl Marcum import com.sun.star.sheet.SheetLinkMode;
42*47b4b2ceSCarl Marcum import com.sun.star.sheet.XSheetLinkable;
43*47b4b2ceSCarl Marcum import com.sun.star.sheet.XSpreadsheet;
44*47b4b2ceSCarl Marcum import com.sun.star.sheet.XSpreadsheetDocument;
45*47b4b2ceSCarl Marcum import com.sun.star.sheet.XSpreadsheets;
46*47b4b2ceSCarl Marcum import com.sun.star.uno.UnoRuntime;
47*47b4b2ceSCarl Marcum import com.sun.star.util.XRefreshable;
48*47b4b2ceSCarl Marcum 
49*47b4b2ceSCarl Marcum import org.openoffice.test.OpenOffice;
50*47b4b2ceSCarl Marcum import org.openoffice.test.vcl.widgets.VclApp;
51*47b4b2ceSCarl Marcum import org.openoffice.test.vcl.widgets.VclMessageBox;
52*47b4b2ceSCarl Marcum import org.openoffice.test.vcl.widgets.VclButton;
53*47b4b2ceSCarl Marcum import org.openoffice.test.vcl.widgets.VclComboBox;
54*47b4b2ceSCarl Marcum import org.openoffice.test.vcl.widgets.VclListBox;
55*47b4b2ceSCarl Marcum import org.openoffice.test.vcl.widgets.VclDialog;
56*47b4b2ceSCarl Marcum import org.openoffice.test.vcl.client.Constant;
57*47b4b2ceSCarl Marcum import static org.openoffice.test.vcl.Tester.sleep;
58*47b4b2ceSCarl Marcum 
59*47b4b2ceSCarl Marcum import org.openoffice.test.vcl.client.VclHookException;
60*47b4b2ceSCarl Marcum 
61*47b4b2ceSCarl Marcum import testlib.uno.SCUtil;
62*47b4b2ceSCarl Marcum 
63*47b4b2ceSCarl Marcum /**
64*47b4b2ceSCarl Marcum  * test inserting linked and non-linked sheets from another Calc spreadsheet.
65*47b4b2ceSCarl Marcum  */
66*47b4b2ceSCarl Marcum public class InsertCalcSheetTest {
67*47b4b2ceSCarl Marcum 
68*47b4b2ceSCarl Marcum     OpenOffice aoo;
69*47b4b2ceSCarl Marcum     UnoApp unoApp;
70*47b4b2ceSCarl Marcum     VclApp vclApp;
71*47b4b2ceSCarl Marcum     VclMessageBox activeMsgBox;
72*47b4b2ceSCarl Marcum     VclButton scAfterCurrentSheet;
73*47b4b2ceSCarl Marcum     VclButton scNewSheetFromFile;
74*47b4b2ceSCarl Marcum     VclButton scFromFileLink;
75*47b4b2ceSCarl Marcum     VclButton scFromFileBrowse;
76*47b4b2ceSCarl Marcum     VclComboBox filePickerPath;
77*47b4b2ceSCarl Marcum     VclButton filePickerOpen;
78*47b4b2ceSCarl Marcum     VclListBox scFromFileSheetList;
79*47b4b2ceSCarl Marcum     VclDialog scInsertSheetDlg;
80*47b4b2ceSCarl Marcum     VclDialog scSelectSheetsDlg;
81*47b4b2ceSCarl Marcum     VclListBox scSheetsList;
82*47b4b2ceSCarl Marcum 
83*47b4b2ceSCarl Marcum     XSpreadsheetDocument scDocument = null;
84*47b4b2ceSCarl Marcum     XComponent scComponent = null;
85*47b4b2ceSCarl Marcum 
86*47b4b2ceSCarl Marcum     @Rule
87*47b4b2ceSCarl Marcum     public Logger log = Logger.getLogger(this);
88*47b4b2ceSCarl Marcum 
89*47b4b2ceSCarl Marcum 
90*47b4b2ceSCarl Marcum     @BeforeClass
setUpBeforeClass()91*47b4b2ceSCarl Marcum     public static void setUpBeforeClass() throws Exception {
92*47b4b2ceSCarl Marcum 
93*47b4b2ceSCarl Marcum     }
94*47b4b2ceSCarl Marcum 
95*47b4b2ceSCarl Marcum     @AfterClass
tearDownAfterClass()96*47b4b2ceSCarl Marcum     public static void tearDownAfterClass() throws Exception {
97*47b4b2ceSCarl Marcum     }
98*47b4b2ceSCarl Marcum 
99*47b4b2ceSCarl Marcum     @Before
setUp()100*47b4b2ceSCarl Marcum     public void setUp() throws Exception {
101*47b4b2ceSCarl Marcum 
102*47b4b2ceSCarl Marcum         OpenOffice aoo = OpenOffice.getDefault();
103*47b4b2ceSCarl Marcum         unoApp = new UnoApp(aoo);
104*47b4b2ceSCarl Marcum         vclApp = new VclApp(aoo);
105*47b4b2ceSCarl Marcum         scAfterCurrentSheet = new VclButton(vclApp, "sc:RadioButton:RID_SCDLG_INSERT_TABLE:RB_BEHIND");
106*47b4b2ceSCarl Marcum         scNewSheetFromFile = new VclButton(vclApp, "sc:RadioButton:RID_SCDLG_INSERT_TABLE:RB_FROMFILE");
107*47b4b2ceSCarl Marcum         scFromFileLink = new VclButton(vclApp, "sc:CheckBox:RID_SCDLG_INSERT_TABLE:CB_LINK");
108*47b4b2ceSCarl Marcum         scFromFileBrowse = new VclButton(vclApp, "sc:PushButton:RID_SCDLG_INSERT_TABLE:BTN_BROWSE");
109*47b4b2ceSCarl Marcum         filePickerPath = new VclComboBox(vclApp, "SVT_HID_FILEDLG_AUTOCOMPLETEBOX");
110*47b4b2ceSCarl Marcum         filePickerOpen = new VclButton(vclApp, "fpicker:PushButton:DLG_SVT_EXPLORERFILE:BTN_EXPLORERFILE_OPEN");
111*47b4b2ceSCarl Marcum         scFromFileSheetList = new VclListBox(vclApp, "sc:MultiListBox:RID_SCDLG_INSERT_TABLE:LB_TABLES");
112*47b4b2ceSCarl Marcum         scInsertSheetDlg = new VclDialog(vclApp, "sc:ModalDialog:RID_SCDLG_INSERT_TABLE");
113*47b4b2ceSCarl Marcum         scSelectSheetsDlg = new VclDialog(vclApp, ".uno:SelectTables");
114*47b4b2ceSCarl Marcum         scSheetsList = new VclListBox(vclApp, "SC_HID_SELECTTABLES");
115*47b4b2ceSCarl Marcum 
116*47b4b2ceSCarl Marcum         // existing setup
117*47b4b2ceSCarl Marcum         unoApp.start();
118*47b4b2ceSCarl Marcum         // New a SC document
119*47b4b2ceSCarl Marcum         scComponent = unoApp.newDocument("scalc");
120*47b4b2ceSCarl Marcum 
121*47b4b2ceSCarl Marcum         // New a document source.ods, add value to 3 sheet
122*47b4b2ceSCarl Marcum         scDocument = SCUtil.getSCDocument(scComponent);
123*47b4b2ceSCarl Marcum         XSpreadsheets spreadsheets = scDocument.getSheets();
124*47b4b2ceSCarl Marcum         XSpreadsheet firstSheet = SCUtil.getSCSheetByIndex(scDocument,
125*47b4b2ceSCarl Marcum                 (short) 0);
126*47b4b2ceSCarl Marcum         XSpreadsheet secondSheet = SCUtil.getSCSheetByIndex(scDocument,
127*47b4b2ceSCarl Marcum                 (short) 1);
128*47b4b2ceSCarl Marcum         XSpreadsheet thirdSheet = SCUtil.getSCSheetByIndex(scDocument,
129*47b4b2ceSCarl Marcum                 (short) 2);
130*47b4b2ceSCarl Marcum         SCUtil.setFormulaToCell(firstSheet, 1, 2, "=1*2"); // cell B3
131*47b4b2ceSCarl Marcum         SCUtil.setFormulaToCell(secondSheet, 1, 2, "=2*2");
132*47b4b2ceSCarl Marcum         SCUtil.setFormulaToCell(thirdSheet, 1, 2, "=3*2");
133*47b4b2ceSCarl Marcum 
134*47b4b2ceSCarl Marcum         // Save and close this document
135*47b4b2ceSCarl Marcum         SCUtil.saveFileAs(scComponent, "source", "ods");
136*47b4b2ceSCarl Marcum         SCUtil.closeFile(scDocument);
137*47b4b2ceSCarl Marcum 
138*47b4b2ceSCarl Marcum     }
139*47b4b2ceSCarl Marcum 
140*47b4b2ceSCarl Marcum     @After
tearDown()141*47b4b2ceSCarl Marcum     public void tearDown() throws Exception {
142*47b4b2ceSCarl Marcum         unoApp.closeDocument(scComponent);
143*47b4b2ceSCarl Marcum         unoApp.close();
144*47b4b2ceSCarl Marcum     }
145*47b4b2ceSCarl Marcum 
146*47b4b2ceSCarl Marcum     /**
147*47b4b2ceSCarl Marcum      * test insert sheet from other file with a normal link meaning the cell
148*47b4b2ceSCarl Marcum      * will return the formula and text values like the source and the link
149*47b4b2ceSCarl Marcum      * will update the cell.
150*47b4b2ceSCarl Marcum      */
151*47b4b2ceSCarl Marcum     @Test()
insertSheetFromFileLinkedNormal()152*47b4b2ceSCarl Marcum     public void insertSheetFromFileLinkedNormal() throws Exception {
153*47b4b2ceSCarl Marcum 
154*47b4b2ceSCarl Marcum         // get source document URL
155*47b4b2ceSCarl Marcum         String SourcestoreUrl = Testspace.getUrl("output/sc/" + "source" + "."
156*47b4b2ceSCarl Marcum                 + "ods");
157*47b4b2ceSCarl Marcum 
158*47b4b2ceSCarl Marcum         // New a document
159*47b4b2ceSCarl Marcum         scComponent = unoApp.newDocument("scalc");
160*47b4b2ceSCarl Marcum         scDocument = SCUtil.getSCDocument(scComponent);
161*47b4b2ceSCarl Marcum         XSpreadsheets spreadsheets = scDocument.getSheets();
162*47b4b2ceSCarl Marcum 
163*47b4b2ceSCarl Marcum         // Insert firstexternalsheet sheet, link with Sheet1 in source document
164*47b4b2ceSCarl Marcum         // and the link mode is NORMAL
165*47b4b2ceSCarl Marcum 
166*47b4b2ceSCarl Marcum         // using VCL
167*47b4b2ceSCarl Marcum         boolean retry = false;
168*47b4b2ceSCarl Marcum         int tryCount = 0;
169*47b4b2ceSCarl Marcum         int maxTries = 5;
170*47b4b2ceSCarl Marcum         do {
171*47b4b2ceSCarl Marcum             tryCount++; // starts at 1
172*47b4b2ceSCarl Marcum             retry = false;
173*47b4b2ceSCarl Marcum             try {
174*47b4b2ceSCarl Marcum                 vclApp.dispatch(".uno:SelectTables");
175*47b4b2ceSCarl Marcum             } catch (java.lang.Exception e) {
176*47b4b2ceSCarl Marcum                 // e.printStackTrace();
177*47b4b2ceSCarl Marcum                 log.info("Exception " + tryCount + "Caught !");
178*47b4b2ceSCarl Marcum                 retry = true;
179*47b4b2ceSCarl Marcum                 if (tryCount == maxTries) {
180*47b4b2ceSCarl Marcum                     throw e; // throw the exception
181*47b4b2ceSCarl Marcum                 }
182*47b4b2ceSCarl Marcum                 sleep(1);
183*47b4b2ceSCarl Marcum             }
184*47b4b2ceSCarl Marcum         } while ((retry) && (tryCount < maxTries));
185*47b4b2ceSCarl Marcum 
186*47b4b2ceSCarl Marcum         // select sheet3
187*47b4b2ceSCarl Marcum         scSheetsList.select(2);
188*47b4b2ceSCarl Marcum 
189*47b4b2ceSCarl Marcum         scSelectSheetsDlg.ok();
190*47b4b2ceSCarl Marcum 
191*47b4b2ceSCarl Marcum         // Open Insert Sheet dialog via main menu Insert-> Sheet
192*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Insert");
193*47b4b2ceSCarl Marcum 
194*47b4b2ceSCarl Marcum         // set after current sheet
195*47b4b2ceSCarl Marcum         scAfterCurrentSheet.setChecked(true);
196*47b4b2ceSCarl Marcum 
197*47b4b2ceSCarl Marcum         // enable new sheet from file
198*47b4b2ceSCarl Marcum         scNewSheetFromFile.setChecked(true);
199*47b4b2ceSCarl Marcum 
200*47b4b2ceSCarl Marcum         // check Link
201*47b4b2ceSCarl Marcum         scFromFileLink.setChecked(true);
202*47b4b2ceSCarl Marcum 
203*47b4b2ceSCarl Marcum         // browse
204*47b4b2ceSCarl Marcum         scFromFileBrowse.click();
205*47b4b2ceSCarl Marcum 
206*47b4b2ceSCarl Marcum         // opens Insert dialog
207*47b4b2ceSCarl Marcum 
208*47b4b2ceSCarl Marcum         // add filename
209*47b4b2ceSCarl Marcum         filePickerPath.setText(SourcestoreUrl);
210*47b4b2ceSCarl Marcum 
211*47b4b2ceSCarl Marcum         // Insert button
212*47b4b2ceSCarl Marcum         filePickerOpen.click();
213*47b4b2ceSCarl Marcum 
214*47b4b2ceSCarl Marcum         // back to Insert Sheet dialog
215*47b4b2ceSCarl Marcum 
216*47b4b2ceSCarl Marcum         // might have to select from
217*47b4b2ceSCarl Marcum         scFromFileSheetList.select(0);
218*47b4b2ceSCarl Marcum 
219*47b4b2ceSCarl Marcum         // select Insert button
220*47b4b2ceSCarl Marcum         scInsertSheetDlg.ok();
221*47b4b2ceSCarl Marcum 
222*47b4b2ceSCarl Marcum         log.info("sheet inserted...");
223*47b4b2ceSCarl Marcum 
224*47b4b2ceSCarl Marcum         activeMsgBox = new VclMessageBox(vclApp, Constant.UID_ACTIVE);
225*47b4b2ceSCarl Marcum         boolean msgExists = activeMsgBox.exists(1); // wait 1 second for the dialog
226*47b4b2ceSCarl Marcum         if (msgExists) {
227*47b4b2ceSCarl Marcum             log.info("got the update links dialog and accepting");
228*47b4b2ceSCarl Marcum             activeMsgBox.yes(); // yes dialog
229*47b4b2ceSCarl Marcum         } else {
230*47b4b2ceSCarl Marcum             log.info("missed the update links dialog");
231*47b4b2ceSCarl Marcum         }
232*47b4b2ceSCarl Marcum         XSpreadsheet firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument,
233*47b4b2ceSCarl Marcum                 (short) 3);
234*47b4b2ceSCarl Marcum         XSheetLinkable xfirstSheetLinkable = (XSheetLinkable) UnoRuntime
235*47b4b2ceSCarl Marcum                 .queryInterface(XSheetLinkable.class, firstexternalsheet);
236*47b4b2ceSCarl Marcum 
237*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet link is NORMAL",
238*47b4b2ceSCarl Marcum                 SheetLinkMode.NORMAL, xfirstSheetLinkable.getLinkMode());
239*47b4b2ceSCarl Marcum 
240*47b4b2ceSCarl Marcum         // Verify firstexternalsheet
241*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet formula should be =1*2", "=1*2",
242*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
243*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet text should be 2", "2",
244*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
245*47b4b2ceSCarl Marcum 
246*47b4b2ceSCarl Marcum         log.info("passed first round of assertions");
247*47b4b2ceSCarl Marcum         log.info("saving document as linked-normal.ods");
248*47b4b2ceSCarl Marcum 
249*47b4b2ceSCarl Marcum         // save document and verify the linked sheet again
250*47b4b2ceSCarl Marcum         SCUtil.saveFileAs(scComponent, "linked-normal", "ods");
251*47b4b2ceSCarl Marcum         log.info("reloading linked-normal.ods...");
252*47b4b2ceSCarl Marcum 
253*47b4b2ceSCarl Marcum         // this will hang on "update links" dialog with no way out - leaving here for others that follow...
254*47b4b2ceSCarl Marcum         // XSpreadsheetDocument tempscDocument = SCUtil.reloadFile(unoApp, scDocument, "linked.ods");
255*47b4b2ceSCarl Marcum 
256*47b4b2ceSCarl Marcum         // open it with VCL instead
257*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Open");
258*47b4b2ceSCarl Marcum         // add filename
259*47b4b2ceSCarl Marcum         filePickerPath.setText("linked-normal.ods");
260*47b4b2ceSCarl Marcum 
261*47b4b2ceSCarl Marcum         // Insert button
262*47b4b2ceSCarl Marcum         filePickerOpen.click();
263*47b4b2ceSCarl Marcum         sleep(1);
264*47b4b2ceSCarl Marcum 
265*47b4b2ceSCarl Marcum         // get the current document as tempscdocument
266*47b4b2ceSCarl Marcum         XDesktop xDesktop = unoApp.getDesktop();
267*47b4b2ceSCarl Marcum         // xDesktop.getCurrentComponent returns an XComponent (XModel)
268*47b4b2ceSCarl Marcum         XComponent xComponent = xDesktop.getCurrentComponent();
269*47b4b2ceSCarl Marcum         XSpreadsheetDocument tempscDocument = (XSpreadsheetDocument)UnoRuntime.queryInterface(
270*47b4b2ceSCarl Marcum                 XSpreadsheetDocument.class, xComponent);
271*47b4b2ceSCarl Marcum 
272*47b4b2ceSCarl Marcum         scDocument = tempscDocument;
273*47b4b2ceSCarl Marcum         firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
274*47b4b2ceSCarl Marcum 
275*47b4b2ceSCarl Marcum         // Verify firstexternalsheet
276*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet formula should be =1*2", "=1*2",
277*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
278*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet text should be 2", "2",
279*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
280*47b4b2ceSCarl Marcum 
281*47b4b2ceSCarl Marcum         log.info("passed second round of assertions");
282*47b4b2ceSCarl Marcum 
283*47b4b2ceSCarl Marcum         log.info("saving the document...");
284*47b4b2ceSCarl Marcum         // save and close document
285*47b4b2ceSCarl Marcum         SCUtil.save(scDocument);
286*47b4b2ceSCarl Marcum         SCUtil.closeFile(scDocument);
287*47b4b2ceSCarl Marcum 
288*47b4b2ceSCarl Marcum         log.info("opening source.ods to modify first sheet...");
289*47b4b2ceSCarl Marcum         // Open source document and change the value in source document
290*47b4b2ceSCarl Marcum         XSpreadsheetDocument sourcescDocument = SCUtil.reloadFile(unoApp,
291*47b4b2ceSCarl Marcum                 scDocument, "source.ods");
292*47b4b2ceSCarl Marcum         XSpreadsheet firstSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 0);
293*47b4b2ceSCarl Marcum         SCUtil.setFormulaToCell(firstSheet, 1, 2, "=1*3");
294*47b4b2ceSCarl Marcum         log.info("saving and closing source.ods...");
295*47b4b2ceSCarl Marcum         SCUtil.save(sourcescDocument);
296*47b4b2ceSCarl Marcum         SCUtil.closeFile(sourcescDocument);
297*47b4b2ceSCarl Marcum 
298*47b4b2ceSCarl Marcum         log.info("opening linked-normal.ods...");
299*47b4b2ceSCarl Marcum         // open test document
300*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Open");
301*47b4b2ceSCarl Marcum         // add filename
302*47b4b2ceSCarl Marcum         filePickerPath.setText("linked-normal.ods");
303*47b4b2ceSCarl Marcum 
304*47b4b2ceSCarl Marcum         // Insert button
305*47b4b2ceSCarl Marcum         filePickerOpen.click();
306*47b4b2ceSCarl Marcum 
307*47b4b2ceSCarl Marcum         msgExists = activeMsgBox.exists(1); // wait 1 second for the dialog
308*47b4b2ceSCarl Marcum         if (msgExists) {
309*47b4b2ceSCarl Marcum             log.info("got the update links dialog and accepting");
310*47b4b2ceSCarl Marcum             activeMsgBox.yes(); // yes dialog
311*47b4b2ceSCarl Marcum         } else {
312*47b4b2ceSCarl Marcum             log.info("missed the update links dialog");
313*47b4b2ceSCarl Marcum         }
314*47b4b2ceSCarl Marcum 
315*47b4b2ceSCarl Marcum         // get the current document as tempscdocument
316*47b4b2ceSCarl Marcum         xDesktop = unoApp.getDesktop();
317*47b4b2ceSCarl Marcum         xComponent = xDesktop.getCurrentComponent();
318*47b4b2ceSCarl Marcum         tempscDocument = (XSpreadsheetDocument)UnoRuntime.queryInterface(
319*47b4b2ceSCarl Marcum                 XSpreadsheetDocument.class, xComponent);
320*47b4b2ceSCarl Marcum 
321*47b4b2ceSCarl Marcum         scDocument = tempscDocument;
322*47b4b2ceSCarl Marcum         spreadsheets = scDocument.getSheets();
323*47b4b2ceSCarl Marcum 
324*47b4b2ceSCarl Marcum         firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
325*47b4b2ceSCarl Marcum 
326*47b4b2ceSCarl Marcum         // get Object SheetLinks for document
327*47b4b2ceSCarl Marcum         XPropertySet sheetpropertyset = (XPropertySet) UnoRuntime
328*47b4b2ceSCarl Marcum                 .queryInterface(XPropertySet.class, scDocument);
329*47b4b2ceSCarl Marcum         Object sheetLinks = sheetpropertyset.getPropertyValue("SheetLinks");
330*47b4b2ceSCarl Marcum 
331*47b4b2ceSCarl Marcum         XIndexAccess xsheetlinks = (XIndexAccess) UnoRuntime.queryInterface(
332*47b4b2ceSCarl Marcum                 XIndexAccess.class, sheetLinks);
333*47b4b2ceSCarl Marcum 
334*47b4b2ceSCarl Marcum         // Refresh all links
335*47b4b2ceSCarl Marcum         log.info("refreshing all links...");
336*47b4b2ceSCarl Marcum         for (int i = 0; i < xsheetlinks.getCount(); i++) {
337*47b4b2ceSCarl Marcum             Object sheetlink = xsheetlinks.getByIndex(i);
338*47b4b2ceSCarl Marcum             XRefreshable xsheetRefreshable = (XRefreshable) UnoRuntime
339*47b4b2ceSCarl Marcum                     .queryInterface(XRefreshable.class, sheetlink);
340*47b4b2ceSCarl Marcum             xsheetRefreshable.refresh();
341*47b4b2ceSCarl Marcum             log.info("in refresh loop " + i);
342*47b4b2ceSCarl Marcum             msgExists = activeMsgBox.exists(1); // wait 1 second for the dialog
343*47b4b2ceSCarl Marcum             if (msgExists) {
344*47b4b2ceSCarl Marcum                 log.info("got the update links dialog and accepting");
345*47b4b2ceSCarl Marcum                 activeMsgBox.yes(); // yes dialog
346*47b4b2ceSCarl Marcum             } else {
347*47b4b2ceSCarl Marcum                 log.info("missed the update links dialog");
348*47b4b2ceSCarl Marcum             }
349*47b4b2ceSCarl Marcum         }
350*47b4b2ceSCarl Marcum 
351*47b4b2ceSCarl Marcum         // Verify firstexternalsheet did change
352*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet formula should be =1*3", "=1*3",
353*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
354*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet text should be 3", "3",
355*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
356*47b4b2ceSCarl Marcum 
357*47b4b2ceSCarl Marcum         // Save the document before close
358*47b4b2ceSCarl Marcum         SCUtil.save(scDocument);
359*47b4b2ceSCarl Marcum     }
360*47b4b2ceSCarl Marcum 
361*47b4b2ceSCarl Marcum     /**
362*47b4b2ceSCarl Marcum      * test insert sheet from other file with a value link, meaning the cell
363*47b4b2ceSCarl Marcum      * will return the text value for both the formula and the text values and
364*47b4b2ceSCarl Marcum      * the link will update the cell.
365*47b4b2ceSCarl Marcum      */
366*47b4b2ceSCarl Marcum     @Test()
insertSheetFromFileLinkedValue()367*47b4b2ceSCarl Marcum     public void insertSheetFromFileLinkedValue() throws Exception {
368*47b4b2ceSCarl Marcum 
369*47b4b2ceSCarl Marcum         // get source document URL
370*47b4b2ceSCarl Marcum         String SourcestoreUrl = Testspace.getUrl("output/sc/" + "source" + "."
371*47b4b2ceSCarl Marcum                 + "ods");
372*47b4b2ceSCarl Marcum 
373*47b4b2ceSCarl Marcum         // New a document
374*47b4b2ceSCarl Marcum         scComponent = unoApp.newDocument("scalc");
375*47b4b2ceSCarl Marcum         scDocument = SCUtil.getSCDocument(scComponent);
376*47b4b2ceSCarl Marcum         XSpreadsheets spreadsheets = scDocument.getSheets();
377*47b4b2ceSCarl Marcum 
378*47b4b2ceSCarl Marcum         // Insert firstexternalsheet sheet, link with Sheet2 in source document
379*47b4b2ceSCarl Marcum         // and the link mode is VALUE
380*47b4b2ceSCarl Marcum 
381*47b4b2ceSCarl Marcum         // using VCL
382*47b4b2ceSCarl Marcum         boolean retry = false;
383*47b4b2ceSCarl Marcum         int tryCount = 0;
384*47b4b2ceSCarl Marcum         int maxTries = 5;
385*47b4b2ceSCarl Marcum         do {
386*47b4b2ceSCarl Marcum             tryCount++; // starts at 1
387*47b4b2ceSCarl Marcum             retry = false;
388*47b4b2ceSCarl Marcum             try {
389*47b4b2ceSCarl Marcum                 vclApp.dispatch(".uno:SelectTables");
390*47b4b2ceSCarl Marcum             } catch (java.lang.Exception e) {
391*47b4b2ceSCarl Marcum                 // e.printStackTrace();
392*47b4b2ceSCarl Marcum                 log.info("Exception " + tryCount + "Caught !");
393*47b4b2ceSCarl Marcum                 retry = true;
394*47b4b2ceSCarl Marcum                 if (tryCount == maxTries) {
395*47b4b2ceSCarl Marcum                     throw e; // throw the exception
396*47b4b2ceSCarl Marcum                 }
397*47b4b2ceSCarl Marcum                 sleep(1);
398*47b4b2ceSCarl Marcum             }
399*47b4b2ceSCarl Marcum         } while ((retry) && (tryCount < maxTries));
400*47b4b2ceSCarl Marcum 
401*47b4b2ceSCarl Marcum         // select sheet3
402*47b4b2ceSCarl Marcum         scSheetsList.select(2);
403*47b4b2ceSCarl Marcum 
404*47b4b2ceSCarl Marcum         scSelectSheetsDlg.ok();
405*47b4b2ceSCarl Marcum 
406*47b4b2ceSCarl Marcum         // Open Insert Sheet dialog via main menu Insert-> Sheet
407*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Insert");
408*47b4b2ceSCarl Marcum 
409*47b4b2ceSCarl Marcum         // set after current sheet
410*47b4b2ceSCarl Marcum         scAfterCurrentSheet.setChecked(true);
411*47b4b2ceSCarl Marcum 
412*47b4b2ceSCarl Marcum         // enable new sheet from file
413*47b4b2ceSCarl Marcum         scNewSheetFromFile.setChecked(true);
414*47b4b2ceSCarl Marcum 
415*47b4b2ceSCarl Marcum         // check Link
416*47b4b2ceSCarl Marcum         scFromFileLink.setChecked(true);
417*47b4b2ceSCarl Marcum 
418*47b4b2ceSCarl Marcum         // browse
419*47b4b2ceSCarl Marcum         scFromFileBrowse.click();
420*47b4b2ceSCarl Marcum 
421*47b4b2ceSCarl Marcum         // opens Insert dialog
422*47b4b2ceSCarl Marcum 
423*47b4b2ceSCarl Marcum         // add filename
424*47b4b2ceSCarl Marcum         filePickerPath.setText(SourcestoreUrl);
425*47b4b2ceSCarl Marcum 
426*47b4b2ceSCarl Marcum         // Insert button
427*47b4b2ceSCarl Marcum         filePickerOpen.click();
428*47b4b2ceSCarl Marcum 
429*47b4b2ceSCarl Marcum         // back to Insert Sheet dialog
430*47b4b2ceSCarl Marcum 
431*47b4b2ceSCarl Marcum         // select sheet 2
432*47b4b2ceSCarl Marcum         scFromFileSheetList.select(1);
433*47b4b2ceSCarl Marcum 
434*47b4b2ceSCarl Marcum         // select Insert button
435*47b4b2ceSCarl Marcum         scInsertSheetDlg.ok();
436*47b4b2ceSCarl Marcum 
437*47b4b2ceSCarl Marcum         log.info("sheet inserted...");
438*47b4b2ceSCarl Marcum 
439*47b4b2ceSCarl Marcum         // check for message box
440*47b4b2ceSCarl Marcum         activeMsgBox = new VclMessageBox(vclApp, Constant.UID_ACTIVE);
441*47b4b2ceSCarl Marcum         boolean msgExists = activeMsgBox.exists(1); // wait 1 second for the dialog
442*47b4b2ceSCarl Marcum         if (msgExists) {
443*47b4b2ceSCarl Marcum             log.info("got the update links dialog and accepting");
444*47b4b2ceSCarl Marcum             activeMsgBox.yes(); // yes dialog
445*47b4b2ceSCarl Marcum         } else {
446*47b4b2ceSCarl Marcum             log.info("missed the update links dialog");
447*47b4b2ceSCarl Marcum         }
448*47b4b2ceSCarl Marcum         XSpreadsheet firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument,
449*47b4b2ceSCarl Marcum                 (short) 3);
450*47b4b2ceSCarl Marcum         XSheetLinkable xfirstSheetLinkable = (XSheetLinkable) UnoRuntime
451*47b4b2ceSCarl Marcum                 .queryInterface(XSheetLinkable.class, firstexternalsheet);
452*47b4b2ceSCarl Marcum 
453*47b4b2ceSCarl Marcum         // this seem the only way to set this as it's not in the UI dialog
454*47b4b2ceSCarl Marcum         xfirstSheetLinkable.setLinkMode(SheetLinkMode.VALUE);
455*47b4b2ceSCarl Marcum 
456*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet link is NORMAL",
457*47b4b2ceSCarl Marcum                 SheetLinkMode.VALUE, xfirstSheetLinkable.getLinkMode());
458*47b4b2ceSCarl Marcum 
459*47b4b2ceSCarl Marcum         // Verify firstexternalsheet
460*47b4b2ceSCarl Marcum         assertEquals("Expect second sheet formula should be 4", "4",
461*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
462*47b4b2ceSCarl Marcum         assertEquals("Expect second sheet text should be 4", "4",
463*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
464*47b4b2ceSCarl Marcum 
465*47b4b2ceSCarl Marcum         log.info("passed first round of assertions...");
466*47b4b2ceSCarl Marcum 
467*47b4b2ceSCarl Marcum         log.info("saving document as linked-value.ods");
468*47b4b2ceSCarl Marcum         // save document and verify the linked sheet again
469*47b4b2ceSCarl Marcum         SCUtil.saveFileAs(scComponent, "linked-value", "ods");
470*47b4b2ceSCarl Marcum 
471*47b4b2ceSCarl Marcum         log.info("reloading linked-value.ods...");
472*47b4b2ceSCarl Marcum 
473*47b4b2ceSCarl Marcum         // this will hang on "update links" dialog with no way out - leaving here for others that follow...
474*47b4b2ceSCarl Marcum         // XSpreadsheetDocument tempscDocument = SCUtil.reloadFile(unoApp, scDocument, "linked.ods");
475*47b4b2ceSCarl Marcum 
476*47b4b2ceSCarl Marcum         // open it with VCL instead
477*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Open");
478*47b4b2ceSCarl Marcum         // add filename
479*47b4b2ceSCarl Marcum         filePickerPath.setText("linked-value.ods");
480*47b4b2ceSCarl Marcum 
481*47b4b2ceSCarl Marcum         // Insert button
482*47b4b2ceSCarl Marcum         filePickerOpen.click();
483*47b4b2ceSCarl Marcum         sleep(1);
484*47b4b2ceSCarl Marcum 
485*47b4b2ceSCarl Marcum         // get the current document as tempscdocument
486*47b4b2ceSCarl Marcum         XDesktop xDesktop = unoApp.getDesktop();
487*47b4b2ceSCarl Marcum         XComponent xComponent = xDesktop.getCurrentComponent();
488*47b4b2ceSCarl Marcum         XSpreadsheetDocument tempscDocument = (XSpreadsheetDocument)UnoRuntime.queryInterface(
489*47b4b2ceSCarl Marcum                 XSpreadsheetDocument.class, xComponent);
490*47b4b2ceSCarl Marcum 
491*47b4b2ceSCarl Marcum         scDocument = tempscDocument;
492*47b4b2ceSCarl Marcum         firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
493*47b4b2ceSCarl Marcum 
494*47b4b2ceSCarl Marcum         // Verify firstexternalsheet
495*47b4b2ceSCarl Marcum         assertEquals("Expect second sheet formula should be 4", "4",
496*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
497*47b4b2ceSCarl Marcum         assertEquals("Expect second sheet text should be 4", "4",
498*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
499*47b4b2ceSCarl Marcum 
500*47b4b2ceSCarl Marcum         log.info("passed second round of assertions");
501*47b4b2ceSCarl Marcum         log.info("saving the document...");
502*47b4b2ceSCarl Marcum 
503*47b4b2ceSCarl Marcum         // save and close document
504*47b4b2ceSCarl Marcum         SCUtil.save(scDocument);
505*47b4b2ceSCarl Marcum         SCUtil.closeFile(scDocument);
506*47b4b2ceSCarl Marcum 
507*47b4b2ceSCarl Marcum         // Open source document and change the value in source document
508*47b4b2ceSCarl Marcum         XSpreadsheetDocument sourcescDocument = SCUtil.reloadFile(unoApp,
509*47b4b2ceSCarl Marcum                 scDocument, "source.ods");
510*47b4b2ceSCarl Marcum         XSpreadsheet secondSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 1);
511*47b4b2ceSCarl Marcum         SCUtil.setFormulaToCell(secondSheet, 1, 2, "=2*3");
512*47b4b2ceSCarl Marcum         SCUtil.save(sourcescDocument);
513*47b4b2ceSCarl Marcum         SCUtil.closeFile(sourcescDocument);
514*47b4b2ceSCarl Marcum 
515*47b4b2ceSCarl Marcum         log.info("opening linked-value.ods...");
516*47b4b2ceSCarl Marcum         // open test document
517*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Open");
518*47b4b2ceSCarl Marcum         // add filename
519*47b4b2ceSCarl Marcum         filePickerPath.setText("linked-value.ods");
520*47b4b2ceSCarl Marcum 
521*47b4b2ceSCarl Marcum         // Insert button
522*47b4b2ceSCarl Marcum         filePickerOpen.click();
523*47b4b2ceSCarl Marcum 
524*47b4b2ceSCarl Marcum         msgExists = activeMsgBox.exists(1); // wait 1 second for the dialog
525*47b4b2ceSCarl Marcum         if (msgExists) {
526*47b4b2ceSCarl Marcum             log.info("got the update links dialog and accepting");
527*47b4b2ceSCarl Marcum             activeMsgBox.yes(); // yes dialog
528*47b4b2ceSCarl Marcum         } else {
529*47b4b2ceSCarl Marcum             log.info("missed the dialog");
530*47b4b2ceSCarl Marcum         }
531*47b4b2ceSCarl Marcum 
532*47b4b2ceSCarl Marcum         // get the current document as tempscdocument
533*47b4b2ceSCarl Marcum         xDesktop = unoApp.getDesktop();
534*47b4b2ceSCarl Marcum         xComponent = xDesktop.getCurrentComponent();
535*47b4b2ceSCarl Marcum         tempscDocument = (XSpreadsheetDocument)UnoRuntime.queryInterface(
536*47b4b2ceSCarl Marcum                 XSpreadsheetDocument.class, xComponent);
537*47b4b2ceSCarl Marcum 
538*47b4b2ceSCarl Marcum         scDocument = tempscDocument;
539*47b4b2ceSCarl Marcum         spreadsheets = scDocument.getSheets();
540*47b4b2ceSCarl Marcum 
541*47b4b2ceSCarl Marcum         firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
542*47b4b2ceSCarl Marcum 
543*47b4b2ceSCarl Marcum         // get Object SheetLinks for document
544*47b4b2ceSCarl Marcum         XPropertySet sheetpropertyset = (XPropertySet) UnoRuntime
545*47b4b2ceSCarl Marcum                 .queryInterface(XPropertySet.class, scDocument);
546*47b4b2ceSCarl Marcum         Object sheetLinks = sheetpropertyset.getPropertyValue("SheetLinks");
547*47b4b2ceSCarl Marcum 
548*47b4b2ceSCarl Marcum         XIndexAccess xsheetlinks = (XIndexAccess) UnoRuntime.queryInterface(
549*47b4b2ceSCarl Marcum                 XIndexAccess.class, sheetLinks);
550*47b4b2ceSCarl Marcum 
551*47b4b2ceSCarl Marcum         log.info("refreshing all links...");
552*47b4b2ceSCarl Marcum         // Refresh all links
553*47b4b2ceSCarl Marcum         for (int i = 0; i < xsheetlinks.getCount(); i++) {
554*47b4b2ceSCarl Marcum             Object sheetlink = xsheetlinks.getByIndex(i);
555*47b4b2ceSCarl Marcum             XRefreshable xsheetRefreshable = (XRefreshable) UnoRuntime
556*47b4b2ceSCarl Marcum                     .queryInterface(XRefreshable.class, sheetlink);
557*47b4b2ceSCarl Marcum             xsheetRefreshable.refresh();
558*47b4b2ceSCarl Marcum             log.info("in refresh loop " + i);
559*47b4b2ceSCarl Marcum             msgExists = activeMsgBox.exists(1); // wait 1 second for the dialog
560*47b4b2ceSCarl Marcum             if (msgExists) {
561*47b4b2ceSCarl Marcum                 log.info("got the update links dialog and accepting");
562*47b4b2ceSCarl Marcum                 activeMsgBox.yes(); // yes dialog
563*47b4b2ceSCarl Marcum             } else {
564*47b4b2ceSCarl Marcum                 log.info("missed the dialog");
565*47b4b2ceSCarl Marcum             }
566*47b4b2ceSCarl Marcum         }
567*47b4b2ceSCarl Marcum 
568*47b4b2ceSCarl Marcum         // Verify firstexternalsheet did change
569*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet formula should be =6", "6",
570*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
571*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet text should be 6", "6",
572*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
573*47b4b2ceSCarl Marcum 
574*47b4b2ceSCarl Marcum         // Save the document before close
575*47b4b2ceSCarl Marcum         SCUtil.save(scDocument);
576*47b4b2ceSCarl Marcum 
577*47b4b2ceSCarl Marcum     }
578*47b4b2ceSCarl Marcum 
579*47b4b2ceSCarl Marcum     /**
580*47b4b2ceSCarl Marcum      * test insert sheet from other file with no link meaning the cell will
581*47b4b2ceSCarl Marcum      * return the formula and text values like the source but the cell will
582*47b4b2ceSCarl Marcum      * not update.
583*47b4b2ceSCarl Marcum      */
584*47b4b2ceSCarl Marcum     @Test()
insertSheetFromFileLinkedNone()585*47b4b2ceSCarl Marcum     public void insertSheetFromFileLinkedNone() throws Exception {
586*47b4b2ceSCarl Marcum 
587*47b4b2ceSCarl Marcum         // get source document URL
588*47b4b2ceSCarl Marcum         String SourcestoreUrl = Testspace.getUrl("output/sc/" + "source" + "."
589*47b4b2ceSCarl Marcum                 + "ods");
590*47b4b2ceSCarl Marcum 
591*47b4b2ceSCarl Marcum         // New a document
592*47b4b2ceSCarl Marcum         scComponent = unoApp.newDocument("scalc");
593*47b4b2ceSCarl Marcum         scDocument = SCUtil.getSCDocument(scComponent);
594*47b4b2ceSCarl Marcum         XSpreadsheets spreadsheets = scDocument.getSheets();
595*47b4b2ceSCarl Marcum 
596*47b4b2ceSCarl Marcum 
597*47b4b2ceSCarl Marcum         // Insert firstexternalsheet sheet, link with Sheet1 in source document
598*47b4b2ceSCarl Marcum         // and the link mode is NORMAL
599*47b4b2ceSCarl Marcum 
600*47b4b2ceSCarl Marcum         // using VCL
601*47b4b2ceSCarl Marcum         boolean retry = false;
602*47b4b2ceSCarl Marcum         int tryCount = 0;
603*47b4b2ceSCarl Marcum         int maxTries = 5;
604*47b4b2ceSCarl Marcum         do {
605*47b4b2ceSCarl Marcum             tryCount++; // starts at 1
606*47b4b2ceSCarl Marcum             retry = false;
607*47b4b2ceSCarl Marcum             try {
608*47b4b2ceSCarl Marcum                 vclApp.dispatch(".uno:SelectTables");
609*47b4b2ceSCarl Marcum             } catch (java.lang.Exception e) {
610*47b4b2ceSCarl Marcum                 // e.printStackTrace();
611*47b4b2ceSCarl Marcum                 log.info("Exception " + tryCount + "Caught !");
612*47b4b2ceSCarl Marcum                 retry = true;
613*47b4b2ceSCarl Marcum                 if (tryCount == maxTries) {
614*47b4b2ceSCarl Marcum                     throw e; // throw the exception
615*47b4b2ceSCarl Marcum                 }
616*47b4b2ceSCarl Marcum                 sleep(1);
617*47b4b2ceSCarl Marcum             }
618*47b4b2ceSCarl Marcum         } while ((retry) && (tryCount < maxTries));
619*47b4b2ceSCarl Marcum 
620*47b4b2ceSCarl Marcum         // select sheet3
621*47b4b2ceSCarl Marcum         scSheetsList.select(2);
622*47b4b2ceSCarl Marcum 
623*47b4b2ceSCarl Marcum         scSelectSheetsDlg.ok();
624*47b4b2ceSCarl Marcum 
625*47b4b2ceSCarl Marcum         // Open Insert Sheet dialog via main menu Insert-> Sheet
626*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Insert");
627*47b4b2ceSCarl Marcum 
628*47b4b2ceSCarl Marcum         // set after current sheet
629*47b4b2ceSCarl Marcum         scAfterCurrentSheet.setChecked(true);
630*47b4b2ceSCarl Marcum 
631*47b4b2ceSCarl Marcum         // enable new sheet from file
632*47b4b2ceSCarl Marcum         scNewSheetFromFile.setChecked(true);
633*47b4b2ceSCarl Marcum 
634*47b4b2ceSCarl Marcum         // check Link
635*47b4b2ceSCarl Marcum         scFromFileLink.setChecked(false); // no link
636*47b4b2ceSCarl Marcum 
637*47b4b2ceSCarl Marcum         // browse
638*47b4b2ceSCarl Marcum         scFromFileBrowse.click();
639*47b4b2ceSCarl Marcum 
640*47b4b2ceSCarl Marcum         // opens Insert dialog
641*47b4b2ceSCarl Marcum 
642*47b4b2ceSCarl Marcum         // add filename
643*47b4b2ceSCarl Marcum         filePickerPath.setText(SourcestoreUrl);
644*47b4b2ceSCarl Marcum 
645*47b4b2ceSCarl Marcum         // Insert button
646*47b4b2ceSCarl Marcum         filePickerOpen.click();
647*47b4b2ceSCarl Marcum 
648*47b4b2ceSCarl Marcum         // back to Insert Sheet dialog
649*47b4b2ceSCarl Marcum 
650*47b4b2ceSCarl Marcum         // select sheet 3
651*47b4b2ceSCarl Marcum         scFromFileSheetList.select(2);
652*47b4b2ceSCarl Marcum 
653*47b4b2ceSCarl Marcum         // select Insert button
654*47b4b2ceSCarl Marcum         scInsertSheetDlg.ok();
655*47b4b2ceSCarl Marcum 
656*47b4b2ceSCarl Marcum         log.info("sheet inserted......");
657*47b4b2ceSCarl Marcum 
658*47b4b2ceSCarl Marcum         XSpreadsheet firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument,
659*47b4b2ceSCarl Marcum                 (short) 3);
660*47b4b2ceSCarl Marcum         XSheetLinkable xfirstSheetLinkable = (XSheetLinkable) UnoRuntime
661*47b4b2ceSCarl Marcum                 .queryInterface(XSheetLinkable.class, firstexternalsheet);
662*47b4b2ceSCarl Marcum 
663*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet link is NONE",
664*47b4b2ceSCarl Marcum                 SheetLinkMode.NONE, xfirstSheetLinkable.getLinkMode());
665*47b4b2ceSCarl Marcum 
666*47b4b2ceSCarl Marcum         // Verify thirdexternalsheet
667*47b4b2ceSCarl Marcum         assertEquals("Expect third sheet formula should be =3*2", "=3*2",
668*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
669*47b4b2ceSCarl Marcum         assertEquals("Expect third sheet text should be 6", "6",
670*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
671*47b4b2ceSCarl Marcum 
672*47b4b2ceSCarl Marcum         log.info("passed first round of assertions...");
673*47b4b2ceSCarl Marcum         log.info("");
674*47b4b2ceSCarl Marcum 
675*47b4b2ceSCarl Marcum         log.info("saving document as linked-none.ods");
676*47b4b2ceSCarl Marcum 
677*47b4b2ceSCarl Marcum         // save document and verify the linked sheet again
678*47b4b2ceSCarl Marcum         SCUtil.saveFileAs(scComponent, "linked-none", "ods");
679*47b4b2ceSCarl Marcum         log.info("reloading linked-none.ods...");
680*47b4b2ceSCarl Marcum 
681*47b4b2ceSCarl Marcum         // this will hang on "update links" dialog with no way out - leaving here for others that follow...
682*47b4b2ceSCarl Marcum         // XSpreadsheetDocument tempscDocument = SCUtil.reloadFile(unoApp, scDocument, "linked.ods");
683*47b4b2ceSCarl Marcum 
684*47b4b2ceSCarl Marcum         // open it with VCL instead
685*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Open");
686*47b4b2ceSCarl Marcum         // add filename
687*47b4b2ceSCarl Marcum         filePickerPath.setText("linked-none.ods");
688*47b4b2ceSCarl Marcum 
689*47b4b2ceSCarl Marcum         // Insert button
690*47b4b2ceSCarl Marcum         filePickerOpen.click();
691*47b4b2ceSCarl Marcum         sleep(1);
692*47b4b2ceSCarl Marcum 
693*47b4b2ceSCarl Marcum         // need to get the current document as tempscdocument
694*47b4b2ceSCarl Marcum         XDesktop xDesktop = unoApp.getDesktop();
695*47b4b2ceSCarl Marcum         // xDesktop.getCurrentComponent returns an XComponent (XModel)
696*47b4b2ceSCarl Marcum         XComponent xComponent = xDesktop.getCurrentComponent();
697*47b4b2ceSCarl Marcum         XSpreadsheetDocument tempscDocument = (XSpreadsheetDocument)UnoRuntime.queryInterface(
698*47b4b2ceSCarl Marcum                 XSpreadsheetDocument.class, xComponent);
699*47b4b2ceSCarl Marcum 
700*47b4b2ceSCarl Marcum         scDocument = tempscDocument;
701*47b4b2ceSCarl Marcum         firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
702*47b4b2ceSCarl Marcum 
703*47b4b2ceSCarl Marcum         // Verify firstexternalsheet
704*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet formula should be =3*2", "=3*2",
705*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
706*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet text should be 6", "6",
707*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
708*47b4b2ceSCarl Marcum 
709*47b4b2ceSCarl Marcum         log.info("passed second round of assertions");
710*47b4b2ceSCarl Marcum         log.info("");
711*47b4b2ceSCarl Marcum 
712*47b4b2ceSCarl Marcum         // save and close document
713*47b4b2ceSCarl Marcum         SCUtil.save(scDocument);
714*47b4b2ceSCarl Marcum         SCUtil.closeFile(scDocument);
715*47b4b2ceSCarl Marcum 
716*47b4b2ceSCarl Marcum         // Open source document and change the value in source document
717*47b4b2ceSCarl Marcum         XSpreadsheetDocument sourcescDocument = SCUtil.reloadFile(unoApp,
718*47b4b2ceSCarl Marcum                 scDocument, "source.ods");
719*47b4b2ceSCarl Marcum         XSpreadsheet thirdSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 2);
720*47b4b2ceSCarl Marcum         SCUtil.setFormulaToCell(thirdSheet, 1, 2, "=3*3");
721*47b4b2ceSCarl Marcum         SCUtil.save(sourcescDocument);
722*47b4b2ceSCarl Marcum         SCUtil.closeFile(sourcescDocument);
723*47b4b2ceSCarl Marcum 
724*47b4b2ceSCarl Marcum         // open test document
725*47b4b2ceSCarl Marcum         vclApp.dispatch(".uno:Open");
726*47b4b2ceSCarl Marcum         // add filename
727*47b4b2ceSCarl Marcum         filePickerPath.setText("linked-none.ods");
728*47b4b2ceSCarl Marcum 
729*47b4b2ceSCarl Marcum         // Insert button
730*47b4b2ceSCarl Marcum         filePickerOpen.click();
731*47b4b2ceSCarl Marcum         sleep(1);
732*47b4b2ceSCarl Marcum 
733*47b4b2ceSCarl Marcum         // get the current document as tempscdocument
734*47b4b2ceSCarl Marcum         xDesktop = unoApp.getDesktop();
735*47b4b2ceSCarl Marcum         xComponent = xDesktop.getCurrentComponent();
736*47b4b2ceSCarl Marcum         tempscDocument = (XSpreadsheetDocument)UnoRuntime.queryInterface(
737*47b4b2ceSCarl Marcum                 XSpreadsheetDocument.class, xComponent);
738*47b4b2ceSCarl Marcum 
739*47b4b2ceSCarl Marcum         scDocument = tempscDocument;
740*47b4b2ceSCarl Marcum         spreadsheets = scDocument.getSheets();
741*47b4b2ceSCarl Marcum 
742*47b4b2ceSCarl Marcum         firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
743*47b4b2ceSCarl Marcum 
744*47b4b2ceSCarl Marcum         // get Object SheetLinks for document
745*47b4b2ceSCarl Marcum         XPropertySet sheetpropertyset = (XPropertySet) UnoRuntime
746*47b4b2ceSCarl Marcum                 .queryInterface(XPropertySet.class, scDocument);
747*47b4b2ceSCarl Marcum         Object sheetLinks = sheetpropertyset.getPropertyValue("SheetLinks");
748*47b4b2ceSCarl Marcum 
749*47b4b2ceSCarl Marcum         XIndexAccess xsheetlinks = (XIndexAccess) UnoRuntime.queryInterface(
750*47b4b2ceSCarl Marcum                 XIndexAccess.class, sheetLinks);
751*47b4b2ceSCarl Marcum 
752*47b4b2ceSCarl Marcum         log.info("Number of Links should be 0");
753*47b4b2ceSCarl Marcum         assertEquals("Number of Links should be 0", 0, xsheetlinks.getCount());
754*47b4b2ceSCarl Marcum 
755*47b4b2ceSCarl Marcum         // Verify firstexternalsheet did not change
756*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet formula should be =3*2", "=3*2",
757*47b4b2ceSCarl Marcum                 SCUtil.getFormulaFromCell(firstexternalsheet, 1, 2));
758*47b4b2ceSCarl Marcum         assertEquals("Expect first sheet text should be 6", "6",
759*47b4b2ceSCarl Marcum                 SCUtil.getTextFromCell(firstexternalsheet, 1, 2));
760*47b4b2ceSCarl Marcum 
761*47b4b2ceSCarl Marcum         // Save the document before close
762*47b4b2ceSCarl Marcum         SCUtil.save(scDocument);
763*47b4b2ceSCarl Marcum 
764*47b4b2ceSCarl Marcum     }
765*47b4b2ceSCarl Marcum 
766*47b4b2ceSCarl Marcum } // end class
767