Java Code Examples for org.apache.poi.xssf.extractor.XSSFExcelExtractor

The following examples show how to use org.apache.poi.xssf.extractor.XSSFExcelExtractor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: carbon-apimgt   Source File: MSExcelIndexerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    excelExtractor = Mockito.mock(ExcelExtractor.class);
    xssfExtractor = Mockito.mock(XSSFExcelExtractor.class);
    msExcelIndexer = new MSExcelIndexerWrapper(xssfExtractor, excelExtractor);
    file2Index = new AsyncIndexer.File2Index("".getBytes(),
            "", "", -1234, "");
}
 
Example 2
Source Project: carbon-apimgt   Source File: MSExcelIndexer.java    License: Apache License 2.0 4 votes vote down vote up
protected XSSFExcelExtractor getXssfExcelExtractor(File2Index fileData) throws IOException {
	XSSFWorkbook xssfSheets = new XSSFWorkbook(new ByteArrayInputStream(fileData.data));
	return new XSSFExcelExtractor(xssfSheets);
}
 
Example 3
Source Project: carbon-apimgt   Source File: MSExcelIndexerWrapper.java    License: Apache License 2.0 4 votes vote down vote up
public MSExcelIndexerWrapper(XSSFExcelExtractor xssfExtractor, ExcelExtractor excelExtractor) {
    this.xssfExcelExtractor = xssfExtractor;
    this.excelExtractor = excelExtractor;
}
 
Example 4
Source Project: carbon-apimgt   Source File: MSExcelIndexerWrapper.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected XSSFExcelExtractor getXssfExcelExtractor(AsyncIndexer.File2Index fileData) throws IOException {
    return this.xssfExcelExtractor;
}
 
Example 5
@WithMockUser(
    username = USERNAME,
    roles = {ROLE_SU})
@Test
public void test() throws IOException {
  Package pack = packageFactory.create("pack");
  pack.setLabel("pack");
  dataService.getMeta().addPackage(pack);

  Package it = packageFactory.create("it");
  it.setLabel("it");
  dataService.getMeta().addPackage(it);

  Package emx = packageFactory.create("it_emx");
  emx.setLabel("it_emx");
  emx.setParent(it);
  dataService.getMeta().addPackage(emx);

  EntityType refEntityType1 = entityTestHarness.createDynamicRefEntityType("pack_refTest1");
  refEntityType1.setPackage(pack);
  EntityType entityType1 =
      entityTestHarness.createDynamicTestEntityType(refEntityType1, "pack_test1");
  entityType1.setPackage(pack);

  dataService.getMeta().addEntityType(refEntityType1);
  dataService.getMeta().addEntityType(entityType1);
  List<Entity> refEntities = entityTestHarness.createTestRefEntities(refEntityType1, 2);
  List<Entity> testEntities =
      entityTestHarness.createTestEntities(entityType1, 4, refEntities).collect(toList());
  dataService.add(refEntityType1.getId(), refEntities.stream());
  dataService.add(entityType1.getId(), testEntities.stream());

  EntityType entityType2 = entityTestHarness.createDynamicRefEntityType("it_emx_test1");

  entityType2.setPackage(emx);
  dataService.getMeta().addEntityType(entityType2);
  dataService.add(
      entityType2.getId(), entityTestHarness.createTestRefEntities(entityType2, 2).stream());
  Path actual = Files.createTempFile("test", ".xlsx");
  // when using the "in memory" it package, created above, the "getChildern" returns null.
  Package actualIt = dataService.getMeta().getPackage("it").get();
  // We're testing the export service, not a job, use TestProgress to check if progress is updated
  TestProgress progress = new TestProgress();
  emxDownloadService.export(
      newArrayList(entityType1, refEntityType1), newArrayList(actualIt), actual, progress);
  try (XSSFWorkbook actualWorkbook = new XSSFWorkbook(Files.newInputStream(actual))) {
    try (XSSFWorkbook expected =
        new XSSFWorkbook(
            new FileInputStream(
                ResourceUtils.getFile(
                    EmxExportServiceIT.class, "/xls/expectedDownloadResult.xlsx")))) {
      // XSSFExcelExtractor results in tab differences between actual and expected even though
      // both excel files are correct
      String actualWorkbookString =
          new XSSFExcelExtractor(actualWorkbook).getText().replaceAll("\t", "");
      String expectedWorkbookString =
          new XSSFExcelExtractor(expected).getText().replaceAll("\t", "");
      assertEquals(expectedWorkbookString, actualWorkbookString);
    }
  }

  TestProgress expectedProgress =
      new TestProgress(
          4,
          4,
          "Downloading 'pack_refTest1'\nDownloading 'pack_test1'\nDownloading 'it_emx_test1'\nFinished downloading package metadata.",
          "");
  assertEquals(expectedProgress.getMessage(), progress.getMessage());
  assertEquals(expectedProgress.getProgress(), progress.getProgress());
  assertEquals(expectedProgress.getProgressMax(), progress.getProgressMax());
  assertEquals(expectedProgress.getResultUrl(), progress.getResultUrl());
}