Search in sources :

Example 11 with Echo

use of org.apache.jena.jdbc.preprocessing.Echo in project jena by apache.

the class AbstractJenaConnectionTests method connection_pre_processors_06.

/**
     * Tests pre-processor management operations
     * 
     * @throws SQLException
     */
@Test
public void connection_pre_processors_06() throws SQLException {
    JenaConnection conn = this.getConnection();
    Assert.assertFalse(conn.getPreProcessors().hasNext());
    // Add a pre-processor
    Echo echo = new Echo();
    conn.addPreProcessor(echo);
    Assert.assertTrue(conn.getPreProcessors().hasNext());
    // Apply the pre-processor
    String input = "SELECT * WHERE { ?s ?p ?o }";
    String output = conn.applyPreProcessors(input);
    Assert.assertEquals(input, output);
    conn.close();
}
Also used : ResultsEcho(org.apache.jena.jdbc.postprocessing.ResultsEcho) Echo(org.apache.jena.jdbc.preprocessing.Echo) Test(org.junit.Test)

Example 12 with Echo

use of org.apache.jena.jdbc.preprocessing.Echo in project jena by apache.

the class AbstractJenaConnectionTests method connection_pre_processors_07.

/**
     * Tests pre-processor management operations
     * 
     * @throws SQLException
     */
@Test
public void connection_pre_processors_07() throws SQLException {
    JenaConnection conn = this.getConnection();
    Assert.assertFalse(conn.getPreProcessors().hasNext());
    // Add a pre-processor
    Echo echo = new Echo();
    conn.addPreProcessor(echo);
    Assert.assertTrue(conn.getPreProcessors().hasNext());
    // Apply the pre-processor
    Query input = QueryFactory.create("SELECT * WHERE { ?s ?p ?o }");
    Query output = conn.applyPreProcessors(input);
    Assert.assertEquals(input, output);
    conn.close();
}
Also used : ResultsEcho(org.apache.jena.jdbc.postprocessing.ResultsEcho) Echo(org.apache.jena.jdbc.preprocessing.Echo) Test(org.junit.Test)

Example 13 with Echo

use of org.apache.jena.jdbc.preprocessing.Echo in project jena by apache.

the class AbstractJenaConnectionTests method connection_pre_processors_02.

/**
     * Tests pre-processor management operations
     * 
     * @throws SQLException
     */
@Test(expected = IndexOutOfBoundsException.class)
public void connection_pre_processors_02() throws SQLException {
    JenaConnection conn = this.getConnection();
    Assert.assertFalse(conn.getPreProcessors().hasNext());
    Echo echo = new Echo();
    // Inserting at zero index should be safe
    conn.insertPreProcessor(0, echo);
    Assert.assertTrue(conn.getPreProcessors().hasNext());
    // Inserting at some random index will cause an error
    try {
        conn.insertPreProcessor(50, echo);
    } finally {
        conn.close();
    }
}
Also used : ResultsEcho(org.apache.jena.jdbc.postprocessing.ResultsEcho) Echo(org.apache.jena.jdbc.preprocessing.Echo) Test(org.junit.Test)

Example 14 with Echo

use of org.apache.jena.jdbc.preprocessing.Echo in project jena by apache.

the class AbstractJenaDriverTests method driver_config_precedence_05.

/**
     * Tests the precedence rules for connection URL parameters
     * 
     * @throws SQLException
     * @throws IOException
     */
@Test
public void driver_config_precedence_05() throws SQLException, IOException {
    File f = null;
    try {
        f = File.createTempFile("config", ".properties");
        FileWriter writer = new FileWriter(f);
        writer.write("test=external");
        writer.close();
        String url = this.getConnectionUrl();
        Assume.assumeNotNull(url);
        Assume.assumeFalse(url.contains(JenaDriver.PARAM_CONFIG + "="));
        url = url + "&" + JenaDriver.PARAM_PRE_PROCESSOR + "=" + Echo.class.getCanonicalName() + "&test=url&" + JenaDriver.PARAM_CONFIG + "=" + f.getAbsolutePath();
        JenaDriver driver = this.getDriver();
        Properties ps = new Properties();
        ps.put("test", "props");
        JenaConnection conn = (JenaConnection) driver.connect(url, ps);
        Iterator<CommandPreProcessor> preProcessors = conn.getPreProcessors();
        Assert.assertTrue(preProcessors.hasNext());
        Echo echo = (Echo) preProcessors.next();
        Properties actual = echo.getProperties();
        Assert.assertEquals("props", actual.getProperty("test"));
        conn.close();
    } finally {
        if (f != null && f.exists()) {
            f.delete();
        }
    }
}
Also used : ResultsEcho(org.apache.jena.jdbc.postprocessing.ResultsEcho) Echo(org.apache.jena.jdbc.preprocessing.Echo) CommandPreProcessor(org.apache.jena.jdbc.preprocessing.CommandPreProcessor) FileWriter(java.io.FileWriter) Properties(java.util.Properties) JenaConnection(org.apache.jena.jdbc.connections.JenaConnection) File(java.io.File) Test(org.junit.Test)

Aggregations

ResultsEcho (org.apache.jena.jdbc.postprocessing.ResultsEcho)14 Echo (org.apache.jena.jdbc.preprocessing.Echo)14 Test (org.junit.Test)14 JenaConnection (org.apache.jena.jdbc.connections.JenaConnection)7 CommandPreProcessor (org.apache.jena.jdbc.preprocessing.CommandPreProcessor)7 Properties (java.util.Properties)6 File (java.io.File)4 FileWriter (java.io.FileWriter)4 ResultsPostProcessor (org.apache.jena.jdbc.postprocessing.ResultsPostProcessor)1 UpdateRequest (org.apache.jena.update.UpdateRequest)1