@Test
  public void updateMetadata() {
    mockRequest(
        InteractionContext.builder()
            .request(
                TestRequest.builder()
                    .method(PUT)
                    .path("/oauth/clients/RpFRZpY3/meta")
                    .payload("fixtures/uaa/clients/PUT_{id}_meta_request.json")
                    .build())
            .response(
                TestResponse.builder()
                    .status(OK)
                    .payload("fixtures/uaa/clients/PUT_{id}_meta_response.json")
                    .build())
            .build());

    this.clients
        .updateMetadata(
            UpdateMetadataRequest.builder()
                .appLaunchUrl("http://changed.app.launch/url")
                .clientId("RpFRZpY3")
                .showOnHomePage(false)
                .build())
        .as(StepVerifier::create)
        .expectNext(
            UpdateMetadataResponse.builder()
                .appLaunchUrl("http://changed.app.launch/url")
                .appIcon("")
                .clientId("RpFRZpY3")
                .showOnHomePage(false)
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void getMetadata() {
    mockRequest(
        InteractionContext.builder()
            .request(TestRequest.builder().method(GET).path("/oauth/clients/P4vuAaSe/meta").build())
            .response(
                TestResponse.builder()
                    .status(OK)
                    .payload("fixtures/uaa/clients/GET_{id}_meta_response.json")
                    .build())
            .build());

    this.clients
        .getMetadata(GetMetadataRequest.builder().clientId("P4vuAaSe").build())
        .as(StepVerifier::create)
        .expectNext(
            GetMetadataResponse.builder()
                .appIcon("aWNvbiBmb3IgY2xpZW50IDQ=")
                .appLaunchUrl("http://myloginpage.com")
                .clientId("P4vuAaSe")
                .showOnHomePage(true)
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void get() {
    mockRequest(
        InteractionContext.builder()
            .request(
                TestRequest.builder().method(GET).path("/oauth/clients/test-client-id").build())
            .response(
                TestResponse.builder()
                    .status(OK)
                    .payload("fixtures/uaa/clients/GET_{id}_response.json")
                    .build())
            .build());

    this.clients
        .get(GetClientRequest.builder().clientId("test-client-id").build())
        .as(StepVerifier::create)
        .expectNext(
            GetClientResponse.builder()
                .allowedProvider("uaa", "ldap", "my-saml-provider")
                .authority("clients.read", "clients.write")
                .authorizedGrantType(CLIENT_CREDENTIALS)
                .autoApprove("true")
                .clientId("4Z3t1r")
                .lastModified(1468364445592L)
                .name("My Client Name")
                .redirectUriPattern("http*://ant.path.wildcard/**/passback/*", "http://test1.com")
                .resourceId("none")
                .scope("clients.read", "clients.write")
                .tokenSalt("mr80UZ")
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void batchDelete() {
    mockRequest(
        InteractionContext.builder()
            .request(
                TestRequest.builder()
                    .method(POST)
                    .path("/oauth/clients/tx/delete")
                    .payload("fixtures/uaa/clients/POST_tx_delete_request.json")
                    .build())
            .response(
                TestResponse.builder()
                    .status(OK)
                    .payload("fixtures/uaa/clients/POST_tx_delete_response.json")
                    .build())
            .build());

    this.clients
        .batchDelete(BatchDeleteClientsRequest.builder().clientId("14pnUs", "qECLyr").build())
        .as(StepVerifier::create)
        .expectNext(
            BatchDeleteClientsResponse.builder()
                .client(
                    Client.builder()
                        .approvalsDeleted(true)
                        .allowedProvider("uaa", "ldap", "my-saml-provider")
                        .authority("clients.read", "clients.write")
                        .authorizedGrantType(CLIENT_CREDENTIALS)
                        .autoApprove("true")
                        .clientId("14pnUs")
                        .lastModified(1468364444461L)
                        .name("My Client Name")
                        .redirectUriPattern(
                            "http*://ant.path.wildcard/**/passback/*", "http://test1.com")
                        .resourceId("none")
                        .scope("clients.read", "clients.write")
                        .tokenSalt("erRsWH")
                        .build())
                .client(
                    Client.builder()
                        .approvalsDeleted(true)
                        .allowedProvider("uaa", "ldap", "my-saml-provider")
                        .authority("clients.read", "clients.write")
                        .authorizedGrantType(CLIENT_CREDENTIALS)
                        .autoApprove("true")
                        .clientId("qECLyr")
                        .lastModified(1468364444868L)
                        .name("My Client Name")
                        .redirectUriPattern(
                            "http*://ant.path.wildcard/**/passback/*", "http://test1.com")
                        .resourceId("none")
                        .scope("clients.read", "clients.write")
                        .tokenSalt("48TIsq")
                        .build())
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void list() {
    mockRequest(
        InteractionContext.builder()
            .request(
                TestRequest.builder()
                    .method(GET)
                    .path(
                        "/oauth/clients?count=10&filter=client_id%2Beq%2B%22EGgNW3%22&sortBy=client_id&sortOrder=descending&startIndex=1")
                    .build())
            .response(
                TestResponse.builder()
                    .status(OK)
                    .payload("fixtures/uaa/clients/GET_response.json")
                    .build())
            .build());

    this.clients
        .list(
            ListClientsRequest.builder()
                .count(10)
                .filter("client_id+eq+\"EGgNW3\"")
                .sortBy("client_id")
                .sortOrder(SortOrder.DESCENDING)
                .startIndex(1)
                .build())
        .as(StepVerifier::create)
        .expectNext(
            ListClientsResponse.builder()
                .resource(
                    Client.builder()
                        .allowedProvider("uaa", "ldap", "my-saml-provider")
                        .authority("clients.read", "clients.write")
                        .authorizedGrantType(CLIENT_CREDENTIALS)
                        .autoApprove("true")
                        .clientId("EGgNW3")
                        .lastModified(1468364445334L)
                        .name("My Client Name")
                        .redirectUriPattern(
                            "http*://ant.path.wildcard/**/passback/*", "http://test1.com")
                        .resourceId("none")
                        .scope("clients.read", "clients.write")
                        .tokenSalt("7uDPJX")
                        .build())
                .startIndex(1)
                .itemsPerPage(1)
                .totalResults(1)
                .schema("http://cloudfoundry.org/schema/scim/oauth-clients-1.0")
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void listMetadatas() {
    mockRequest(
        InteractionContext.builder()
            .request(TestRequest.builder().method(GET).path("/oauth/clients/meta").build())
            .response(
                TestResponse.builder()
                    .status(OK)
                    .payload("fixtures/uaa/clients/GET_meta_response.json")
                    .build())
            .build());

    this.clients
        .listMetadatas(ListMetadatasRequest.builder().build())
        .as(StepVerifier::create)
        .expectNext(
            ListMetadatasResponse.builder()
                .metadata(
                    Metadata.builder()
                        .appIcon("Y2xpZW50IDMgaWNvbg==")
                        .appLaunchUrl("http://client3.com/app")
                        .clientId("9134O7y4")
                        .showOnHomePage(true)
                        .build())
                .metadata(
                    Metadata.builder()
                        .appIcon("")
                        .appLaunchUrl("http://changed.app.launch/url")
                        .clientId("RpFRZpY3")
                        .showOnHomePage(false)
                        .build())
                .metadata(
                    Metadata.builder()
                        .appIcon("aWNvbiBmb3IgY2xpZW50IDQ=")
                        .appLaunchUrl("http://client4.com/app")
                        .clientId("ewegZo0R")
                        .showOnHomePage(false)
                        .build())
                .metadata(
                    Metadata.builder()
                        .appIcon("aWNvbiBmb3IgY2xpZW50IDQ=")
                        .appLaunchUrl("http://myloginpage.com")
                        .clientId("lqhK1n8q")
                        .showOnHomePage(true)
                        .build())
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void create() {
    mockRequest(
        InteractionContext.builder()
            .request(
                TestRequest.builder()
                    .method(POST)
                    .path("/oauth/clients")
                    .payload("fixtures/uaa/clients/POST_request.json")
                    .build())
            .response(
                TestResponse.builder()
                    .status(CREATED)
                    .payload("fixtures/uaa/clients/POST_response.json")
                    .build())
            .build());

    this.clients
        .create(
            CreateClientRequest.builder()
                .allowedProvider("uaa", "ldap", "my-saml-provider")
                .authority("clients.read", "clients.write")
                .authorizedGrantType(CLIENT_CREDENTIALS)
                .autoApprove("true")
                .clientId("aPq3I1")
                .clientSecret("secret")
                .name("My Client Name")
                .redirectUriPattern("http://test1.com", "http*://ant.path.wildcard/**/passback/*")
                .scope("clients.read", "clients.write")
                .tokenSalt("hRZ21X")
                .build())
        .as(StepVerifier::create)
        .expectNext(
            CreateClientResponse.builder()
                .allowedProvider("uaa", "ldap", "my-saml-provider")
                .authority("clients.read", "clients.write")
                .authorizedGrantType(CLIENT_CREDENTIALS)
                .autoApprove("true")
                .clientId("aPq3I1")
                .lastModified(1468364445109L)
                .name("My Client Name")
                .redirectUriPattern("http*://ant.path.wildcard/**/passback/*", "http://test1.com")
                .resourceId("none")
                .scope("clients.read", "clients.write")
                .tokenSalt("hRZ21X")
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void deserialize() {
    mockRequest(
        InteractionContext.builder()
            .request(TestRequest.builder().method(GET).path("/oauth/clients").build())
            .response(
                TestResponse.builder()
                    .status(OK)
                    .payload("fixtures/uaa/clients/GET_response_deserialize.json")
                    .build())
            .build());

    this.clients
        .list(ListClientsRequest.builder().build())
        .as(StepVerifier::create)
        .expectNext(
            ListClientsResponse.builder()
                .resource(
                    Client.builder()
                        .action("none")
                        .authority("uaa.none")
                        .authorizedGrantType(AUTHORIZATION_CODE, REFRESH_TOKEN)
                        .autoApprove("true")
                        .clientId("ssh-proxy")
                        .lastModified(1469112324000L)
                        .redirectUriPattern("/login")
                        .resourceId("none")
                        .scope("openid", "cloud_controller.read", "cloud_controller.write")
                        .build())
                .resource(
                    Client.builder()
                        .action("none")
                        .authority("routing.routes.write", "routing.routes.read")
                        .authorizedGrantType(CLIENT_CREDENTIALS, REFRESH_TOKEN)
                        .autoApprove("routing.routes.write", "routing.routes.read")
                        .clientId("tcp_emitter")
                        .lastModified(1469112324000L)
                        .resourceId("none")
                        .scope("uaa.none")
                        .build())
                .startIndex(1)
                .itemsPerPage(2)
                .totalResults(2)
                .schema("http://cloudfoundry.org/schema/scim/oauth-clients-1.0")
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void changeSecrets() {
    mockRequest(
        InteractionContext.builder()
            .request(
                TestRequest.builder()
                    .method(PUT)
                    .path("/oauth/clients/BMGkqk/secret")
                    .payload("fixtures/uaa/clients/PUT_{id}_secret_request.json")
                    .build())
            .response(
                TestResponse.builder()
                    .status(OK)
                    .payload("fixtures/uaa/clients/PUT_{id}_secret_response.json")
                    .build())
            .build());

    this.clients
        .changeSecret(ChangeSecretRequest.builder().clientId("BMGkqk").secret("new_secret").build())
        .as(StepVerifier::create)
        .expectNext(ChangeSecretResponse.builder().message("secret updated").status("ok").build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }
  @Test
  public void batchChangeSecret() {
    mockRequest(
        InteractionContext.builder()
            .request(
                TestRequest.builder()
                    .method(POST)
                    .path("/oauth/clients/tx/secret")
                    .payload("fixtures/uaa/clients/POST_tx_secret_request.json")
                    .build())
            .response(
                TestResponse.builder()
                    .status(CREATED)
                    .payload("fixtures/uaa/clients/POST_tx_secret_response.json")
                    .build())
            .build());

    this.clients
        .batchChangeSecret(
            BatchChangeSecretRequest.builder()
                .changeSecret(
                    ChangeSecret.builder().clientId("Zkgt1Y").secret("new_secret").build())
                .changeSecret(
                    ChangeSecret.builder().clientId("Xm43aH").secret("new_secret").build())
                .build())
        .as(StepVerifier::create)
        .expectNext(
            BatchChangeSecretResponse.builder()
                .client(
                    Client.builder()
                        .accessTokenValidity(2700L)
                        .allowedProvider("uaa", "ldap", "my-saml-provider")
                        .approvalsDeleted(true)
                        .authority("clients.read", "clients.write")
                        .authorizedGrantType(CLIENT_CREDENTIALS)
                        .autoApprove("true")
                        .clientId("Zkgt1Y")
                        .lastModified(1474923482301L)
                        .name("My Client Name")
                        .redirectUriPattern(
                            "http*://ant.path.wildcard/**/passback/*", "http://test1.com")
                        .refreshTokenValidity(7000L)
                        .resourceId("none")
                        .scope("clients.read", "clients.write")
                        .tokenSalt("uHICvG")
                        .build())
                .client(
                    Client.builder()
                        .accessTokenValidity(2700L)
                        .allowedProvider("uaa", "ldap", "my-saml-provider")
                        .approvalsDeleted(true)
                        .authority("clients.read", "new.authority", "clients.write")
                        .authorizedGrantType(CLIENT_CREDENTIALS)
                        .autoApprove("true")
                        .clientId("Xm43aH")
                        .lastModified(1474923482302L)
                        .name("My Client Name")
                        .redirectUriPattern(
                            "http*://ant.path.wildcard/**/passback/*", "http://test1.com")
                        .refreshTokenValidity(7000L)
                        .resourceId("none")
                        .scope("clients.read", "clients.write")
                        .tokenSalt("WjlWvu")
                        .build())
                .build())
        .expectComplete()
        .verify(Duration.ofSeconds(5));
  }