Skip to content

Commit c9bb68b

Browse files
feat: add XLIFF file type to FTS API (#132)
1 parent 22c5f9e commit c9bb68b

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

smartling-file-translations-api/src/main/java/com/smartling/api/filetranslations/v2/pto/FileType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public enum FileType
2929
XLSX_TEMPLATE("application/octet-stream", false), // Smartling XLSX - https://help.smartling.com/hc/en-us/articles/1260804224670-Translating-Spreadsheets#h_01F3TKVZBVPFJSF2XZEBHDH1EQ
3030
ANDROID("application/xml", true), // ANDROID parser
3131
JSON("application/json", true),
32+
XLIFF("application/xml", true), // XLIFF 1.2 parser
3233
;
3334
private final String identifier;
3435
private final String mimeType;

smartling-file-translations-api/src/test/java/com/smartling/api/filetranslations/v2/FileTranslationsApiTest.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.github.tomakehurst.wiremock.junit.WireMockRule;
6-
import com.google.common.collect.ImmutableList;
7-
import com.google.common.collect.ImmutableMap;
86
import com.smartling.api.filetranslations.v2.pto.Error;
97
import com.smartling.api.filetranslations.v2.pto.FileType;
108
import com.smartling.api.filetranslations.v2.pto.LanguagePTO;
@@ -44,8 +42,9 @@
4442
import java.io.ByteArrayInputStream;
4543
import java.io.IOException;
4644
import java.io.InputStream;
47-
import java.io.UnsupportedEncodingException;
4845
import java.nio.charset.StandardCharsets;
46+
import java.util.Arrays;
47+
import java.util.Collections;
4948
import java.util.LinkedHashMap;
5049
import java.util.Map;
5150

@@ -59,13 +58,13 @@
5958
public class FileTranslationsApiTest
6059
{
6160
private static final String SUCCESS_RESPONSE_ENVELOPE = "{\"response\":{\"code\":\"SUCCESS\",\"data\":%s}})";
62-
private static final String ACCOUNT_UID = RandomStringUtils.randomAlphabetic(10);
63-
private static final String FILE_UID = RandomStringUtils.randomAlphabetic(10);
64-
private static final String MT_UID = RandomStringUtils.randomAlphabetic(10);
65-
private static final String LANGUAGE_DETECTION_UID = RandomStringUtils.randomAlphabetic(10);
66-
private static final String SOURCE_LOCALE_ID = RandomStringUtils.randomAlphabetic(10);
67-
private static final String TARGET_LOCALE_ID_1 = RandomStringUtils.randomAlphabetic(5);
68-
private static final String TARGET_LOCALE_ID_2 = RandomStringUtils.randomAlphabetic(5);
61+
private static final String ACCOUNT_UID = RandomStringUtils.insecure().nextAlphabetic(10);
62+
private static final String FILE_UID = RandomStringUtils.insecure().nextAlphabetic(10);
63+
private static final String MT_UID = RandomStringUtils.insecure().nextAlphabetic(10);
64+
private static final String LANGUAGE_DETECTION_UID = RandomStringUtils.insecure().nextAlphabetic(10);
65+
private static final String SOURCE_LOCALE_ID = RandomStringUtils.insecure().nextAlphabetic(10);
66+
private static final String TARGET_LOCALE_ID_1 = RandomStringUtils.insecure().nextAlphabetic(5);
67+
private static final String TARGET_LOCALE_ID_2 = RandomStringUtils.insecure().nextAlphabetic(5);
6968

7069
private MockWebServer mockWebServer;
7170
private FileTranslationsApi sut;
@@ -123,21 +122,21 @@ public void mtFile() throws InterruptedException
123122

124123
MtRequest request = new MtRequest();
125124
request.setSourceLocaleId(SOURCE_LOCALE_ID);
126-
request.setTargetLocaleIds(ImmutableList.of(TARGET_LOCALE_ID_1, TARGET_LOCALE_ID_2));
125+
request.setTargetLocaleIds(Arrays.asList(TARGET_LOCALE_ID_1, TARGET_LOCALE_ID_2));
127126

128127
MtResponse response = sut.mtFile(ACCOUNT_UID, FILE_UID, request);
129128

130129
MtRequest recordedRequest = toObj(getRequestWithValidation(HttpMethod.POST,
131130
String.format("/file-translations-api/v2/accounts/%s/files/%s/mt", ACCOUNT_UID, FILE_UID)).getBody().readUtf8(), MtRequest.class);
132131
assertThat(recordedRequest.getSourceLocaleId(), is(SOURCE_LOCALE_ID));
133-
assertThat(recordedRequest.getTargetLocaleIds(), is(ImmutableList.of(TARGET_LOCALE_ID_1, TARGET_LOCALE_ID_2)));
132+
assertThat(recordedRequest.getTargetLocaleIds(), is(Arrays.asList(TARGET_LOCALE_ID_1, TARGET_LOCALE_ID_2)));
134133

135134
assertNotNull(response);
136135
assertEquals(MT_UID, response.getMtUid());
137136
}
138137

139138
@Test
140-
public void cancelFileProcessing() throws InterruptedException, UnsupportedEncodingException
139+
public void cancelFileProcessing() throws InterruptedException
141140
{
142141
assignResponse(HttpStatus.SC_OK, String.format(SUCCESS_RESPONSE_ENVELOPE, "{}"));
143142

@@ -192,7 +191,7 @@ public void getMTStatus() throws InterruptedException, IOException
192191
MtStatusResponse response = new MtStatusResponse();
193192
response.setState(MtState.COMPLETED);
194193
response.setRequestedStringCount(100L);
195-
Error<Map<String,String>> error = new Error<>("some.key", "some message", ImmutableMap.of("key1", "val1"));
194+
Error<Map<String,String>> error = new Error<>("some.key", "some message", Collections.singletonMap("key1", "val1"));
196195
response.setError(error);
197196
MtLocaleStatus locale1Status = new MtLocaleStatus();
198197
locale1Status.setLocaleId(TARGET_LOCALE_ID_1);
@@ -226,7 +225,7 @@ public void getMTStatus() throws InterruptedException, IOException
226225
assertEquals(response.getRequestedStringCount(), status.getRequestedStringCount());
227226
assertThat(response.getError().getKey(), is("some.key"));
228227
assertThat(response.getError().getMessage(), is("some message"));
229-
assertThat(response.getError().getDetails(), is(ImmutableMap.of("key1", "val1")));
228+
assertThat(response.getError().getDetails(), is(Collections.singletonMap("key1", "val1")));
230229
assertEquals(response.getLocaleProcessStatuses().size(), status.getLocaleProcessStatuses().size());
231230
assertEquals(response.getLocaleProcessStatuses().get(0).getLocaleId(), status.getLocaleProcessStatuses().get(0).getLocaleId());
232231
assertEquals(response.getLocaleProcessStatuses().get(0).getProcessedStringCount(), status.getLocaleProcessStatuses().get(0).getProcessedStringCount());
@@ -258,7 +257,7 @@ public void detectSourceLanguage() throws InterruptedException
258257
public void getLDStatus() throws InterruptedException, IOException
259258
{
260259
LanguageDetectionStatusResponse response = new LanguageDetectionStatusResponse();
261-
Error<Map<String,String>> error = new Error<>("some.key", "some message", ImmutableMap.of("key1", "val1"));
260+
Error<Map<String,String>> error = new Error<>("some.key", "some message", Collections.singletonMap("key1", "val1"));
262261
response.setError(error);
263262
response.setState(LanguageDetectionState.COMPLETED);
264263
LanguagePTO languagePTO1 = new LanguagePTO();
@@ -267,7 +266,7 @@ public void getLDStatus() throws InterruptedException, IOException
267266
LanguagePTO languagePTO2 = new LanguagePTO();
268267
languagePTO2.setLanguageId("de");
269268
languagePTO2.setDefaultLocaleId("de-DE");
270-
response.setDetectedSourceLanguages(ImmutableList.of(languagePTO1, languagePTO2));
269+
response.setDetectedSourceLanguages(Arrays.asList(languagePTO1, languagePTO2));
271270
String responseBody = objectMapper.writeValueAsString(response);
272271
assignResponse(HttpStatus.SC_OK, String.format(SUCCESS_RESPONSE_ENVELOPE, responseBody));
273272

@@ -279,7 +278,7 @@ public void getLDStatus() throws InterruptedException, IOException
279278
assertEquals(response.getState(), status.getState());
280279
assertThat(response.getError().getKey(), is("some.key"));
281280
assertThat(response.getError().getMessage(), is("some message"));
282-
assertThat(response.getError().getDetails(), is(ImmutableMap.of("key1", "val1")));
281+
assertThat(response.getError().getDetails(), is(Collections.singletonMap("key1", "val1")));
283282

284283
assertEquals(response.getDetectedSourceLanguages().size(), status.getDetectedSourceLanguages().size());
285284

@@ -335,12 +334,10 @@ private LinkedHashMap<String, Part> toParts(RecordedRequest recordedRequest)
335334

336335
private static class Part
337336
{
338-
private okhttp3.Headers headers;
339-
private byte[] body;
337+
private final byte[] body;
340338

341339
public Part(Headers headers, byte[] body)
342340
{
343-
this.headers = headers;
344341
this.body = body;
345342
}
346343

0 commit comments

Comments
 (0)