TitleBlockWriter { public byte[] createTitleBlock() throws IOException { writeEntityInfo(); writeAttributes(); writeLifeCycleState(); return documentToByteArray(document); } TitleBlockWriter();  TitleBlockWriter(TitleBlockData pData); byte[] createTitleBlock();  }
@Test public void createTitleBlockForDocumentIterationTest() throws Exception { DocumentTitleBlockData documentTitleData = new DocumentTitleBlockData(documentIteration, new Locale("en")); byte[] titleBlock = new TitleBlockWriter(documentTitleData).createTitleBlock(); PDDocument loadedDocument = PDDocument.load(titleBlock); Assert.assertNotNull(loadedDocument); String text = new PDFTextStripper().getText(loadedDocument); loadedDocument.close(); Assert.assertFalse(text.isEmpty()); Assert.assertTrue(text.contains(user.getLogin())); Assert.assertTrue(text.contains(documentIteration.getId())); Assert.assertTrue(text.contains(documentIteration.getDocumentRevision().getDescription())); }
@Test public void createTitleBlockForPartIterationTest() throws Exception { PartTitleBlockData partTitleBlockData = new PartTitleBlockData(partIteration, new Locale("en")); byte[] titleBlock = new TitleBlockWriter(partTitleBlockData).createTitleBlock(); PDDocument loadedDocument = PDDocument.load(titleBlock); Assert.assertNotNull(loadedDocument); String text = new PDFTextStripper().getText(loadedDocument); loadedDocument.close(); Assert.assertFalse(text.isEmpty()); Assert.assertTrue(text.contains(user.getLogin())); Assert.assertTrue(text.contains(partIteration.getNumber())); Assert.assertTrue(text.contains(partIteration.getPartRevision().getDescription())); }
@Test public void mergeTitleBlock() throws IOException { PartTitleBlockData partTitleBlockData = new PartTitleBlockData(partIteration, new Locale("en")); byte[] titleBlock = new TitleBlockWriter(partTitleBlockData).createTitleBlock(); URL resource = TitleBlockWriterTest.class.getClassLoader() .getResource("org/polarsys/eplmp/server/extras/sample.pdf"); Assert.assertNotNull(resource); byte[] pdfBytes = IOUtils.toByteArray(new FileInputStream(resource.getPath())); ByteArrayInputStream pdfStream = new ByteArrayInputStream(pdfBytes); InputStream merge = TitleBlockGenerator.merge(pdfStream, titleBlock); PDDocument mergedDocument = PDDocument.load(merge); PDDocument pdfAsDocument = PDDocument.load(pdfBytes); PDDocument titleBlockAsDocument = PDDocument.load(titleBlock); Assert.assertEquals(mergedDocument.getNumberOfPages(), titleBlockAsDocument.getNumberOfPages() + pdfAsDocument.getNumberOfPages()); String titleBlockText = new PDFTextStripper().getText(titleBlockAsDocument); String pdfText = new PDFTextStripper().getText(pdfAsDocument); String mergedText = new PDFTextStripper().getText(mergedDocument); Assert.assertEquals(mergedText, titleBlockText + pdfText); }