use of org.apache.ibatis.session.ResultHandler in project sonarqube by SonarSource.
the class IssueMapperTest method scrollClosedByComponentUuid_return_one_row_per_status_diff_to_CLOSED_sorted_by_most_recent_creation_date_first.
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_return_one_row_per_status_diff_to_CLOSED_sorted_by_most_recent_creation_date_first(RuleType ruleType) {
ComponentDto component = randomComponent();
IssueDto issue = insertNewClosedIssue(component, ruleType);
Date date = new Date();
IssueChangeDto[] changes = new IssueChangeDto[] { insertToClosedDiff(issue, DateUtils.addDays(date, -10)), insertToClosedDiff(issue, DateUtils.addDays(date, -60)), insertToClosedDiff(issue, date), insertToClosedDiff(issue, DateUtils.addDays(date, -5)) };
RecorderResultHandler resultHandler = new RecorderResultHandler();
underTest.scrollClosedByComponentUuid(component.uuid(), NO_FILTERING_ON_CLOSE_DATE, resultHandler);
assertThat(resultHandler.issues).hasSize(4).extracting(IssueDto::getKey, t -> t.getClosedChangeData().get()).containsExactly(tuple(issue.getKey(), changes[2].getChangeData()), tuple(issue.getKey(), changes[3].getChangeData()), tuple(issue.getKey(), changes[0].getChangeData()), tuple(issue.getKey(), changes[1].getChangeData()));
}
use of org.apache.ibatis.session.ResultHandler in project sonarqube by SonarSource.
the class IssueMapperTest method scrollClosedByComponentUuid_does_not_return_closed_issues_of_non_existing_rule.
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_non_existing_rule(RuleType ruleType) {
ComponentDto component = randomComponent();
IssueDto issueWithRule = insertNewClosedIssue(component, ruleType);
IssueChangeDto issueChange = insertToClosedDiff(issueWithRule);
IssueDto issueWithoutRule = insertNewClosedIssue(component, new RuleDefinitionDto().setType(ruleType).setUuid("uuid-50"));
insertToClosedDiff(issueWithoutRule);
RecorderResultHandler resultHandler = new RecorderResultHandler();
underTest.scrollClosedByComponentUuid(component.uuid(), NO_FILTERING_ON_CLOSE_DATE, resultHandler);
assertThat(resultHandler.issues).extracting(IssueDto::getKey, t -> t.getClosedChangeData().get()).containsOnly(tuple(issueWithRule.getKey(), issueChange.getChangeData()));
}
use of org.apache.ibatis.session.ResultHandler in project sonarqube by SonarSource.
the class DBSessionsImplTest method openSession_with_caching_returns_wrapper_of_MyBatis_DbSession_which_delegates_all_methods_but_close.
@Test
public void openSession_with_caching_returns_wrapper_of_MyBatis_DbSession_which_delegates_all_methods_but_close() {
boolean batchOrRegular = random.nextBoolean();
underTest.enableCaching();
verifyFirstDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
dbSession.rollback();
verify(myBatisDbSession).rollback();
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
boolean flag = random.nextBoolean();
dbSession.rollback(flag);
verify(myBatisDbSession).rollback(flag);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
dbSession.commit();
verify(myBatisDbSession).commit();
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
boolean flag = random.nextBoolean();
dbSession.commit(flag);
verify(myBatisDbSession).commit(flag);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
dbSession.selectOne(str);
verify(myBatisDbSession).selectOne(str);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object object = new Object();
dbSession.selectOne(str, object);
verify(myBatisDbSession).selectOne(str, object);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
dbSession.selectList(str);
verify(myBatisDbSession).selectList(str);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object object = new Object();
dbSession.selectList(str, object);
verify(myBatisDbSession).selectList(str, object);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object parameter = new Object();
RowBounds rowBounds = new RowBounds();
dbSession.selectList(str, parameter, rowBounds);
verify(myBatisDbSession).selectList(str, parameter, rowBounds);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
String mapKey = randomAlphabetic(10);
dbSession.selectMap(str, mapKey);
verify(myBatisDbSession).selectMap(str, mapKey);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object parameter = new Object();
String mapKey = randomAlphabetic(10);
dbSession.selectMap(str, parameter, mapKey);
verify(myBatisDbSession).selectMap(str, parameter, mapKey);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object parameter = new Object();
String mapKey = randomAlphabetic(10);
RowBounds rowBounds = new RowBounds();
dbSession.selectMap(str, parameter, mapKey, rowBounds);
verify(myBatisDbSession).selectMap(str, parameter, mapKey, rowBounds);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
ResultHandler handler = mock(ResultHandler.class);
dbSession.select(str, handler);
verify(myBatisDbSession).select(str, handler);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object parameter = new Object();
ResultHandler handler = mock(ResultHandler.class);
dbSession.select(str, parameter, handler);
verify(myBatisDbSession).select(str, parameter, handler);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object parameter = new Object();
ResultHandler handler = mock(ResultHandler.class);
RowBounds rowBounds = new RowBounds();
dbSession.select(str, parameter, rowBounds, handler);
verify(myBatisDbSession).select(str, parameter, rowBounds, handler);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
dbSession.insert(str);
verify(myBatisDbSession).insert(str);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object object = new Object();
dbSession.insert(str, object);
verify(myBatisDbSession).insert(str, object);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
dbSession.update(str);
verify(myBatisDbSession).update(str);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object object = new Object();
dbSession.update(str, object);
verify(myBatisDbSession).update(str, object);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
dbSession.delete(str);
verify(myBatisDbSession).delete(str);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
String str = randomAlphabetic(10);
Object object = new Object();
dbSession.delete(str, object);
verify(myBatisDbSession).delete(str, object);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
dbSession.flushStatements();
verify(myBatisDbSession).flushStatements();
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
dbSession.clearCache();
verify(myBatisDbSession).clearCache();
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
Configuration expected = mock(Configuration.class);
when(myBatisDbSession.getConfiguration()).thenReturn(expected);
assertThat(dbSession.getConfiguration()).isSameAs(expected);
verify(myBatisDbSession).getConfiguration();
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
Class<Object> clazz = Object.class;
Object expected = new Object();
when(myBatisDbSession.getMapper(clazz)).thenReturn(expected);
assertThat(dbSession.getMapper(clazz)).isSameAs(expected);
verify(myBatisDbSession).getMapper(clazz);
});
verifyDelegation(batchOrRegular, (myBatisDbSession, dbSession) -> {
Connection connection = mock(Connection.class);
when(myBatisDbSession.getConnection()).thenReturn(connection);
assertThat(dbSession.getConnection()).isSameAs(connection);
verify(myBatisDbSession).getConnection();
});
}
use of org.apache.ibatis.session.ResultHandler in project sonarqube by SonarSource.
the class ComponentDaoTest method assertSelectForIndexing.
private ListAssert<String> assertSelectForIndexing(@Nullable String projectUuid) {
db.prepareDbUnit(getClass(), "selectForIndexing.xml");
List<ComponentDto> components = new ArrayList<>();
underTest.selectForIndexing(dbSession, projectUuid, new ResultHandler() {
@Override
public void handleResult(ResultContext context) {
components.add((ComponentDto) context.getResultObject());
}
});
return assertThat(components).extracting(ComponentDto::uuid);
}
use of org.apache.ibatis.session.ResultHandler in project mybatis-3 by mybatis.
the class CommonPropertyDeferLoadError method testDeferLoadAfterResultHandlerWithLazyLoad.
@Test
public void testDeferLoadAfterResultHandlerWithLazyLoad() {
SqlSession sqlSession = lazyLoadSqlSessionFactory.openSession();
try {
class MyResultHandler implements ResultHandler {
List<Child> children = new ArrayList<Child>();
@Override
public void handleResult(ResultContext context) {
Child child = (Child) context.getResultObject();
children.add(child);
}
}
;
MyResultHandler myResultHandler = new MyResultHandler();
sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", myResultHandler);
for (Child child : myResultHandler.children) {
assertNotNull(child.getFather());
}
} finally {
sqlSession.close();
}
}
Aggregations