11package com .crowdin .client .tasks ;
22
3- import com .crowdin .client .core .model .DownloadLink ;
4- import com .crowdin .client .core .model .PatchOperation ;
5- import com .crowdin .client .core .model .PatchRequest ;
6- import com .crowdin .client .core .model .ResponseList ;
7- import com .crowdin .client .core .model .ResponseObject ;
3+ import com .crowdin .client .core .model .*;
84import com .crowdin .client .framework .RequestMock ;
95import com .crowdin .client .framework .TestClient ;
106import com .crowdin .client .tasks .model .*;
@@ -29,6 +25,9 @@ public class TasksApiTest extends TestClient {
2925 private final Long enterpriseProjectId = 13L ;
3026 private final Long multiStatusProjectId = 14L ;
3127 private final Long singleStatusProjectId = 15L ;
28+ private final Long tasksProjectIdSortByIdAsc = 16L ;
29+ private final Long tasksProjectIdSortByIdDesc = 17L ;
30+ private final Long tasksProjectIdSortByIdDescTitleAsc = 18L ;
3231 private final Long taskId = 2L ;
3332 private final Long prevTaskId = 1L ;
3433 private final Status status = Status .TODO ;
@@ -55,6 +54,15 @@ public List<RequestMock> getMocks() {
5554 }}),
5655 RequestMock .build (this .url + "/projects/" + singleStatusProjectId + "/tasks" , HttpGet .METHOD_NAME , "api/tasks/singleStatusListTasks.json" , new HashMap <String , String >() {{
5756 put ("status" , "in_progress" );
57+ }}),
58+ RequestMock .build (this .url + "/projects/" + tasksProjectIdSortByIdAsc + "/tasks" , HttpGet .METHOD_NAME , "api/tasks/listTasksSortByIdAsc.json" , new HashMap <String , String >() {{
59+ put ("orderBy" , "id%20asc" );
60+ }}),
61+ RequestMock .build (this .url + "/projects/" + tasksProjectIdSortByIdDesc + "/tasks" , HttpGet .METHOD_NAME , "api/tasks/listTasksSortByIdDesc.json" , new HashMap <String , String >() {{
62+ put ("orderBy" , "id%20desc" );
63+ }}),
64+ RequestMock .build (this .url + "/projects/" + tasksProjectIdSortByIdDescTitleAsc + "/tasks" , HttpGet .METHOD_NAME , "api/tasks/listTasksSortByIdDescTitleAsc.json" , new HashMap <String , String >() {{
65+ put ("orderBy" , "id%20desc%2Ctitle%20asc" );
5866 }})
5967 );
6068 }
@@ -72,6 +80,80 @@ public void listTasksTest() {
7280 assertListTasks (taskResponseList );
7381 }
7482
83+ @ Test
84+ public void listTasksTest_noSortDefined () {
85+ TimeZone .setDefault (TimeZone .getTimeZone ("GMT" ));
86+ ResponseList <Task > taskResponseList = this .getTasksApi ().listTasks (projectId , null , null , null , null , null );
87+
88+ assertNotNull (taskResponseList .getData ().get (0 ).getData ());
89+ assertEquals (1 , taskResponseList .getData ().size ());
90+
91+ assertEquals (projectId , taskResponseList .getData ().get (0 ).getData ().getProjectId ());
92+
93+ assertListTasks (taskResponseList );
94+ }
95+
96+ @ Test
97+ public void listTasksTest_testSortByIdDefault () {
98+ Map <String , SortOrder > orderBy = new LinkedHashMap <>();
99+ orderBy .put ("id" , null );
100+ ResponseList <Task > taskResponseList = this .getTasksApi ().listTasks (tasksProjectIdSortByIdAsc , null , null , null , null , orderBy );
101+
102+ assertNotNull (taskResponseList .getData ().get (0 ).getData ());
103+ assertEquals (2 , taskResponseList .getData ().size ());
104+
105+ assertEquals (1 , taskResponseList .getData ().get (0 ).getData ().getId ());
106+ assertEquals (2 , taskResponseList .getData ().get (1 ).getData ().getId ());
107+ }
108+
109+ @ Test
110+ public void listTasksTest_testSortByIdAsc () {
111+ Map <String , SortOrder > orderBy = new LinkedHashMap <>();
112+ orderBy .put ("id" , SortOrder .ASC );
113+ ResponseList <Task > taskResponseList = this .getTasksApi ().listTasks (tasksProjectIdSortByIdAsc , null , null , null , null , orderBy );
114+
115+ assertNotNull (taskResponseList .getData ().get (0 ).getData ());
116+ assertEquals (2 , taskResponseList .getData ().size ());
117+
118+ assertEquals (1 , taskResponseList .getData ().get (0 ).getData ().getId ());
119+ assertEquals (2 , taskResponseList .getData ().get (1 ).getData ().getId ());
120+ }
121+
122+ @ Test
123+ public void listTasksTest_testSortByIdDesc () {
124+ Map <String , SortOrder > orderBy = new LinkedHashMap <>();
125+ orderBy .put ("id" , SortOrder .DESC );
126+
127+ ResponseList <Task > taskResponseList = this .getTasksApi ().listTasks (tasksProjectIdSortByIdDesc , null , null , null , null , orderBy );
128+
129+ assertNotNull (taskResponseList .getData ().get (0 ).getData ());
130+ assertEquals (2 , taskResponseList .getData ().size ());
131+
132+ assertEquals (2 , taskResponseList .getData ().get (0 ).getData ().getId ());
133+ assertEquals (1 , taskResponseList .getData ().get (1 ).getData ().getId ());
134+ }
135+
136+ @ Test
137+ public void listTasksTest_testSortByIdDescTitleAsc () {
138+ Map <String , SortOrder > orderBy = new LinkedHashMap <>();
139+ orderBy .put ("id" , SortOrder .DESC );
140+ orderBy .put ("title" , null );
141+
142+ ResponseList <Task > taskResponseList = this .getTasksApi ().listTasks (tasksProjectIdSortByIdDescTitleAsc , null , null , null , null , orderBy );
143+
144+ assertNotNull (taskResponseList .getData ().get (0 ).getData ());
145+ assertEquals (2 , taskResponseList .getData ().size ());
146+
147+ assertEquals (2 , taskResponseList .getData ().get (0 ).getData ().getId ());
148+ assertNotNull (taskResponseList .getData ().get (0 ).getData ().getTitle ());
149+ assertEquals ("French#1" , taskResponseList .getData ().get (0 ).getData ().getTitle ());
150+
151+
152+ assertEquals (1 , taskResponseList .getData ().get (1 ).getData ().getId ());
153+ assertNotNull (taskResponseList .getData ().get (1 ).getData ().getTitle ());
154+ assertEquals ("French#2" , taskResponseList .getData ().get (1 ).getData ().getTitle ());
155+ }
156+
75157 @ Test
76158 public void listTasksTest_testSingleStatus () {
77159 TimeZone .setDefault (TimeZone .getTimeZone ("GMT" ));
0 commit comments