public void addChildren(List<BandData> bands) { for (BandData band : bands) addChild(band); }
public void addChildren(List<BandData> bands) { for (BandData band : bands) addChild(band); }
private BandData band(String name, BandData root) { BandData band1 = new BandData(name, root, BandOrientation.HORIZONTAL); band1.setData(new HashMap<>()); root.addChild(band1); return band1; }
private BandData randomBand(String name, BandData root) { BandData band1 = new BandData(name, root, BandOrientation.HORIZONTAL); band1.setData(new RandomMap()); root.addChild(band1); return band1; }
@Test public void testXls() throws Exception { BandData root = createRootBand(); BandData date = new BandData("Date", root); BandData dateHeader = new BandData("DateHeader", root); date.addData("date", new Date()); root.addChild(dateHeader); root.addChild(date); List<BandData> band1objects = root.getChildrenByName("Band1"); for (int i = 0; i < band1objects.size(); i++) { BandData bandData = band1objects.get(i); if (i % 2 == 0) { bandData.addData("theStyle", "red"); } } FileOutputStream outputStream = new FileOutputStream("./result/smoke/result.xls"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("xls", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.xls", "./modules/core/test/smoketest/test.xls", ReportOutputType.xls), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testFormats() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); HashMap<String, Object> rootData = new HashMap<String, Object>(); root.setData(rootData); BandData band1 = new BandData("Band1", root, BandOrientation.HORIZONTAL); band1.addData("date", new SimpleDateFormat("dd-MM-yyyy").parse("12-04-1961")); root.addChild(band1); FileOutputStream outputStream = new FileOutputStream("./result/integration/result-formats.xls"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("xls", root, new ReportTemplateImpl("", "./modules/core/test/integration/test-formats.xls", "./modules/core/test/integration/test-formats.xls", ReportOutputType.xls), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); compareFiles("./modules/core/test/integration/etalon-formats.xls", "./result/integration/result-formats.xls"); }
private BandData createBand(String name, int multiplier, BandData root, BandOrientation childOrient) { BandData band1_1 = new BandData(name, root, BandOrientation.HORIZONTAL); band1_1.addData("col1", 1 * multiplier); band1_1.addData("col2", 2 * multiplier); BandData band11_1 = new BandData(name + "1", band1_1, childOrient); band11_1.addData("col1", 10 * multiplier); band11_1.addData("col2", 20 * multiplier); BandData band11_2 = new BandData(name + "1", band1_1, childOrient); band11_2.addData("col1", 100 * multiplier); band11_2.addData("col2", 200 * multiplier); band1_1.addChild(band11_1); band1_1.addChild(band11_2); return band1_1; }
@Override public void run() { try { BandData root = createRootBand(); root.addReportFieldFormats(Arrays.asList(new ReportFieldFormatImpl("Band1.col2", "${html}"))); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result_parallel3.doc"); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("doc", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.doc", "./modules/core/test/smoketest/test.doc", ReportOutputType.doc), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); } catch (IOException e) { Assert.fail(); } finally { countDownLatch.countDown(); } } }.start();
@Test public void testDocxWithSplittedAlias() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); HashMap<String, Object> rootData = new HashMap<>(); rootData.put("param1", "AAAAAA"); root.setData(rootData); BandData cover = new BandData("Cover", root, BandOrientation.HORIZONTAL); cover.setData(new HashMap<>()); cover.addData("index", "123"); cover.addData("volume", "321"); cover.addData("name", "AAA"); BandData documents = new BandData("Documents", root, BandOrientation.HORIZONTAL); documents.setData(new HashMap<>()); root.addChild(cover); root.addChild(documents); FileOutputStream outputStream = new FileOutputStream("./result/smoke/splitted-aliases.docx"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/splitted-aliases.docx", "./modules/core/test/smoketest/splitted-aliases.docx", ReportOutputType.docx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testHtmlFormatter() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); BandData userBand = new BandData("User", root, BandOrientation.HORIZONTAL); userBand.addData("active", true); userBand.addData("login", "admin"); root.addChild(userBand); root.setFirstLevelBandDefinitionNames(new HashSet<String>()); root.getFirstLevelBandDefinitionNames().add("User"); FileOutputStream outputStream = new FileOutputStream("./result/integration/html-groovy-test-result.html"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("html", root, new ReportTemplateImpl("", "./modules/core/test/integration/html-groovy-test-template.html", "./modules/core/test/integration/html-groovy-test-template.html", ReportOutputType.html, true), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); File sample = new File("./modules/core/test/integration/html-groovy-test-template-result.html"); File result = new File("./result/integration/html-groovy-test-result.html"); boolean isTwoEqual = FileUtils.contentEqualsIgnoreEOL(sample, result, null); Assert.assertTrue("Files are not equal", isTwoEqual); } }
@Test public void testHtml() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); HashMap<String, Object> rootData = new HashMap<>(); rootData.put("param1", "AAAAAA"); root.setData(rootData); BandData band11 = new BandData("Band1", root, BandOrientation.HORIZONTAL); band11.setData(new RandomMap()); BandData band12 = new BandData("Band1", root, BandOrientation.HORIZONTAL); band12.setData(new RandomMap()); root.addChild(band11); root.addChild(band12); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result.html"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("html", root, new ReportTemplateImpl("", "test.ftl", "./modules/core/test/smoketest/test.ftl", ReportOutputType.html), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Ignore("Fails on Travis CI") @Test public void testXlsxFormats() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); HashMap<String, Object> rootData = new HashMap<String, Object>(); root.setData(rootData); BandData header = new BandData("Header", root, BandOrientation.VERTICAL); BandData band = new BandData("Band", root, BandOrientation.VERTICAL); band.addData("number", BigDecimal.valueOf(-200015)); band.addData("date", new Date(1440747161585L)); band.addData("money", -113123d); band.addData("text", "someText"); root.addChild(header); root.addChild(band); FileOutputStream outputStream = new FileOutputStream("./result/integration/result-formats.xlsx"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("xlsx", root, new ReportTemplateImpl("", "./modules/core/test/integration/test-formats.xlsx", "./modules/core/test/integration/test-formats.xlsx", ReportOutputType.xlsx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); compareFiles("./result/integration/result-formats.xlsx", "./modules/core/test/integration/etalon-formats.xlsx"); }
@Test public void testDocxToHtml() throws Exception { BandData root = createRootBand(); root.addReportFieldFormats(Collections.singletonList(new ReportFieldFormatImpl("Band1.col2", "${html}"))); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result_docx.html"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.docx", "./modules/core/test/smoketest/test.docx", ReportOutputType.html), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testDocxTableWithSplittedBandAlias() throws Exception { BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL); HashMap<String, Object> rootData = new HashMap<>(); root.setData(rootData); BandData ride = new BandData("ride", root, BandOrientation.HORIZONTAL); ride.setData(new RandomMap()); root.addChild(ride); FileOutputStream outputStream = new FileOutputStream("./result/smoke/splitted-aliases-in-table.docx"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/splitted-aliases-in-table.docx", "./modules/core/test/smoketest/splitted-aliases-in-table.docx", ReportOutputType.docx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testDocx() throws Exception { BandData root = createRootBand(); root.addReportFieldFormats(Collections.singletonList(new ReportFieldFormatImpl("Band1.col2", "${html}"))); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footerChild.addData("nestedData.withPoint", "NESTED_DATA_WITH_POINT"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result.docx"); ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.docx", "./modules/core/test/smoketest/test.docx", ReportOutputType.docx), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testTableOdt() throws Exception { BandData root = new BandData("Root"); root.setData(new RandomMap()); BandData ship = new BandData("Ship", root); ship.setData(new RandomMap()); BandData corrosion = new BandData("Corrosion", root); corrosion.setData(new RandomMap()); BandData custom = new BandData("Custom", root); custom.setData(new RandomMap()); root.addChild(ship); root.addChild(corrosion); root.addChild(custom); FileOutputStream outputStream = new FileOutputStream("./result/smoke/table.doc"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); defaultFormatterFactory.setOfficeIntegration(new OfficeIntegration(openOfficePath, 8100)); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("odt", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/table.odt", "./modules/core/test/smoketest/table.odt", ReportOutputType.doc), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testOdt() throws Exception { BandData root = createRootBand(); root.addReportFieldFormats(Collections.singletonList(new ReportFieldFormatImpl("Band1.col2", "${html}"))); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result.doc"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); defaultFormatterFactory.setOfficeIntegration(new OfficeIntegration(openOfficePath, 8100)); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("odt", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.odt", "./modules/core/test/smoketest/test.odt", ReportOutputType.doc), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testDocxToHtml_OfficeIntegration() throws Exception { BandData root = createRootBand(); root.addReportFieldFormats(Collections.singletonList(new ReportFieldFormatImpl("Band1.col2", "${html}"))); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result_docx_office.html"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); defaultFormatterFactory.setOfficeIntegration(new OfficeIntegration(openOfficePath, 8100)); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.docx", "./modules/core/test/smoketest/test.docx", ReportOutputType.html), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testDocxToPdf() throws Exception { BandData root = createRootBand(); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result_docx.pdf"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); defaultFormatterFactory.setOfficeIntegration(new OfficeIntegration(openOfficePath, 8100)); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("docx", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.docx", "./modules/core/test/smoketest/test.docx", ReportOutputType.pdf), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }
@Test public void testDoc() throws Exception { BandData root = createRootBand(); root.addReportFieldFormats(Collections.singletonList(new ReportFieldFormatImpl("Band1.col2", "${html}"))); BandData footer = root.getChildByName("Footer"); BandData footerChild = new BandData("FooterChild", footer); footerChild.addData("nestedData", "NESTED_DATA"); footer.addChild(footerChild); FileOutputStream outputStream = new FileOutputStream("./result/smoke/result2.doc"); DefaultFormatterFactory defaultFormatterFactory = new DefaultFormatterFactory(); defaultFormatterFactory.setOfficeIntegration(new OfficeIntegration(openOfficePath, 8100)); ReportFormatter formatter = defaultFormatterFactory.createFormatter(new FormatterFactoryInput("doc", root, new ReportTemplateImpl("", "./modules/core/test/smoketest/test.doc", "./modules/core/test/smoketest/test.doc", ReportOutputType.doc), outputStream)); formatter.renderDocument(); IOUtils.closeQuietly(outputStream); }