@Test public void testMoveKeyTask() { if (I18nModule.isTransToolEnabled()) { prepareDevToolTests(); Locale testLocale = i18nMgr.getLocaleOrDefault("de"); String ktm = "key.to.move"; i18nMgr.setCachingEnabled(true); Properties sourcePropResolved = i18nMgr.getResolvedProperties(testLocale, testSourceBundle); Properties sourceProp = i18nMgr.getPropertiesWithoutResolvingRecursively(testLocale, testSourceBundle); String matchString = sourceProp.getProperty(ktm); assertTrue(sourcePropResolved.getProperty("key.to.stay2").indexOf(matchString) != -1); tDMgr.moveKeyToOtherBundle(testSourceBundle, testTargetBundle, ktm); sourceProp = i18nMgr.getPropertiesWithoutResolvingRecursively(testLocale, testSourceBundle); Properties targetProp = i18nMgr.getPropertiesWithoutResolvingRecursively(testLocale, testTargetBundle); assertNull(sourceProp.getProperty(ktm)); assertNotNull(targetProp.getProperty(ktm)); Properties sourceMetaProp = i18nMgr.getPropertiesWithoutResolvingRecursively(null, testSourceBundle); Properties targetMetaProp = i18nMgr.getPropertiesWithoutResolvingRecursively(null, testTargetBundle); assertNull(sourceMetaProp.getProperty(ktm + I18nManager.METADATA_ANNOTATION_POSTFIX)); assertNull(sourceMetaProp.getProperty(ktm + I18nManager.METADATA_KEY_PRIORITY_POSTFIX)); assertTrue(targetMetaProp.containsKey(ktm + I18nManager.METADATA_ANNOTATION_POSTFIX)); assertEquals( "100", targetMetaProp.getProperty(ktm + I18nManager.METADATA_KEY_PRIORITY_POSTFIX)); // check for changed references in value // if correctly done, should still be resolvable assertTrue(sourcePropResolved.getProperty("key.to.stay2").indexOf(matchString) != -1); tDMgr.logToFile("moveKey"); } }
@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()); } }
@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 } }
/** Test methods i18nManager.getBundlePriority(), i18nManager.getKeyPriority() */ @Test public void testGetBundleAndKeyPriority() { // existing bundle prios String bundleName = "org.olat.core.util.i18n.junittestdata"; Properties metadataProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(null, bundleName); assertNotNull(metadataProperties); assertTrue(metadataProperties.size() > 0); assertEquals(900, i18nMgr.getBundlePriority(bundleName)); assertEquals( 20, i18nMgr.getKeyPriority(metadataProperties, "no.need.to.translate.this", bundleName)); // default values bundleName = "org.olat.core.util.i18n.junittestdata.subtest"; metadataProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(null, bundleName); assertNotNull(metadataProperties); assertTrue(metadataProperties.size() == 0); assertEquals( I18nManager.DEFAULT_BUNDLE_PRIORITY, i18nMgr.getBundlePriority("bla.bla")); // default priority assertEquals( I18nManager.DEFAULT_KEY_PRIORITY, i18nMgr.getKeyPriority(metadataProperties, "no.need.to.translate.this", bundleName)); }
@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()); } }
@Test public void testMoveLanguageTask() { if (I18nModule.isTransToolEnabled()) { prepareDevToolTests(); String srcPath = I18nModule.getTransToolApplicationLanguagesSrcDir().getAbsolutePath() + "/../../test/java/org/olat/core/util/i18n/junittestdata/devtools"; String targetPath = srcPath + "/../movetarget"; // only copy: target should exist Locale mvLocale = i18nMgr.getLocaleOrDefault("de"); // test before move Properties sourceProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(mvLocale, testSourceBundle); assertFalse(sourceProperties.isEmpty()); Properties moveProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(mvLocale, testMoveTargetBundle); assertTrue(moveProperties.isEmpty()); // copy tDMgr.moveLanguageTask(mvLocale, srcPath, targetPath, false); // test after copy sourceProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(mvLocale, testSourceBundle); assertFalse(sourceProperties.isEmpty()); moveProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(mvLocale, testMoveTargetBundle); assertFalse(moveProperties.isEmpty()); // move tDMgr.moveLanguageTask(mvLocale, srcPath, targetPath, true); // test after move sourceProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(mvLocale, testSourceBundle); assertTrue(sourceProperties.isEmpty()); moveProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(mvLocale, testMoveTargetBundle); assertFalse(moveProperties.isEmpty()); } }