killbill-aplcache

util: make catalog translation files path configurable Signed-off-by:

7/5/2012 10:34:16 PM

Details

diff --git a/api/src/main/java/com/ning/billing/util/template/translation/TranslatorConfig.java b/api/src/main/java/com/ning/billing/util/template/translation/TranslatorConfig.java
index 14dacf5..8d4e06e 100644
--- a/api/src/main/java/com/ning/billing/util/template/translation/TranslatorConfig.java
+++ b/api/src/main/java/com/ning/billing/util/template/translation/TranslatorConfig.java
@@ -22,13 +22,23 @@ import org.skife.config.Default;
 import com.ning.billing.invoice.api.formatters.InvoiceFormatterFactory;
 
 public interface TranslatorConfig {
-    @Config("killbill.template.default.locale")
+    // Common
+
+    @Config("killbill.default.locale")
     @Default("en_US")
     public String getDefaultLocale();
 
+    // Catalog
+
+    @Config("killbill.catalog.bundlePath")
+    @Default("com/ning/billing/util/template/translation/CatalogTranslation")
+    String getCatalogBundlePath();
+
+    // Invoices
+
     @Config("killbill.template.bundlePath")
     @Default("com/ning/billing/util/template/translation/InvoiceTranslation")
-    public String getBundlePath();
+    public String getInvoiceTemplateBundlePath();
 
     @Config("killbill.template.name")
     @Default("com/ning/billing/util/email/templates/HtmlInvoiceTemplate.mustache")
diff --git a/invoice/src/main/java/com/ning/billing/invoice/template/translator/DefaultInvoiceTranslator.java b/invoice/src/main/java/com/ning/billing/invoice/template/translator/DefaultInvoiceTranslator.java
index bad6d1b..3e00120 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/template/translator/DefaultInvoiceTranslator.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/template/translator/DefaultInvoiceTranslator.java
@@ -36,7 +36,7 @@ public class DefaultInvoiceTranslator extends DefaultTranslatorBase implements I
 
     @Override
     protected String getBundlePath() {
-        return config.getBundlePath();
+        return config.getInvoiceTemplateBundlePath();
     }
 
     @Override
diff --git a/util/src/main/java/com/ning/billing/util/template/translation/DefaultCatalogTranslator.java b/util/src/main/java/com/ning/billing/util/template/translation/DefaultCatalogTranslator.java
index a6027f5..f1b0ef7 100644
--- a/util/src/main/java/com/ning/billing/util/template/translation/DefaultCatalogTranslator.java
+++ b/util/src/main/java/com/ning/billing/util/template/translation/DefaultCatalogTranslator.java
@@ -26,7 +26,7 @@ public class DefaultCatalogTranslator extends DefaultTranslatorBase {
 
     @Override
     protected String getBundlePath() {
-        return "com/ning/billing/util/template/translation/CatalogTranslation";
+        return config.getCatalogBundlePath();
     }
 
     @Override
diff --git a/util/src/test/java/com/ning/billing/util/email/DefaultCatalogTranslationTest.java b/util/src/test/java/com/ning/billing/util/email/DefaultCatalogTranslationTest.java
index d092a5a..529616e 100644
--- a/util/src/test/java/com/ning/billing/util/email/DefaultCatalogTranslationTest.java
+++ b/util/src/test/java/com/ning/billing/util/email/DefaultCatalogTranslationTest.java
@@ -29,7 +29,6 @@ import com.ning.billing.util.template.translation.TranslatorConfig;
 
 import static org.testng.Assert.assertEquals;
 
-@Test(groups = {"fast", "email"})
 public class DefaultCatalogTranslationTest {
     private Translator translation;
 
@@ -49,49 +48,49 @@ public class DefaultCatalogTranslationTest {
         translation = new DefaultCatalogTranslator(config);
     }
 
-    @Test(groups = {"fast", "email"}, enabled = false)
+    @Test(groups = "fast")
     public void testInitialization() {
-        final String ningPlusText = "ning-plus";
-        final String ningProText = "ning-pro";
+        final String shotgunMonthly = "shotgun-monthly";
+        final String shotgunAnnual = "shotgun-annual";
         final String badText = "Bad text";
 
-        assertEquals(translation.getTranslation(Locale.US, ningPlusText), "Plus");
-        assertEquals(translation.getTranslation(Locale.US, ningProText), "Pro");
+        assertEquals(translation.getTranslation(Locale.US, shotgunMonthly), "Monthly shotgun plan");
+        assertEquals(translation.getTranslation(Locale.US, shotgunAnnual), "Annual shotgun plan");
         assertEquals(translation.getTranslation(Locale.US, badText), badText);
 
-        assertEquals(translation.getTranslation(Locale.CANADA_FRENCH, ningPlusText), "Plus en francais");
-        assertEquals(translation.getTranslation(Locale.CANADA_FRENCH, ningProText), "Pro");
+        assertEquals(translation.getTranslation(Locale.CANADA_FRENCH, shotgunMonthly), "Fusil de chasse mensuel");
+        assertEquals(translation.getTranslation(Locale.CANADA_FRENCH, shotgunAnnual), "Fusil de chasse annuel");
         assertEquals(translation.getTranslation(Locale.CANADA_FRENCH, badText), badText);
 
-        assertEquals(translation.getTranslation(Locale.CHINA, ningPlusText), "Plus");
-        assertEquals(translation.getTranslation(Locale.CHINA, ningProText), "Pro");
+        assertEquals(translation.getTranslation(Locale.CHINA, shotgunMonthly), "Monthly shotgun plan");
+        assertEquals(translation.getTranslation(Locale.CHINA, shotgunAnnual), "Annual shotgun plan");
         assertEquals(translation.getTranslation(Locale.CHINA, badText), badText);
     }
 
-    @Test(enabled = false)
+    @Test(groups = "fast")
     public void testExistingTranslation() {
-        // if the translation exists, return the translation
-        final String originalText = "ning-plus";
-        assertEquals(translation.getTranslation(Locale.US, originalText), "Plus");
+        // If the translation exists, return the translation
+        final String originalText = "shotgun-monthly";
+        assertEquals(translation.getTranslation(Locale.US, originalText), "Monthly shotgun plan");
     }
 
-    @Test
+    @Test(groups = "fast")
     public void testMissingTranslation() {
-        // if the translation is missing from the file, return the original text
+        // If the translation is missing from the file, return the original text
         final String originalText = "missing translation";
         assertEquals(translation.getTranslation(Locale.US, originalText), originalText);
     }
 
-    @Test(enabled = false)
+    @Test(groups = "fast")
     public void testMissingTranslationFileWithEnglishText() {
-        // if the translation file doesn't exist, return the "English" translation
-        final String originalText = "ning-plus";
-        assertEquals(translation.getTranslation(Locale.CHINA, originalText), "Plus");
+        // If the translation file doesn't exist, return the "English" translation
+        final String originalText = "shotgun-monthly";
+        assertEquals(translation.getTranslation(Locale.CHINA, originalText), "Monthly shotgun plan");
     }
 
-    @Test
+    @Test(groups = "fast")
     public void testMissingFileAndText() {
-        // if the file is missing, and the "English" translation is missing, return the original text
+        // If the file is missing, and the "English" translation is missing, return the original text
         final String originalText = "missing translation";
         assertEquals(translation.getTranslation(Locale.CHINA, originalText), originalText);
     }
diff --git a/util/src/test/resources/com/ning/billing/util/template/translation/CatalogTranslation_en_US.properties b/util/src/test/resources/com/ning/billing/util/template/translation/CatalogTranslation_en_US.properties
new file mode 100644
index 0000000..0bde4ee
--- /dev/null
+++ b/util/src/test/resources/com/ning/billing/util/template/translation/CatalogTranslation_en_US.properties
@@ -0,0 +1,2 @@
+shotgun-monthly = Monthly shotgun plan
+shotgun-annual = Annual shotgun plan
\ No newline at end of file
diff --git a/util/src/test/resources/com/ning/billing/util/template/translation/CatalogTranslation_fr_CA.properties b/util/src/test/resources/com/ning/billing/util/template/translation/CatalogTranslation_fr_CA.properties
new file mode 100644
index 0000000..2415908
--- /dev/null
+++ b/util/src/test/resources/com/ning/billing/util/template/translation/CatalogTranslation_fr_CA.properties
@@ -0,0 +1,2 @@
+shotgun-monthly = Fusil de chasse mensuel
+shotgun-annual = Fusil de chasse annuel
\ No newline at end of file