PdfFileSourceAdapter { public PdfFileSource getPdfFileSource() { return pdfFileSource; } PdfFileSourceAdapter(String filePathAndPassword); PdfFileSource getPdfFileSource(); static final String PASSWORD_SEPARATOR_CHARACTER; }
@Test public void windowsFileWithPassword() { PdfFileSource result = new PdfFileSourceAdapter("/tmp/inputFile1.pdf:secret123").getPdfFileSource(); assertThat(result.getPassword(), is("secret123")); assertThat(result.getSource(), CombinableMatcher.<File> either(is(new File("/tmp/inputFile1.pdf"))).or( is(new File("c:\\tmp\\inputFile1.pdf")))); }
@Test public void windowsFileNoPassword() { PdfFileSource result = new PdfFileSourceAdapter("/tmp/inputFile1.pdf").getPdfFileSource(); assertNull(result.getPassword()); assertThat(result.getSource(), CombinableMatcher.<File> either(is(new File("/tmp/inputFile1.pdf"))).or( is(new File("c:\\tmp\\inputFile1.pdf")))); }
@Test public void protectedFileWithPasswordContainingSeparator() { PdfFileSource result = new PdfFileSourceAdapter("/tmp/inputFile1.pdf:secret.pdf:password").getPdfFileSource(); assertThat(result.getPassword(), is("secret.pdf:password")); assertThat(result.getSource(), CombinableMatcher.<File> either(is(new File("/tmp/inputFile1.pdf"))).or( is(new File("c:\\tmp\\inputFile1.pdf")))); }
@Test public void fileDoestExist() { try { new PdfFileSourceAdapter("/tmp/doesntexist.pdf:secret").getPdfFileSource(); } catch (SejdaRuntimeException e) { assertThat(e.getMessage(), containsString("does not exist")); } }