Example usage for org.aspectj.util FileUtil writeAsString

List of usage examples for org.aspectj.util FileUtil writeAsString

Introduction

In this page you can find the example usage for org.aspectj.util FileUtil writeAsString.

Prototype

public static String writeAsString(File file, String contents) 

Source Link

Document

Write contents to file, returning null on success or error message otherwise.

Usage

From source file:org.collectionspace.chain.csp.persistence.TestBase.java

License:Educational Community License

public void testUIspec(ServletTester jetty, String url, String uijson) throws Exception {
    log.info("testUISpec(" + url + ", " + uijson + ")");

    String errMsg = String.format("Failed to create correct uispec for '%s' compared with file '%s'", url,
            uijson);/*  w  ww  .ja va 2  s . c  om*/
    JSONObject generated = new JSONObject("{}");
    JSONObject baseline = new JSONObject("{}");
    boolean success = false;

    try {
        HttpTester response = GETData(url, jetty);

        generated = new JSONObject(response.getContent());
        baseline = new JSONObject(getResourceString(uijson));
        xxxfixOptions(generated);
        xxxfixOptions(baseline);

        // You can use these, Chris, to write stuff out if the spec has
        // changed to alter the test file -- dan
        // hendecasyllabic:tmp csm22$ cat gschema.out | pbcopy

        success = JSONUtils.checkJSONEquivOrEmptyStringKey(generated, baseline);
    } catch (Exception e) {
        log.error(errMsg, e);
        errMsg = String.format("%s. %s", errMsg, e.getMessage()); // Append the exception message to our default error message.
    }

    if (!success) {
        File tempDir = FileUtil.getTempDir(uijson);
        // Baseline spec
        File baselineFile = new File(tempDir, uijson + ".baseline.json");
        FileUtil.writeAsString(baselineFile, baseline.toString());

        // Generated spec
        File generatedFile = new File(tempDir, uijson + ".generated.json");
        FileUtil.writeAsString(generatedFile, generated.toString());

        log.error("The following baseline and generated UI specs did not match:");
        log.error("testUIspec(" + uijson + ") BASELINE from file" + baselineFile.getPath());
        log.error("testUIspec(" + url + ") GENERATED from url" + generatedFile.getPath());
    }

    assertTrue(errMsg, success);
}