Search in sources :

Example 1 with UserFilter

use of com.auth0.client.mgmt.filter.UserFilter in project auth0-java by auth0.

the class UsersEntityTest method shouldGetUserWithFields.

@Test
public void shouldGetUserWithFields() throws Exception {
    UserFilter filter = new UserFilter().withFields("some,random,fields", true);
    Request<User> request = api.users().get("1", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_USER, 200);
    User response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/users/1"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("fields", "some,random,fields"));
    assertThat(recordedRequest, hasQueryParameter("include_fields", "true"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) User(com.auth0.json.mgmt.users.User) UserFilter(com.auth0.client.mgmt.filter.UserFilter) Test(org.junit.Test)

Example 2 with UserFilter

use of com.auth0.client.mgmt.filter.UserFilter in project auth0-java by auth0.

the class UsersEntityTest method shouldListUsersWithTotals.

@Test
public void shouldListUsersWithTotals() throws Exception {
    UserFilter filter = new UserFilter().withTotals(true);
    Request<UsersPage> request = api.users().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_USERS_PAGED_LIST, 200);
    UsersPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/users"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("include_totals", "true"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
    assertThat(response.getStart(), is(0));
    assertThat(response.getLength(), is(14));
    assertThat(response.getTotal(), is(14));
    assertThat(response.getLimit(), is(50));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UserFilter(com.auth0.client.mgmt.filter.UserFilter) UsersPage(com.auth0.json.mgmt.users.UsersPage) Test(org.junit.Test)

Example 3 with UserFilter

use of com.auth0.client.mgmt.filter.UserFilter in project auth0-java by auth0.

the class UsersEntityTest method shouldListUsersWithPage.

@Test
public void shouldListUsersWithPage() throws Exception {
    UserFilter filter = new UserFilter().withPage(23, 5);
    Request<UsersPage> request = api.users().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_USERS_LIST, 200);
    UsersPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/users"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("page", "23"));
    assertThat(recordedRequest, hasQueryParameter("per_page", "5"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UserFilter(com.auth0.client.mgmt.filter.UserFilter) UsersPage(com.auth0.json.mgmt.users.UsersPage) Test(org.junit.Test)

Example 4 with UserFilter

use of com.auth0.client.mgmt.filter.UserFilter in project auth0-java by auth0.

the class UsersEntityTest method shouldListUsersWithSort.

@Test
public void shouldListUsersWithSort() throws Exception {
    UserFilter filter = new UserFilter().withSort("date:1");
    Request<UsersPage> request = api.users().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_USERS_LIST, 200);
    UsersPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/users"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("sort", "date:1"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UserFilter(com.auth0.client.mgmt.filter.UserFilter) UsersPage(com.auth0.json.mgmt.users.UsersPage) Test(org.junit.Test)

Example 5 with UserFilter

use of com.auth0.client.mgmt.filter.UserFilter in project auth0-java by auth0.

the class UsersEntityTest method shouldListUsersWithQuery.

@Test
public void shouldListUsersWithQuery() throws Exception {
    UserFilter filter = new UserFilter().withQuery("email:\\*@gmail.com");
    Request<UsersPage> request = api.users().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_USERS_LIST, 200);
    UsersPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/users"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, not(hasQueryParameter("search_engine")));
    assertThat(recordedRequest, hasQueryParameter("q", "email:\\*@gmail.com"));
    assertThat(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UserFilter(com.auth0.client.mgmt.filter.UserFilter) UsersPage(com.auth0.json.mgmt.users.UsersPage) Test(org.junit.Test)

Aggregations

UserFilter (com.auth0.client.mgmt.filter.UserFilter)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 Test (org.junit.Test)6 UsersPage (com.auth0.json.mgmt.users.UsersPage)5 User (com.auth0.json.mgmt.users.User)1