77import com .auth0 .json .mgmt .jobs .JobErrorDetails ;
88import com .auth0 .json .mgmt .jobs .UsersExportField ;
99import com .auth0 .net .Request ;
10+ import com .auth0 .net .Response ;
1011import com .auth0 .net .client .HttpMethod ;
1112import com .auth0 .net .client .multipart .FilePart ;
1213import com .auth0 .net .client .multipart .KeyValuePart ;
@@ -100,18 +101,21 @@ public void shouldGetJobErrorDetails_noErrors() throws Exception {
100101 }
101102
102103 @ Test
104+ @ SuppressWarnings ("deprecation" )
103105 public void shouldThrowOnRequestUsersExportWithNullConnectionId () {
104106 exception .expect (IllegalArgumentException .class );
105107 exception .expectMessage ("'connection id' cannot be null!" );
106108 api .jobs ().exportUsers (null , null );
107109 }
108110
109111 @ Test
112+ @ SuppressWarnings ("deprecation" )
110113 public void shouldNotThrowOnRequestUsersExportWithNullFilter () {
111114 api .jobs ().exportUsers ("con_123456789" , null );
112115 }
113116
114117 @ Test
118+ @ SuppressWarnings ("deprecation" )
115119 public void shouldRequestUsersExport () throws Exception {
116120 Request <Job > request = api .jobs ().exportUsers ("con_123456789" , null );
117121 assertThat (request , is (notNullValue ()));
@@ -132,6 +136,105 @@ public void shouldRequestUsersExport() throws Exception {
132136 }
133137
134138 @ Test
139+ @ SuppressWarnings ("deprecation" )
140+ public void usersExportWithFilterOverridesClientId () throws Exception {
141+ UsersExportFilter filter = new UsersExportFilter ();
142+ filter .withConnectionId ("filter_con" );
143+
144+ Request <Job > request = api .jobs ().exportUsers ("con_123456789" , filter );
145+ assertThat (request , is (notNullValue ()));
146+
147+ server .jsonResponse (MGMT_JOB_POST_USERS_EXPORTS , 200 );
148+ Job response = request .execute ().getBody ();
149+ RecordedRequest recordedRequest = server .takeRequest ();
150+
151+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/api/v2/jobs/users-exports" ));
152+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/json" ));
153+ assertThat (recordedRequest , hasHeader ("Authorization" , "Bearer apiToken" ));
154+
155+ Map <String , Object > body = bodyFromRequest (recordedRequest );
156+ assertThat (body .size (), is (1 ));
157+ assertThat (body , hasEntry ("connection_id" , "filter_con" ));
158+
159+ assertThat (response , is (notNullValue ()));
160+ }
161+
162+ @ Test
163+ public void shouldRequestUsersExportWithoutConnectionOrFilter () throws Exception {
164+ Request <Job > request = api .jobs ().exportUsers (null );
165+ assertThat (request , is (notNullValue ()));
166+
167+ server .jsonResponse (MGMT_JOB_POST_USERS_EXPORTS , 200 );
168+ Job response = request .execute ().getBody ();
169+ RecordedRequest recordedRequest = server .takeRequest ();
170+
171+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/api/v2/jobs/users-exports" ));
172+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/json" ));
173+ assertThat (recordedRequest , hasHeader ("Authorization" , "Bearer apiToken" ));
174+
175+ Map <String , Object > body = bodyFromRequest (recordedRequest );
176+ assertThat (body .size (), is (0 ));
177+
178+ assertThat (response , is (notNullValue ()));
179+ }
180+
181+ @ Test
182+ public void shouldRequestUsersExportWithFilter () throws Exception {
183+ UsersExportFilter filter = new UsersExportFilter ();
184+ filter .withConnectionId ("conId" );
185+ filter .withFormat ("json" );
186+ List <UsersExportField > fields = new ArrayList <>();
187+ fields .add (new UsersExportField ("full_name" ));
188+ fields .add (new UsersExportField ("user_metadata.company_name" , "company" ));
189+ filter .withFields (fields );
190+
191+ Request <Job > request = api .jobs ().exportUsers (filter );
192+ assertThat (request , is (notNullValue ()));
193+
194+ server .jsonResponse (MGMT_JOB_POST_USERS_EXPORTS , 200 );
195+ Job response = request .execute ().getBody ();
196+ RecordedRequest recordedRequest = server .takeRequest ();
197+
198+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/api/v2/jobs/users-exports" ));
199+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/json" ));
200+ assertThat (recordedRequest , hasHeader ("Authorization" , "Bearer apiToken" ));
201+
202+ Map <String , Object > body = bodyFromRequest (recordedRequest );
203+ assertThat (body .size (), is (3 ));
204+ assertThat (body , hasEntry ("connection_id" , "conId" ));
205+ assertThat (body , hasEntry ("format" , "json" ));
206+ assertThat (body , hasKey ("fields" ));
207+ @ SuppressWarnings ("unchecked" )
208+ List <Map <String , String >> bodyFields = (List <Map <String , String >>) body .get ("fields" );
209+ assertThat (bodyFields .get (0 ).get ("name" ), is ("full_name" ));
210+ assertThat (bodyFields .get (0 ).get ("export_as" ), is (nullValue ()));
211+ assertThat (bodyFields .get (1 ).get ("name" ), is ("user_metadata.company_name" ));
212+ assertThat (bodyFields .get (1 ).get ("export_as" ), is ("company" ));
213+
214+ assertThat (response , is (notNullValue ()));
215+ }
216+
217+ @ Test
218+ public void usersExportShouldHandleNullFilter () throws Exception {
219+ Request <Job > request = api .jobs ().exportUsers (null );
220+ assertThat (request , is (notNullValue ()));
221+
222+ server .jsonResponse (MGMT_JOB_POST_USERS_EXPORTS , 200 );
223+ Job response = request .execute ().getBody ();
224+ RecordedRequest recordedRequest = server .takeRequest ();
225+
226+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/api/v2/jobs/users-exports" ));
227+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/json" ));
228+ assertThat (recordedRequest , hasHeader ("Authorization" , "Bearer apiToken" ));
229+
230+ Map <String , Object > body = bodyFromRequest (recordedRequest );
231+ assertThat (body .size (), is (0 ));
232+
233+ assertThat (response , is (notNullValue ()));
234+ }
235+
236+ @ Test
237+ @ SuppressWarnings ("deprecation" )
135238 public void shouldRequestUsersExportWithLimit () throws Exception {
136239 UsersExportFilter filter = new UsersExportFilter ();
137240 filter .withLimit (82 );
@@ -155,6 +258,7 @@ public void shouldRequestUsersExportWithLimit() throws Exception {
155258 }
156259
157260 @ Test
261+ @ SuppressWarnings ("deprecation" )
158262 public void shouldRequestUsersExportWithFormat () throws Exception {
159263 UsersExportFilter filter = new UsersExportFilter ();
160264 filter .withFormat ("csv" );
@@ -178,6 +282,7 @@ public void shouldRequestUsersExportWithFormat() throws Exception {
178282 }
179283
180284 @ Test
285+ @ SuppressWarnings ("deprecation" )
181286 public void shouldRequestUsersExportWithFields () throws Exception {
182287 UsersExportFilter filter = new UsersExportFilter ();
183288 ArrayList <UsersExportField > fields = new ArrayList <>();
@@ -437,5 +542,4 @@ public void shouldRequestUsersImportWithOptions() throws Exception {
437542
438543 assertThat (response , is (notNullValue ()));
439544 }
440-
441545}
0 commit comments