コード例 #1
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldUseDefaultLocaleIfMissingValueInLocalizedBundle() {
   assertThat(
       manager.message(Locale.FRENCH, "only.in.english", null), Is.is("Missing in French bundle"));
   assertThat(
       manager.message(Locale.CHINA, "only.in.english", null), Is.is("Missing in French bundle"));
 }
コード例 #2
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 // see SONAR-3596
 @Test
 public void shouldLookInCoreClassloaderForPluginsThatDontEmbedAllLanguages() {
   assertThat(manager.message(Locale.ENGLISH, "forge_plugin.page", null))
       .isEqualTo("This is my plugin");
   assertThat(manager.message(Locale.FRENCH, "forge_plugin.page", null))
       .isEqualTo("C'est mon plugin");
 }
コード例 #3
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 // see SONAR-3783 => test that there will be no future regression on fallback for keys spread
 // accross several classloaders
 @Test
 public void shouldFallbackOnOriginalPluginIfTranslationNotPresentInLanguagePack() {
   // the "forge_plugin.page" has been translated in French
   assertThat(manager.message(Locale.FRENCH, "forge_plugin.page", null))
       .isEqualTo("C'est mon plugin");
   // but not the "forge_plugin.key_not_translated" key
   assertThat(manager.message(Locale.FRENCH, "forge_plugin.key_not_translated", null))
       .isEqualTo("Key Not Translated");
 }
コード例 #4
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
  @Test
  public void shouldNotKeepInCache() {
    assertThat(manager.getFileContentCache().size(), Is.is(0));
    boolean keepInCache = false;
    String html =
        manager.messageFromFile(
            Locale.ENGLISH, "ArchitectureRule.html", "checkstyle.rule1.name" /*
                                                                                                            * any property in the same
                                                                                                            * bundle
                                                                                                            */, keepInCache);

    assertThat(html, not(nullValue()));
    assertThat(manager.getFileContentCache().size(), Is.is(0));
  }
コード例 #5
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
  @Test
  public void shouldKeepInCache() {
    assertThat(manager.getFileContentCache().size(), Is.is(0));
    boolean keepInCache = true;
    String html =
        manager.messageFromFile(
            Locale.ENGLISH, "ArchitectureRule.html", "checkstyle.rule1.name" /*
                                                                                                            * any property in the same
                                                                                                            * bundle
                                                                                                            */, keepInCache);

    assertThat(html, not(nullValue()));
    Map<String, Map<Locale, String>> cache = manager.getFileContentCache();
    assertThat(cache.size(), Is.is(1));
    assertThat(
        cache.get("ArchitectureRule.html").get(Locale.ENGLISH),
        Is.is("This is the architecture rule"));
  }
コード例 #6
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldNotFindFile() {
   String html =
       manager.messageFromFile(
           Locale.ENGLISH,
           "UnknownRule.html",
           "checkstyle.rule1.name" /* any property in the same bundle */,
           false);
   assertThat(html, nullValue());
 }
コード例 #7
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldFindEnglishFile() {
   String html =
       manager.messageFromFile(
           Locale.ENGLISH, "ArchitectureRule.html", "checkstyle.rule1.name" /*
                                                                                                           * any property in the same
                                                                                                           * bundle
                                                                                                           */, false);
   assertThat(html, Is.is("This is the architecture rule"));
 }
コード例 #8
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldNotFindMissingLocale() {
   String html =
       manager.messageFromFile(
           Locale.CHINA,
           "ArchitectureRule.html",
           "checkstyle.rule1.name" /* any property in the same bundle */,
           false);
   assertThat(html, nullValue());
 }
コード例 #9
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldFindFrenchFile() {
   String html =
       manager.messageFromFile(
           Locale.FRENCH,
           "ArchitectureRule.html",
           "checkstyle.rule1.name" /* any property in the same bundle */,
           false);
   assertThat(html, Is.is("Règle d'architecture"));
 }
コード例 #10
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
  @Test
  public void shouldFindKeysInEnglishLanguagePack() {
    assertThat(manager.message(Locale.ENGLISH, "checkstyle.rule1.name", null), Is.is("Rule one"));
    assertThat(manager.message(Locale.ENGLISH, "by", null), Is.is("By"));
    assertThat(manager.message(Locale.ENGLISH, "sqale.page", null), Is.is("Sqale page title"));

    assertThat(manager.message(Locale.FRENCH, "checkstyle.rule1.name", null), Is.is("Rule un"));
    assertThat(manager.message(Locale.FRENCH, "by", null), Is.is("Par"));
    assertThat(manager.message(Locale.FRENCH, "sqale.page", null), Is.is("Titre de la page Sqale"));
  }
