@Test(groups = "slow", description = "Test Account create Child with a non existing Parent", expectedExceptions = AccountApiException.class, expectedExceptionsMessageRegExp = "Account does not exist for id .*") public void testCreateChildAccountWithInvalidParent() throws Exception { final AccountModelDao childAccountModel = createTestAccount(); childAccountModel.setParentAccountId(UUID.randomUUID()); final AccountData childAccountData = new DefaultAccount(childAccountModel); final Account childAccount = accountUserApi.createAccount(childAccountData, callContext); }
Account childAccount1 = accountUserApi.createAccount(new DefaultAccount(childAccountModelDao1), callContext); Assert.assertNull(childAccount1.getParentAccountId()); Assert.assertFalse(childAccount1.isPaymentDelegatedToParent()); final Account parentAccount = accountUserApi.createAccount(new DefaultAccount(createTestAccount()), callContext); Assert.assertNull(parentAccount.getParentAccountId()); Assert.assertFalse(parentAccount.isPaymentDelegatedToParent()); List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); Assert.assertEquals(childrenAccounts.size(), 0); childAccountModelDao1.setParentAccountId(parentAccount.getId()); childAccountModelDao1.setIsPaymentDelegatedToParent(true); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao1), callContext); childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext); Assert.assertEquals(childAccount1.getParentAccountId(), parentAccount.getId()); Assert.assertTrue(childAccount1.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); Assert.assertEquals(childrenAccounts.size(), 1); Assert.assertEquals(childrenAccounts.get(0).getId(), childAccount1.getId()); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao1), callContext); childAccount1 = accountUserApi.getAccountById(childAccount1.getId(), callContext); Assert.assertNull(childAccount1.getParentAccountId()); Assert.assertFalse(childAccount1.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); Assert.assertEquals(childrenAccounts.size(), 0);
final AccountModelDao account1ModelDao = new AccountModelDao(UUID.randomUUID(), mutableAccountData1); final AccountData accountData1 = new DefaultAccount(account1ModelDao); accountUserApi.createAccount(accountData1, callContext); final AccountModelDao account2ModelDao = new AccountModelDao(UUID.randomUUID(), mutableAccountData2); final AccountData accountData2 = new DefaultAccount(account2ModelDao); accountUserApi.createAccount(accountData2, callContext); final Pagination<Account> search1 = accountUserApi.searchAccounts("Inc.", 0L, 5L, callContext); Assert.assertEquals(search1.getCurrentOffset(), (Long) 0L); Assert.assertNull(search1.getNextOffset()); final Pagination<Account> search2 = accountUserApi.searchAccounts("Inc.", 0L, 1L, callContext); Assert.assertEquals(search2.getCurrentOffset(), (Long) 0L); Assert.assertEquals(search2.getNextOffset(), (Long) 1L); final Pagination<Account> search3 = accountUserApi.searchAccounts("acme.com", 0L, 5L, callContext); Assert.assertEquals(search3.getCurrentOffset(), (Long) 0L); Assert.assertNull(search3.getNextOffset()); final Pagination<Account> search4 = accountUserApi.searchAccounts("acme.com", -1L, 1L, callContext); Assert.assertEquals(search4.getCurrentOffset(), (Long) 0L); Assert.assertNull(search4.getNextOffset()); final Pagination<Account> search5 = accountUserApi.searchAccounts("john@acme.com", -1L, 1L, callContext); Assert.assertEquals(search5.getCurrentOffset(), (Long) 0L); Assert.assertNull(search5.getNextOffset());
@Test(groups = "slow", description = "Test Account create Parent and Child") public void testCreateParentAndChildAccounts() throws Exception { final Account parentAccount = accountUserApi.createAccount(new DefaultAccount(createTestAccount()), callContext); final AccountModelDao childAccountModel = createTestAccount(); childAccountModel.setParentAccountId(parentAccount.getId()); childAccountModel.setIsPaymentDelegatedToParent(true); final AccountData childAccountData = new DefaultAccount(childAccountModel); final Account childAccount = accountUserApi.createAccount(childAccountData, callContext); final Account retrievedChildAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); Assert.assertNull(parentAccount.getParentAccountId()); Assert.assertNotNull(retrievedChildAccount.getParentAccountId()); Assert.assertEquals(retrievedChildAccount.getId(), childAccount.getId()); Assert.assertEquals(retrievedChildAccount.getParentAccountId(), parentAccount.getId()); Assert.assertEquals(retrievedChildAccount.isPaymentDelegatedToParent(), childAccount.isPaymentDelegatedToParent()); }
@Test(groups = "slow", description = "Test Account update with null values") public void testShouldBeAbleToPassNullForSomeFieldsToAvoidUpdate() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(null, null, null, 0, null, null, false, 0, null, clock.getUTCNow(), null, null, null, null, null, null, null, null, null, null, null, false); final String newAddress1 = UUID.randomUUID().toString(); mutableAccountData.setAddress1(newAddress1); accountUserApi.updateAccount(account.getId(), mutableAccountData, callContext); final Account retrievedAccount = accountUserApi.getAccountById(account.getId(), callContext); Assert.assertEquals(retrievedAccount.getAddress1(), newAddress1); Assert.assertEquals(retrievedAccount.getAddress2(), account.getAddress2()); Assert.assertEquals(retrievedAccount.getCurrency(), account.getCurrency()); Assert.assertEquals(retrievedAccount.getExternalKey(), account.getExternalKey()); Assert.assertEquals(retrievedAccount.getBillCycleDayLocal(), account.getBillCycleDayLocal()); }
protected LocalDate toLocalDateDefaultToday(final UUID accountId, @Nullable final String inputDate, final TenantContext context) throws AccountApiException { final Account account = accountId != null ? accountUserApi.getAccountById(accountId, context) : null; return toLocalDateDefaultToday(account, inputDate, context); }
childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); assertNull(childAccount.getParentAccountId()); assertFalse(childAccount.isPaymentDelegatedToParent()); List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); assertEquals(childrenAccounts.size(), 0); childAccountModelDao.setParentAccountId(parentAccount.getId()); childAccountModelDao.setIsPaymentDelegatedToParent(false); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext); childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); assertEquals(childAccount.getParentAccountId(), parentAccount.getId()); assertFalse(childAccount.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); assertEquals(childrenAccounts.size(), 1); assertEquals(childrenAccounts.get(0).getId(), childAccount.getId()); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext); childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); assertEquals(childAccount.getParentAccountId(), parentAccount.getId()); assertTrue(childAccount.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); assertEquals(childrenAccounts.size(), 1); assertEquals(childrenAccounts.get(0).getId(), childAccount.getId());
protected Account getOrCreateAccount(final AccountJson accountJson, final CallContext callContext) throws AccountApiException { // Attempt to retrieve by accountId if specified if (accountJson.getAccountId() != null) { return accountUserApi.getAccountById(accountJson.getAccountId(), callContext); } if (accountJson.getExternalKey() != null) { // Attempt to retrieve by account externalKey, ignore if does not exist so we can create it with the key specified. try { return accountUserApi.getAccountByKey(accountJson.getExternalKey(), callContext); } catch (final AccountApiException ignore) { } } // Finally create if does not exist return accountUserApi.createAccount(accountJson.toAccount(null), callContext); }
@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account externalKey throws an exception") public void testShouldntBeAbleToUpdateExternalKey() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData(); otherAccount.setExternalKey(UUID.randomUUID().toString()); accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), callContext); }
accountUserApi.getAccountById(accountId, callContext); final AccountEmail existingEmail = Iterables.<AccountEmail>tryFind(accountUserApi.getEmails(accountId, callContext), new Predicate<AccountEmail>() { @Override accountUserApi.addEmail(accountId, json.toAccountEmail(UUIDs.randomUUID()), callContext);
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + CHILDREN) @Produces(APPLICATION_JSON) @ApiOperation(value = "List children accounts", response = AccountJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid parent account id supplied"), @ApiResponse(code = 404, message = "Parent Account not found")}) public Response getChildrenAccounts(@PathParam("accountId") final UUID parentAccountId, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE) @DefaultValue("false") final Boolean accountWithBalance, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE_AND_CBA) @DefaultValue("false") final Boolean accountWithBalanceAndCBA, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException { final TenantContext tenantContext = context.createTenantContextWithAccountId(parentAccountId, request); final List<Account> accounts = accountUserApi.getChildrenAccounts(parentAccountId, tenantContext); final List<AccountJson> accountJson = new ArrayList<AccountJson>(); for (final Account account : accounts) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); accountJson.add(getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext)); } return Response.status(Status.OK).entity(accountJson).build(); }
@TimedResource @GET @Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Search accounts", response = AccountJson.class, responseContainer = "List") @ApiResponses(value = {}) public Response searchAccounts(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE) @DefaultValue("false") final Boolean accountWithBalance, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE_AND_CBA) @DefaultValue("false") final Boolean accountWithBalanceAndCBA, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Pagination<Account> accounts = accountUserApi.searchAccounts(searchKey, offset, limit, tenantContext); final URI nextPageUri = uriBuilder.nextPage(AccountResource.class, "searchAccounts", accounts.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_ACCOUNT_WITH_BALANCE, accountWithBalance.toString(), QUERY_ACCOUNT_WITH_BALANCE_AND_CBA, accountWithBalanceAndCBA.toString(), QUERY_AUDIT, auditMode.getLevel().toString())); return buildStreamingPaginationResponse(accounts, new Function<Account, AccountJson>() { @Override public AccountJson apply(final Account account) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); } }, nextPageUri ); }
@TimedResource @GET @Path("/{invoiceItemId:" + UUID_PATTERN + "}/" + TAGS) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve invoice item tags", response = TagJson.class, responseContainer = "List", nickname = "getInvoiceItemTags") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid invoice item id supplied"), @ApiResponse(code = 404, message = "Account not found")}) public Response getTags(@PathParam(ID_PARAM_NAME) final UUID id, @ApiParam(required=true) @QueryParam(QUERY_ACCOUNT_ID) final UUID accountId, @QueryParam(QUERY_TAGS_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException, AccountApiException { final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final Account account = accountUserApi.getAccountById(accountId, tenantContext); return super.getTags(account.getId(), id, auditMode, includedDeleted, tenantContext); }
protected Account createAccount(final AccountData accountData) throws Exception { final Account account = accountUserApi.createAccount(accountData, callContext); assertNotNull(account); refreshCallContext(account.getId()); return accountUserApi.getAccountById(account.getId(), callContext); }
childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); assertEquals(childAccount.getParentAccountId(), parentAccount.getId()); assertTrue(childAccount.isPaymentDelegatedToParent()); List<Account> childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); assertEquals(childrenAccounts.size(), 1); assertEquals(childrenAccounts.get(0).getId(), childAccount.getId()); childAccountModelDao.setParentAccountId(null); childAccountModelDao.setIsPaymentDelegatedToParent(false); accountUserApi.updateAccount(new DefaultAccount(childAccountModelDao), callContext); childAccount = accountUserApi.getAccountById(childAccount.getId(), callContext); assertNull(childAccount.getParentAccountId()); assertFalse(childAccount.isPaymentDelegatedToParent()); childrenAccounts = accountUserApi.getChildrenAccounts(parentAccount.getId(), callContext); assertEquals(childrenAccounts.size(), 0);
accountUserApi.updateAccount(newAccount, callContext); final Account retrievedAccount = accountUserApi.getAccountById(account.getId(), callContext);
@Test(groups = "slow", description = "Test failure on resetting externalKey", expectedExceptions = IllegalArgumentException.class) public void testAccountResetExternalKey() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setExternalKey(null); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + OVERDUE) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve overdue state for account", response = OverdueStateJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found")}) public Response getOverdueAccount(@PathParam("accountId") final UUID accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, OverdueException, OverdueApiException { final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final Account account = accountUserApi.getAccountById(accountId, tenantContext); final OverdueState overdueState = overdueApi.getOverdueStateFor(account.getId(), tenantContext); return Response.status(Status.OK).entity(new OverdueStateJson(overdueState, paymentConfig)).build(); }
protected Account createAccount(final AccountData accountData) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); refreshCallContext(account.getId()); return account; } }
@Test(groups = "slow", description = "Test failure on changing externalKey", expectedExceptions = IllegalArgumentException.class) public void testAccountChangeExternalKey() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setExternalKey("somethingVeryDifferent"); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }