DBMessageQuery extends MappingSqlQuery { @Override protected Object mapRow(ResultSet rs, int rowNum) throws SQLException { String code = null; String language = null; String country = null; String variant = null; String message = null; code = rs.getString(rsCodeColumn); if (code == null) { code = ""; if (log.isWarnEnabled()) { log.warn("MessageCode is null"); } } if (rsLanguageColumn != null) { language = rs.getString(rsLanguageColumn); if (language == null) { language = ""; } } if (rsCountryColumn != null) { country = rs.getString(rsCountryColumn); if (country == null) { country = ""; } } if (rsVariantColumn != null) { variant = rs.getString(rsVariantColumn); if (variant == null) { variant = ""; } } message = rs.getString(rsMessageColumn); if (message == null) { message = ""; } if (log.isDebugEnabled()) { log.debug(code + "," + language + "," + country + "," + variant + "," + message); } return new DBMessage(code, language, country, variant, message); } DBMessageQuery(DataSource ds, String sql, String codeColumn,
            String languageColumn, String countryColumn, String variantColumn,
            String messageColumn);   }
@Test public void testMapRow01() throws Exception { DataSource ds = mock(DataSource.class); DBMessageQuery db = new DBMessageQuery(ds, "SELECT CODE,MESSAGE FROM MESSAGES", "CODE", "LANGUAGE", "COUNTRY", "VARIANT", "MESSAGE"); int rowNum = 0; db.rsCodeColumn = "code"; db.rsLanguageColumn = "language"; db.rsCountryColumn = "country"; db.rsVariantColumn = "variant"; db.rsMessageColumn = "message"; ResultSet rs = mock(ResultSet.class); when(rs.getString("code")).thenReturn("test01"); when(rs.getString("language")).thenReturn("ja"); when(rs.getString("country")).thenReturn("JP"); when(rs.getString("variant")).thenReturn("kansai"); when(rs.getString("message")).thenReturn("テストメッセージ０１"); rs.first(); DBMessage dbmReturn = (DBMessage) db.mapRow(rs, rowNum); assertEquals("test01", dbmReturn.getCode()); assertEquals("ja", dbmReturn.getLanguage()); assertEquals("JP", dbmReturn.getCountry()); assertEquals("kansai", dbmReturn.getVariant()); assertEquals("テストメッセージ０１", dbmReturn.getMessage()); }
@Test public void testMapRow02() throws Exception { DataSource ds = mock(DataSource.class); DBMessageQuery db = new DBMessageQuery(ds, "SELECT CODE,MESSAGE FROM MESSAGES", "CODE", "LANGUAGE", "COUNTRY", "VARIANT", "MESSAGE"); int rowNum = 0; db.rsCodeColumn = "code"; db.rsLanguageColumn = "language"; db.rsCountryColumn = "country"; db.rsVariantColumn = "variant"; db.rsMessageColumn = "message"; ResultSet rs = mock(ResultSet.class); when(rs.getString("code")).thenReturn(""); when(rs.getString("language")).thenReturn(""); when(rs.getString("country")).thenReturn(""); when(rs.getString("variant")).thenReturn(""); when(rs.getString("message")).thenReturn(""); rs.first(); DBMessage dbmReturn = (DBMessage) db.mapRow(rs, rowNum); assertEquals("", dbmReturn.getCode()); assertEquals("", dbmReturn.getLanguage()); assertEquals("", dbmReturn.getCountry()); assertEquals("", dbmReturn.getVariant()); assertEquals("", dbmReturn.getMessage()); }
@Test public void testMapRowResultSetint03() throws Exception { logger.setEnabledLevels(Level.WARN); DataSource ds = mock(DataSource.class); DBMessageQuery db = new DBMessageQuery(ds, "SELECT CODE,MESSAGE FROM MESSAGES", "CODE", "LANGUAGE", "COUNTRY", "VARIANT", "MESSAGE"); int rowNum = 0; db.rsCodeColumn = "code"; db.rsLanguageColumn = "language"; db.rsCountryColumn = "country"; db.rsVariantColumn = "variant"; db.rsMessageColumn = "message"; ResultSet rs = mock(ResultSet.class); when(rs.getString("code")).thenReturn(null); when(rs.getString("language")).thenReturn(null); when(rs.getString("country")).thenReturn(null); when(rs.getString("variant")).thenReturn(null); when(rs.getString("message")).thenReturn(null); rs.first(); logger.clear(); logger.clear(); DBMessage dbmReturn = (DBMessage) db.mapRow(rs, rowNum); assertEquals("", dbmReturn.getCode()); assertEquals("", dbmReturn.getLanguage()); assertEquals("", dbmReturn.getCountry()); assertEquals("", dbmReturn.getVariant()); assertEquals("", dbmReturn.getMessage()); assertThat(logger.getLoggingEvents(), is(asList(warn( "MessageCode is null"), debug(",,,,")))); }