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();
}
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();
}
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();
}
}
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();
}
}
}
Aggregations