@Override public Connection getConnection(String username, String password) throws SQLException { return this.dataSource.getConnection(username, password); }
@Override public Connection getConnection() throws SQLException { return this.dataSource.getConnection(); }
@Before public void setUpSchema() throws SQLException { executeSqlScript(db.getConnection(), usersSchema()); }
@Test public void executeSqlScriptContainingMultiLineComments() throws SQLException { executeSqlScript(db.getConnection(), resource("test-data-with-multi-line-comments.sql")); assertUsersDatabaseCreated("Hoeller", "Brannen"); }
/** * @since 4.2 */ @Test public void executeSqlScriptContainingSingleQuotesNestedInsideDoubleQuotes() throws SQLException { executeSqlScript(db.getConnection(), resource("users-data-with-single-quotes-nested-in-double-quotes.sql")); assertUsersDatabaseCreated("Hoeller", "Brannen"); }
@Test public void setDatasetData_DiRuntime() throws Exception { // given String payload = IOUtils.toString(getClass().getResourceAsStream("jdbc_component_write_properties_on_DI.json")) .replace("{jdbc_url}", dbUrl); // when given().content(payload).contentType(APPLICATION_JSON_UTF8_VALUE) // .expect().statusCode(200).log().ifError() // .put(getVersionPrefix() + "/runtimes/data"); // then Statement statement = db.getConnection().createStatement(); ResultSet countRS = statement.executeQuery("SELECT COUNT(*) AS count FROM users"); countRS.next(); assertEquals(101, countRS.getInt("count")); ResultSet resultSet = statement.executeQuery("SELECT * FROM users WHERE email='david.bowie@awesome.uk'"); while (resultSet.next()) { assertEquals("1", resultSet.getString("id")); assertEquals("David", resultSet.getString("first_name")); assertEquals("Bowie", resultSet.getString("last_name")); assertEquals("david.bowie@awesome.uk", resultSet.getString("email")); assertEquals("male", resultSet.getString("gender")); assertEquals("127.0.0.1", resultSet.getString("ip_address")); } }
@Before public void setUp() throws Exception { db = new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.DERBY).setName("testdb") .setScriptEncoding("UTF-8").addScript("/org/talend/components/service/rest/schema.sql") .addScript("/org/talend/components/service/rest/data_users.sql").build(); // addresss: Starting embedded database: // url='jdbc:derby:memory:2dc86c66-5d3a-48fd-b903-56aa27d20e3b;create=true', // username='sa' try (Connection connection = db.getConnection()) { dbUrl = connection.getMetaData().getURL(); } RestAssured.port = localServerPort; }