aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-testing-harness/src/test
diff options
context:
space:
mode:
authorGAUDIN <gaudol@gmail.com>2011-09-30 16:31:22 +0200
committerGAUDIN <gaudol@gmail.com>2011-09-30 16:31:22 +0200
commitb5016f504b3a7a29654e41c19ca78da2c8fa3be6 (patch)
treec61c40da1dd802fc974ee7cb441d7924236faf01 /sonar-testing-harness/src/test
parent43f27118331e8395365562c3859986489e38fb0a (diff)
parent520ebfd35bc581fa12c8e8267a548dc4d56317c6 (diff)
downloadsonarqube-2.11.tar.gz
sonarqube-2.11.zip
Merge branch Release-2.112.11
Diffstat (limited to 'sonar-testing-harness/src/test')
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java143
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/l10n/core.properties4
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr.properties4
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr_CA.properties4
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin.properties4
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr.properties4
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr_CA.properties4
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr_QB.properties5
8 files changed, 172 insertions, 0 deletions
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
new file mode 100644
index 00000000000..6568ff16101
--- /dev/null
+++ b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java
@@ -0,0 +1,143 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 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 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;
+import static org.sonar.test.i18n.I18nMatchers.isBundleUpToDate;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.SortedMap;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.test.TestUtils;
+
+public class BundleSynchronizedTest {
+
+ private static final String GITHUB_RAW_FILE_PATH = "https://raw.github.com/SonarSource/sonar/master/sonar-testing-harness/src/test/resources/org/sonar/l10n/";
+ private BundleSynchronizedMatcher matcher;
+
+ @Before
+ public void test() throws Exception {
+ matcher = new BundleSynchronizedMatcher(null);
+ }
+
+ @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", isBundleUpToDate());
+ assertFalse(new File("target/l10n/myPlugin_fr_CA.properties.report.txt").exists());
+ // missing keys
+ try {
+ assertThat("myPlugin_fr.properties", isBundleUpToDate());
+ assertTrue(new File("target/l10n/myPlugin_fr.properties.report.txt").exists());
+ } catch (AssertionError e) {
+ assertThat(e.getMessage(), containsString("Missing translations are:\nsecond.prop"));
+ }
+ // unnecessary many keys
+ try {
+ assertThat("myPlugin_fr_QB.properties", isBundleUpToDate());
+ assertTrue(new File("target/l10n/myPlugin_fr_QB.properties.report.txt").exists());
+ } catch (AssertionError e) {
+ assertThat(e.getMessage(), containsString("The following translations do not exist in the reference bundle:\nfourth.prop"));
+ }
+ }
+
+ @Test
+ // The case of a Sonar Language Pack that translates the Core bundles
+ public void testBundlesOfLanguagePack() {
+ // synchronized bundle
+ assertThat("core_fr_CA.properties", new BundleSynchronizedMatcher(null, GITHUB_RAW_FILE_PATH));
+ // missing keys
+ try {
+ assertThat("core_fr.properties", new BundleSynchronizedMatcher(null, GITHUB_RAW_FILE_PATH));
+ } 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_FILE_PATH);
+ matcher.getBundleFileFromGithub("core.properties");
+ assertTrue(new File("target/l10n/download/core.properties").exists());
+ }
+
+ @Test
+ public void testExtractDefaultBundleName() throws Exception {
+ assertThat(matcher.extractDefaultBundleName("myPlugin_fr.properties"), is("myPlugin.properties"));
+ assertThat(matcher.extractDefaultBundleName("myPlugin_fr_QB.properties"), is("myPlugin.properties"));
+ try {
+ matcher.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(matcher.isCoreBundle("core.properties"));
+ assertFalse(matcher.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<String, String> 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/core.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core.properties
new file mode 100644
index 00000000000..d182159860d
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core.properties
@@ -0,0 +1,4 @@
+## -------- 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
new file mode 100644
index 00000000000..aed2acc6f0e
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr.properties
@@ -0,0 +1,4 @@
+## -------- 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
new file mode 100644
index 00000000000..d182159860d
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/core_fr_CA.properties
@@ -0,0 +1,4 @@
+## -------- 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/myPlugin.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin.properties
new file mode 100644
index 00000000000..d182159860d
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin.properties
@@ -0,0 +1,4 @@
+## -------- 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/myPlugin_fr.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr.properties
new file mode 100644
index 00000000000..79c32ed5e81
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr.properties
@@ -0,0 +1,4 @@
+## -------- Test file for the BundleSynchronizedMatcher -------- ##
+first.prop = C'est ma première propriété
+#second.prop = C'est ma deuxième propriété
+third.prop = C'est ma troisième propriété \ No newline at end of file
diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr_CA.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr_CA.properties
new file mode 100644
index 00000000000..462cc8bcf36
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr_CA.properties
@@ -0,0 +1,4 @@
+## -------- Test file for the BundleSynchronizedMatcher -------- ##
+first.prop = C'est ma première propriété
+second.prop = C'est ma deuxième propriété
+third.prop = C'est ma troisième propriété \ No newline at end of file
diff --git a/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr_QB.properties b/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr_QB.properties
new file mode 100644
index 00000000000..5076dd808c8
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/l10n/myPlugin_fr_QB.properties
@@ -0,0 +1,5 @@
+## -------- Test file for the BundleSynchronizedMatcher -------- ##
+first.prop = C'est ma première propriété
+second.prop = C'est ma deuxième propriété
+third.prop = C'est ma troisième propriété
+fourth.prop = C'est ma quatrième propriété \ No newline at end of file