public void integrationTest()

in apache-rat-core/src/it/java/org/apache/rat/ReportTest.java [90:146]


    public void integrationTest(String testName, Document commandLineDoc) throws Exception {
        DefaultLog.getInstance().log(Log.Level.INFO, "Running test for " + testName);
        File baseDir = new File(commandLineDoc.getName().getName()).getParentFile();

        // get the arguments
        List<String> argsList = IOUtils.readLines(commandLineDoc.reader());

        CommandLine commandLine = DefaultParser.builder().setDeprecatedHandler(DeprecationReporter.getLogReporter())
                .setAllowPartialMatching(true).build().parse(Arg.getOptions(), asArgs(argsList));

        File outputFile = new File(baseDir,"output.txt");
        if (!commandLine.hasOption(Arg.OUTPUT_FILE.option())) {
            argsList.add(0, "--" + Arg.OUTPUT_FILE.option().getLongOpt());
            argsList.add(1, outputFile.getAbsolutePath());
        } else {
            outputFile = new File(baseDir, commandLine.getOptionValue(Arg.OUTPUT_FILE.option()));
        }

        File logFile = new File(baseDir,"log.txt");
        FileLog fileLog = new FileLog(logFile);
        Log oldLog = null;
        try {
            oldLog = DefaultLog.setInstance(fileLog);

            File src = new File(baseDir, "src");
            if (src.isDirectory()) {
                argsList.add(src.getAbsolutePath());
            }

            File expectedMsg = new File(baseDir, "expected-message.txt");
            if (expectedMsg.exists()) {
                String msg = IOUtils.readLines(new FileReader(expectedMsg)).get(0).trim();
                assertThrows(RatDocumentAnalysisException.class, () -> Report.main(asArgs(argsList)),
                        msg);
            } else {
                Report.main(asArgs(argsList));
            }
        } finally {
            DefaultLog.setInstance(oldLog);
            fileLog.close();
        }

        File groovyScript = new File(baseDir, "verify.groovy");
        if (groovyScript.exists()) {
            // call groovy expressions from Java code
            CompilerConfiguration compilerConfiguration = new CompilerConfiguration();

            GroovyShell shell = new GroovyShell(compilerConfiguration);
            for (String classPath : System.getProperty("java.class.path").split(File.pathSeparator)) {
                shell.getClassLoader().addClasspath(classPath);
            }
            Object value = shell.run(groovyScript, new String[]{outputFile.getAbsolutePath(), logFile.getAbsolutePath()});
            if (value != null) {
                fail(String.format("%s",value));
            }
        }
    }