/** * Test method for {@link * org.verapdf.cli.VeraPdfCliProcessor#createProcessorFromArgs(org.verapdf.cli.commands.VeraCliArgParser)} * . * * @throws IOException * @throws FileNotFoundException * @throws ProfileException * @throws JAXBException */ @Test public final void testCreateProcessorFromArgsNewProfile() throws ProfileException, FileNotFoundException, IOException, JAXBException { VeraCliArgParser parser = new VeraCliArgParser(); JCommander jCommander = VeraPdfCliProcessorTest.initialiseJCommander(parser); jCommander.parse(new String[] {}); VeraPdfCliProcessor proc = VeraPdfCliProcessor.createProcessorFromArgs(parser); assertTrue(proc.validator.getProfile().getPDFAFlavour() == PDFAFlavour.PDFA_1_B); ProfileDirectory directory = Profiles.getVeraProfileDirectory(); assertTrue(directory.getValidationProfiles().size() > 0); for (ValidationProfile profile : directory.getValidationProfiles()) { File tmpProfile = File.createTempFile("verapdf", "profile"); try (OutputStream os = new FileOutputStream(tmpProfile)) { Profiles.profileToXml(profile, os, Boolean.FALSE); testWithProfileFile(profile.getPDFAFlavour(), tmpProfile); } } }
private static void testWithProfileFile(final PDFAFlavour flavour, final File profileFile) throws ProfileException, FileNotFoundException, IOException, JAXBException { String[] argVals = new String[] {"-p", "--profile"}; VeraCliArgParser parser = new VeraCliArgParser(); JCommander jCommander = VeraPdfCliProcessorTest.initialiseJCommander(parser); for (String arg : argVals) { jCommander.parse(new String[] {arg, profileFile.getAbsolutePath()}); VeraPdfCliProcessor proc = VeraPdfCliProcessor.createProcessorFromArgs(parser); try (InputStream is = new FileInputStream(profileFile)) { ValidationProfile profile = Profiles.profileFromXml(is); assertEquals(flavour, proc.validator.getProfile().getPDFAFlavour()); assertTrue(profile != proc.validator.getProfile()); assertEquals( Profiles.profileToXml(profile, Boolean.TRUE) + "\n" + Profiles.profileToXml(proc.validator.getProfile(), Boolean.TRUE), profile.getRules(), proc.validator.getProfile().getRules()); } } }