1 package fvt.uno.sw.frame;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.After;
6 import org.junit.AfterClass;
7 import org.junit.Before;
8 import org.junit.Test;
9 import org.openoffice.test.common.Testspace;
10 import org.openoffice.test.uno.UnoApp;
11 
12 import testlib.uno.SWUtil;
13 
14 import com.sun.star.beans.XPropertySet;
15 import com.sun.star.container.XNameAccess;
16 import com.sun.star.lang.XMultiServiceFactory;
17 import com.sun.star.text.XText;
18 import com.sun.star.text.XTextCursor;
19 import com.sun.star.text.XTextDocument;
20 import com.sun.star.text.XTextFrame;
21 import com.sun.star.text.XTextFramesSupplier;
22 import com.sun.star.uno.UnoRuntime;
23 
24 public class FrameHyperlink {
25 	private static final UnoApp app = new UnoApp();
26 	private XTextDocument xTextDocument=null;
27 	private XMultiServiceFactory xWriterFactory=null;
28 	private XText xText=null;
29 	@Before
30 	public void setUp() throws Exception {
31 		app.start();
32 	}
33 
34 	@After
35 	public void tearDown() throws Exception {
36 		app.closeDocument(xTextDocument);
37 	}
38 	@AfterClass
39 	public static void tearDownConnection() throws Exception {
40 		app.close();
41 	}
42 
43 	@Test
44 	public void testFrameHyperlink() throws Exception {
45 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
46 		xText=xTextDocument.getText();
47 		XTextCursor xTextCursor = xText.createTextCursor();
48 		// get internal service factory of the document
49 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
50 		// Create a new table from the document's factory
51 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
52 		xText.insertTextContent(xTextCursor,xTextFrame,false);
53 		XPropertySet xTextFrameProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame);
54 		xTextFrameProps.setPropertyValue("HyperLinkURL","http://www.google.com.hk/");
55 		xTextFrameProps.setPropertyValue("HyperLinkTarget","google");
56 		xTextFrameProps.setPropertyValue("HyperLinkName","FrameHyperlinkToGoogle");
57 
58 		//save and reopen the document
59 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
60 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
61 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
62 		XTextFrame xTextFrame_Assert=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrames_odt.getByName("Frame1"));
63 		XPropertySet xTextFrameProps_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert);
64 		assertEquals("assert Frame hyperlink url","http://www.google.com.hk/", xTextFrameProps_assert.getPropertyValue("HyperLinkURL"));
65 		assertEquals("assert Frame hyperlink target","google", xTextFrameProps_assert.getPropertyValue("HyperLinkTarget"));
66 		assertEquals("assert Frame hyperlink name", "FrameHyperlinkToGoogle",xTextFrameProps_assert.getPropertyValue("HyperLinkName"));
67 	}
68 }
69