1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 /**
22  *
23  */
24 package fvt.uno.sd.file;
25 import static org.junit.Assert.*;
26 
27 import org.junit.After;
28 import org.junit.AfterClass;
29 import org.junit.Before;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.openoffice.test.uno.UnoApp;
33 import org.openoffice.test.common.FileUtil;
34 import org.openoffice.test.common.Testspace;
35 
36 import com.sun.star.beans.IllegalTypeException;
37 import com.sun.star.beans.Property;
38 import com.sun.star.beans.PropertyAttribute;
39 import com.sun.star.beans.PropertyExistException;
40 import com.sun.star.beans.PropertyValue;
41 import com.sun.star.beans.UnknownPropertyException;
42 import com.sun.star.beans.XPropertyContainer;
43 import com.sun.star.beans.XPropertySet;
44 import com.sun.star.beans.XPropertySetInfo;
45 import com.sun.star.container.XNameAccess;
46 import com.sun.star.document.XDocumentProperties;
47 import com.sun.star.document.XDocumentPropertiesSupplier;
48 import java.util.Calendar;
49 import com.sun.star.util.DateTime;
50 import com.sun.star.util.Date;
51 import com.sun.star.util.Duration;
52 import com.sun.star.lang.IllegalArgumentException;
53 import com.sun.star.lang.WrappedTargetException;
54 import com.sun.star.lang.XComponent;
55 import com.sun.star.lang.XMultiServiceFactory;
56 import com.sun.star.uno.UnoRuntime;
57 
58 /**
59  * @author LouQL
60  *
61  */
62 public class CheckFileProperties {
63 
64 	private static final UnoApp app = new UnoApp();
65 
66 	private XComponent m_xSDComponent = null;
67 	private static String m_filePath = null;
68 
69 	@Before
70 	public void setUpDocument() throws Exception {
71 		if (FileUtil.fileExists(m_filePath)) {//load
72 			m_xSDComponent = app.loadDocument(m_filePath);
73 		} else {//new
74 			m_xSDComponent = (XComponent) UnoRuntime.queryInterface(
75 					XComponent.class, app.newDocument("simpress"));
76 		}
77 	}
78 
79 	private String getUserName() throws com.sun.star.uno.Exception
80 	{
81 		Object configurationProvider = app.getServiceFactory().
82 				createInstance("com.sun.star.configuration.ConfigurationProvider");
83 
84 		XMultiServiceFactory msFac = (XMultiServiceFactory)UnoRuntime.queryInterface(
85 				XMultiServiceFactory.class, configurationProvider);
86 
87 		PropertyValue[] propValue = new PropertyValue[1];
88 		propValue[0] = new PropertyValue();
89 		propValue[0].Name = "nodepath";
90 		propValue[0].Value = "/org.openoffice.UserProfile/Data";
91 
92 		Object configurationAccess = msFac.createInstanceWithArguments(
93 				"com.sun.star.configuration.ConfigurationAccess", propValue);
94 		XNameAccess nameAcc = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, configurationAccess);
95 		String givenname = (String)nameAcc.getByName("givenname");
96 		String sn = (String)nameAcc.getByName("sn");
97 		String name = null;
98 		if(givenname.length() == 0) name = sn;
99 		else	name = givenname+" "+sn;
100 
101 		return name;
102 	}
103 
104 	private XDocumentProperties getDocumentProperties(){
105 		XDocumentPropertiesSupplier xDocumentProSupplier = (XDocumentPropertiesSupplier)UnoRuntime.queryInterface(
106 				XDocumentPropertiesSupplier.class, this.m_xSDComponent);
107 		return xDocumentProSupplier.getDocumentProperties();
108 	}
109 
110 	@After
111 	public void tearDownDocument() {
112 		app.closeDocument(m_xSDComponent);
113 
114 	}
115 
116 	@BeforeClass
117 	public static void setUpConnection() throws Exception {
118 		app.start();
119 		m_filePath = Testspace.getPath("temp/CheckFileProperties.odp");
120 		FileUtil.deleteFile(m_filePath);
121 	}
122 
123 	@AfterClass
124 	public static void tearDownConnection() throws InterruptedException,
125 			Exception {
126 		app.close();
127 		//remove the temp file
128 		FileUtil.deleteFile(Testspace.getPath("temp"));
129 	}
130 
131 	/*
132 	 * UI entry: File->Properties->General->Created*/
133 	@Test
134 	public void testGeneralAuthor() throws Exception {
135 		String author = getUserName();
136 		XDocumentProperties xDocPro = getDocumentProperties();
137 		xDocPro.setAuthor(author);
138 
139 		app.saveDocument(m_xSDComponent, m_filePath);
140 		app.closeDocument(m_xSDComponent);
141 		m_xSDComponent = app.loadDocument(m_filePath);
142 		XDocumentProperties xDocPro2 = getDocumentProperties();
143 		assertEquals("Author should be "+ author, author, xDocPro2.getAuthor());
144 	}
145 
146 	private boolean DateTimeEquals(DateTime datetime1, DateTime datetime2){
147 
148 		if(datetime1.Seconds == datetime2.Seconds &&
149 				datetime1.Minutes == datetime2.Minutes &&
150 				datetime1.Hours == datetime2.Hours &&
151 				datetime1.Day == datetime2.Day &&
152 				datetime1.Month == datetime2.Month &&
153 				datetime1.Year == datetime2.Year)
154 			return true;
155 		else
156 			return false;
157 	}
158 
159 	private boolean DateEquals(Date date1, Date date2){
160 
161 		if(date1.Day == date2.Day &&
162 		   date1.Month == date2.Month &&
163 			date1.Year == date2.Year)
164 			return true;
165 		else
166 			return false;
167 	}
168 
169 	private boolean DurationEquals(Duration d1, Duration d2){
170 
171 		if(d1.Seconds == d2.Seconds &&
172 				d1.Minutes == d2.Minutes &&
173 				d1.Hours == d2.Hours &&
174 				d1.Days == d2.Days &&
175 				d1.Months == d2.Months &&
176 				d1.Years == d2.Years)
177 			return true;
178 		else
179 			return false;
180 	}
181 
182 	private DateTime getCurrentDateTime(){
183 		Calendar ca = Calendar.getInstance();
184 		DateTime currentDateTime = new DateTime();
185 		currentDateTime.Year = (short)ca.get(Calendar.YEAR);
186 		currentDateTime.Month = (short)ca.get(Calendar.MONTH);
187 		currentDateTime.Day = (short)ca.get(Calendar.DATE);
188 		currentDateTime.Minutes = (short)ca.get(Calendar.MINUTE);
189 		currentDateTime.Hours = (short)ca.get(Calendar.HOUR);
190 		currentDateTime.Seconds = (short)ca.get(Calendar.SECOND);
191 
192 		return currentDateTime;
193 	}
194 
195 	private Date getCurrentDate(){
196 		Calendar ca = Calendar.getInstance();
197 		Date currentDate = new Date();
198 		currentDate.Year = (short)ca.get(Calendar.YEAR);
199 		currentDate.Month = (short)ca.get(Calendar.MONTH);
200 		currentDate.Day = (short)ca.get(Calendar.DATE);
201 
202 		return currentDate;
203 	}
204 
205 	/*
206 	 * UI entry: File->Properties->General->Created*/
207 	@Test
208 	public void testGeneralCreationDate() throws Exception {
209 		DateTime creationDate = getCurrentDateTime();
210 
211 		XDocumentProperties xDocPro = getDocumentProperties();
212 
213 		xDocPro.setCreationDate(creationDate);
214 
215 		app.saveDocument(m_xSDComponent, m_filePath);
216 		app.closeDocument(m_xSDComponent);
217 		m_xSDComponent = app.loadDocument(m_filePath);
218 		XDocumentProperties xDocPro2 = getDocumentProperties();
219 		DateTime result = xDocPro2.getCreationDate();
220 		assertTrue("CreationDate should be the same as set", this.DateTimeEquals(creationDate, result));
221 	}
222 
223 	/*
224 	 * UI entry: File->Properties->General->Modified*/
225 	@Test
226 	//ModifiedBy will be set each time the file loaded. The value is the one set in Tools->options->User data->Last name
227 	public void testGeneralModifiedBy() throws Exception {
228 		String modifiedBy = this.getUserName();
229 		XDocumentProperties xDocPro = getDocumentProperties();
230 		xDocPro.setModifiedBy(modifiedBy);
231 
232 
233 		app.saveDocument(m_xSDComponent, m_filePath);
234 		app.closeDocument(m_xSDComponent);
235 		m_xSDComponent = app.loadDocument(m_filePath);
236 		XDocumentProperties xDocPro2 = getDocumentProperties();
237 		assertEquals("The file is modified by "+ modifiedBy, modifiedBy, xDocPro2.getModifiedBy());
238 	}
239 
240 	/*
241 	 * UI entry: File->Properties->General->Modified*/
242 	@Test
243 	public void testGeneralModificationDate() throws Exception {
244 		//modification date will be set each time the file saved, so I don't save after set.
245 		DateTime modificationDate = getCurrentDateTime();
246 
247 		XDocumentProperties xDocPro = getDocumentProperties();
248 
249 		xDocPro.setModificationDate(modificationDate);
250 
251 		DateTime result = xDocPro.getModificationDate();
252 		assertTrue("ModificationDate should be the same as set", this.DateTimeEquals(modificationDate, result));
253 	}
254 
255 	/*
256 	 * UI entry: File->Properties->General->Last printed*/
257 	@Test
258 	public void testGeneralPrintBy() throws Exception {
259 		String printBy = "PrintBy";
260 		XDocumentProperties xDocPro = getDocumentProperties();
261 
262 		xDocPro.setPrintedBy(printBy);
263 
264 		app.saveDocument(m_xSDComponent, m_filePath);
265 		app.closeDocument(m_xSDComponent);
266 		m_xSDComponent = app.loadDocument(m_filePath);
267 		XDocumentProperties xDocPro2 = getDocumentProperties();
268 		assertEquals("This document is printed by "+ printBy, printBy, xDocPro2.getPrintedBy());
269 	}
270 
271 	/*
272 	 * UI entry: File->Properties->General->Last printed*/
273 	@Test
274 	public void testGeneralPrintDate() throws Exception {
275 		DateTime printDate = getCurrentDateTime();
276 
277 		XDocumentProperties xDocPro = getDocumentProperties();
278 
279 		xDocPro.setPrintDate(printDate);
280 
281 		app.saveDocument(m_xSDComponent, m_filePath);
282 		app.closeDocument(m_xSDComponent);
283 		m_xSDComponent = app.loadDocument(m_filePath);
284 		XDocumentProperties xDocPro2 = getDocumentProperties();
285 		DateTime result = xDocPro2.getPrintDate();
286 		assertTrue("PrintDate should be the same as set", this.DateTimeEquals(printDate, result));
287 	}
288 
289 	/*
290 	 * UI entry: File->Properties->General->Total editing time*/
291 	@Test
292 	public void testGeneralEditingDuration() throws Exception {
293 		int editingDuration = 60;
294 
295 		XDocumentProperties xDocPro = getDocumentProperties();
296 
297 		xDocPro.setEditingDuration(editingDuration);
298 
299 		app.saveDocument(m_xSDComponent, m_filePath);
300 		app.closeDocument(m_xSDComponent);
301 		m_xSDComponent = app.loadDocument(m_filePath);
302 		XDocumentProperties xDocPro2 = getDocumentProperties();
303 		assertEquals("Totally editing time should be "+ editingDuration, editingDuration, xDocPro2.getEditingDuration());
304 	}
305 
306 	/*
307 	 * UI entry: File->Properties->General->Revision number*/
308 	@Test
309 	public void testGeneralRevisionNumber() throws Exception {
310 		short revisionNumber = 10;
311 
312 		XDocumentProperties xDocPro = getDocumentProperties();
313 
314 		xDocPro.setEditingCycles(revisionNumber);
315 
316 		app.saveDocument(m_xSDComponent, m_filePath);
317 		app.closeDocument(m_xSDComponent);
318 		m_xSDComponent = app.loadDocument(m_filePath);
319 		XDocumentProperties xDocPro2 = getDocumentProperties();
320 		assertEquals("Revision number should be "+ revisionNumber, revisionNumber, xDocPro2.getEditingCycles());
321 	}
322 
323 	/*
324 	 * UI entry: File->Properties->General->template*/
325 	@Test
326 	public void testGeneralTemplateName() throws Exception {
327 		String templateName = "I'm a template";
328 
329 		XDocumentProperties xDocPro = getDocumentProperties();
330 
331 		xDocPro.setTemplateName(templateName);
332 
333 		app.saveDocument(m_xSDComponent, m_filePath);
334 		app.closeDocument(m_xSDComponent);
335 		m_xSDComponent = app.loadDocument(m_filePath);
336 		XDocumentProperties xDocPro2 = getDocumentProperties();
337 		assertEquals("Template name should be "+ templateName, templateName, xDocPro2.getTemplateName());
338 	}
339 
340 	/*
341 	 * UI entry: File->Properties->General->Reset*/
342 	@Test
343 	public void testGeneralReset() throws Exception {
344 		String author = "ResetAuthor";
345 		XDocumentProperties xDocPro = getDocumentProperties();
346 		xDocPro.resetUserData(author);
347 
348 		assertEquals("Author should be "+ author, author, xDocPro.getAuthor());
349 		assertEquals("Modified should be empty", "", xDocPro.getModifiedBy());
350 		assertTrue("ModificationDate should be empty",
351 				DateTimeEquals(new DateTime(), xDocPro.getModificationDate()));
352 		assertEquals("PrintBy should be empty", "", xDocPro.getPrintedBy());
353 		assertTrue("PrintDate should be empty",
354 				DateTimeEquals(new DateTime(), xDocPro.getPrintDate()));
355 		assertEquals("Totally editing time should be empty", 0, xDocPro.getEditingDuration());
356 		assertEquals("Revision number should be empty", 1, xDocPro.getEditingCycles());
357 	}
358 
359 	// UI entry: File->Properties->General->Apply user data
360 
361 	// UI entry: File->Properties->General->digital signature
362 
363 	//Description begin
364 	/*
365 	 * UI entry: File->Properties->Description->Title*/
366 	@Test
367 	public void testDescriptionTitle() throws Exception{
368 		String title = "titleForTest";
369 		XDocumentProperties xDocPro = getDocumentProperties();
370 		xDocPro.setTitle(title);
371 
372 		app.saveDocument(m_xSDComponent, m_filePath);
373 		app.closeDocument(m_xSDComponent);
374 		m_xSDComponent = app.loadDocument(m_filePath);
375 		XDocumentProperties xDocPro2 = getDocumentProperties();
376 		assertEquals("Title should be "+ title, title, xDocPro2.getTitle());
377 	}
378 
379 	/*
380 	 * UI entry: File->Properties->Description->Subject*/
381 	@Test
382 	public void testDescriptionSubject() throws Exception{
383 		String subject = "subjectForTest";
384 		XDocumentProperties xDocPro = getDocumentProperties();
385 		xDocPro.setSubject(subject);
386 
387 		app.saveDocument(m_xSDComponent, m_filePath);
388 		app.closeDocument(m_xSDComponent);
389 		m_xSDComponent = app.loadDocument(m_filePath);
390 		XDocumentProperties xDocPro2 = getDocumentProperties();
391 		assertEquals("Subject should be "+ subject, subject, xDocPro2.getSubject());
392 	}
393 
394 	/*
395 	 * UI entry: File->Properties->Description->Keywords*/
396 	@Test
397 	public void testDescriptionKeywords() throws Exception{
398 		String[] keywords = {"keyword1", "keyword2"};
399 		XDocumentProperties xDocPro = getDocumentProperties();
400 		xDocPro.setKeywords(keywords);
401 
402 		app.saveDocument(m_xSDComponent, m_filePath);
403 		app.closeDocument(m_xSDComponent);
404 
405 		m_xSDComponent = app.loadDocument(m_filePath);
406 		XDocumentProperties xDocPro2 = getDocumentProperties();
407 		String[] keywordsResult = xDocPro2.getKeywords();
408 		assertEquals("There should be 2 Keywords", 2, keywordsResult.length);
409 		for(int i=0;i<keywordsResult.length;i++)
410 		{
411 			String num = Integer.toString(i+1);
412 			assertEquals("The keywords should be keyword"+num, "keyword"+num, keywordsResult[i]);
413 		}
414 	}
415 
416 	/*
417 	 * UI entry: File->Properties->Description->Comments*/
418 	@Test
419 	public void testDescriptionComments() throws Exception{
420 		String comments = "This is the comment.";
421 		XDocumentProperties xDocPro = getDocumentProperties();
422 		xDocPro.setDescription(comments);
423 
424 		app.saveDocument(m_xSDComponent, m_filePath);
425 		app.closeDocument(m_xSDComponent);
426 
427 		m_xSDComponent = app.loadDocument(m_filePath);
428 		XDocumentProperties xDocPro2 = getDocumentProperties();
429 
430 		assertEquals("Comments should be "+comments, comments, xDocPro2.getDescription());
431 	}
432 	//Description end
433 
434 	//custom properties begin
435 	//UI entry: File->Properties->Custom properties
436 		private void addCustomPro(String propertyName, Object value) throws PropertyExistException, IllegalTypeException, IllegalArgumentException{
437 			XDocumentProperties xDocPro = getDocumentProperties();
438 			XPropertyContainer proContainer = xDocPro.getUserDefinedProperties();
439 			proContainer.addProperty(propertyName, PropertyAttribute.REMOVEABLE, value);
440 		}
441 
442 		private Object getCustomPro(String propertyName) throws UnknownPropertyException, WrappedTargetException{
443 			XDocumentProperties xDocPro = getDocumentProperties();
444 			XPropertyContainer proContainer = xDocPro.getUserDefinedProperties();
445 			XPropertySet xProSet = (XPropertySet)UnoRuntime.queryInterface(
446 					XPropertySet.class, proContainer);
447 
448 			return xProSet.getPropertyValue(propertyName);
449 		}
450 
451 		@Test
452 		public void testCustomAddPro_Text() throws Exception{
453 			String addedProName = "TextPro";
454 			String addedProDefaultValue = "testUser";
455 
456 			addCustomPro(addedProName, addedProDefaultValue);
457 
458 			app.saveDocument(m_xSDComponent, m_filePath);
459 			app.closeDocument(m_xSDComponent);
460 
461 			m_xSDComponent = app.loadDocument(m_filePath);
462 
463 			String result = (String)getCustomPro(addedProName);
464 
465 			assertTrue("added Text property \""+addedProName+"\" should exist", result != null);
466 			assertEquals("value of added property should be "+addedProDefaultValue,
467 					addedProDefaultValue, result);
468 		}
469 
470 		@Test
471 		public void testCustomAddPro_DateTime() throws Exception{
472 			String addedProName = "DateTimePro";
473 			DateTime addedProDefaultValue = getCurrentDateTime();
474 
475 			addCustomPro(addedProName, addedProDefaultValue);
476 
477 			app.saveDocument(m_xSDComponent, m_filePath);
478 			app.closeDocument(m_xSDComponent);
479 
480 			m_xSDComponent = app.loadDocument(m_filePath);
481 
482 			DateTime result = (DateTime)getCustomPro(addedProName);
483 			assertTrue("added DateTime property \""+addedProName+"\" should exist", result != null);
484 			assertTrue("value of added property should be the same as set",
485 					this.DateTimeEquals(result, addedProDefaultValue));
486 		}
487 
488 		@Test
489 		public void testCustomAddPro_Date() throws Exception{
490 			String addedProName = "DatePro";
491 			Date addedProDefaultValue = getCurrentDate();
492 
493 			addCustomPro(addedProName, addedProDefaultValue);
494 
495 			app.saveDocument(m_xSDComponent, m_filePath);
496 			app.closeDocument(m_xSDComponent);
497 
498 			m_xSDComponent = app.loadDocument(m_filePath);
499 
500 			Date result = (Date)getCustomPro(addedProName);
501 			assertTrue("added Date property \""+addedProName+"\" should exist", result != null);
502 			assertTrue("value of added property should be the same as set",
503 					this.DateEquals(result, addedProDefaultValue));
504 		}
505 
506 		@Test
507 		public void testCustomAddPro_Duration() throws Exception{
508 			String addedProName = "DurationPro";
509 			Duration addedProDefaultValue = new Duration();
510 			addedProDefaultValue.Days = 1;
511 
512 			addCustomPro(addedProName, addedProDefaultValue);
513 
514 			app.saveDocument(m_xSDComponent, m_filePath);
515 			app.closeDocument(m_xSDComponent);
516 
517 			m_xSDComponent = app.loadDocument(m_filePath);
518 
519 			Duration result = (Duration)getCustomPro(addedProName);
520 			assertTrue("added Date property \""+addedProName+"\" should exist", result != null);
521 			assertTrue("value of added property should the same as set", DurationEquals(addedProDefaultValue, result));
522 		}
523 
524 		@Test
525 		public void testCustomAddPro_Number() throws Exception{
526 			String addedProName = "NumberPro";
527 			Double addedProDefaultValue = (double)10;
528 
529 			addCustomPro(addedProName, addedProDefaultValue);
530 
531 			app.saveDocument(m_xSDComponent, m_filePath);
532 			app.closeDocument(m_xSDComponent);
533 
534 			m_xSDComponent = app.loadDocument(m_filePath);
535 
536 			Object oResult = getCustomPro(addedProName);
537 
538 			Double result = (Double)oResult;
539 			assertTrue("added Number property \""+addedProName+"\" should exist", oResult != null);
540 			assertEquals("value of added property should be "+Double.toString(addedProDefaultValue),
541 					addedProDefaultValue, result);
542 		}
543 
544 		@Test
545 		public void testCustomAddPro_Boolean() throws Exception{
546 			String addedProName = "BooleanPro";
547 			Boolean addedProDefaultValue = true;
548 
549 			addCustomPro(addedProName, addedProDefaultValue);
550 
551 			app.saveDocument(m_xSDComponent, m_filePath);
552 			app.closeDocument(m_xSDComponent);
553 
554 			m_xSDComponent = app.loadDocument(m_filePath);
555 
556 			Object oResult = getCustomPro(addedProName);
557 
558 			boolean result = (Boolean)oResult;
559 			assertTrue("added Number property \""+addedProName+"\" should exist", oResult != null);
560 			assertEquals("value of added property should be "+Boolean.toString(addedProDefaultValue),
561 					addedProDefaultValue, result);
562 		}
563 
564 		@Test
565 		public void testCustomRemovePro() throws Exception{
566 			XDocumentProperties xDocPro = getDocumentProperties();
567 			XPropertyContainer proContainer = xDocPro.getUserDefinedProperties();
568 			XPropertySet xProSet = (XPropertySet)UnoRuntime.queryInterface(
569 					XPropertySet.class, proContainer);
570 			XPropertySetInfo xproSetInfo = xProSet.getPropertySetInfo();
571 			Property[] pros = xproSetInfo.getProperties();
572 
573 			if(pros.length == 0) //if there is no custom property, add one
574 			{
575 				addCustomPro("testPro", "value");
576 			}
577 
578 			for(int i=0; i< pros.length;i++)
579 			{
580 				proContainer.removeProperty(pros[i].Name);
581 			}
582 
583 			app.saveDocument(m_xSDComponent, m_filePath);
584 			app.closeDocument(m_xSDComponent);
585 
586 			m_xSDComponent = app.loadDocument(m_filePath);
587 
588 			XDocumentProperties xDocPro2 = getDocumentProperties();
589 			XPropertyContainer proContainer2 = xDocPro2.getUserDefinedProperties();
590 			XPropertySet xProSet2 = (XPropertySet)UnoRuntime.queryInterface(
591 					XPropertySet.class, proContainer2);
592 			XPropertySetInfo xproSetInfo2 = xProSet2.getPropertySetInfo();
593 			Property[] pros2 = xproSetInfo2.getProperties();
594 
595 			assertEquals("number of custom property should be zero ",
596 					0, pros2.length);
597 		}
598 	//custom properties end
599 
600 		//Internet begin
601 		private void setAutoLoad(String URL, int secs) throws IllegalArgumentException
602 		{
603 			XDocumentProperties xDocPro = getDocumentProperties();
604 			xDocPro.setAutoloadURL(URL);
605 			xDocPro.setAutoloadSecs(secs);
606 			xDocPro.setDefaultTarget("_blank");
607 		}
608 
609 		@Test
610 		public void testNoRefresh() throws Exception{
611 			String autoLoadURL = "";
612 			int autoLoadSecs = 0;
613 			setAutoLoad(autoLoadURL, autoLoadSecs);
614 
615 			app.saveDocument(m_xSDComponent, m_filePath);
616 			app.closeDocument(m_xSDComponent);
617 
618 			m_xSDComponent = app.loadDocument(m_filePath);
619 			XDocumentProperties xDocPro2 = getDocumentProperties();
620 
621 			assertEquals("AutoLoadURL should be empty", autoLoadURL, xDocPro2.getAutoloadURL());
622 			assertEquals("AutoLoadSecs should be 0", autoLoadSecs, xDocPro2.getAutoloadSecs());
623 		}
624 
625 		@Test
626 		public void testRefreshEvery60Secs() throws Exception{
627 			String autoLoadURL = "";
628 			int autoLoadSecs = 60;
629 			setAutoLoad(autoLoadURL, autoLoadSecs);
630 
631 			app.saveDocument(m_xSDComponent, m_filePath);
632 			app.closeDocument(m_xSDComponent);
633 
634 			m_xSDComponent = app.loadDocument(m_filePath);
635 			XDocumentProperties xDocPro2 = getDocumentProperties();
636 
637 			assertEquals("AutoLoadURL should be empty", autoLoadURL, xDocPro2.getAutoloadURL());
638 			assertEquals("AutoLoadSecs should be "+Integer.toString(autoLoadSecs), autoLoadSecs, xDocPro2.getAutoloadSecs());
639 		}
640 
641 		@Test
642 		public void testRedirect() throws Exception{
643 			String autoLoadURL = "http://www.openoffice.com/";
644 			int autoLoadSecs = 5;
645 			setAutoLoad(autoLoadURL, autoLoadSecs);
646 
647 			app.saveDocument(m_xSDComponent, m_filePath);
648 			app.closeDocument(m_xSDComponent);
649 
650 			m_xSDComponent = app.loadDocument(m_filePath);
651 			XDocumentProperties xDocPro2 = getDocumentProperties();
652 
653 			assertEquals("AutoLoadURL should be empty", autoLoadURL, xDocPro2.getAutoloadURL());
654 			assertEquals("AutoLoadSecs should be "+Integer.toString(autoLoadSecs), autoLoadSecs, xDocPro2.getAutoloadSecs());
655 		}
656 		//Internet end
657 }
658