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); } }
private ResponseEntity<ScimUser> createUser( String username, String firstName, String lastName, String email) { ScimUser user = new ScimUser(); user.setUserName(username); user.setName(new ScimUser.Name(firstName, lastName)); user.addEmail(email); user.setPassword("pas5Word"); user.setVerified(true); return client.postForEntity(serverRunning.getUrl(userEndpoint), user, ScimUser.class); }
private ScimUser createUnapprovedUser() throws Exception { String userName = "******" + new RandomValueStringGenerator().generate(); String userEmail = userName + "@example.com"; RestOperations restTemplate = serverRunning.getRestTemplate(); ScimUser user = new ScimUser(); user.setUserName(userName); user.setPassword("s3Cretsecret"); user.addEmail(userEmail); user.setActive(true); user.setVerified(true); ResponseEntity<ScimUser> result = restTemplate.postForEntity(serverRunning.getUrl("/Users"), user, ScimUser.class); assertEquals(HttpStatus.CREATED, result.getStatusCode()); return user; }
private void createClient(RestOperations client, ClientDetails clientDetails) { ResponseEntity<String> response = client.postForEntity(serverRunning.getClientsUri(), clientDetails, String.class); assertEquals(HttpStatus.CREATED, response.getStatusCode()); }