Search in sources :

Example 81 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class RulesConfigsEntityTest method shouldListRules.

@Test
public void shouldListRules() throws Exception {
    Request<List<RulesConfig>> request = api.rulesConfigs().list();
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RULES_CONFIGS_LIST, 200);
    List<RulesConfig> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/rules-configs"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) RulesConfig(com.auth0.json.mgmt.RulesConfig) List(java.util.List) Test(org.junit.Test)

Example 82 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class RulesEntityTest method shouldGetRule.

@Test
public void shouldGetRule() throws Exception {
    Request<Rule> request = api.rules().get("1", null);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RULE, 200);
    Rule response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/rules/1"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Rule(com.auth0.json.mgmt.Rule) Test(org.junit.Test)

Example 83 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class RulesEntityTest method shouldCreateRule.

@Test
public void shouldCreateRule() throws Exception {
    Request<Rule> request = api.rules().create(new Rule("my-rule", "function(){}"));
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_RULE, 200);
    Rule response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/rules"));
    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("name", "my-rule"));
    assertThat(body, hasEntry("script", "function(){}"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Rule(com.auth0.json.mgmt.Rule) Test(org.junit.Test)

Example 84 with Request

use of com.auth0.net.Request 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 85 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class RulesEntityTest method shouldListRulesWithoutFilter.

@Test
public void shouldListRulesWithoutFilter() throws Exception {
    Request<RulesPage> request = api.rules().listAll(null);
    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(response, is(notNullValue()));
    assertThat(response.getItems(), hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) RulesPage(com.auth0.json.mgmt.RulesPage) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)193 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)185 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)77 IOException (java.io.IOException)76 List (java.util.List)63 Algorithm (com.auth0.jwt.algorithms.Algorithm)35 VoidRequest (com.auth0.net.VoidRequest)33 Auth0Exception (com.auth0.exception.Auth0Exception)30 APIException (com.auth0.exception.APIException)27 RateLimitException (com.auth0.exception.RateLimitException)25 HashMap (java.util.HashMap)24 PageFilter (com.auth0.client.mgmt.filter.PageFilter)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 ServletException (javax.servlet.ServletException)23 TokenHolder (com.auth0.json.auth.TokenHolder)22 JWTVerifier (com.auth0.jwt.JWTVerifier)22 ArrayList (java.util.ArrayList)22 Test (org.junit.jupiter.api.Test)22 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)20 Date (java.util.Date)20