Search in sources :

Example 1 with ResultContext

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);
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) ArrayList(java.util.ArrayList) ResultHandler(org.apache.ibatis.session.ResultHandler) Test(org.junit.Test)

Example 2 with ResultContext

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);
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) ArrayList(java.util.ArrayList) ResultHandler(org.apache.ibatis.session.ResultHandler) Test(org.junit.Test)

Example 3 with ResultContext

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());
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) RowBounds(org.apache.ibatis.session.RowBounds) ResultHandler(org.apache.ibatis.session.ResultHandler) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 4 with ResultContext

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();
    }
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) List(java.util.List) ResultHandler(org.apache.ibatis.session.ResultHandler) Test(org.junit.Test)

Example 5 with ResultContext

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);
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ResultHandler(org.apache.ibatis.session.ResultHandler)

Aggregations

ResultContext (org.apache.ibatis.session.ResultContext)9 ResultHandler (org.apache.ibatis.session.ResultHandler)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 SqlSession (org.apache.ibatis.session.SqlSession)6 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 List (java.util.List)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 RowBounds (org.apache.ibatis.session.RowBounds)1 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)1 GroupDto (org.sonar.db.user.GroupDto)1 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)1