|
1 | 1 | package com.auth0.client.mgmt; |
2 | 2 |
|
3 | 3 | import com.auth0.client.mgmt.filter.ConnectionFilter; |
| 4 | +import com.auth0.client.mgmt.filter.EnabledClientsFilter; |
4 | 5 | import com.auth0.json.mgmt.connections.*; |
5 | 6 | import com.auth0.net.Request; |
6 | 7 | import com.auth0.net.client.HttpMethod; |
@@ -545,6 +546,108 @@ public void shouldCheckConnectionStatus() throws Exception { |
545 | 546 | assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); |
546 | 547 | } |
547 | 548 |
|
| 549 | + @Test |
| 550 | + public void shouldThrowOnGetEnabledClientsWithNullId() { |
| 551 | + verifyThrows(IllegalArgumentException.class, |
| 552 | + () -> api.connections().getEnabledClients(null, new EnabledClientsFilter()), |
| 553 | + "'connection id' cannot be null!"); |
| 554 | + } |
| 555 | + |
| 556 | + @Test |
| 557 | + public void shouldGetEnabledClientsWithoutFilter() throws Exception { |
| 558 | + Request<EnabledClientResponse> request = api.connections().getEnabledClients("1", null); |
| 559 | + assertThat(request, is(notNullValue())); |
| 560 | + |
| 561 | + server.jsonResponse(MGMT_ENABLED_CLIENTS_FOR_CONNECTION, 200); |
| 562 | + EnabledClientResponse response = request.execute().getBody(); |
| 563 | + RecordedRequest recordedRequest = server.takeRequest(); |
| 564 | + |
| 565 | + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections/1/clients")); |
| 566 | + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); |
| 567 | + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); |
| 568 | + |
| 569 | + assertThat(response, is(notNullValue())); |
| 570 | + assertThat(response.getClients(), hasSize(2)); |
| 571 | + } |
| 572 | + |
| 573 | + @Test |
| 574 | + public void shouldGetEnabledClientsWithFromFilter() throws Exception { |
| 575 | + EnabledClientsFilter filter = new EnabledClientsFilter().withFrom("1"); |
| 576 | + Request<EnabledClientResponse> request = api.connections().getEnabledClients("1", filter); |
| 577 | + assertThat(request, is(notNullValue())); |
| 578 | + |
| 579 | + server.jsonResponse(MGMT_ENABLED_CLIENTS_FOR_CONNECTION, 200); |
| 580 | + EnabledClientResponse response = request.execute().getBody(); |
| 581 | + RecordedRequest recordedRequest = server.takeRequest(); |
| 582 | + |
| 583 | + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections/1/clients")); |
| 584 | + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); |
| 585 | + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); |
| 586 | + assertThat(recordedRequest, hasQueryParameter("from", "1")); |
| 587 | + |
| 588 | + assertThat(response, is(notNullValue())); |
| 589 | + assertThat(response.getClients(), hasSize(2)); |
| 590 | + } |
| 591 | + |
| 592 | + @Test |
| 593 | + public void shouldGetEnabledClientsWithTakeFilter() throws Exception { |
| 594 | + EnabledClientsFilter filter = new EnabledClientsFilter().withTake(2); |
| 595 | + Request<EnabledClientResponse> request = api.connections().getEnabledClients("1", filter); |
| 596 | + assertThat(request, is(notNullValue())); |
| 597 | + |
| 598 | + server.jsonResponse(MGMT_ENABLED_CLIENTS_FOR_CONNECTION, 200); |
| 599 | + EnabledClientResponse response = request.execute().getBody(); |
| 600 | + RecordedRequest recordedRequest = server.takeRequest(); |
| 601 | + |
| 602 | + assertThat(recordedRequest, hasMethodAndPath(HttpMethod.GET, "/api/v2/connections/1/clients")); |
| 603 | + assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); |
| 604 | + assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); |
| 605 | + assertThat(recordedRequest, hasQueryParameter("take", "2")); |
| 606 | + |
| 607 | + assertThat(response, is(notNullValue())); |
| 608 | + assertThat(response.getClients(), hasSize(2)); |
| 609 | + } |
| 610 | + |
| 611 | + @Test |
| 612 | + public void shouldThrowOnUpdateEnabledClientsWithNullId() { |
| 613 | + EnabledClientRequest clientRequest = new EnabledClientRequest("clientId", true); |
| 614 | + List<EnabledClientRequest> enabledClientRequests = new ArrayList<>(); |
| 615 | + enabledClientRequests.add(clientRequest); |
| 616 | + verifyThrows(IllegalArgumentException.class, |
| 617 | + () -> api.connections().updateEnabledClients(null, enabledClientRequests), |
| 618 | + "'connection id' cannot be null!"); |
| 619 | + } |
| 620 | + |
| 621 | +// @Test |
| 622 | +// public void shouldThrowOnUpdateEnabledClientsWithNullRequest() { |
| 623 | +//; verifyThrows(IllegalArgumentException.class, |
| 624 | +// () -> api.connections().updateEnabledClients("1", null), |
| 625 | +// "'client id' cannot be null!"); |
| 626 | +// } |
| 627 | + |
| 628 | + |
| 629 | +// @Test |
| 630 | +// public void shouldUpdateEnabledClients() throws Exception { |
| 631 | +// EnabledClientRequest clientRequest = new EnabledClientRequest("clientId", true); |
| 632 | +// List<EnabledClientRequest> enabledClientRequests = new ArrayList<>(); |
| 633 | +// enabledClientRequests.add(clientRequest); |
| 634 | +// Request<Void> request = api.connections().updateEnabledClients("1", enabledClientRequests); |
| 635 | +// assertThat(request, is(notNullValue())); |
| 636 | +// |
| 637 | +// server.jsonResponse(MGMT_ENABLED_CLIENTS_FOR_CONNECTION, 200); |
| 638 | +// request.execute().getBody(); |
| 639 | +// RecordedRequest recordedRequest = server.takeRequest(); |
| 640 | +// |
| 641 | +// assertThat(recordedRequest, hasMethodAndPath(HttpMethod.PATCH, "/api/v2/connections/1/clients")); |
| 642 | +// assertThat(recordedRequest, hasHeader("Content-Type", "application/json")); |
| 643 | +// assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken")); |
| 644 | +// |
| 645 | +// Map<String, Object> body = bodyFromRequest(recordedRequest); |
| 646 | +// assertThat(body.size(), is(2)); |
| 647 | +// assertThat(body, hasEntry("client_id", "clientId")); |
| 648 | +// assertThat(body, hasEntry("status", true)); |
| 649 | +// } |
| 650 | + |
548 | 651 | private ScimTokenRequest getScimToken() { |
549 | 652 | ScimTokenRequest request = new ScimTokenRequest(); |
550 | 653 | List<String> scopes = new ArrayList<>(); |
|
0 commit comments