77import com .crowdin .client .core .model .ResponseObject ;
88import com .crowdin .client .framework .RequestMock ;
99import com .crowdin .client .framework .TestClient ;
10- import com .crowdin .client .tasks .model .AssignedTeam ;
11- import com .crowdin .client .tasks .model .Assignee ;
12- import com .crowdin .client .tasks .model .AssigneeRequest ;
13- import com .crowdin .client .tasks .model .CreateTaskEnterpriseStringsBasedRequest ;
14- import com .crowdin .client .tasks .model .CreateTaskRequest ;
15- import com .crowdin .client .tasks .model .CreateTaskEnterpriseVendorRequest ;
16- import com .crowdin .client .tasks .model .CreateTaskStringsBasedRequest ;
17- import com .crowdin .client .tasks .model .Progress ;
18- import com .crowdin .client .tasks .model .Status ;
19- import com .crowdin .client .tasks .model .Task ;
20- import com .crowdin .client .tasks .model .Type ;
10+ import com .crowdin .client .tasks .model .*;
2111import com .crowdin .client .tasks .model .pending .CreateEnterprisePendingTaskRequest ;
2212import com .crowdin .client .tasks .model .pending .CreatePendingTaskRequest ;
13+ import lombok .SneakyThrows ;
2314import org .apache .http .client .methods .HttpDelete ;
2415import org .apache .http .client .methods .HttpGet ;
2516import org .apache .http .client .methods .HttpPatch ;
2617import org .apache .http .client .methods .HttpPost ;
2718import org .junit .jupiter .api .Test ;
2819
29- import java .util .Arrays ;
30- import java .util .Calendar ;
31- import java .util .Date ;
32- import java .util .HashMap ;
33- import java .util .List ;
34- import java .util .Map ;
35- import java .util .TimeZone ;
20+ import java .util .*;
3621
3722import static java .util .Collections .singletonList ;
38- import static org .junit .jupiter .api .Assertions .assertEquals ;
23+ import static org .junit .jupiter .api .Assertions .*;
24+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
3925
4026public class TasksApiTest extends TestClient {
4127
4228 private final Long projectId = 12L ;
4329 private final Long enterpriseProjectId = 13L ;
30+ private final Long multiStatusProjectId = 14L ;
31+ private final Long singleStatusProjectId = 15L ;
4432 private final Long taskId = 2L ;
4533 private final Long prevTaskId = 1L ;
4634 private final Status status = Status .TODO ;
@@ -61,26 +49,61 @@ public List<RequestMock> getMocks() {
6149 RequestMock .build (this .url + "/projects/" + projectId + "/tasks/" + taskId , HttpDelete .METHOD_NAME ),
6250 RequestMock .build (this .url + "/projects/" + projectId + "/tasks/" + taskId , HttpPatch .METHOD_NAME , "api/tasks/editTask.json" , "api/tasks/task.json" ),
6351 RequestMock .build (this .url + "/user/tasks" , HttpGet .METHOD_NAME , "api/tasks/listTasks.json" ),
64- RequestMock .build (this .url + "/user/tasks/" + taskId , HttpPatch .METHOD_NAME , "api/tasks/editTask.json" , "api/tasks/task.json" )
52+ RequestMock .build (this .url + "/user/tasks/" + taskId , HttpPatch .METHOD_NAME , "api/tasks/editTask.json" , "api/tasks/task.json" ),
53+ RequestMock .build (this .url + "/projects/" + multiStatusProjectId + "/tasks" , HttpGet .METHOD_NAME , "api/tasks/multiStatusListTasks.json" , new HashMap <String , String >() {{
54+ put ("status" , "todo,done" );
55+ }}),
56+ RequestMock .build (this .url + "/projects/" + singleStatusProjectId + "/tasks" , HttpGet .METHOD_NAME , "api/tasks/singleStatusListTasks.json" , new HashMap <String , String >() {{
57+ put ("status" , "in_progress" );
58+ }})
6559 );
6660 }
6761
6862 @ Test
6963 public void listTasksTest () {
70- Assignee assignee = new Assignee ();
71- assignee .setId (1L );
72- assignee .setUsername ("john_smith" );
73- assignee .setFullName ("john_smith" );
74- assignee .setAvatarUrl ("" );
75- assignee .setWordsCount (5 );
76- assignee .setWordsLeft (3 );
7764 TimeZone .setDefault (TimeZone .getTimeZone ("GMT" ));
7865 ResponseList <Task > taskResponseList = this .getTasksApi ().listTasks (projectId , null , null , null , null );
79- assertEquals (taskResponseList .getData ().size (), 1 );
80- assertEquals (taskResponseList .getData ().get (0 ).getData ().getId (), taskId );
81- assertEquals (taskResponseList .getData ().get (0 ).getData ().getStatus (), status );
82- assertEquals (new Date (119 , Calendar .SEPTEMBER ,27 ,7 ,0 ,14 ), taskResponseList .getData ().get (0 ).getData ().getDeadline ());
83- assertEquals (taskResponseList .getData ().get (0 ).getData ().getAssignees ().get (0 ), assignee );
66+
67+ assertNotNull (taskResponseList .getData ().get (0 ).getData ());
68+ assertEquals (1 , taskResponseList .getData ().size ());
69+
70+ assertEquals (projectId , taskResponseList .getData ().get (0 ).getData ().getProjectId ());
71+
72+ assertListTasks (taskResponseList );
73+ }
74+
75+ @ Test
76+ public void listTasksTest_testSingleStatus () {
77+ TimeZone .setDefault (TimeZone .getTimeZone ("GMT" ));
78+ ResponseList <Task > taskResponseList = this .getTasksApi ().listTasks (singleStatusProjectId , null , null , Status .IN_PROGRESS , null );
79+
80+ assertNotNull (taskResponseList .getData ().get (0 ).getData ());
81+ assertEquals (1 , taskResponseList .getData ().size ());
82+ assertEquals (singleStatusProjectId , taskResponseList .getData ().get (0 ).getData ().getProjectId ());
83+ assertEquals (Status .IN_PROGRESS , taskResponseList .getData ().get (0 ).getData ().getStatus ());
84+
85+ assertListTasks (taskResponseList );
86+ }
87+
88+ @ Test
89+ public void listTasksTest_multipleStatuses () {
90+ TimeZone .setDefault (TimeZone .getTimeZone ("GMT" ));
91+
92+ EnumSet <Status > statuses = EnumSet .of (Status .TODO , Status .DONE );
93+
94+ ListTasksParams listTasksParams = new ListTasksParams ();
95+ listTasksParams .setStatuses (statuses );
96+
97+ ResponseList <Task > taskResponseList = this .getTasksApi ().listTasks (multiStatusProjectId , listTasksParams );
98+
99+ assertNotNull (taskResponseList .getData ().get (0 ).getData ());
100+ assertEquals (1 , taskResponseList .getData ().size ());
101+ assertEquals (multiStatusProjectId , taskResponseList .getData ().get (0 ).getData ().getProjectId ());
102+
103+ Status responseProjectStatus = taskResponseList .getData ().get (0 ).getData ().getStatus ();
104+ assertTrue (statuses .contains (responseProjectStatus ));
105+
106+ assertListTasks (taskResponseList );
84107 }
85108
86109 @ Test
@@ -282,4 +305,21 @@ public void editUserTaskTest() {
282305 assertEquals (taskResponseObject .getData ().getId (), taskId );
283306 assertEquals (taskResponseObject .getData ().getStatus (), status );
284307 }
308+
309+ //<editor-fold desc="Common method for listTasks assertion">
310+ @ SneakyThrows
311+ private void assertListTasks (ResponseList <Task > taskResponseList ) {
312+ Assignee assignee = new Assignee ();
313+ assignee .setId (1L );
314+ assignee .setUsername ("john_smith" );
315+ assignee .setFullName ("john_smith" );
316+ assignee .setAvatarUrl ("" );
317+ assignee .setWordsCount (5 );
318+ assignee .setWordsLeft (3 );
319+
320+ assertEquals (taskId , taskResponseList .getData ().get (0 ).getData ().getId ());
321+ assertEquals (new Date (119 , Calendar .SEPTEMBER ,27 ,7 ,0 ,14 ), taskResponseList .getData ().get (0 ).getData ().getDeadline ());
322+ assertEquals (assignee , taskResponseList .getData ().get (0 ).getData ().getAssignees ().get (0 ));
323+ }
324+ //</editor-fold>
285325}
0 commit comments