|
9 | 9 | import java.util.*;
|
10 | 10 | import java.util.stream.Stream;
|
11 | 11 | import org.junit.jupiter.api.*;
|
| 12 | +import org.junit.jupiter.api.condition.EnabledIf; |
12 | 13 | import org.junit.jupiter.params.ParameterizedTest;
|
13 | 14 | import org.junit.jupiter.params.provider.Arguments;
|
14 | 15 | import org.junit.jupiter.params.provider.CsvSource;
|
@@ -344,6 +345,31 @@ void testUserAgent(
|
344 | 345 | }
|
345 | 346 | }
|
346 | 347 |
|
| 348 | + @Test |
| 349 | + @EnabledIf("runV1ApiTests") |
| 350 | + void testV1Api() throws DeepLException, InterruptedException { |
| 351 | + SessionOptions sessionOptions = new SessionOptions(); |
| 352 | + DeepLClientOptions clientOptions = |
| 353 | + (new DeepLClientOptions()).setApiVersion(DeepLApiVersion.VERSION_1); |
| 354 | + DeepLClient client = createDeepLClient(sessionOptions, clientOptions); |
| 355 | + |
| 356 | + for (Map.Entry<String, String> entry : exampleText.entrySet()) { |
| 357 | + String inputText = entry.getValue(); |
| 358 | + String sourceLang = LanguageCode.removeRegionalVariant(entry.getKey()); |
| 359 | + TextResult result = client.translateText(inputText, sourceLang, "en-US"); |
| 360 | + Assertions.assertTrue(result.getText().toLowerCase(Locale.ENGLISH).contains("proton")); |
| 361 | + Assertions.assertEquals(inputText.length(), result.getBilledCharacters()); |
| 362 | + } |
| 363 | + Usage usage = client.getUsage(); |
| 364 | + Assertions.assertTrue(usage.toString().contains("Usage this billing period")); |
| 365 | + |
| 366 | + List<Language> sourceLanguages = client.getSourceLanguages(); |
| 367 | + List<Language> targetLanguages = client.getTargetLanguages(); |
| 368 | + Assertions.assertTrue(sourceLanguages.size() > 20); |
| 369 | + Assertions.assertTrue(targetLanguages.size() > 20); |
| 370 | + Assertions.assertTrue(targetLanguages.size() >= sourceLanguages.size()); |
| 371 | + } |
| 372 | + |
347 | 373 | // Session options & Translator options: Used to construct the `Translator`
|
348 | 374 | // Next arg: List of Strings that must be contained in the user agent header
|
349 | 375 | // Last arg: List of Strings that must not be contained in the user agent header
|
@@ -391,4 +417,8 @@ private static Stream<? extends Arguments> provideUserAgentTestData() {
|
391 | 417 | customUserAgent,
|
392 | 418 | detailedPlatformInfoWithAppInfo));
|
393 | 419 | }
|
| 420 | + |
| 421 | + boolean runV1ApiTests() { |
| 422 | + return Boolean.getBoolean("runV1ApiTests"); |
| 423 | + } |
394 | 424 | }
|
0 commit comments