Search in sources :

Example 6 with JSONParser

use of beast.util.JSONParser in project beast2 by CompEvol.

the class ExampleJSONParsingTest method test_ThatJSONExamplesParse.

public void test_ThatJSONExamplesParse(String dir) {
    try {
        Randomizer.setSeed(127);
        Logger.FILE_MODE = Logger.LogFileMode.overwrite;
        System.out.println("Test JSON Examples in " + dir);
        File exampleDir = new File(dir);
        String[] exampleFiles = exampleDir.list(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".json");
            }
        });
        List<String> failedFiles = new ArrayList<String>();
        for (String fileName : exampleFiles) {
            System.out.println("Processing " + fileName);
            JSONParser parser = new JSONParser();
            try {
                parser.parseFile(new File(dir + "/" + fileName));
            } catch (Exception e) {
                System.out.println("ExampleJSONParsing::Failed for " + fileName + ": " + e.getMessage());
                failedFiles.add(fileName);
            }
            System.out.println("Done " + fileName);
        }
        if (failedFiles.size() > 0) {
            System.out.println("\ntest_ThatJSONExamplesParse::Failed for : " + failedFiles.toString());
        } else {
            System.out.println("\ntest_ThatJSONExamplesParse::Success");
        }
        assertTrue(failedFiles.toString(), failedFiles.size() == 0);
    } catch (Exception e) {
        System.out.println("exception thrown ");
        System.out.println(e.getMessage());
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) JSONParser(beast.util.JSONParser) File(java.io.File)

Aggregations

JSONParser (beast.util.JSONParser)6 File (java.io.File)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 BEASTObject (beast.core.BEASTObject)2 JSONProducer (beast.util.JSONProducer)2 FilenameFilter (java.io.FilenameFilter)2 BeastDialog (beast.app.beastapp.BeastDialog)1 Version (beast.app.util.Version)1 BEASTInterface (beast.core.BEASTInterface)1 MCMC (beast.core.MCMC)1 RealParameter (beast.core.parameter.RealParameter)1 Taxon (beast.evolution.alignment.Taxon)1 JSONParserException (beast.util.JSONParserException)1 XMLParser (beast.util.XMLParser)1 XMLParserException (beast.util.XMLParserException)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1