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()));
}
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()));
}
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;
}
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));
}
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));
}
Aggregations