You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OSGiSpreadsheetIT.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.osgi;
  16. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  17. import org.apache.poi.ss.usermodel.Sheet;
  18. import org.apache.poi.ss.usermodel.Workbook;
  19. import org.apache.poi.ss.usermodel.WorkbookFactory;
  20. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  21. import org.junit.Test;
  22. import org.junit.runner.RunWith;
  23. import org.ops4j.pax.exam.junit.PaxExam;
  24. import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
  25. import org.ops4j.pax.exam.spi.reactors.PerClass;
  26. import java.io.ByteArrayInputStream;
  27. import java.io.ByteArrayOutputStream;
  28. import static org.junit.Assert.assertEquals;
  29. /**
  30. * Test to ensure that all our main formats can create, write
  31. * and read back in, when running under OSGi
  32. */
  33. @RunWith(PaxExam.class)
  34. @ExamReactorStrategy(PerClass.class)
  35. public class OSGiSpreadsheetIT extends BaseOSGiTestCase {
  36. // create a workbook, validate and write back
  37. void testWorkbook(Workbook wb) throws Exception {
  38. Sheet s = wb.createSheet("OSGi");
  39. s.createRow(0).createCell(0).setCellValue("With OSGi");
  40. s.createRow(1).createCell(0).setCellFormula("SUM(A1:B3)");
  41. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  42. wb.write(baos);
  43. ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  44. wb = WorkbookFactory.create(bais);
  45. assertEquals(1, wb.getNumberOfSheets());
  46. s = wb.getSheet("OSGi");
  47. assertEquals("With OSGi", s.getRow(0).getCell(0).toString());
  48. assertEquals("SUM(A1:B3)", s.getRow(1).getCell(0).toString());
  49. }
  50. @Test
  51. public void testHSSF() throws Exception {
  52. testWorkbook(new HSSFWorkbook());
  53. }
  54. @Test
  55. public void testXSSF() throws Exception {
  56. testWorkbook(new XSSFWorkbook());
  57. }
  58. @Test
  59. public void testSXSSF() throws Exception {
  60. testWorkbook(new XSSFWorkbook());
  61. }
  62. @Test
  63. public void testFormulaEvaluation() throws Exception {
  64. testWorkbook(new XSSFWorkbook());
  65. }
  66. }