コード例 #11
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
  @Before
  public void init() {
    Map<String, ClassLoader> bundleToClassLoaders = Maps.newHashMap();
    // following represents the English language pack + a core plugin : they use the same
    // classloader
    coreClassLoader = newCoreClassLoader();
    bundleToClassLoaders.put(BUNDLE_PACKAGE + "core", coreClassLoader);
    bundleToClassLoaders.put(BUNDLE_PACKAGE + "checkstyle", coreClassLoader);
    // following represents a commercial plugin that must embed all its bundles, whatever the
    // language
    sqaleClassLoader = newSqaleClassLoader();
    bundleToClassLoaders.put(BUNDLE_PACKAGE + "sqale", sqaleClassLoader);
    // following represents a forge plugin that embeds only the english bundle, and lets the
    // language
    // packs embed all the bundles for the other languages
    forgeClassLoader = newForgeClassLoader();
    bundleToClassLoaders.put(BUNDLE_PACKAGE + "forge", forgeClassLoader);

    manager = new I18nManager(bundleToClassLoaders, coreClassLoader);
    manager.start();
  }
コード例 #12
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
  @Test
  public void shouldExtractPluginFromKey() {
    Map<String, ClassLoader> bundleToClassLoaders = Maps.newHashMap();
    bundleToClassLoaders.put(BUNDLE_PACKAGE + "core", getClass().getClassLoader());
    bundleToClassLoaders.put(BUNDLE_PACKAGE + "checkstyle", getClass().getClassLoader());
    bundleToClassLoaders.put(BUNDLE_PACKAGE + "sqale", getClass().getClassLoader());
    I18nManager i18n = new I18nManager(bundleToClassLoaders, coreClassLoader);
    i18n.start();

    assertThat(i18n.extractBundleFromKey("by"), Is.is(BUNDLE_PACKAGE + "core"));
    assertThat(
        i18n.extractBundleFromKey("violations_drilldown.page"), Is.is(BUNDLE_PACKAGE + "core"));
    assertThat(
        i18n.extractBundleFromKey("checkstyle.rule1.name"), Is.is(BUNDLE_PACKAGE + "checkstyle"));
    assertThat(i18n.extractBundleFromKey("sqale.console.page"), Is.is(BUNDLE_PACKAGE + "sqale"));
  }
コード例 #13
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldGetClassLoaderByProperty() {
   assertThat(manager.getClassLoaderForProperty("foo.unknown", Locale.ENGLISH), nullValue());
   assertThat(manager.getClassLoaderForProperty("by", Locale.ENGLISH), Is.is(coreClassLoader));
   // The following plugin defines its own bundles, whatever the language
   assertThat(
       manager.getClassLoaderForProperty("sqale.page", Locale.ENGLISH), Is.is(sqaleClassLoader));
   assertThat(
       manager.getClassLoaderForProperty("sqale.page", Locale.FRENCH), Is.is(sqaleClassLoader));
   // The following plugin defines only the English bundle, and lets the language packs handle the
   // translations
   assertThat(
       manager.getClassLoaderForProperty("forge_plugin.page", Locale.ENGLISH),
       Is.is(forgeClassLoader));
   assertThat(
       manager.getClassLoaderForProperty("forge_plugin.page", Locale.FRENCH),
       Is.is(coreClassLoader));
 }
コード例 #14
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldUseDefaultLocale() {
   assertThat(manager.message(Locale.CHINA, "checkstyle.rule1.name", null), Is.is("Rule one"));
   assertThat(manager.message(Locale.CHINA, "by", null), Is.is("By"));
   assertThat(manager.message(Locale.CHINA, "sqale.page", null), Is.is("Sqale page title"));
 }
コード例 #15
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldReturnDefaultValueIfMissingKey() {
   assertThat(manager.message(Locale.ENGLISH, "foo.unknown", "default"), Is.is("default"));
   assertThat(manager.message(Locale.FRENCH, "foo.unknown", "default"), Is.is("default"));
 }
コード例 #16
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldAcceptEmptyLabels() {
   assertThat(manager.message(Locale.ENGLISH, "empty", "default"), Is.is(""));
   assertThat(manager.message(Locale.FRENCH, "empty", "default"), Is.is(""));
 }
コード例 #17
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldFormatMessageWithParameters() {
   assertThat(
       manager.message(Locale.ENGLISH, "with.parameters", null, "one", "two"),
       Is.is("First is one and second is two"));
 }
コード例 #18
0
ファイル: I18nManagerTest.java プロジェクト: peterlynch/sonar
 @Test
 public void shouldUseLanguagePack() {
   assertThat(manager.message(Locale.FRENCH, "checkstyle.rule1.name", null), Is.is("Rule un"));
   assertThat(manager.message(Locale.FRENCH, "by", null), Is.is("Par"));
   assertThat(manager.message(Locale.FRENCH, "sqale.page", null), Is.is("Titre de la page Sqale"));
 }