diff --git a/functional-test/pom.xml b/functional-test/pom.xml
index 9f19ef3efc..e030c0f597 100644
--- a/functional-test/pom.xml
+++ b/functional-test/pom.xml
@@ -199,6 +199,11 @@
zanata-adapter-po
+
+ org.fedorahosted.openprops
+ openprops
+
+
org.zanata
diff --git a/functional-test/src/main/java/org/zanata/util/TestFileGenerator.java b/functional-test/src/main/java/org/zanata/util/TestFileGenerator.java
index a5d7dca8bb..1902b53bad 100644
--- a/functional-test/src/main/java/org/zanata/util/TestFileGenerator.java
+++ b/functional-test/src/main/java/org/zanata/util/TestFileGenerator.java
@@ -189,6 +189,7 @@ private static void marshall(File output, T object, Class xmlClass) {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(xmlClass);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
+ jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(object, output);
}
catch (JAXBException e) {
@@ -196,22 +197,23 @@ private static void marshall(File output, T object, Class xmlClass) {
}
}
- @XmlRootElement(namespace = "http://zanata.org/namespace/config/",
+ @XmlRootElement(namespace = ZanataXml.NS,
name = "config")
@Setter
private static class ZanataXml {
- @XmlElement
+ static final String NS = "http://zanata.org/namespace/config/";
+ @XmlElement(namespace = ZanataXml.NS)
private String url = PropertiesHolder
.getProperty(Constants.zanataInstance.value());
- @XmlElement
+ @XmlElement(namespace = ZanataXml.NS)
private String project;
- @XmlElement(name = "project-version")
+ @XmlElement(name = "project-version", namespace = ZanataXml.NS)
private String projectVersion;
- @XmlElement(name = "project-type")
+ @XmlElement(name = "project-type", namespace = ZanataXml.NS)
private String projectType;
- @XmlElementWrapper(name="locales")
+ @XmlElementWrapper(name="locales", namespace = ZanataXml.NS)
@XmlElements(
- @XmlElement(name = "locale")
+ @XmlElement(name = "locale", namespace = ZanataXml.NS)
)
private List locales;
}
diff --git a/functional-test/src/test/java/org/zanata/feature/clientserver/PropertiesRoundTripTest.java b/functional-test/src/test/java/org/zanata/feature/clientserver/PropertiesRoundTripTest.java
new file mode 100644
index 0000000000..ad6a6d104d
--- /dev/null
+++ b/functional-test/src/test/java/org/zanata/feature/clientserver/PropertiesRoundTripTest.java
@@ -0,0 +1,138 @@
+package org.zanata.feature.clientserver;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.List;
+
+import org.fedorahosted.openprops.Properties;
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.zanata.feature.DetailedTest;
+import org.zanata.page.webtrans.EditorPage;
+import org.zanata.util.SampleProjectRule;
+import org.zanata.util.TestFileGenerator;
+import org.zanata.util.ZanataRestCaller;
+import org.zanata.workflow.BasicWorkFlow;
+import org.zanata.workflow.ClientPushWorkFlow;
+import org.zanata.workflow.LoginWorkFlow;
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * This will cover TCMS case 139837
+ *
+ * @author Patrick Huang pahuang@redhat.com
+ */
+@Category(DetailedTest.class)
+public class PropertiesRoundTripTest {
+ @Rule
+ public SampleProjectRule sampleProjectRule = new SampleProjectRule();
+
+ private ClientPushWorkFlow client = new ClientPushWorkFlow();
+ private ZanataRestCaller restCaller;
+
+ private File tempDir = Files.createTempDir();
+
+ private String userConfigPath = ClientPushWorkFlow
+ .getUserConfigPath("admin");
+
+ @Before
+ public void setUp() throws IOException {
+ restCaller = new ZanataRestCaller("admin");
+ // generate a properties source
+ Properties properties = new Properties();
+ properties.setProperty("hello", "hello world");
+ properties.setProperty("greeting", "this is from Huston");
+ properties.setProperty("hey", "hey hey");
+ File propertiesSource = new File(tempDir, "test.properties");
+ properties.store(new FileWriter(propertiesSource), "comment");
+ // copy a pom file
+ File pluralProjectRoot = client.getProjectRootPath("plural");
+ Files.copy(new File(pluralProjectRoot, "pom.xml"), new File(tempDir,
+ "pom.xml"));
+ }
+
+ @Test
+ public void canPushAndPullProperties() throws IOException,
+ InterruptedException {
+ restCaller.createProjectAndVersion("properties-test", "master",
+ "properties");
+ // generate a zanata.xml
+ new TestFileGenerator().generateZanataXml(new File(tempDir,
+ "zanata.xml"), "properties-test", "master", "properties", Lists
+ .newArrayList("pl"));
+ List output =
+ client.callWithTimeout(tempDir,
+ "mvn -B zanata:push -Dzanata.srcDir=. -Dzanata.userConfig="
+ + userConfigPath);
+
+ assertThat(client.isPushSuccessful(output), Matchers.equalTo(true));
+
+ EditorPage editorPage = verifyPushedToEditor()
+ .setSyntaxHighlighting(false);
+ editorPage =
+ editorPage.translateTargetAtRowIndex(2,
+ "translation updated approved")
+ .approveSelectedTranslation();
+
+ editorPage.translateTargetAtRowIndex(1, "translation updated fuzzy")
+ .saveAsFuzzySelectedTranslation();
+
+ output =
+ client.callWithTimeout(tempDir,
+ "mvn -B zanata:pull -Dzanata.userConfig="
+ + userConfigPath);
+
+ assertThat(client.isPushSuccessful(output), Matchers.is(true));
+ File transFile = new File(tempDir, "test_pl.properties");
+ assertThat(transFile.exists(), Matchers.is(true));
+ Properties translations = new Properties();
+ translations.load(new FileReader(transFile));
+ assertThat(translations.size(), Matchers.is(1));
+ assertThat(translations.getProperty("hey"),
+ Matchers.equalTo("translation updated approved"));
+
+ // change on client side
+ translations.setProperty("greeting", "translation updated on client");
+ translations.store(new FileWriter(transFile), null);
+
+ // push again
+ client.callWithTimeout(
+ tempDir,
+ "mvn -B zanata:push -Dzanata.pushType=trans -Dzanata.srcDir=. -Dzanata.userConfig="
+ + userConfigPath);
+
+ final EditorPage editor =
+ new BasicWorkFlow().goToPage(String.format(
+ BasicWorkFlow.EDITOR_TEMPLATE, "properties-test",
+ "master", "pl", "test"), EditorPage.class);
+ assertThat(editor.getTranslationTargetAtRowIndex(1),
+ Matchers.equalTo("translation updated on client"));
+ }
+
+ private static EditorPage verifyPushedToEditor() {
+ new LoginWorkFlow().signIn("admin", "admin");
+ EditorPage editorPage =
+ new BasicWorkFlow().goToPage(String.format(
+ BasicWorkFlow.EDITOR_TEMPLATE, "properties-test",
+ "master", "pl", "test"), EditorPage.class);
+
+ assertThat(editorPage.getTranslationSourceAtRowIndex(0),
+ Matchers.equalTo("hello world"));
+ assertThat(editorPage.getTranslationSourceAtRowIndex(1),
+ Matchers.equalTo("this is from Huston"));
+ assertThat(editorPage.getTranslationSourceAtRowIndex(2),
+ Matchers.equalTo("hey hey"));
+
+ return editorPage;
+ }
+}