use of org.apache.ibatis.session.ResultContext in project sonarqube by SonarSource.
the class PermissionTemplateDaoTest method group_count_by_template_and_permission.
@Test
public void group_count_by_template_and_permission() {
PermissionTemplateDto template1 = templateDb.insertTemplate();
PermissionTemplateDto template2 = templateDb.insertTemplate();
PermissionTemplateDto template3 = templateDb.insertTemplate();
GroupDto group1 = db.users().insertGroup(newGroupDto());
GroupDto group2 = db.users().insertGroup(newGroupDto());
GroupDto group3 = db.users().insertGroup(newGroupDto());
templateDb.addGroupToTemplate(42L, group1.getId(), ISSUE_ADMIN);
templateDb.addGroupToTemplate(template1.getId(), group1.getId(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getId(), group2.getId(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getId(), group3.getId(), CODEVIEWER);
templateDb.addGroupToTemplate(template1.getId(), null, CODEVIEWER);
templateDb.addGroupToTemplate(template1.getId(), group1.getId(), ADMIN);
templateDb.addGroupToTemplate(template2.getId(), group1.getId(), ADMIN);
final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
underTest.groupsCountByTemplateIdAndPermission(dbSession, Arrays.asList(template1.getId(), template2.getId(), template3.getId()), new ResultHandler() {
@Override
public void handleResult(ResultContext context) {
result.add((CountByTemplateAndPermissionDto) context.getResultObject());
}
});
assertThat(result).hasSize(3);
assertThat(result).extracting("permission").containsOnly(ADMIN, CODEVIEWER);
assertThat(result).extracting("templateId").containsOnly(template1.getId(), template2.getId());
assertThat(result).extracting("count").containsOnly(4, 1);
}
use of org.apache.ibatis.session.ResultContext in project sonarqube by SonarSource.
the class RuleDaoTest method selectEnabled_with_ResultHandler.
@Test
public void selectEnabled_with_ResultHandler() {
dbTester.prepareDbUnit(getClass(), "selectEnabled.xml");
final List<RuleDto> rules = new ArrayList<>();
ResultHandler resultHandler = new ResultHandler() {
@Override
public void handleResult(ResultContext resultContext) {
rules.add((RuleDto) resultContext.getResultObject());
}
};
underTest.selectEnabled(dbTester.getSession(), resultHandler);
assertThat(rules.size()).isEqualTo(1);
RuleDto ruleDto = rules.get(0);
assertThat(ruleDto.getId()).isEqualTo(1);
}
use of org.apache.ibatis.session.ResultContext in project mybatis-3 by mybatis.
the class NestedResultHandlerAssociationTest method shouldHandleRowBounds.
@Test
public void shouldHandleRowBounds() throws Exception {
SqlSession sqlSession = sqlSessionFactory.openSession();
final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
Date targetMonth = fmt.parse("2014-01-01");
final List<Account> accounts = new ArrayList<Account>();
try {
sqlSession.select("collectPageByBirthMonth", targetMonth, new RowBounds(1, 2), new ResultHandler() {
@Override
public void handleResult(ResultContext context) {
Account account = (Account) context.getResultObject();
accounts.add(account);
}
});
} finally {
sqlSession.close();
}
assertEquals(2, accounts.size());
assertEquals("Bob2", accounts.get(0).getAccountName());
assertEquals("Bob3", accounts.get(1).getAccountName());
}
use of org.apache.ibatis.session.ResultContext in project mybatis-3 by mybatis.
the class CommonPropertyDeferLoadError method testDeferLoadAfterResultHandler.
@Test
public void testDeferLoadAfterResultHandler() {
SqlSession sqlSession = sqlSessionFactory.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();
}
}
use of org.apache.ibatis.session.ResultContext 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);
}
Aggregations