This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
GettextPluralSupportTest.java
156 lines (132 loc) · 6.13 KB
/
GettextPluralSupportTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package org.zanata.feature.clientserver;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.xml.sax.InputSource;
import org.zanata.adapter.po.PoReader2;
import org.zanata.common.LocaleId;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.page.webtrans.EditorPage;
import org.zanata.page.webtrans.Plurals;
import org.zanata.rest.dto.resource.TextFlow;
import org.zanata.rest.dto.resource.TextFlowTarget;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.ZanataRestCaller;
import org.zanata.workflow.BasicWorkFlow;
import org.zanata.workflow.ClientWorkFlow;
import org.zanata.workflow.LoginWorkFlow;
import com.google.common.io.Files;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* This covers TCMS case <a
* href="https://tcms.engineering.redhat.com/case/217601/">217601</a> and case
* <a href="https://tcms.engineering.redhat.com/case/217905/">217905</a>
*
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Category(DetailedTest.class)
public class GettextPluralSupportTest extends ZanataTestCase {
@Rule
public SampleProjectRule sampleProjectRule = new SampleProjectRule();
private ClientWorkFlow client = new ClientWorkFlow();
private ZanataRestCaller restCaller;
private File tempDir = Files.createTempDir();
private String userConfigPath = ClientWorkFlow
.getUserConfigPath("admin");
private File projectRootPath;
@Before
public void setUp() throws IOException {
projectRootPath = client.getProjectRootPath("plural");
Files.copy(new File(projectRootPath, "pom.xml"), new File(tempDir,
"pom.xml"));
Files.copy(new File(projectRootPath, "zanata.xml"), new File(tempDir,
"zanata.xml"));
File potDir = new File(tempDir, "pot");
potDir.mkdirs();
File plDir = new File(tempDir, "pl");
plDir.mkdirs();
Files.copy(new File(projectRootPath + "/pot", "test.pot"), new File(
potDir, "test.pot"));
Files.copy(new File(projectRootPath + "/pl", "test.po"), new File(
plDir, "test.po"));
restCaller = new ZanataRestCaller();
}
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void canPushAndPullPlural() throws IOException {
restCaller.createProjectAndVersion("plurals", "master", "podir");
List<String> output =
client.callWithTimeout(tempDir,
"mvn -B zanata:push -Dzanata.pushType=both -Dzanata.userConfig="
+ userConfigPath);
assertThat(client.isPushSuccessful(output), Matchers.is(true));
EditorPage editorPage = verifyPluralPushedToEditor();
File pullDir = Files.createTempDir();
String pullDirPath = pullDir.getAbsolutePath();
String command =
"mvn -B zanata:pull -Dzanata.pullType=both -Dzanata.srcDir="
+ pullDirPath + " -Dzanata.transDir=" + pullDirPath
+ " -Dzanata.userConfig=" + userConfigPath;
output = client.callWithTimeout(tempDir, command);
assertThat(client.isPushSuccessful(output), Matchers.is(true));
// source round trip
List<TextFlow> originalTextFlows =
getTextFlows(new File(projectRootPath + "/pot/test.pot"));
List<TextFlow> pulledTextFlows =
getTextFlows(new File(pullDir, "test.pot"));
assertThat(pulledTextFlows, Matchers.equalTo(originalTextFlows));
// translation round trip
List<TextFlowTarget> originalTargets =
getTextFlowTargets(new File(projectRootPath + "/pl/test.po"));
List<TextFlowTarget> pulledTargets =
getTextFlowTargets(new File(pullDir + "/pl/test.po"));
assertThat(pulledTargets, Matchers.equalTo(originalTargets));
// translate on web UI and pull again
editorPage.translateTargetAtRowIndex(0, "one aoeuaouaou")
.saveAsFuzzyAtRow(0);
client.callWithTimeout(tempDir, command);
List<String> newContents =
getTextFlowTargets(new File(pullDir + "/pl/test.po")).get(0)
.getContents();
assertThat(newContents, Matchers.hasItem("one aoeuaouaou"));
}
private static EditorPage verifyPluralPushedToEditor() {
// verify first message
new LoginWorkFlow().signIn("admin", "admin");
EditorPage editorPage = new BasicWorkFlow()
.goToEditor("plurals", "master", "pl", "test");
assertThat(editorPage.getMessageSourceAtRowIndex(0, Plurals.SourceSingular),
Matchers.equalTo("One file removed"));
assertThat(editorPage.getMessageSourceAtRowIndex(0, Plurals.SourcePlural),
Matchers.equalTo("%d files removed"));
// nplural for Polish is 3
assertThat(editorPage.getBasicTranslationTargetAtRowIndex(0, Plurals.TargetSingular),
Matchers.equalTo("1 aoeuaouaou"));
assertThat(editorPage.getBasicTranslationTargetAtRowIndex(0, Plurals.TargetPluralOne),
Matchers.equalTo("%d aoeuaouao"));
assertThat(editorPage.getBasicTranslationTargetAtRowIndex(0, Plurals.TargetPluralTwo),
Matchers.equalTo(""));
return editorPage;
}
private static List<TextFlow> getTextFlows(File file)
throws FileNotFoundException {
return new PoReader2().extractTemplate(
new InputSource(new FileInputStream(file)), LocaleId.EN_US,
file.getName()).getTextFlows();
}
private static List<TextFlowTarget> getTextFlowTargets(File file)
throws FileNotFoundException {
return new PoReader2().extractTarget(
new InputSource(new FileInputStream(file)))
.getTextFlowTargets();
}
}