@Override public User get() { Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(creds.get().identity); User currentUser = null; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } return currentUser; } }
protected void checkAccount(Account account) { assert account.getId() != null : account; assertEquals(account.toString(), client.getAccountClient().getAccount(account.getId()).toString()); assert account.getName() != null : account; assert account.getType() != null && account.getType() != Account.Type.UNRECOGNIZED : account;
@Override public User get() { Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(creds.get().identity); User currentUser = null; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } return currentUser; } }
@Test public void testListAccounts() throws Exception { for (Account securityAccount : client.getAccountClient().listAccounts()) checkAccount(securityAccount); }
private static User verifyCurrentUserIsOfType(String identity, AccountClient accountClient, Account.Type type) { Iterable<User> users = Iterables.concat(accountClient.listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(identity); User currentUser; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } if (currentUser.getAccountType() != type) { Logger.getAnonymousLogger().warning( String.format("Expecting an user with type %s. Got: %s", type.toString(), currentUser.toString())); } return currentUser; }
Set<Account> listOfAccounts = client.getAccountClient().listAccounts();
Set<Account> listOfAccounts = client.getAccountClient().listAccounts();
private void checkAuthAsUser(ApiKeyPair keyPair) { ComputeServiceContext context = createView(credentialsAsProperties(keyPair), setupModules()); CloudStackClient client = context.unwrap(CloudStackApiMetadata.CONTEXT_TOKEN).getApi(); Set<Account> accounts = client.getAccountClient().listAccounts(); assert accounts.size() > 0; context.close(); }
public void testLoginWithPasswordSetsSessionKeyAndCookie() { AccountClient client = requestsSendResponses( login, loginResponse, HttpRequest.builder() .method("GET") .endpoint("http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&sessionkey=" + Strings2.urlEncode(sessionKey, '/')) .addHeader("Accept", "application/json") .addHeader(HttpHeaders.COOKIE, "JSESSIONID=" + jSessionId) .build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/listaccountsresponse.json")) .build() ,logout, logoutResponse); assertNotNull(client.listAccounts()); }
.secretKey("SECRETKEY").build()); assertEquals(client.listAccounts(), ImmutableSet.of(Account.builder() .id("505")