diff options
Diffstat (limited to 'ucb/qa/complex/tdoc/CheckTransientDocumentsContentProvider.java')
-rwxr-xr-x | ucb/qa/complex/tdoc/CheckTransientDocumentsContentProvider.java | 83 |
1 files changed, 57 insertions, 26 deletions
diff --git a/ucb/qa/complex/tdoc/CheckTransientDocumentsContentProvider.java b/ucb/qa/complex/tdoc/CheckTransientDocumentsContentProvider.java index ddac0cbb2d47..d5aebc7fc3cd 100755 --- a/ucb/qa/complex/tdoc/CheckTransientDocumentsContentProvider.java +++ b/ucb/qa/complex/tdoc/CheckTransientDocumentsContentProvider.java @@ -41,15 +41,23 @@ import com.sun.star.ucb.XContentIdentifierFactory; import com.sun.star.ucb.XContentProvider; import com.sun.star.ucb.XDynamicResultSet; import com.sun.star.uno.UnoRuntime; -import complexlib.ComplexTestCase; +// import complexlib.ComplexTestCase; import util.WriterTools; -import util.utils; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; /** * */ -public class CheckTransientDocumentsContentProvider extends ComplexTestCase { - private final String testDocuments[] = new String[]{"sForm.sxw", "chinese.sxw", "Iterator.sxw"}; +public class CheckTransientDocumentsContentProvider { + // TODO: document doesn't exists + private final String testDocuments[] = new String[]{/*"sForm.sxw",*/ "chinese.sxw", "Iterator.sxw"}; private final int countDocs = testDocuments.length; private XMultiServiceFactory xMSF = null; private XTextDocument[] xTextDoc = null; @@ -58,17 +66,18 @@ public class CheckTransientDocumentsContentProvider extends ComplexTestCase { return new String[]{"checkTransientDocumentsContentProvider"}; } - public void before() { - xMSF = (XMultiServiceFactory)param.getMSF(); + @Before public void before() { + xMSF = getMSF(); xTextDoc = new XTextDocument[countDocs]; - log.println("Open some documents."); + System.out.println("Open some documents."); for (int i=0; i<countDocs; i++) { - String fileName = utils.getFullTestURL(testDocuments[i]); + String fileName = TestDocument.getUrl(testDocuments[i]); xTextDoc[i] = WriterTools.loadTextDoc(xMSF, fileName); + assertNotNull("Can't load document " + fileName, xTextDoc[i]); } } - public void after() { - log.println("Close all documents."); + @After public void after() { + System.out.println("Close all documents."); for (int i=0; i<countDocs; i++) { xTextDoc[i].dispose(); } @@ -78,18 +87,16 @@ public class CheckTransientDocumentsContentProvider extends ComplexTestCase { * Check the provider of document content: open some documents * and look if they are accessible. */ - public void checkTransientDocumentsContentProvider() { + @Test public void checkTransientDocumentsContentProvider() { try { // create a content provider Object o = xMSF.createInstance("com.sun.star.comp.ucb.TransientDocumentsContentProvider"); XContentProvider xContentProvider = - (XContentProvider)UnoRuntime.queryInterface(XContentProvider.class, o); + UnoRuntime.queryInterface(XContentProvider.class, o); // create the ucb XContentIdentifierFactory xContentIdentifierFactory = - (XContentIdentifierFactory)UnoRuntime.queryInterface( - XContentIdentifierFactory.class, xMSF.createInstance( - "com.sun.star.ucb.UniversalContentBroker")); + UnoRuntime.queryInterface(XContentIdentifierFactory.class, xMSF.createInstance("com.sun.star.ucb.UniversalContentBroker")); // create a content identifier from the ucb for tdoc XContentIdentifier xContentIdentifier = xContentIdentifierFactory.createContentIdentifier("vnd.sun.star.tdoc:/"); @@ -97,7 +104,7 @@ public class CheckTransientDocumentsContentProvider extends ComplexTestCase { XContent xContent = xContentProvider.queryContent(xContentIdentifier); // actual test: execute an "open" command with the content - XCommandProcessor xCommandProcessor = (XCommandProcessor)UnoRuntime.queryInterface(XCommandProcessor.class, xContent); + XCommandProcessor xCommandProcessor = UnoRuntime.queryInterface(XCommandProcessor.class, xContent); // build up the command Command command = new Command(); OpenCommandArgument2 commandarg2 = new OpenCommandArgument2(); @@ -109,35 +116,59 @@ public class CheckTransientDocumentsContentProvider extends ComplexTestCase { Object result = xCommandProcessor.execute(command, 0, null); // check the result - log.println("Result: "+ result.getClass().toString()); - XDynamicResultSet xDynamicResultSet = (XDynamicResultSet)UnoRuntime.queryInterface(XDynamicResultSet.class, result); + System.out.println("Result: "+ result.getClass().toString()); + XDynamicResultSet xDynamicResultSet = UnoRuntime.queryInterface(XDynamicResultSet.class, result); // check bug of wrong returned service name. - XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(XServiceInfo.class, xDynamicResultSet); + XServiceInfo xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, xDynamicResultSet); String[] sNames = xServiceInfo.getSupportedServiceNames(); String serviceName = sNames[0]; if (sNames.length > 1) - failed("Implementation has been changed. Check this test!"); - assure("The service name '" + serviceName + "' is not valid.", !serviceName.equals("com.sun.star.ucb.DynamicContentResultSet"), true); + { + fail("Implementation has been changed. Check this test!"); + } + assertTrue("The service name '" + serviceName + "' is not valid.", !serviceName.equals("com.sun.star.ucb.DynamicContentResultSet")); XResultSet xResultSet = xDynamicResultSet.getStaticResultSet(); - XContentAccess xContentAccess = (XContentAccess)UnoRuntime.queryInterface(XContentAccess.class, xResultSet); + XContentAccess xContentAccess = UnoRuntime.queryInterface(XContentAccess.class, xResultSet); // iterate over the result: three docs were opened, we should have at least three content identifier strings int countContentIdentifiers = 0; while(xResultSet.next()) { countContentIdentifiers++; String identifier = xContentAccess.queryContentIdentifierString(); - log.println("Identifier of row " + xResultSet.getRow() + ": " + identifier); + System.out.println("Identifier of row " + xResultSet.getRow() + ": " + identifier); } // some feeble test: if the amount >2, we're ok. // 2do: check better - assure("Did only find " + countContentIdentifiers + " open documents." + + assertTrue("Did only find " + countContentIdentifiers + " open documents." + " Should have been at least 3.", countContentIdentifiers>2); } catch (com.sun.star.uno.Exception e) { - e.printStackTrace((java.io.PrintWriter)log); - failed("Could not create test objects."); + e.printStackTrace(); + fail("Could not create test objects."); } } + + private XMultiServiceFactory getMSF() + { + final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + return xMSF1; + } + + // setup and close connections + @BeforeClass public static void setUpConnection() throws Exception { + System.out.println("setUpConnection()"); + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println("tearDownConnection()"); + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); + } |