aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-testing-harness/src/test
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-09-02 17:12:41 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-09-02 17:13:23 +0200
commitf0559fe73cd8d29a5f505c5a80c0c6784b97430c (patch)
tree114baf55cdaa6b6aa73510975aefe43fd4f1497e /sonar-testing-harness/src/test
parentda60f0621e41a441bc67e522ac2ead3648bd06ad (diff)
downloadsonarqube-f0559fe73cd8d29a5f505c5a80c0c6784b97430c.tar.gz
sonarqube-f0559fe73cd8d29a5f505c5a80c0c6784b97430c.zip
SONAR-2693 Hamcrest matcher to compare a pair of translation bundles
First commit and push to GitHub before activating other tests that require this code to be pushed.
Diffstat (limited to 'sonar-testing-harness/src/test')
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java121
-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/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
7 files changed, 146 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..0bac5a9047b
--- /dev/null
+++ b/sonar-testing-harness/src/test/java/org/sonar/test/i18n/BundleSynchronizedTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.isBundleSynchronized;
+
+import java.io.File;
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.sonar.test.TestUtils;
+
+public class BundleSynchronizedTest {
+
+ private BundleSynchronizedMatcher matcher;
+
+ @Before
+ public void test() throws Exception {
+ matcher = new BundleSynchronizedMatcher("https://raw.github.com/SonarSource/sonar/master/sonar-testing-harness/src/test/resources/org/sonar/l10n/");
+ }
+
+ @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", isBundleSynchronized());
+ // missing keys
+ try {
+ assertThat("myPlugin_fr.properties", isBundleSynchronized());
+ } catch (AssertionError e) {
+ assertThat(e.getMessage(), containsString("Missing keys are:\n\t- second.prop"));
+ }
+ // unnecessary many keys
+ try {
+ assertThat("myPlugin_fr_QB.properties", isBundleSynchronized());
+ } catch (AssertionError e) {
+ assertThat(e.getMessage(), containsString("Also, the following keys do not exist in the default bundle:\n\t- fourth.prop"));
+ }
+ }
+
+ @Test
+ @Ignore
+ // The case of a Sonar Language Pack that translates the Core bundles
+ public void testBundlesOfLanguagePack() {
+ assertThat("core_fr.properties", isBundleSynchronized());
+ }
+
+ @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
+ @Ignore
+ public void testGetBundleFileFromGithub() throws Exception {
+ 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");
+
+ Collection<String> diffs = matcher.retrieveMissingKeys(frBundle, defaultBundle);
+ assertThat(diffs.size(), is(1));
+ assertThat(diffs, hasItem("second.prop"));
+
+ diffs = matcher.retrieveMissingKeys(qbBundle, defaultBundle);
+ assertThat(diffs.size(), is(0));
+ }
+}
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/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