Пример #1
0
  private void initializeUserAccount(RestOperations client) {

    if (this.user == null) {

      UaaUser user = testAccounts.getUser();
      @SuppressWarnings("rawtypes")
      ResponseEntity<Map> results =
          client.getForEntity(
              serverRunning.getUserUri() + "?filter=userName eq '" + user.getUsername() + "'",
              Map.class);
      assertEquals(HttpStatus.OK, results.getStatusCode());
      @SuppressWarnings("unchecked")
      List<Map<String, ?>> resources = (List<Map<String, ?>>) results.getBody().get("resources");
      Map<String, ?> map;
      if (!resources.isEmpty()) {
        map = resources.get(0);
      } else {
        map = getUserAsMap(user);
        @SuppressWarnings("rawtypes")
        ResponseEntity<Map> response =
            client.postForEntity(serverRunning.getUserUri(), map, Map.class);
        Assert.state(
            response.getStatusCode() == HttpStatus.CREATED,
            "User account not created: status was " + response.getStatusCode());
        @SuppressWarnings("unchecked")
        Map<String, ?> value = response.getBody();
        map = value;
      }
      this.user = getUserFromMap(map);
    }
  }
Пример #2
0
 private boolean clientExists(RestOperations client, OAuth2ProtectedResourceDetails resource) {
   ResponseEntity<String> response =
       client.getForEntity(
           serverRunning.getClientsUri() + "/" + resource.getClientId(), String.class);
   return response != null && response.getStatusCode() == HttpStatus.OK;
 }