Search in sources :

Example 1 with Rule

use of com.auth0.json.mgmt.Rule 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 2 with Rule

use of com.auth0.json.mgmt.Rule 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 3 with Rule

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

the class RulesEntity method delete.

/**
 * Delete an existing Rule. A token with scope delete:rules is needed.
 * See https://auth0.com/docs/api/management/v2#!/Rules/delete_rules_by_id
 *
 * @param ruleId the rule id
 * @return a Request to execute.
 */
public Request<Void> delete(String ruleId) {
    Asserts.assertNotNull(ruleId, "rule id");
    String url = baseUrl.newBuilder().addPathSegments("api/v2/rules").addPathSegment(ruleId).build().toString();
    VoidRequest request = new VoidRequest(client, url, "DELETE");
    request.addHeader("Authorization", "Bearer " + apiToken);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 4 with Rule

use of com.auth0.json.mgmt.Rule 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 5 with Rule

use of com.auth0.json.mgmt.Rule 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)

Aggregations

Rule (com.auth0.json.mgmt.Rule)9 Test (org.junit.Test)9 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 RulesFilter (com.auth0.client.mgmt.filter.RulesFilter)4 List (java.util.List)4 VoidRequest (com.auth0.net.VoidRequest)1