diff options
Diffstat (limited to 'osgi/src')
-rw-r--r-- | osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java (renamed from osgi/src/test/java/org/apache/poi/osgi/TestOSGiBundle.java) | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/osgi/src/test/java/org/apache/poi/osgi/TestOSGiBundle.java b/osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java index 738d96b994..ea139e7e50 100644 --- a/osgi/src/test/java/org/apache/poi/osgi/TestOSGiBundle.java +++ b/osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java @@ -28,11 +28,15 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.net.URISyntaxException; +import java.lang.invoke.MethodHandles; +import java.util.Arrays; -import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.Test; import org.junit.runner.RunWith; import org.ops4j.pax.exam.Configuration; @@ -40,9 +44,9 @@ import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerMethod; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Test to ensure that all our main formats can create, write @@ -50,35 +54,64 @@ import org.osgi.framework.ServiceReference; */ @RunWith(PaxExam.class) @ExamReactorStrategy(PerMethod.class) -public class TestOSGiBundle { +public class OSGiSpreadsheetIT { + private final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final File TARGET = new File("target"); + public static final String POI_BUNDLE_SYMBOLIC_NAME = "org.apache.poi.bundle"; @Inject private BundleContext bc; @Configuration - public Option[] configuration() throws IOException, URISyntaxException { - File base = new File(TARGET, "test-bundles"); + public Option[] configuration() throws IOException { + String bundlePath = System.getProperty("bundle.filename"); return options( junitBundles(), - bundle(new File(base, "poi-bundle.jar").toURI().toURL().toString())); + bundle(new File(bundlePath).toURI().toURL().toString())); } @Test - public void testHSSF() throws Exception { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet("OSGi"); + public void testBundleLoaded() { + boolean hasBundle = Arrays.stream(bc.getBundles()).anyMatch(b -> + POI_BUNDLE_SYMBOLIC_NAME.equals(b.getSymbolicName())); + assertTrue(POI_BUNDLE_SYMBOLIC_NAME + " not found", hasBundle); + } + + // create a workbook, validate and write back + void testWorkbook(Workbook wb) throws Exception { + logger.info("testing " + wb.getClass().getSimpleName()); + + Sheet s = wb.createSheet("OSGi"); s.createRow(0).createCell(0).setCellValue("With OSGi"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); wb.write(baos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - wb = new HSSFWorkbook(bais); + if(wb instanceof HSSFWorkbook) + wb = new HSSFWorkbook(bais); + else + wb = new XSSFWorkbook(bais); assertEquals(1, wb.getNumberOfSheets()); s = wb.getSheet("OSGi"); assertEquals("With OSGi", s.getRow(0).getCell(0).toString()); + + + } + + @Test + public void testHSSF() throws Exception { + testWorkbook(new HSSFWorkbook()); + } + + @Test + public void testXSSF() throws Exception { + testWorkbook(new XSSFWorkbook()); + } + + @Test + public void testSXSSF() throws Exception { + testWorkbook(new SXSSFWorkbook()); } } |