DataSourceMessageSource extends AbstractMessageSource implements
        InitializingBean { protected String internalResolveCodeWithoutArguments( String code, Locale locale) { String msg = getMessages(locale).getProperty(code); if (msg != null) { return msg; } List<Locale> locales = getAlternativeLocales(locale); for (int i = 0; i < locales.size(); i++) { msg = getMessages(locales.get(i)).getProperty(code); if (msg != null) { return msg; } } return null; }  void setDefaultLocale(Locale defaultLocale); synchronized void setDbMessageResourceDAO(
            DBMessageResourceDAO dbMessageResourceDAO); @Override void afterPropertiesSet(); synchronized void reloadDataSourceMessage();  }
@Test public void testInternalResolveCodeWithoutArguments01() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); ds.cachedMergedProperties = null; String code = "code01"; Locale locale = new Locale("ja", "JP", ""); ds.defaultLocale = null; Map<Locale, Properties> map = new HashMap<Locale, Properties>(); Properties props = new Properties(); String msg = "テストメッセージ０１"; props.put(code, msg); map.put(locale, props); ds.cachedMergedProperties = map; String returnMsg = ds.internalResolveCodeWithoutArguments(code, locale); assertEquals(msg, returnMsg); }
@Test public void testInternalResolveCodeWithoutArguments02() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); String code = "code01"; Locale locale = new Locale("ja", "JP", ""); ds.defaultLocale = null; Map<Locale, Properties> map = new HashMap<Locale, Properties>(); Properties props = new Properties(); Locale msglocale = new Locale("ja", "", ""); String msg = "テストメッセージ０１"; props.put(code, msg); map.put(msglocale, props); ds.cachedMergedProperties = map; String returnMsg = ds.internalResolveCodeWithoutArguments(code, locale); assertEquals("テストメッセージ０１", returnMsg); }
@Test public void testInternalResolveCodeWithoutArguments03() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); String code = "code01"; Locale locale = new Locale("ja", "JP", ""); ds.defaultLocale = new Locale("en", "US", ""); Map<Locale, Properties> map = new HashMap<Locale, Properties>(); Properties props = new Properties(); Locale msglocale = new Locale("en", "", ""); String msg = "テストメッセージ０１"; props.put(code, msg); map.put(msglocale, props); ds.cachedMergedProperties = map; String returnMsg = ds.internalResolveCodeWithoutArguments(code, locale); assertEquals("テストメッセージ０１", returnMsg); }
@Test public void testInternalResolveCodeWithoutArguments04() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); String code = "code01"; Locale locale = new Locale("ja", "JP", ""); ds.defaultLocale = new Locale("en", "US", ""); Map<Locale, Properties> map = new HashMap<Locale, Properties>(); Properties props = new Properties(); Locale msglocale = new Locale("ja", "JP", "kansai"); String msg = "テストメッセージ０１やで"; props.put(code, msg); map.put(msglocale, props); ds.cachedMergedProperties = map; String returnMsg = ds.internalResolveCodeWithoutArguments(code, locale); assertNull(returnMsg); }
@Test public void testInternalResolveCodeWithoutArguments05() throws Exception { DataSourceMessageSource ds = new DataSourceMessageSource(); String code = "code01"; Locale locale = new Locale("ja", "", ""); ds.defaultLocale = null; Map<Locale, Properties> map = new HashMap<Locale, Properties>(); Properties props = new Properties(); Locale msglocale = new Locale("ja", "JP", "kansai"); String msg = "テストメッセージ０１やで"; props.put(code, msg); map.put(msglocale, props); ds.cachedMergedProperties = map; String returnMsg = ds.internalResolveCodeWithoutArguments(code, locale); assertNull(returnMsg); }