Search in sources :

Example 1 with ConnectionFilter

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

the class ConnectionsEntityTest method shouldListConnectionsWithFields.

@Test
public void shouldListConnectionsWithFields() throws Exception {
    ConnectionFilter filter = new ConnectionFilter().withFields("some,random,fields", true);
    @SuppressWarnings("deprecation") Request<List<Connection>> request = api.connections().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CONNECTIONS_LIST, 200);
    List<Connection> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections"));
    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) ConnectionFilter(com.auth0.client.mgmt.filter.ConnectionFilter) Connection(com.auth0.json.mgmt.Connection) List(java.util.List) Test(org.junit.Test)

Example 2 with ConnectionFilter

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

the class ConnectionsEntityTest method shouldListConnectionsWithName.

@Test
public void shouldListConnectionsWithName() throws Exception {
    ConnectionFilter filter = new ConnectionFilter().withName("my-connection");
    @SuppressWarnings("deprecation") Request<List<Connection>> request = api.connections().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CONNECTIONS_LIST, 200);
    List<Connection> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(recordedRequest, hasQueryParameter("name", "my-connection"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasSize(2));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ConnectionFilter(com.auth0.client.mgmt.filter.ConnectionFilter) Connection(com.auth0.json.mgmt.Connection) List(java.util.List) Test(org.junit.Test)

Example 3 with ConnectionFilter

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

the class ConnectionsEntityTest method shouldListConnectionsWithPage.

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

Example 4 with ConnectionFilter

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

the class ConnectionsEntityTest method shouldNotListConnectionsWithTotals.

@Test
public void shouldNotListConnectionsWithTotals() throws Exception {
    ConnectionFilter filter = new ConnectionFilter().withTotals(true);
    @SuppressWarnings("deprecation") Request<List<Connection>> request = api.connections().list(filter);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_CONNECTIONS_LIST, 200);
    List<Connection> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/connections"));
    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) ConnectionFilter(com.auth0.client.mgmt.filter.ConnectionFilter) Connection(com.auth0.json.mgmt.Connection) List(java.util.List) Test(org.junit.Test)

Example 5 with ConnectionFilter

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

the class ConnectionsEntityTest method shouldListConnectionsWithTotals.

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

Aggregations

ConnectionFilter (com.auth0.client.mgmt.filter.ConnectionFilter)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 Test (org.junit.Test)7 Connection (com.auth0.json.mgmt.Connection)5 List (java.util.List)4 ConnectionsPage (com.auth0.json.mgmt.ConnectionsPage)2