import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.Set;
+import org.apache.commons.io.IOUtils;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.sonar.test.TestUtils;
}
}
if ( !nonExistingKeys.isEmpty()) {
- details.append("\n\nAlso, the following keys do not exist in the default bundle:");
+ details.append("\n\nThe following keys do not exist in the default bundle:");
for (String key : nonExistingKeys) {
details.append("\n\t- " + key);
}
}
details.append("\n\n=======================");
+ printReport(details.toString());
+
description.appendText(details.toString());
}
+ private void printReport(String details) {
+ File dumpFile = new File("target/l10n/" + bundleName + ".report.txt");
+ if (dumpFile.exists()) {
+ dumpFile.delete();
+ }
+ dumpFile.getParentFile().mkdirs();
+ FileWriter writer = null;
+ try {
+ writer = new FileWriter(dumpFile);
+ writer.write(details);
+ } catch (IOException e) {
+ System.out.println("Unable to write the report to 'target/l10n/" + bundleName + ".report.txt'.");
+ } finally {
+ IOUtils.closeQuietly(writer);
+ }
+ }
+
protected Collection<String> retrieveMissingKeys(File bundle, File defaultBundle) throws IOException {
Collection<String> missingKeys = Lists.newArrayList();
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 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("https://raw.github.com/SonarSource/sonar/master/sonar-testing-harness/src/test/resources/org/sonar/l10n/");
+ matcher = new BundleSynchronizedMatcher();
}
@Test
public void testBundlesInsideSonarPlugin() {
// synchronized bundle
assertThat("myPlugin_fr_CA.properties", isBundleSynchronized());
+ assertFalse(new File("target/l10n/myPlugin_fr_CA.properties.report.txt").exists());
// missing keys
try {
assertThat("myPlugin_fr.properties", isBundleSynchronized());
+ assertTrue(new File("target/l10n/myPlugin_fr.properties.report.txt").exists());
} catch (AssertionError e) {
assertThat(e.getMessage(), containsString("Missing keys are:\n\t- second.prop"));
}
// unnecessary many keys
try {
assertThat("myPlugin_fr_QB.properties", isBundleSynchronized());
+ assertTrue(new File("target/l10n/myPlugin_fr_QB.properties.report.txt").exists());
} catch (AssertionError e) {
- assertThat(e.getMessage(), containsString("Also, the following keys do not exist in the default bundle:\n\t- fourth.prop"));
+ assertThat(e.getMessage(), containsString("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());
+ // synchronized bundle
+ assertThat("core_fr_CA.properties", new BundleSynchronizedMatcher(GITHUB_RAW_FILE_PATH));
+ // missing keys
+ try {
+ assertThat("core_fr.properties", new BundleSynchronizedMatcher(GITHUB_RAW_FILE_PATH));
+ } catch (AssertionError e) {
+ assertThat(e.getMessage(), containsString("Missing keys are:\n\t- second.prop"));
+ }
}
@Test
}
@Test
- @Ignore
public void testGetBundleFileFromGithub() throws Exception {
+ matcher = new BundleSynchronizedMatcher(GITHUB_RAW_FILE_PATH);
matcher.getBundleFileFromGithub("core.properties");
assertTrue(new File("target/l10n/download/core.properties").exists());
}