@Before public void setUp() throws Exception { this.queryRunner = mock(QueryRunner.class); this.conn = this.datasource.getConnection(); final DataSource mockDataSource = mock(this.datasource.getClass()); when(this.queryRunner.getDataSource()).thenReturn(mockDataSource); when(mockDataSource.getConnection()).thenReturn(this.conn); this.dbOperator = new DatabaseOperator(this.queryRunner); list.add(index_1); list.add(index_2); // valid query returns correct value when(this.queryRunner.query("select * from blah where ? = ?", this.handler, "id", 2)) .thenReturn(index_2); // If select an non-existing entry, handler returns 0. when(this.queryRunner.query("select * from blah where ? = ?", this.handler, "id", 3)) .thenReturn(0); //If typos, throw Exceptions. doThrow(SQLException.class).when(this.queryRunner) .query("sele * from blah where ? = ?", this.handler, "id", 2); doAnswer(invocation -> { index_1 = 26; return 1; }).when(this.queryRunner).update("update blah set ? = ?", "1", 26); }
public static DatabaseOperator initTestDB() throws Exception { final AzkabanDataSource dataSource = new EmbeddedH2BasicDataSource(); final String sqlScriptsDir = new File("../azkaban-db/src/main/sql/").getCanonicalPath(); final DatabaseSetup setup = new DatabaseSetup(dataSource, sqlScriptsDir); setup.updateDatabase(); return new DatabaseOperator(new QueryRunner(dataSource)); }
public static DatabaseOperator initQuartzDB() throws Exception { final AzkabanDataSource dataSource = new EmbeddedH2BasicDataSource(); final String sqlScriptsDir = new File("../azkaban-web-server/src/test/resources/") .getCanonicalPath(); final DatabaseSetup setup = new DatabaseSetup(dataSource, sqlScriptsDir); setup.updateDatabase(); return new DatabaseOperator(new QueryRunner(dataSource)); }