Skip to content

Commit

Permalink
fix: test case expectation
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Sep 13, 2023
1 parent a8f0a80 commit 8f42400
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.omegat.machinetranslators.libretranslate;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.omegat.core.TestCore;
import org.omegat.util.Language;
import org.omegat.util.Preferences;
Expand Down Expand Up @@ -42,29 +44,28 @@ public void testGetJsonResultsWithWrongJson() {

@Test
public void testResponse() throws Exception {
ObjectMapper mapper = new ObjectMapper();
Preferences.setPreference(LibreTranslate.ALLOW_LIBRE_TRANSLATE, true);
String sourceText = "Hello, how are you today?";
String encoded = URLEncoder.encode(sourceText, StandardCharsets.UTF_8);
JsonNode json = mapper.readTree("{\n \"translatedText\": \n \"Hola, ¿cómo estás hoy?\"\n}");

WireMock.stubFor(WireMock.post(WireMock.anyUrl())
.withHeader("Content-Type", WireMock.equalTo("application/x-www-form-urlencoded"))
.withRequestBody(WireMock.and(
WireMock.containing("q=" + encoded),
WireMock.containing("source=en"),
WireMock.containing("target=es")
))
// .withHeader("Accept", WireMock.equalTo("application/json"))
.willReturn(WireMock.aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("{\n"
+ " \"translatedText\": \n"
+ " \"Hola, \u00BFc\u00F3mo est\u00E1s hoy?\"\n"
+ "}")));
.withHeader("Content-Type", "application/json;charset=UTF-8")
.withJsonBody(json)));

int port = wireMockRule.port();
String url = String.format("http://localhost:%d/translate", port);
LibreTranslate translator = new LibreTranslate(url);
String result = translator.translate(new Language("en"), new Language("es"), sourceText);
assertEquals("Hola, \u00BFc\u00F3mo est\u00E1s hoy?", result);
assertEquals("Hola, ¿cómo estás hoy?", result);
}
}

0 comments on commit 8f42400

Please sign in to comment.