Search in sources :

Example 26 with Request

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

the class JobsEntityTest method shouldRequestUsersExportWithLimit.

@Test
public void shouldRequestUsersExportWithLimit() throws Exception {
    UsersExportFilter filter = new UsersExportFilter();
    filter.withLimit(82);
    Request<Job> request = api.jobs().exportUsers("con_123456789", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_JOB_POST_USERS_EXPORTS, 200);
    Job response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/jobs/users-exports"));
    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("connection_id", "con_123456789"));
    assertThat(body, hasEntry("limit", 82));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UsersExportFilter(com.auth0.client.mgmt.filter.UsersExportFilter) Job(com.auth0.json.mgmt.jobs.Job) Test(org.junit.Test)

Example 27 with Request

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

the class JobsEntityTest method shouldRequestUsersExportWithFormat.

@Test
public void shouldRequestUsersExportWithFormat() throws Exception {
    UsersExportFilter filter = new UsersExportFilter();
    filter.withFormat("csv");
    Request<Job> request = api.jobs().exportUsers("con_123456789", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_JOB_POST_USERS_EXPORTS, 200);
    Job response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/jobs/users-exports"));
    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("connection_id", "con_123456789"));
    assertThat(body, hasEntry("format", "csv"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UsersExportFilter(com.auth0.client.mgmt.filter.UsersExportFilter) Job(com.auth0.json.mgmt.jobs.Job) Test(org.junit.Test)

Example 28 with Request

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

the class JobsEntityTest method shouldRequestUsersExportWithFields.

@Test
public void shouldRequestUsersExportWithFields() throws Exception {
    UsersExportFilter filter = new UsersExportFilter();
    ArrayList<UsersExportField> fields = new ArrayList<>();
    fields.add(new UsersExportField("full_name"));
    fields.add(new UsersExportField("user_metadata.company_name", "company"));
    filter.withFields(fields);
    Request<Job> request = api.jobs().exportUsers("con_123456789", filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_JOB_POST_USERS_EXPORTS, 200);
    Job response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/jobs/users-exports"));
    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("connection_id", "con_123456789"));
    assertThat(body, hasKey("fields"));
    @SuppressWarnings("unchecked") List<Map<String, String>> bodyFields = (List<Map<String, String>>) body.get("fields");
    assertThat(bodyFields.get(0).get("name"), is("full_name"));
    assertThat(bodyFields.get(0).get("export_as"), is(nullValue()));
    assertThat(bodyFields.get(1).get("name"), is("user_metadata.company_name"));
    assertThat(bodyFields.get(1).get("export_as"), is("company"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ArrayList(java.util.ArrayList) UsersExportField(com.auth0.json.mgmt.jobs.UsersExportField) UsersExportFilter(com.auth0.client.mgmt.filter.UsersExportFilter) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.auth0.json.mgmt.jobs.Job) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 29 with Request

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

the class JobsEntityTest method shouldGetJobErrorDetails.

@Test
public void shouldGetJobErrorDetails() throws Exception {
    Request<List<JobErrorDetails>> request = api.jobs().getErrorDetails("1");
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_JOB_ERROR_DETAILS, 200);
    List<JobErrorDetails> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/jobs/1/errors"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(1));
    assertThat(response.get(0).getErrors(), hasSize(1));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) JobErrorDetails(com.auth0.json.mgmt.jobs.JobErrorDetails) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 30 with Request

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

the class LogEventsEntityTest method shouldListLogEventsWithSort.

@Test
public void shouldListLogEventsWithSort() throws Exception {
    LogEventFilter filter = new LogEventFilter().withSort("date:1");
    Request<LogEventsPage> request = api.logEvents().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_LOG_EVENTS_LIST, 200);
    LogEventsPage response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/logs"));
    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) LogEventsPage(com.auth0.json.mgmt.logevents.LogEventsPage) LogEventFilter(com.auth0.client.mgmt.filter.LogEventFilter) 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