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
/
TextFlowServiceTest.java
70 lines (60 loc) · 2.37 KB
/
TextFlowServiceTest.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
package org.zanata.rest.editor.service;
import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.zanata.common.ContentState;
import org.zanata.common.LocaleId;
import org.zanata.dao.TextFlowDAO;
import org.zanata.model.HLocale;
import org.zanata.rest.editor.dto.TransUnits;
import org.zanata.rest.service.ResourceUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.util.Lists.newArrayList;
import static org.mockito.Mockito.when;
import static org.zanata.model.TestFixture.makeHTextFlow;
import static org.zanata.model.TestFixture.makeTransUnit;
public class TextFlowServiceTest {
private TextFlowService service;
@Mock
private TextFlowDAO textFlowDAO;
private TransUnitUtils transUnitUtils;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
transUnitUtils = new TransUnitUtils(new ResourceUtils());
service = new TextFlowService(textFlowDAO, transUnitUtils);
}
@Test
public void willReturnEmptyIfIdIsEmpty() {
Response response = service.get("");
assertThat(response.getStatus()).isEqualTo(200);
TransUnits transUnits = (TransUnits) response.getEntity();
assertThat(transUnits).isEmpty();
}
@Test
public void willReturnForbiddenIfIdIsOverSizeLimit() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < TransUnitUtils.MAX_SIZE; i++) {
builder.append(i).append(",");
}
builder.append("9999");
Response response = service.get(builder.toString());
assertThat(response.getStatus()).isEqualTo(
Response.Status.FORBIDDEN.getStatusCode());
}
@Test
public void willReturnList() {
HLocale targetLocale = new HLocale(LocaleId.DE);
when(textFlowDAO.findByIdList(newArrayList(1L, 2L)))
.thenReturn(
newArrayList(
makeHTextFlow(1, targetLocale,
ContentState.NeedReview),
makeHTextFlow(2, targetLocale,
ContentState.Translated)));
Response response = service.get("1,2");
assertThat(response.getStatus()).isEqualTo(200);
}
}