From 380e99142f502196320736dcbd518c85d18b091b Mon Sep 17 00:00:00 2001 From: efloden Date: Wed, 28 Feb 2018 13:22:59 +1000 Subject: [PATCH] test(ZNTA-2297): transunithistory returns bad request on null localeid or transunitid --- .../service/TransUnitHistoryService.java | 10 +++++ .../service/TransUnitHistoryServiceTest.java | 39 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 server/services/src/test/java/org/zanata/rest/editor/service/TransUnitHistoryServiceTest.java diff --git a/server/services/src/main/java/org/zanata/rest/editor/service/TransUnitHistoryService.java b/server/services/src/main/java/org/zanata/rest/editor/service/TransUnitHistoryService.java index 04398abebe..cf34b1236f 100644 --- a/server/services/src/main/java/org/zanata/rest/editor/service/TransUnitHistoryService.java +++ b/server/services/src/main/java/org/zanata/rest/editor/service/TransUnitHistoryService.java @@ -66,4 +66,14 @@ public Response get(String localeId, Long transUnitId) { historyHandler.getTranslationHistory(localeId, transUnitId); return Response.ok(result).build(); } + + public TransUnitHistoryService() { + } + + @java.beans.ConstructorProperties({"historyHandler"}) + protected TransUnitHistoryService( + final GetTranslationHistoryHandler historyHandler + ) { + this.historyHandler = historyHandler; + } } diff --git a/server/services/src/test/java/org/zanata/rest/editor/service/TransUnitHistoryServiceTest.java b/server/services/src/test/java/org/zanata/rest/editor/service/TransUnitHistoryServiceTest.java new file mode 100644 index 0000000000..96c7ed94e5 --- /dev/null +++ b/server/services/src/test/java/org/zanata/rest/editor/service/TransUnitHistoryServiceTest.java @@ -0,0 +1,39 @@ +package org.zanata.rest.editor.service; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.zanata.webtrans.server.rpc.GetTranslationHistoryHandler; +import org.zanata.webtrans.shared.rpc.GetTranslationHistoryResult; + +import javax.ws.rs.core.Response; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TransUnitHistoryServiceTest { + private TransUnitHistoryService service; + @Mock + private GetTranslationHistoryHandler historyHandler; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + historyHandler = new GetTranslationHistoryHandler(); + service = new TransUnitHistoryService(historyHandler); + } + + @Test + public void nullOrEmptyLocaleWillReturnBadRequest() { + Long transUnitID = 1L; + Response response = service.get(null, transUnitID); + assertThat(response.getStatus()).isEqualTo(400); + } + + @Test + public void nullTransUnitIdWillReturnBadRequest() { + String localeId = "ja"; + Response response = service.get(localeId, null); + assertThat(response.getStatus()).isEqualTo(400); + } +}