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 FrameDescription {
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 testFrameDescription() 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("Title", "Frame");
55 		xTextFrameProps.setPropertyValue("Description", "Test Frame");
56 
57 		//save and reopen the document
58 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
59 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
60 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
61 		XPropertySet xTextFrameProps_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrames_odt.getByName("Frame1"));
62 		assertEquals("Test Frame title","Frame", xTextFrameProps_odt.getPropertyValue("Title"));
63 		assertEquals("Test Frame description","Test Frame", xTextFrameProps_odt.getPropertyValue("Description"));
64 	}
65 }
66