-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from FreemanZhang/master
Add unit test for OS SDK OSGi
- Loading branch information
Showing
4 changed files
with
170 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
.../birt-packages/birt-runtime-test/src/test/java/org/eclipse/birt/sdk/BaseTestTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2013 Actuate Corporation. | ||
* All rights reserved. | ||
*******************************************************************************/ | ||
package org.eclipse.birt.sdk; | ||
|
||
import java.io.File; | ||
import java.io.FilenameFilter; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
*/ | ||
|
||
public abstract class BaseTestTemplate | ||
{ | ||
|
||
protected Class mainClass; | ||
protected ClassLoader loader; | ||
|
||
@Test | ||
public void testMain( ) throws Exception | ||
{ | ||
String output = "./target/output.html"; | ||
new File( output ).delete( ); | ||
int result = run( new String[]{"-o", output, "-m", "RunAndRender", | ||
"./target/birt-runtime/ReportEngine/samples/hello_world.rptdesign"} ); | ||
Assert.assertEquals( 0, result ); | ||
Assert.assertTrue( new File( output ).exists( ) ); | ||
Assert.assertTrue( new String( Files.readAllBytes( Paths.get( output ) ), StandardCharsets.UTF_8 ) | ||
.contains( "If you can see this report, it means that the BIRT viewer is installed correctly." ) ); | ||
} | ||
|
||
@Test | ||
public void testTable( ) throws Exception | ||
{ | ||
String output = "./target/table.html"; | ||
new File( output ).delete( ); | ||
int result = run( new String[]{"-o", output, "-m", "RunAndRender", "./src/test/resources/table.rptdesign"} ); | ||
Assert.assertEquals( 0, result ); | ||
Assert.assertTrue( new File( output ).exists( ) ); | ||
//USA's customer count is 36 | ||
Assert.assertTrue( | ||
new String( Files.readAllBytes( Paths.get( output ) ), StandardCharsets.UTF_8 ).contains( "36" ) ); | ||
} | ||
|
||
@Test | ||
public void testXtab( ) throws Exception | ||
{ | ||
String output = "./target/xtab.html"; | ||
new File( output ).delete( ); | ||
int result = run( new String[]{"-o", output, "-m", "RunAndRender", "./src/test/resources/xtab.rptdesign"} ); | ||
Assert.assertEquals( 0, result ); | ||
Assert.assertTrue( new File( output ).exists( ) ); | ||
//USA's customer count is 36 | ||
Assert.assertTrue( | ||
new String( Files.readAllBytes( Paths.get( output ) ), StandardCharsets.UTF_8 ).contains( "36" ) ); | ||
} | ||
|
||
@Test | ||
public void testChart( ) throws Exception | ||
{ | ||
String output = "./target/chart.html"; | ||
new File( output ).delete( ); | ||
int result = run( new String[]{"-o", output, "-m", "RunAndRender", "./src/test/resources/chart.rptdesign"} ); | ||
Assert.assertEquals( 0, result ); | ||
Assert.assertTrue( new File( output ).exists( ) ); | ||
//there is a svg image output as type="image/svg+xml" | ||
Assert.assertTrue( new String( Files.readAllBytes( Paths.get( output ) ), StandardCharsets.UTF_8 ) | ||
.contains( "image/svg+xml" ) ); | ||
} | ||
|
||
protected File[] listJars( String folder ) | ||
{ | ||
return new File( folder ).listFiles( new FilenameFilter( ) { | ||
|
||
@Override | ||
public boolean accept( File dir, String name ) | ||
{ | ||
if ( name.endsWith( ".jar" ) ) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} ); | ||
} | ||
|
||
protected ClassLoader createClassLoader( String folder ) throws MalformedURLException | ||
{ | ||
File[] jarFiles = listJars( folder ); | ||
URL[] urls = new URL[jarFiles.length]; | ||
for ( int i = 0; i < jarFiles.length; i++ ) | ||
{ | ||
urls[i] = jarFiles[i].toURI( ).toURL( ); | ||
} | ||
return new URLClassLoader( urls ); | ||
} | ||
|
||
public abstract int run( String[] args ) throws Exception; | ||
} |
31 changes: 31 additions & 0 deletions
31
...d/birt-packages/birt-runtime-test/src/test/java/org/eclipse/birt/sdk/RuntimeOSGiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2013 Actuate Corporation. | ||
* All rights reserved. | ||
*******************************************************************************/ | ||
package org.eclipse.birt.sdk; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* | ||
*/ | ||
|
||
public class RuntimeOSGiTest extends BaseTestTemplate | ||
{ | ||
public int run( String[] args ) throws Exception | ||
{ | ||
if ( mainClass == null ) | ||
{ | ||
System.setProperty( "BIRT_HOME", new File("./target/birt-runtime-osgi/ReportEngine").getAbsolutePath() ); | ||
loader = createClassLoader( "./target/birt-runtime-osgi/ReportEngine/lib" ); //$NON-NLS-1$ | ||
mainClass = loader.loadClass( "org.eclipse.birt.report.engine.api.ReportRunner" ); //$NON-NLS-1$ | ||
} | ||
Constructor constructor = mainClass.getConstructor( String[].class ); | ||
Object runner = constructor.newInstance( new Object[]{args} ); | ||
Method execute = mainClass.getMethod( "execute", null ); | ||
Object result = execute.invoke( runner, null ); | ||
return ( (Integer) result ).intValue( ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters