2007-07-24 12:24:22 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 06:54:29 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2007-07-24 12:24:22 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2007-07-24 12:24:22 +00:00
|
|
|
*
|
2008-04-11 06:54:29 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2007-07-24 12:24:22 +00:00
|
|
|
*
|
2008-04-11 06:54:29 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2007-07-24 12:24:22 +00:00
|
|
|
*
|
2008-04-11 06:54:29 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2007-07-24 12:24:22 +00:00
|
|
|
*
|
2008-04-11 06:54:29 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2007-07-24 12:24:22 +00:00
|
|
|
*
|
2008-04-11 06:54:29 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2007-07-24 12:24:22 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
// package name: as default, start with complex
|
|
|
|
package complex.api_internal;
|
|
|
|
|
|
|
|
// imports
|
|
|
|
import helper.OfficeProvider;
|
|
|
|
import helper.ProcessHandler;
|
|
|
|
import com.sun.star.task.XJob;
|
|
|
|
import com.sun.star.beans.XPropertyAccess;
|
|
|
|
import com.sun.star.lang.XMultiServiceFactory;
|
|
|
|
import com.sun.star.beans.PropertyValue;
|
|
|
|
import com.sun.star.uno.UnoRuntime;
|
|
|
|
import com.sun.star.beans.NamedValue;
|
|
|
|
|
|
|
|
import java.util.Vector;
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
|
2010-06-28 12:54:49 +02:00
|
|
|
|
|
|
|
// ---------- junit imports -----------------
|
|
|
|
import lib.TestParameters;
|
|
|
|
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.*;
|
|
|
|
// ------------------------------------------
|
|
|
|
|
2007-07-24 12:24:22 +00:00
|
|
|
/**
|
|
|
|
* This test executes the API tests internally in StarOffice. Prerequiste is
|
|
|
|
* that a OOoRunner.jar is registered inseide of StarOffice. Adjust the joblist
|
|
|
|
* inside of the ChekAPI.props to determine which tetss will be executed.
|
|
|
|
*/
|
2010-06-28 12:54:49 +02:00
|
|
|
public class CheckAPI {
|
2007-07-24 12:24:22 +00:00
|
|
|
|
|
|
|
// The name of the tested service
|
|
|
|
private final String testName = "StarOfficeAPI";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all test methods.
|
|
|
|
* @return The test methods.
|
|
|
|
*/
|
2010-06-28 12:54:49 +02:00
|
|
|
// public String[] getTestMethodNames() {
|
|
|
|
// return new String[]{"checkAPI"};
|
|
|
|
// }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The test parameters
|
|
|
|
*/
|
|
|
|
private static TestParameters param = null;
|
2007-07-24 12:24:22 +00:00
|
|
|
|
2010-06-28 12:54:49 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Before public void before()
|
|
|
|
{
|
|
|
|
param = new TestParameters();
|
|
|
|
}
|
2007-07-24 12:24:22 +00:00
|
|
|
/**
|
|
|
|
* Execute the API tests inside of the Office. If the Office crashes, it
|
|
|
|
* will be restarted and the job will continue after the one that caused the crash.
|
|
|
|
*/
|
2010-06-28 12:54:49 +02:00
|
|
|
@Test public void checkAPI() {
|
|
|
|
System.out.println("Start with test");
|
2007-07-24 12:24:22 +00:00
|
|
|
// if test is idle for 5 minutes, assume that it hangs and kill it.
|
2010-06-28 12:54:49 +02:00
|
|
|
// param.put("TimeOut", new Integer("300000"));
|
|
|
|
XMultiServiceFactory xMSF = getMSF();
|
2007-07-24 12:24:22 +00:00
|
|
|
Object oObj = null;
|
|
|
|
try {
|
|
|
|
oObj = xMSF.createInstance("org.openoffice.RunnerService");
|
|
|
|
}
|
|
|
|
catch(com.sun.star.uno.Exception e) {
|
2010-06-28 12:54:49 +02:00
|
|
|
fail("Could not create Instance of 'org.openoffice.RunnerService'");
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
2010-06-28 12:54:49 +02:00
|
|
|
assertNotNull("Cannot create 'org.openoffice.RunnerService'", oObj);
|
|
|
|
|
2007-07-24 12:24:22 +00:00
|
|
|
// get the parameters for the internal test
|
|
|
|
String paramList = (String)param.get("ParamList");
|
|
|
|
Vector p = new Vector();
|
|
|
|
StringTokenizer paramTokens = new StringTokenizer(paramList, " ");
|
2010-06-28 12:54:49 +02:00
|
|
|
while(paramTokens.hasMoreTokens())
|
|
|
|
{
|
2007-07-24 12:24:22 +00:00
|
|
|
p.add(paramTokens.nextToken());
|
|
|
|
}
|
|
|
|
int length = p.size()/2+1;
|
|
|
|
NamedValue[] internalParams = new NamedValue[length];
|
|
|
|
for (int i=0; i<length-1; i++) {
|
|
|
|
internalParams[i] = new NamedValue();
|
|
|
|
internalParams[i].Name = (String)p.get(i*2);
|
|
|
|
internalParams[i].Value = p.get(i*2+1);
|
2010-06-28 12:54:49 +02:00
|
|
|
System.out.println("Name: "+internalParams[i].Name);
|
|
|
|
System.out.println("Value: "+(String)internalParams[i].Value);
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// do we have test jobs?
|
|
|
|
String testJob = (String)param.get("job");
|
|
|
|
PropertyValue[]props;
|
2010-06-28 12:54:49 +02:00
|
|
|
if (testJob==null)
|
|
|
|
{
|
|
|
|
if ( param.get("job1")==null )
|
|
|
|
{
|
2007-07-24 12:24:22 +00:00
|
|
|
// get all test jobs from runner service
|
|
|
|
XPropertyAccess xPropAcc = (XPropertyAccess)UnoRuntime.queryInterface(XPropertyAccess.class, oObj);
|
|
|
|
props = xPropAcc.getPropertyValues();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int index=1;
|
|
|
|
p = new Vector();
|
|
|
|
while ( param.get("job"+index) != null ) {
|
|
|
|
p.add(param.get("job"+index));
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
props = new PropertyValue[p.size()];
|
|
|
|
for ( int i=0; i<props.length; i++ ) {
|
|
|
|
props[i] = new PropertyValue();
|
|
|
|
props[i].Value = p.get(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
props = new PropertyValue[1];
|
|
|
|
props[0] = new PropertyValue();
|
|
|
|
props[0].Value = testJob;
|
|
|
|
}
|
|
|
|
|
2010-06-28 12:54:49 +02:00
|
|
|
System.out.println("Props length: "+ props.length);
|
2007-07-24 12:24:22 +00:00
|
|
|
for (int i=0; i<props.length; i++) {
|
2010-06-28 12:54:49 +02:00
|
|
|
XJob xJob = UnoRuntime.queryInterface(XJob.class, oObj);
|
2007-07-24 12:24:22 +00:00
|
|
|
internalParams[length-1] = new NamedValue();
|
|
|
|
internalParams[length-1].Name = "-o";
|
|
|
|
internalParams[length-1].Value = props[i].Value;
|
2010-06-28 12:54:49 +02:00
|
|
|
System.out.println("Executing: " + (String)props[i].Value);
|
2007-07-24 12:24:22 +00:00
|
|
|
|
|
|
|
String erg = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
erg = (String)xJob.execute(internalParams);
|
|
|
|
}
|
|
|
|
catch(Throwable t) {
|
|
|
|
// restart and go on with test!!
|
2010-06-28 12:54:49 +02:00
|
|
|
t.printStackTrace();
|
|
|
|
fail("Test run '" + (String)props[i].Value +"' could not be executed: Office crashed and is killed!");
|
2007-07-24 12:24:22 +00:00
|
|
|
xMSF = null;
|
|
|
|
ProcessHandler handler = (ProcessHandler)param.get("AppProvider");
|
|
|
|
handler.kill();
|
|
|
|
try {
|
|
|
|
Thread.sleep(10000);
|
|
|
|
}
|
|
|
|
catch(java.lang.InterruptedException e) {}
|
|
|
|
OfficeProvider op = new OfficeProvider();
|
|
|
|
xMSF = (XMultiServiceFactory)op.getManager(param);
|
|
|
|
param.put("ServiceFactory",xMSF);
|
|
|
|
try {
|
|
|
|
oObj = xMSF.createInstance("org.openoffice.RunnerService");
|
|
|
|
}
|
|
|
|
catch(com.sun.star.uno.Exception e) {
|
2010-06-28 12:54:49 +02:00
|
|
|
fail("Could not create Instance of 'org.openoffice.RunnerService'");
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-28 12:54:49 +02:00
|
|
|
System.out.println(erg);
|
2007-07-24 12:24:22 +00:00
|
|
|
String processedErg = parseResult(erg);
|
2010-06-28 12:54:49 +02:00
|
|
|
assertTrue("Run '" + (String)props[i].Value + "' has result '" + processedErg + "'", processedErg == null);
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String parseResult(String erg) {
|
|
|
|
String lineFeed = System.getProperty("line.separator");
|
|
|
|
String processedErg = null;
|
|
|
|
if (erg != null) {
|
|
|
|
StringTokenizer token = new StringTokenizer(erg, lineFeed);
|
|
|
|
String previousLine = null;
|
|
|
|
while ( token.hasMoreTokens() ) {
|
|
|
|
String line = token.nextToken();
|
|
|
|
// got a failure!
|
|
|
|
if ( line.indexOf("FAILED") != -1 ) {
|
|
|
|
processedErg = (processedErg == null)?"":processedErg + ";";
|
|
|
|
processedErg += previousLine + ":" + line;
|
|
|
|
}
|
|
|
|
if ( line.startsWith("Execute:") ) {
|
|
|
|
previousLine = line;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
previousLine += " " + line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return processedErg;
|
|
|
|
}
|
2010-06-28 12:54:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2007-07-24 12:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|