@Override public Account getAccountById(final UUID accountId, final InternalTenantContext context) throws AccountApiException { return super.getAccountById(accountId, context); }
@Override public void updateAccount(final UUID accountId, final AccountData accountData, final CallContext context) throws AccountApiException { updateAccount(accountId, accountData, false, context); }
@Override public Account getAccountByRecordId(final Long recordId, final InternalTenantContext context) throws AccountApiException { return super.getAccountByRecordId(recordId, context); }
@Override protected void postBusEventFromTransaction(final AccountModelDao account, final AccountModelDao savedAccount, final ChangeType changeType, final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InternalCallContext context) throws BillingExceptionBase { // This is only called for the create call (see update below) switch (changeType) { case INSERT: break; default: return; } final Long recordId = savedAccount.getRecordId(); // We need to re-hydrate the callcontext with the account record id final InternalCallContext rehydratedContext = internalCallContextFactory.createInternalCallContext(savedAccount, recordId, context); final AccountCreationInternalEvent creationEvent = new DefaultAccountCreationEvent(new DefaultAccountData(savedAccount), savedAccount.getId(), rehydratedContext.getAccountRecordId(), rehydratedContext.getTenantRecordId(), rehydratedContext.getUserToken()); try { eventBus.postFromTransaction(creationEvent, entitySqlDaoWrapperFactory.getHandle().getConnection()); } catch (final EventBusException e) { log.warn("Failed to post account creation event for accountId='{}'", savedAccount.getId(), e); } }
@Test(groups = "fast", description="Test Account event serialization") public void testAccountCreationEvent() throws Exception { final DefaultAccountData data = new DefaultAccountData("dsfdsf", "bobo", 3, "bobo@yahoo.com", 12, "USD", null, false, UUID.randomUUID(), new DateTime().toString(), "UTC", "US", "21 avenue", "", "Gling", "San Franciso", "CA", "94110", "USA", "4126789887", "notes", false); final DefaultAccountCreationEvent e = new DefaultAccountCreationEvent(data, UUID.randomUUID(), 1L, 2L, null); final String json = mapper.writeValueAsString(e); final DefaultAccountCreationEvent obj = mapper.readValue(json, DefaultAccountCreationEvent.class); Assert.assertTrue(obj.equals(e)); } }
@Override public void updateAccount(final String externalKey, final AccountData accountData, final CallContext context) throws AccountApiException { final Account currentAccount = getAccountByKey(externalKey, context); if (currentAccount == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY, externalKey); } updateAccount(currentAccount.getId(), accountData, false, context); }
@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); }
protected Account getAccountByRecordId(final Long recordId, final InternalTenantContext context) throws AccountApiException { final Account account = getAccountByRecordIdInternal(recordId, context); if (account == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_RECORD_ID, recordId); } return account; }
@Override public Account getAccountByKey(final String key, final InternalTenantContext context) throws AccountApiException { return super.getAccountByKey(key, context); }
@Override public Account getAccountById(final UUID id, final TenantContext context) throws AccountApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(id, context); return getAccountById(id, internalTenantContext); }
public DefaultAccountChangeEvent(final UUID id, final AccountModelDao oldData, final AccountModelDao newData, final Long searchKey1, final Long searchKey2, final UUID userToken, final DateTime changeDate) { super(searchKey1, searchKey2, userToken); this.accountId = id; this.changedFields = calculateChangedFields(oldData, newData, changeDate); }
@Override public Account getAccountByKey(final String key, final TenantContext context) throws AccountApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(context); return getAccountByKey(key, internalTenantContext); }
@Override public Boolean call() throws Exception { return eventHandler.getAccountCreationInternalEvents().size() == 1; } });
@BeforeMethod(groups = "fast") public void setUp() throws Exception { accountDao = new MockAccountDao(Mockito.mock(PersistentBus.class), clock); accountUserApi = new DefaultAccountUserApi(immutableAccountInternalApi, accountDao, nonEntityDao, controllerDispatcher, internalFactory); }
@Override public void create(final AccountModelDao account, final InternalCallContext context) throws AccountApiException { super.create(account, context); try { final Long accountRecordId = getRecordId(account.getId(), context); final long tenantRecordId = context == null ? InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID : context.getTenantRecordId(); eventBus.post(new DefaultAccountCreationEvent(new DefaultAccountData(account), account.getId(), accountRecordId, tenantRecordId, UUID.randomUUID())); } catch (final EventBusException ex) { Assert.fail(ex.toString()); } }
@Test(groups = "slow", description = "Test failure on changing currency", expectedExceptions = IllegalArgumentException.class) public void testAccountChangeCurrency() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); // Update the address and leave other fields null final MutableAccountData mutableAccountData = new DefaultMutableAccountData(account); mutableAccountData.setCurrency(Currency.AFN); DefaultAccount newAccount = new DefaultAccount(account.getId(), mutableAccountData); accountUserApi.updateAccount(newAccount, callContext); }
@Override public void updateAccount(final Account account, final CallContext context) throws AccountApiException { updateAccount(account.getId(), account, true, context); }
protected Account getAccountById(final UUID accountId, final InternalTenantContext context) throws AccountApiException { final Long recordId = nonEntityDao.retrieveRecordIdFromObject(accountId, ObjectType.ACCOUNT, recordIdCacheController); final Account account = getAccountByRecordIdInternal(recordId, context); if (account == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, accountId); } accountCacheController.putIfAbsent(recordId, new DefaultImmutableAccountData(account)); return account; }
@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account currency throws an exception") public void testShouldntBeAbleToUpdateCurrency() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData(); otherAccount.setCurrency(Currency.GBP); accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), callContext); }
@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class, description = "Test updating Account BCD does throws an exception") public void testShouldntBeAbleToUpdateBillCycleDay() throws Exception { final Account account = createAccount(new DefaultAccount(createTestAccount())); final MutableAccountData otherAccount = new DefaultAccount(account.getId(), account).toMutableAccountData(); otherAccount.setBillCycleDayLocal(account.getBillCycleDayLocal() + 2); accountUserApi.updateAccount(new DefaultAccount(account.getId(), otherAccount), callContext); }