AttributeOptionComboLoader { public CategoryOptionCombo getAttributeOptionCombo( CategoryCombo categoryCombo, String categoryOptions, String attributeOptionCombo, IdScheme idScheme ) { final Set<String> opts = TextUtils.splitToArray( categoryOptions, TextUtils.SEMICOLON ); return getAttributeOptionCombo( categoryCombo, opts, attributeOptionCombo, idScheme ); } AttributeOptionComboLoader( @Qualifier( "readOnlyJdbcTemplate" ) JdbcTemplate jdbcTemplate ); CategoryOptionCombo getCategoryOptionCombo( IdScheme idScheme, String id ); CategoryOptionCombo getAttributeOptionCombo( CategoryCombo categoryCombo, String categoryOptions,
                                                        String attributeOptionCombo, IdScheme idScheme ); CategoryOptionCombo getDefault(); final static String SQL_GET_CATEGORYOPTIONCOMBO; final static String SQL_GET_CATEGORYOPTIONCOMBO_BY_CATEGORYIDS; }
@Test public void verifyGetAttributeOptionComboWithNullCategoryCombo() { thrown.expect( IllegalQueryException.class ); thrown.expectMessage( "Illegal category combo" ); subject.getAttributeOptionCombo( null, "", "", IdScheme.UID ); }
@Test public void verifyGetAttributeOptionComboWithNonExistingCategoryOption() { thrown.expect( IllegalQueryException.class ); thrown.expectMessage( "Illegal category option identifier: abcdef" ); CategoryCombo cc = new CategoryCombo(); subject.getAttributeOptionCombo( cc, "abcdef", "", IdScheme.UID ); }
@Test public void verifyGetAttributeOptionCombo() { CategoryCombo cc = createCategoryCombo( 'B' ); CategoryOption categoryOption = createCategoryOption( 'A' ); categoryOption.setId( 100L ); when( jdbcTemplate.queryForObject( eq( "select categoryoptionid, uid, code, name from dataelementcategoryoption where uid = 'abcdef'" ), any( RowMapper.class ) ) ).thenReturn( categoryOption ); when( jdbcTemplate.query( anyString(), any( RowMapper.class ) ) ) .thenReturn( singletonList( createCategoryOptionCombo( cc, categoryOption ) ) ); CategoryOptionCombo categoryOptionCombo = subject.getAttributeOptionCombo( cc, "abcdef", "", IdScheme.UID ); assertThat( categoryOptionCombo, is( notNullValue() ) ); verify( jdbcTemplate ).query( sqlCaptor.capture(), any( RowMapper.class ) ); final String sql = sqlCaptor.getValue(); assertThat( sql, is( replace( SQL_GET_CATEGORYOPTIONCOMBO_BY_CATEGORYIDS, "resolvedScheme", "uid = '" + cc.getUid() + "'", "option_ids", "'100'" ) ) ); }