Search in sources :

Example 1 with UsersExportField

use of com.auth0.json.mgmt.jobs.UsersExportField in project auth0-java by auth0.

the class JobsEntityTest method shouldRequestUsersExportWithFields.

@Test
public void shouldRequestUsersExportWithFields() throws Exception {
    UsersExportFilter filter = new UsersExportFilter();
    ArrayList<UsersExportField> fields = new ArrayList<>();
    fields.add(new UsersExportField("full_name"));
    fields.add(new UsersExportField("user_metadata.company_name", "company"));
    filter.withFields(fields);
    Request<Job> request = api.jobs().exportUsers("con_123456789", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_JOB_POST_USERS_EXPORTS, 200);
    Job response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/jobs/users-exports"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(2));
    assertThat(body, hasEntry("connection_id", "con_123456789"));
    assertThat(body, hasKey("fields"));
    @SuppressWarnings("unchecked") List<Map<String, String>> bodyFields = (List<Map<String, String>>) body.get("fields");
    assertThat(bodyFields.get(0).get("name"), is("full_name"));
    assertThat(bodyFields.get(0).get("export_as"), is(nullValue()));
    assertThat(bodyFields.get(1).get("name"), is("user_metadata.company_name"));
    assertThat(bodyFields.get(1).get("export_as"), is("company"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ArrayList(java.util.ArrayList) UsersExportField(com.auth0.json.mgmt.jobs.UsersExportField) UsersExportFilter(com.auth0.client.mgmt.filter.UsersExportFilter) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.auth0.json.mgmt.jobs.Job) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with UsersExportField

use of com.auth0.json.mgmt.jobs.UsersExportField in project auth0-java by auth0.

the class UsersExportFilterTest method shouldFilterByFields.

@Test
public void shouldFilterByFields() {
    ArrayList<UsersExportField> fields = new ArrayList<>();
    fields.add(new UsersExportField("first_name"));
    fields.add(new UsersExportField("last_name"));
    fields.add(new UsersExportField("metadata.custom_property", "custom"));
    filter.withFields(fields);
    UsersExportFilter instance = filter.withFields(fields);
    assertThat(filter, is(instance));
    assertThat(filter.getAsMap(), is(notNullValue()));
    assertThat(filter.getAsMap(), Matchers.hasKey("fields"));
    @SuppressWarnings("unchecked") List<UsersExportField> bodyFields = (List<UsersExportField>) filter.getAsMap().get("fields");
    assertThat(bodyFields.get(0).getName(), is("first_name"));
    assertThat(bodyFields.get(0).getExportAs(), is(nullValue()));
    assertThat(bodyFields.get(1).getName(), is("last_name"));
    assertThat(bodyFields.get(1).getExportAs(), is(nullValue()));
    assertThat(bodyFields.get(2).getName(), is("metadata.custom_property"));
    assertThat(bodyFields.get(2).getExportAs(), is("custom"));
}
Also used : UsersExportField(com.auth0.json.mgmt.jobs.UsersExportField) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

UsersExportField (com.auth0.json.mgmt.jobs.UsersExportField)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 UsersExportFilter (com.auth0.client.mgmt.filter.UsersExportFilter)1 Job (com.auth0.json.mgmt.jobs.Job)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1