Search in sources :

Example 1 with Quidem

use of net.hydromatic.quidem.Quidem in project calcite by apache.

the class QuidemTest method checkRun.

protected void checkRun(String path) throws Exception {
    final File inFile;
    final File outFile;
    final File f = new File(path);
    if (f.isAbsolute()) {
        // e.g. path = "/tmp/foo.iq"
        inFile = f;
        outFile = new File(path + ".out");
    } else {
        // e.g. path = "sql/outer.iq"
        // inUrl = "file:/home/fred/calcite/core/target/test-classes/sql/outer.iq"
        final URL inUrl = JdbcTest.class.getResource("/" + n2u(path));
        String x = u2n(inUrl.getFile());
        assert x.endsWith(path) : "x: " + x + "; path: " + path;
        x = x.substring(0, x.length() - path.length());
        assert x.endsWith(u2n("/test-classes/"));
        x = x.substring(0, x.length() - u2n("/test-classes/").length());
        final File base = new File(x);
        inFile = new File(base, u2n("/test-classes/") + path);
        outFile = new File(base, u2n("/surefire/") + path);
    }
    Util.discard(outFile.getParentFile().mkdirs());
    try (final Reader reader = Util.reader(inFile);
        final Writer writer = Util.printWriter(outFile);
        final Closer closer = new Closer()) {
        new Quidem(reader, writer, env(), createConnectionFactory()).withPropertyHandler(new Quidem.PropertyHandler() {

            public void onSet(String propertyName, Object value) {
                if (propertyName.equals("bindable")) {
                    final boolean b = value instanceof Boolean && (Boolean) value;
                    closer.add(Hook.ENABLE_BINDABLE.addThread(Hook.property(b)));
                }
                if (propertyName.equals("expand")) {
                    final boolean b = value instanceof Boolean && (Boolean) value;
                    closer.add(Prepare.THREAD_EXPAND.push(b));
                }
            }
        }).execute();
    }
    final String diff = DiffTestCase.diff(inFile, outFile);
    if (!diff.isEmpty()) {
        fail("Files differ: " + outFile + " " + inFile + "\n" + diff);
    }
}
Also used : Closer(org.apache.calcite.util.Closer) Reader(java.io.Reader) File(java.io.File) Quidem(net.hydromatic.quidem.Quidem) URL(java.net.URL) Writer(java.io.Writer)

Aggregations

File (java.io.File)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 URL (java.net.URL)1 Quidem (net.hydromatic.quidem.Quidem)1 Closer (org.apache.calcite.util.Closer)1