Exemplo n.º 1
0
 @Test
 public void testMergePackageTask() {
   if (I18nModule.isTransToolEnabled()) {
     prepareDevToolTests();
     tDMgr.mergePackageTask(testSourceBundle, testTargetBundle);
     i18nMgr.clearCaches();
     assertTrue(
         i18nMgr.getPropertiesWithoutResolvingRecursively(null, testSourceBundle).isEmpty());
     // TODO: manipulate source/target first, merge and check if all is in target!
     // try to merge existing key
   }
 }
Exemplo n.º 2
0
 @Test
 public void testMovePackageByMovingSingleKeysTask() {
   if (I18nModule.isTransToolEnabled()) {
     prepareDevToolTests();
     tDMgr.movePackageByMovingSingleKeysTask(testSourceBundle, testTargetBundle);
     i18nMgr.clearCaches();
     Properties sourceProp =
         i18nMgr.getPropertiesWithoutResolvingRecursively(null, testSourceBundle);
     assertTrue(sourceProp.isEmpty());
     Properties targetProp =
         i18nMgr.getPropertiesWithoutResolvingRecursively(null, testTargetBundle);
     assertFalse(targetProp.isEmpty());
   }
 }
Exemplo n.º 3
0
 @Test
 public void testRenameLanguageTask() {
   if (I18nModule.isTransToolEnabled()) {
     prepareDevToolTests();
     // create source
     Locale xxLocale = new Locale("xx");
     String key = "key.to.move";
     I18nItem i18nItem = i18nMgr.getI18nItem(testSourceBundle, key, xxLocale);
     i18nMgr.saveOrUpdateI18nItem(i18nItem, "I have to go");
     i18nMgr.setAnnotation(i18nItem, "an annotation");
     i18nMgr.setKeyPriority(testSourceBundle, key, 100);
     // copy to target
     Locale yyLocale = new Locale("yy");
     tDMgr.renameLanguageTask(xxLocale, yyLocale);
     i18nMgr.clearCaches();
     // test
     Properties deletedProperties =
         i18nMgr.getPropertiesWithoutResolvingRecursively(xxLocale, testSourceBundle);
     assertTrue(deletedProperties.isEmpty());
     Properties targetProp =
         i18nMgr.getPropertiesWithoutResolvingRecursively(yyLocale, testSourceBundle);
     assertFalse(targetProp.isEmpty());
   }
 }
Exemplo n.º 4
0
 /**
  * Test methods i18nManager.getProperties(), i18nManager.saveOrUpdateProperties() and
  * i18nManager.deleteProperties()
  */
 @Ignore
 @Test
 public void testGetSaveOrUpdateAndDeleteProperties() {
   // test with existing files
   Properties props =
       i18nMgr.getResolvedProperties(i18nMgr.getLocaleOrDefault("de"), "org.olat.core");
   assertNotNull(props);
   assertTrue(props.size() > 0);
   // test with non existing files
   String testNewBundle = "org.olat.core.util.i18n.junittestdata.new";
   Locale testLocale = i18nMgr.getLocaleOrDefault("de");
   File baseDir = I18nModule.getPropertyFilesBaseDir(testLocale, testNewBundle);
   File testFile = i18nMgr.getPropertiesFile(testLocale, testNewBundle, baseDir);
   // clean first existing files from previous broken testcase
   if (testFile.exists()) {
     i18nMgr.deleteProperties(testLocale, testNewBundle);
   }
   props = i18nMgr.getResolvedProperties(testLocale, testNewBundle);
   assertNotNull(props);
   assertEquals(0, props.size());
   // test deleting of non existing
   assertFalse(testFile.exists());
   i18nMgr.deleteProperties(testLocale, testNewBundle);
   assertFalse(testFile.exists());
   // test saving of non existing
   props.setProperty("test.key", "Hello wörld !");
   i18nMgr.saveOrUpdateProperties(props, testLocale, testNewBundle);
   assertTrue(testFile.exists());
   assertEquals(
       "Hello wörld !",
       i18nMgr.getLocalizedString(testNewBundle, "test.key", null, testLocale, false, false));
   // test saving of existing
   props = new Properties();
   props.setProperty("hello.world", "&%çest françias, ê alors");
   i18nMgr.saveOrUpdateProperties(props, testLocale, testNewBundle);
   assertTrue(testFile.exists());
   assertEquals(
       "&%çest françias, ê alors",
       i18nMgr.getLocalizedString(testNewBundle, "hello.world", null, testLocale, false, false));
   assertFalse(
       "Hello wörld !"
           .equals(
               i18nMgr.getLocalizedString(
                   testNewBundle, "test.key", null, testLocale, false, false)));
   // test various special cases
   props.setProperty("chinesetest", "请选择你的大学");
   props.setProperty("specialtest", "that's like \"really\" bad");
   props.setProperty("multiline", "bla\tbla\nsecond line");
   props.setProperty("html", "<h1>Hello World</h1>");
   props.setProperty("empty.property", "");
   i18nMgr.saveOrUpdateProperties(props, testLocale, testNewBundle);
   i18nMgr.clearCaches();
   assertEquals(
       "请选择你的大学",
       i18nMgr.getLocalizedString(testNewBundle, "chinesetest", null, testLocale, false, false));
   assertEquals(
       "that's like \"really\" bad",
       i18nMgr.getLocalizedString(testNewBundle, "specialtest", null, testLocale, false, false));
   assertEquals(
       "bla\tbla\nsecond line",
       i18nMgr.getLocalizedString(testNewBundle, "multiline", null, testLocale, false, false));
   assertEquals(
       "<h1>Hello World</h1>",
       i18nMgr.getLocalizedString(testNewBundle, "html", null, testLocale, false, false));
   assertEquals(
       "",
       i18nMgr.getLocalizedString(
           testNewBundle, "empty.property", null, testLocale, false, false));
   assertEquals(
       null,
       i18nMgr.getLocalizedString(
           testNewBundle, "not.existing.property", null, testLocale, false, false));
   // test deleting of existing
   i18nMgr.deleteProperties(testLocale, testNewBundle);
   assertFalse(testFile.exists());
   assertFalse(
       "Hello wörld !"
           .equals(
               i18nMgr.getLocalizedString(
                   testNewBundle, "test.key", null, testLocale, false, false)));
   assertFalse(
       "&%çest françias, ê alors"
           .equals(
               i18nMgr.getLocalizedString(
                   testNewBundle, "hello.world", null, testLocale, false, false)));
   // clean up
   if (testFile.exists()) {
     i18nMgr.deleteProperties(testLocale, testNewBundle);
   }
   if (testFile.getParentFile().exists()) testFile.getParentFile().delete();
 }