From: Fabrice Bellingard Date: Wed, 19 Sep 2012 15:45:05 +0000 (+0200) Subject: SONAR-3736 Use Maven dependencies for I18n Harmcrest matchers X-Git-Tag: 3.3~279 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=da68ac0b2b86a0042b4d6dbc384a70b492defdf4;p=sonarqube.git SONAR-3736 Use Maven dependencies for I18n Harmcrest matchers - Do not use URLs anymore, to make it easier to test (no need for an internet connection) --- diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java index 4ae41847827..ca49bcec1de 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java @@ -20,25 +20,15 @@ package org.sonar.test.i18n; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.commons.io.IOUtils; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; -import org.sonar.test.TestUtils; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.Collection; import java.util.Map; import java.util.Properties; import java.util.SortedMap; @@ -51,63 +41,34 @@ import static org.junit.Assert.fail; public class BundleSynchronizedMatcher extends BaseMatcher { public static final String L10N_PATH = "/org/sonar/l10n/"; - private static final Collection CORE_BUNDLES = Lists.newArrayList("checkstyle.properties", "core.properties", - "findbugs.properties", "gwt.properties", "pmd.properties", "squidjava.properties"); - private static final String GITHUB_RAW_FILE_PATH = "https://raw.github.com/SonarSource/sonar/master/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/"; - private String sonarVersion; - private URI referenceEnglishBundleURI; - // we use this variable to be able to unit test this class without looking at the real Github core bundles that change all the time - private String remote_file_path; private String bundleName; private SortedMap missingKeys; private SortedMap additionalKeys; - public BundleSynchronizedMatcher() { - this(null, GITHUB_RAW_FILE_PATH); - } - - public BundleSynchronizedMatcher(URI referenceEnglishBundleURI) { - this.referenceEnglishBundleURI = referenceEnglishBundleURI; - } - - public BundleSynchronizedMatcher(String sonarVersion) { - this(sonarVersion, GITHUB_RAW_FILE_PATH); - } - - @VisibleForTesting - BundleSynchronizedMatcher(String sonarVersion, String remote_file_path) { - this.sonarVersion = sonarVersion; - this.remote_file_path = remote_file_path; - } - public boolean matches(Object arg0) { if (!(arg0 instanceof String)) { return false; } bundleName = (String) arg0; - File bundle = getBundleFileFromClasspath(bundleName); + // Find the bundle that needs to be verified + InputStream bundleInputStream = getBundleFileInputStream(bundleName); - // Find the default bundle name which should be compared to - String defaultBundleName = extractDefaultBundleName(bundleName); - File defaultBundle; - if (isCoreBundle(defaultBundleName)) { - defaultBundle = getBundleFileFromGithub(defaultBundleName); - } else if (referenceEnglishBundleURI != null) { - defaultBundle = getBundleFileFromProvidedURI(defaultBundleName); - } else { - defaultBundle = getBundleFileFromClasspath(defaultBundleName); - } + // Find the default bundle which the provided one should be compared to + InputStream defaultBundleInputStream = getDefaultBundleFileInputStream(bundleName); - // and now let's compare + // and now let's compare! try { - missingKeys = retrieveMissingTranslations(bundle, defaultBundle); - additionalKeys = retrieveMissingTranslations(defaultBundle, bundle); + missingKeys = retrieveMissingTranslations(bundleInputStream, defaultBundleInputStream); + additionalKeys = retrieveMissingTranslations(defaultBundleInputStream, bundleInputStream); return missingKeys.isEmpty(); } catch (IOException e) { fail("An error occured while reading the bundles: " + e.getMessage()); return false; + } finally { + IOUtils.closeQuietly(bundleInputStream); + IOUtils.closeQuietly(defaultBundleInputStream); } } @@ -159,7 +120,8 @@ public class BundleSynchronizedMatcher extends BaseMatcher { } } - protected SortedMap retrieveMissingTranslations(File bundle, File referenceBundle) throws IOException { + @VisibleForTesting + protected static SortedMap retrieveMissingTranslations(InputStream bundle, InputStream referenceBundle) throws IOException { SortedMap missingKeys = Maps.newTreeMap(); Properties bundleProps = loadProperties(bundle); @@ -175,98 +137,34 @@ public class BundleSynchronizedMatcher extends BaseMatcher { return missingKeys; } - private Properties loadProperties(File f) throws IOException { + @VisibleForTesting + protected static Properties loadProperties(InputStream inputStream) throws IOException { Properties props = new Properties(); - FileInputStream input = new FileInputStream(f); - try { - props.load(input); - return props; - - } finally { - IOUtils.closeQuietly(input); - } - } - - protected File getBundleFileFromGithub(String defaultBundleName) { - String remoteFile = computeGitHubURL(defaultBundleName, sonarVersion); - URL remoteFileURL = null; - try { - remoteFileURL = new URL(remoteFile); - } catch (MalformedURLException e) { - fail("Could not download the original core bundle at: " + remote_file_path + defaultBundleName); - } - return downloadRemoteFile(defaultBundleName, remoteFileURL); - } - - protected String computeGitHubURL(String defaultBundleName, String sonarVersion) { - String computedURL = remote_file_path + defaultBundleName; - if (sonarVersion != null && !sonarVersion.contains("-SNAPSHOT")) { - computedURL = computedURL.replace("/master/", "/" + sonarVersion + "/"); - } - return computedURL; + props.load(inputStream); + return props; } - protected File getBundleFileFromClasspath(String bundleName) { - File bundle = TestUtils.getResource(L10N_PATH + bundleName); + @VisibleForTesting + protected static InputStream getBundleFileInputStream(String bundleName) { + InputStream bundle = BundleSynchronizedMatcher.class.getResourceAsStream(L10N_PATH + bundleName); assertThat("File '" + bundleName + "' does not exist in '/org/sonar/l10n/'.", bundle, notNullValue()); - assertThat("File '" + bundleName + "' does not exist in '/org/sonar/l10n/'.", bundle.exists(), is(true)); return bundle; } - private File getBundleFileFromProvidedURI(String defaultBundleName) { - URL remoteFileURL = null; - try { - remoteFileURL = referenceEnglishBundleURI.toURL(); - } catch (MalformedURLException e) { - fail("Could not download the original bundle at: " + remote_file_path + defaultBundleName); - } - return downloadRemoteFile(defaultBundleName, remoteFileURL); - } - - private File downloadRemoteFile(String defaultBundleName, URL remoteFileUrl) { - File localBundle = new File("target/l10n/download/" + defaultBundleName); - try { - saveUrlToLocalFile(remoteFileUrl, localBundle); - } catch (IOException e) { - fail("Could not download the original core bundle at: " + remoteFileUrl.toString() + defaultBundleName); - } - assertThat("File 'target/tmp/" + defaultBundleName + "' has been downloaded but does not exist.", localBundle, notNullValue()); - assertThat("File 'target/tmp/" + defaultBundleName + "' has been downloaded but does not exist.", localBundle.exists(), is(true)); - return localBundle; - } - - private void saveUrlToLocalFile(URL url, File localFile) throws IOException { - if (localFile.exists()) { - localFile.delete(); - } - localFile.getParentFile().mkdirs(); - - InputStream in = null; - OutputStream fout = null; - try { - in = new BufferedInputStream(url.openStream()); - fout = new FileOutputStream(localFile); - - byte data[] = new byte[1024]; - int count; - while ((count = in.read(data, 0, 1024)) != -1) { - fout.write(data, 0, count); - } - } finally { - IOUtils.closeQuietly(in); - IOUtils.closeQuietly(fout); - } + @VisibleForTesting + protected static InputStream getDefaultBundleFileInputStream(String bundleName) { + String defaultBundleName = extractDefaultBundleName(bundleName); + InputStream bundle = BundleSynchronizedMatcher.class.getResourceAsStream(L10N_PATH + defaultBundleName); + assertThat("Default bundle '" + defaultBundleName + "' could not be found: add a dependency to the corresponding plugin in your POM.", bundle, notNullValue()); + return bundle; } - public static String extractDefaultBundleName(String bundleName) { + @VisibleForTesting + protected static String extractDefaultBundleName(String bundleName) { int firstUnderScoreIndex = bundleName.indexOf('_'); assertThat("The bundle '" + bundleName + "' is a default bundle (without locale), so it can't be compared.", firstUnderScoreIndex > 0, is(true)); return bundleName.substring(0, firstUnderScoreIndex) + ".properties"; } - public static boolean isCoreBundle(String defaultBundleName) { - return CORE_BUNDLES.contains(defaultBundleName); - } - } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java index ea4ac5f5965..b0a492550cc 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java @@ -25,8 +25,6 @@ import org.apache.commons.lang.StringUtils; import org.sonar.test.TestUtils; import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; import java.util.Collection; import java.util.Map; @@ -39,42 +37,7 @@ public final class I18nMatchers { } /** - *

- * Used by language packs that translate Core bundles. - *

- * Returns a matcher which checks that a translation bundle is up to date with the corresponding English Core bundle. - *
    - *
  • If a version of Sonar is specified, then the check is done against this version of the bundle found on Sonar Github repository.
  • - *
  • If sonarVersion is set to NULL, the check is done against the latest version of this bundle found on Github (master branch).
  • - *
- * - * @param sonarVersion - * the version of the bundle to check against, or NULL to check against the latest source on GitHub - * @return the matcher - */ - public static BundleSynchronizedMatcher isBundleUpToDate(String sonarVersion) { - return new BundleSynchronizedMatcher(sonarVersion); - } - - /** - *

- * Used by language packs that translate third-party bundles. - *

- * Returns a matcher which checks that a translation bundle is up to date with the given reference English bundle from a third-party plugin. - * - * @param referenceEnglishBundleURI - * the URI referencing the English bundle to check against - * @return the matcher - */ - public static BundleSynchronizedMatcher isBundleUpToDate(URI referenceEnglishBundleURI) { - return new BundleSynchronizedMatcher(referenceEnglishBundleURI); - } - - /** - *

- * Used only by independent plugins that embeds their own bundles for every language. - *

- * Returns a matcher which checks that a translation bundle is up to date with the corresponding default one found in the same folder. + * Returns a matcher which checks that a translation bundle is up to date with the corresponding default one found in the classpath. * * @return the matcher */ @@ -83,53 +46,9 @@ public final class I18nMatchers { } /** - *

- * Must be used only by independent plugins that embeds their own bundles for every language. - *

- * Checks that all the translation bundles found on the classpath are up to date with the corresponding default one found in the same - * folder. + * Checks that all the translation bundles found on the classpath are up to date with the corresponding default ones found in the classpath. */ public static void assertAllBundlesUpToDate() { - try { - assertAllBundlesUpToDate(null, null); - } catch (URISyntaxException e) { - // Ignore, this can't happen here - } - } - - /** - *

- * Must be used only by language packs. - *

- *

- * Depending on the parameters, this method does the following: - *

    - *
  • sonarVersion: checks that all the Core translation bundles found on the classpath are up to date with the corresponding English ones found on Sonar - * GitHub repository for the given Sonar version. - *
    • Note: if sonarVersion is set to NULL, the check is done against the latest version of this bundles found the master branch of the GitHub repository.
    - *
  • - *
  • pluginIdsToBundleUrlMap: checks that other translation bundles found on the classpath are up to date with the reference English bundles of the corresponding - * plugins given by the "pluginIdsToBundleUrlMap" parameter. - *
  • - *
- *

- *


- * The following example will check that the translation of the Core bundles are up to date with version 3.2 of Sonar English Language Pack, and it - * will also check that the translation of the bundle of the Web plugin is up to date with the reference English bundle of version 1.2 of the Web plugin: - *

-   * Map pluginIdsToBundleUrlMap = Maps.newHashMap();
-   * pluginIdsToBundleUrlMap.put("web", "http://svn.codehaus.org/sonar-plugins/tags/sonar-web-plugin-1.2/src/main/resources/org/sonar/l10n/web.properties");
-   * assertAllBundlesUpToDate("3.2", pluginIdsToBundleUrlMap);
-   * 
- *

- * - * @param sonarVersion - * the version of the bundles to check against, or NULL to check against the latest source on GitHub - * @param pluginIdsToBundleUrlMap - * a map that gives, for a given plugin, the URL of the English bundle that must be used to check the translation. - * @throws URISyntaxException if the provided URLs in the "pluginIdsToBundleUrlMap" parameter are not correct - */ - public static void assertAllBundlesUpToDate(String sonarVersion, Map pluginIdsToBundleUrlMap) throws URISyntaxException { File bundleFolder = TestUtils.getResource(BundleSynchronizedMatcher.L10N_PATH); if (bundleFolder == null || !bundleFolder.isDirectory()) { fail("No bundle found in '" + BundleSynchronizedMatcher.L10N_PATH + "'"); @@ -141,18 +60,7 @@ public final class I18nMatchers { String bundleName = bundle.getName(); if (bundleName.indexOf('_') > 0) { try { - String baseBundleName = BundleSynchronizedMatcher.extractDefaultBundleName(bundleName); - String pluginId = StringUtils.substringBefore(baseBundleName, "."); - if (BundleSynchronizedMatcher.isCoreBundle(baseBundleName)) { - // this is a core bundle => must be checked againt the provided version of Sonar - assertThat(bundleName, isBundleUpToDate(sonarVersion)); - } else if (pluginIdsToBundleUrlMap != null && pluginIdsToBundleUrlMap.get(pluginId) != null) { - // this is a third-party plugin translated by a language pack => must be checked against the provided URL - assertThat(bundleName, isBundleUpToDate(new URI(pluginIdsToBundleUrlMap.get(pluginId)))); - } else { - // this is the case of a plugin that provides all the bundles for every language => check the bundles inside the plugin - assertThat(bundleName, isBundleUpToDate()); - } + assertThat(bundleName, isBundleUpToDate()); } catch (AssertionError e) { failedAssertionMessages.put(bundleName, e.getMessage()); } diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java new file mode 100644 index 00000000000..2eb97a82a6e --- /dev/null +++ b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedMatcherTest.java @@ -0,0 +1,132 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.test.i18n; + +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.SortedMap; + +import static org.fest.assertions.Assertions.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class BundleSynchronizedMatcherTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private BundleSynchronizedMatcher matcher; + + @Before + public void init() { + matcher = new BundleSynchronizedMatcher(); + } + + @Test + public void shouldMatch() { + assertThat("myPlugin_fr_CA.properties", matcher); + assertFalse(new File("target/l10n/myPlugin_fr_CA.properties.report.txt").exists()); + } + + @Test + public void shouldNotMatch() { + try { + assertThat("myPlugin_fr.properties", matcher); + assertTrue(new File("target/l10n/myPlugin_fr.properties.report.txt").exists()); + } catch (AssertionError e) { + assertThat(e.getMessage(), containsString("Missing translations are:\nsecond.prop")); + } + } + + @Test + public void shouldNotMatchIfNotString() { + assertThat(matcher.matches(3)).isFalse(); + } + + @Test + public void testGetBundleFileFromClasspath() { + // OK + assertThat(BundleSynchronizedMatcher.getBundleFileInputStream("myPlugin_fr.properties")) + .isNotNull(); + + // KO + thrown.expect(AssertionError.class); + thrown.expectMessage("File 'unexistingBundle.properties' does not exist in '/org/sonar/l10n/'."); + BundleSynchronizedMatcher.getBundleFileInputStream("unexistingBundle.properties"); + } + + @Test + public void testGetDefaultBundleFileFromClasspath() { + thrown.expect(AssertionError.class); + thrown.expectMessage("Default bundle 'unexistingBundle.properties' could not be found: add a dependency to the corresponding plugin in your POM."); + BundleSynchronizedMatcher.getDefaultBundleFileInputStream("unexistingBundle_fr.properties"); + } + + @Test + public void testExtractDefaultBundleName() throws Exception { + // OK + assertThat(BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin_fr.properties"), is("myPlugin.properties")); + assertThat(BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin_fr_QB.properties"), is("myPlugin.properties")); + + // KO + thrown.expect(AssertionError.class); + thrown.expectMessage("The bundle 'myPlugin.properties' is a default bundle (without locale), so it can't be compared."); + BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin.properties"); + } + + @Test + public void testRetrieveMissingKeys() throws Exception { + InputStream defaultBundleIS = this.getClass().getResourceAsStream(BundleSynchronizedMatcher.L10N_PATH + "myPlugin.properties"); + InputStream frBundleIS = this.getClass().getResourceAsStream(BundleSynchronizedMatcher.L10N_PATH + "myPlugin_fr.properties"); + InputStream qbBundleIS = this.getClass().getResourceAsStream(BundleSynchronizedMatcher.L10N_PATH + "myPlugin_fr_QB.properties"); + + try { + SortedMap diffs = BundleSynchronizedMatcher.retrieveMissingTranslations(frBundleIS, defaultBundleIS); + assertThat(diffs.size(), is(1)); + assertThat(diffs.keySet(), hasItem("second.prop")); + + diffs = BundleSynchronizedMatcher.retrieveMissingTranslations(qbBundleIS, defaultBundleIS); + assertThat(diffs.size(), is(0)); + } finally { + IOUtils.closeQuietly(defaultBundleIS); + IOUtils.closeQuietly(frBundleIS); + IOUtils.closeQuietly(qbBundleIS); + } + } + + @Test + public void shouldFailToLoadUnexistingPropertiesFile() throws Exception { + thrown.expect(IOException.class); + BundleSynchronizedMatcher.loadProperties(new FileInputStream("foo.blabla")); + } + +} diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java deleted file mode 100644 index e510f909545..00000000000 --- a/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.test.i18n; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.test.TestUtils; - -import java.io.File; -import java.net.URI; -import java.util.SortedMap; - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class BundleSynchronizedTest { - - private static final String GITHUB_RAW_TESTING_FILE_PATH = "https://raw.github.com/SonarSource/sonar/master/sonar-testing-harness/src/test/resources/org/sonar/l10n/"; - private BundleSynchronizedMatcher matcher; - - @Before - public void init() { - matcher = new BundleSynchronizedMatcher(); - } - - @Test - // The case of a Sonar Language Pack that translates the Core bundles - public void shouldMatchBundlesOfLanguagePack() { - // synchronized bundle - assertThat("core_fr_CA.properties", new BundleSynchronizedMatcher(null, GITHUB_RAW_TESTING_FILE_PATH)); - // missing keys - try { - assertThat("core_fr.properties", new BundleSynchronizedMatcher(null, GITHUB_RAW_TESTING_FILE_PATH)); - } catch (AssertionError e) { - assertThat(e.getMessage(), containsString("Missing translations are:\nsecond.prop")); - } - } - - @Test - // The case of a Sonar Language Pack that translates plugin bundles - public void shouldMatchWithProvidedURI() throws Exception { - matcher = new BundleSynchronizedMatcher(new URI("http://svn.codehaus.org/sonar-plugins/tags/sonar-abacus-plugin-0.1/src/main/resources/org/sonar/l10n/abacus.properties")); - assertThat("abacus_fr.properties", matcher); - } - - @Test - // The case of a Sonar plugin that embeds all the bundles for every language - public void testBundlesInsideSonarPlugin() { - // synchronized bundle - assertThat("myPlugin_fr_CA.properties", matcher); - assertFalse(new File("target/l10n/myPlugin_fr_CA.properties.report.txt").exists()); - // missing keys - try { - assertThat("myPlugin_fr.properties", matcher); - assertTrue(new File("target/l10n/myPlugin_fr.properties.report.txt").exists()); - } catch (AssertionError e) { - assertThat(e.getMessage(), containsString("Missing translations are:\nsecond.prop")); - } - } - - @Test - public void testGetBundleFileFromClasspath() { - matcher.getBundleFileFromClasspath("core_fr.properties"); - try { - matcher.getBundleFileFromClasspath("unexistingBundle.properties"); - } catch (AssertionError e) { - assertThat(e.getMessage(), containsString("File 'unexistingBundle.properties' does not exist in '/org/sonar/l10n/'.")); - } - } - - @Test - public void testGetBundleFileFromGithub() throws Exception { - matcher = new BundleSynchronizedMatcher(null, GITHUB_RAW_TESTING_FILE_PATH); - matcher.getBundleFileFromGithub("core.properties"); - assertTrue(new File("target/l10n/download/core.properties").exists()); - } - - @Test - public void testExtractDefaultBundleName() throws Exception { - assertThat(BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin_fr.properties"), is("myPlugin.properties")); - assertThat(BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin_fr_QB.properties"), is("myPlugin.properties")); - try { - BundleSynchronizedMatcher.extractDefaultBundleName("myPlugin.properties"); - } catch (AssertionError e) { - assertThat(e.getMessage(), - containsString("The bundle 'myPlugin.properties' is a default bundle (without locale), so it can't be compared.")); - } - } - - @Test - public void testIsCoreBundle() throws Exception { - assertTrue(BundleSynchronizedMatcher.isCoreBundle("core.properties")); - assertFalse(BundleSynchronizedMatcher.isCoreBundle("myPlugin.properties")); - } - - @Test - public void testRetrieveMissingKeys() throws Exception { - File defaultBundle = TestUtils.getResource(BundleSynchronizedMatcher.L10N_PATH + "myPlugin.properties"); - File frBundle = TestUtils.getResource(BundleSynchronizedMatcher.L10N_PATH + "myPlugin_fr.properties"); - File qbBundle = TestUtils.getResource(BundleSynchronizedMatcher.L10N_PATH + "myPlugin_fr_QB.properties"); - - SortedMap diffs = matcher.retrieveMissingTranslations(frBundle, defaultBundle); - assertThat(diffs.size(), is(1)); - assertThat(diffs.keySet(), hasItem("second.prop")); - - diffs = matcher.retrieveMissingTranslations(qbBundle, defaultBundle); - assertThat(diffs.size(), is(0)); - } - - @Test - public void testComputeGitHubURL() throws Exception { - assertThat( - matcher.computeGitHubURL("core.properties", null), - is("https://raw.github.com/SonarSource/sonar/master/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties")); - assertThat( - matcher.computeGitHubURL("core.properties", "2.11-SNAPSHOT"), - is("https://raw.github.com/SonarSource/sonar/master/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties")); - assertThat(matcher.computeGitHubURL("core.properties", "2.10"), - is("https://raw.github.com/SonarSource/sonar/2.10/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties")); - } - -} diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/abacus_fr.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/abacus_fr.properties index 03ee2266df9..6586b7acb54 100644 --- a/sonar-testing-harness/src/test/resources/org/sonar/l10n/abacus_fr.properties +++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/abacus_fr.properties @@ -1,4 +1,3 @@ -## -------- Test file for the BundleSynchronizedMatcher -------- ## widget.abacus.name=Abaques widget.abacus.description=Calcule la complexit\u00e9 de chaque composant pour vous aider \u00e0 utiliser vos abaques. @@ -25,4 +24,6 @@ abacus.error.defaultDisplay.incorrectValue=La valeur du param\u00e8tre de widget abacus.noData=Pas de donn\u00e9es abacus.numberOfFilesDistribution=Distribution en nombre de fichiers abacus.percentageDistribution=Distribution en % -abacus.title=Abaques \ No newline at end of file + +# Added property that does not exit +abacus.foo=Foo \ No newline at end of file diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/branding_fr.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/branding_fr.properties new file mode 100644 index 00000000000..7759f1a0f17 --- /dev/null +++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/branding_fr.properties @@ -0,0 +1,8 @@ +property.sonar.branding.image.name=URL de l'image +property.sonar.branding.image.description=Exemple : http://www.codehaus.org/codehaus-small.gif + +property.sonar.branding.logo.location.name=Position du logo dans l'IHM de Sonar +property.sonar.branding.logo.location.description=Valeurs possibles : TOP, MENU + +widget.project-logo.name=Logo du projet +widget.project-logo.description=Affiche le logo du projet \ No newline at end of file diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/core.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core.properties deleted file mode 100644 index d182159860d..00000000000 --- a/sonar-testing-harness/src/test/resources/org/sonar/l10n/core.properties +++ /dev/null @@ -1,4 +0,0 @@ -## -------- Test file for the BundleSynchronizedMatcher -------- ## -first.prop = This is my first property -second.prop = This is my second property -third.prop = This is my third property \ No newline at end of file diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr.properties deleted file mode 100644 index aed2acc6f0e..00000000000 --- a/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr.properties +++ /dev/null @@ -1,4 +0,0 @@ -## -------- Test file for the BundleSynchronizedMatcher -------- ## -first.prop = This is my first property -#second.prop = This is my second property -third.prop = This is my third property \ No newline at end of file diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr_CA.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr_CA.properties deleted file mode 100644 index d182159860d..00000000000 --- a/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr_CA.properties +++ /dev/null @@ -1,4 +0,0 @@ -## -------- Test file for the BundleSynchronizedMatcher -------- ## -first.prop = This is my first property -second.prop = This is my second property -third.prop = This is my third property \ No newline at end of file diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys.properties deleted file mode 100644 index 3fb9281f6a7..00000000000 --- a/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys.properties +++ /dev/null @@ -1 +0,0 @@ -foo=Foo \ No newline at end of file diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys_fr.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys_fr.properties deleted file mode 100644 index 9df3201b51f..00000000000 --- a/sonar-testing-harness/src/test/resources/org/sonar/l10n/noMissingKeys_fr.properties +++ /dev/null @@ -1,2 +0,0 @@ -foo=Hein -not_in_reference=Not in reference \ No newline at end of file diff --git a/sonar-testing-harness/src/test/resources/org/sonar/test/i18n/BundleSynchronizedMatcherTest/bundle.properties b/sonar-testing-harness/src/test/resources/org/sonar/test/i18n/BundleSynchronizedMatcherTest/bundle.properties new file mode 100644 index 00000000000..144d5795dd3 --- /dev/null +++ b/sonar-testing-harness/src/test/resources/org/sonar/test/i18n/BundleSynchronizedMatcherTest/bundle.properties @@ -0,0 +1,3 @@ +first.prop = This is my first property +second.prop = This is my second property +third.prop = This is my third property \ No newline at end of file