Java 类org.jooq.tools.jdbc.MockExecuteContext 实例源码

项目:droptools    文件:JooqHealthCheckTest.java   
@Test
public void isUnhealthyIfTransactionFails() throws Exception {
    MockDataProvider mockDataProvider = new MockDataProvider() {
        @Override
        public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
            throw new SQLException("BOOM");
        }
    };

    try {
        runHealthCheck(mockDataProvider);
        assert_().fail();
    } catch (DataAccessException e) {
        assertThat(e.getMessage()).contains(validationQuery);
        assertThat(e.getMessage()).contains("BOOM");
    }
}
项目:dropwizard-jooq    文件:JooqHealthCheckTest.java   
@Override
public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
    MockResult[] mock = new MockResult[1];

    // The execute context contains SQL string(s), bind values, and other meta-data
    String sql = ctx.sql();

    // Exceptions are propagated through the JDBC and jOOQ APIs
    if (sql.equals("SELECT 1")) {
        mock[0] = new MockResult(1, DSL.using(SQLDialect.HSQLDB).newResult());
    } else {
        throw new DataAccessException("Incorrect validation query");
    }

    return mock;
}
项目:club-tracker    文件:MockDataProviderBuilder.java   
private void loadStatements(MockExecuteContext ctx) {
    Collection<Object> bindings = new ArrayList<>(Arrays.asList(ctx.bindings()));
    int start, next = 0;
    StatementVerifier previous = null;
    for (StatementVerifier statement : statements) {
        StatementType type1 = statement.getType();
        String name = type1.name();
        start = next;
        String sql = ctx.sql();
        next = sql.toUpperCase().indexOf(name, start);
        if (next > start && previous != null) {
            previous.bind(sql.substring(start, next), bindings);
        } else if (next == -1) {
            fail(name + " not found");
        }
        previous = statement;
    }
    if (previous != null) {
        previous.bind(ctx.sql().substring(next), bindings);
    }
}
项目:droptools    文件:JooqHealthCheckTest.java   
@Test
public void isHealthyIfNoExceptionIsThrown() throws Exception {
    MockDataProvider mockDataProvider = new MockDataProvider() {
        @Override
        public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
            return new MockResult[0];
        }
    };

    HealthCheck.Result result = runHealthCheck(mockDataProvider);
    assertThat(result.isHealthy()).named("is healthy").isTrue();
}
项目:SMRTMS    文件:DBManagerTest.java   
@Override
public MockResult[] execute(MockExecuteContext ctx) throws SQLException {

    // You might need a DSLContext to create org.jooq.Result and org.jooq.Record objects
    DSLContext create = DSL.using(SQLDialect.MYSQL);
    MockResult[] mock = new MockResult[1];

    // The execute context contains SQL string(s), bind values, and other meta-data
    String sql = ctx.sql();
    System.out.println("SQL Query: " + sql);

    // Exceptions are propagated through the JDBC and jOOQ APIs
    if (sql.toUpperCase().startsWith("DROP")) {
        throw new SQLException("Statement not supported: " + sql);
    }

    // You decide, whether any given statement returns results, and how many
    else if (sql.toUpperCase().startsWith("SELECT")) {

        // Always return one author record
        Result<UserRecord> result = create.newResult(USER);
        result.add(create.newRecord(USER));
        result.get(0).setValue(USER.ID, 1);
        result.get(0).setValue(USER.USERNAME, "Orwell");
        mock[0] = new MockResult(1, result);
    }

    else if (sql.toUpperCase().startsWith("INSERT")) {
        mock[0] = new MockResult(1, create.newResult(USER));
    }

    else if (sql.toUpperCase().startsWith("UPDATE")) {
        mock[0] = new MockResult(1, create.newResult(USER));
    }

    else if (sql.toUpperCase().startsWith("DELETE")) {
        mock[0] = new MockResult(1, create.newResult(USER));
    }

    // You can detect batch statements easily
    else if (ctx.batch()) {
        // [...]
    }

    return mock;
}
项目:club-tracker    文件:MockDataProviderBuilder.java   
public MockDataProviderBuilder verify(Consumer<MockExecuteContext> r) {
    verifications.add(r);
    return this;
}
项目:club-tracker    文件:OrganizationBrokerTest.java   
private void assertWhere(String id, MockExecuteContext ctx) {
    Object[] bindings = ctx.bindings();
    assertEquals(id, new String((byte[]) bindings[bindings.length-1]));
}