Search in sources :

Example 1 with RulesFilter

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

the class RulesEntityTest method shouldListRulesWithTotals.

@Test
public void shouldListRulesWithTotals() throws Exception {
    RulesFilter filter = new RulesFilter().withTotals(true);
    Request<RulesPage> request = api.rules().listAll(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RULES_PAGED_LIST, 200);
    RulesPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/rules"));
    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) RulesFilter(com.auth0.client.mgmt.filter.RulesFilter) RulesPage(com.auth0.json.mgmt.RulesPage) Test(org.junit.Test)

Example 2 with RulesFilter

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

the class RulesEntityTest method shouldListRulesWithEnabled.

@Test
public void shouldListRulesWithEnabled() throws Exception {
    RulesFilter filter = new RulesFilter().withEnabled(true);
    @SuppressWarnings("deprecation") Request<List<Rule>> request = api.rules().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RULES_LIST, 200);
    List<Rule> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/rules"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("enabled", "true"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) List(java.util.List) Rule(com.auth0.json.mgmt.Rule) RulesFilter(com.auth0.client.mgmt.filter.RulesFilter) Test(org.junit.Test)

Example 3 with RulesFilter

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

the class RulesEntityTest method shouldListRulesWithPage.

@Test
public void shouldListRulesWithPage() throws Exception {
    RulesFilter filter = new RulesFilter().withPage(23, 5);
    Request<RulesPage> request = api.rules().listAll(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RULES_LIST, 200);
    RulesPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/rules"));
    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) RulesFilter(com.auth0.client.mgmt.filter.RulesFilter) RulesPage(com.auth0.json.mgmt.RulesPage) Test(org.junit.Test)

Example 4 with RulesFilter

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

the class RulesEntityTest method shouldNotListRulesWithTotals.

@Test
public void shouldNotListRulesWithTotals() throws Exception {
    RulesFilter filter = new RulesFilter().withTotals(true);
    @SuppressWarnings("deprecation") Request<List<Rule>> request = api.rules().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RULES_LIST, 200);
    List<Rule> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/rules"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, not(hasQueryParameter("include_totals")));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) List(java.util.List) Rule(com.auth0.json.mgmt.Rule) RulesFilter(com.auth0.client.mgmt.filter.RulesFilter) Test(org.junit.Test)

Example 5 with RulesFilter

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

the class RulesEntityTest method shouldListRulesWithFields.

@Test
public void shouldListRulesWithFields() throws Exception {
    RulesFilter filter = new RulesFilter().withFields("some,random,fields", true);
    @SuppressWarnings("deprecation") Request<List<Rule>> request = api.rules().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RULES_LIST, 200);
    List<Rule> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/rules"));
    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()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) List(java.util.List) Rule(com.auth0.json.mgmt.Rule) RulesFilter(com.auth0.client.mgmt.filter.RulesFilter) Test(org.junit.Test)

Aggregations

RulesFilter (com.auth0.client.mgmt.filter.RulesFilter)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 Test (org.junit.Test)6 Rule (com.auth0.json.mgmt.Rule)4 List (java.util.List)3 RulesPage (com.auth0.json.mgmt.RulesPage)2