Search in sources :

Example 1 with SqlRecorder

use of com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder in project midpoint by Evolveum.

the class SqaleRepoSmokeTest method test400SqlLogger.

@Test
public void test400SqlLogger() throws Exception {
    if (!SqlRecorder.LOGGER.isDebugEnabled()) {
        throw new SkipException("We need debug on SqlRecorder logger for this test");
    }
    OperationResult result = createOperationResult();
    // INSERT + UPDATE
    queryRecorder.clearBufferAndStartRecording();
    String oid = repositoryService.addObject(new UserType(prismContext).name("user" + getTestNumber()).asPrismObject(), null, result);
    // These assertions are quite implementation dependent, obviously.
    Queue<SqlRecorder.QueryEntry> queryBuffer = queryRecorder.getQueryBuffer();
    assertThat(queryBuffer).hasSize(2);
    SqlRecorder.QueryEntry entry = queryBuffer.remove();
    assertThat(entry.sql).startsWith("insert into m_user");
    entry = queryBuffer.remove();
    assertThat(entry.sql).startsWith("update m_user");
    // param for where oid = ...
    assertThat(entry.params.get(2)).isEqualTo(oid);
    // COUNT
    queryRecorder.clearBufferAndStartRecording();
    int count = repositoryService.countObjects(UserType.class, null, null, result);
    // at least user from above should be there
    assertThat(count).isGreaterThanOrEqualTo(1);
    queryBuffer = queryRecorder.getQueryBuffer();
    assertThat(queryBuffer).hasSize(1);
    entry = queryBuffer.remove();
    assertThat(entry.sql).startsWith("select count(*)");
    // normal select
    queryRecorder.clearBufferAndStartRecording();
    SearchResultList<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, null, null, result);
    assertThat(users).isNotEmpty();
    queryBuffer = queryRecorder.getQueryBuffer();
    assertThat(queryBuffer).hasSize(1);
    entry = queryBuffer.remove();
    assertThat(entry.sql).startsWith("select u.oid, u.fullObject");
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SqlRecorder(com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 2 with SqlRecorder

use of com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder in project midpoint by Evolveum.

the class SqaleRepoBaseTest method initDatabase.

@BeforeClass
public void initDatabase() throws Exception {
    queryRecorder = new SqlRecorder(QUERY_BUFFER_SIZE);
    sqlRepoContext.setQuerydslSqlListener(queryRecorder);
    if (System.getProperty(SYSTEM_PROPERTY_SKIP_DB_CLEAR) == null) {
        clearDatabase();
    }
}
Also used : SqlRecorder(com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

SqlRecorder (com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SkipException (org.testng.SkipException)1 BeforeClass (org.testng.annotations.BeforeClass)1 Test (org.testng.annotations.Test)1