@Test(groups = "slow", description = "Test Account DAO: duplicate emails throws an exception") public void testHandleDuplicateEmails() throws AccountApiException { final UUID accountId = UUID.randomUUID(); final AccountEmail email = new DefaultAccountEmail(accountId, "test@gmail.com"); Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 0); final AccountEmailModelDao accountEmailModelDao = new AccountEmailModelDao(email); accountDao.addEmail(accountEmailModelDao, internalCallContext); Assert.assertEquals(accountDao.getEmailsByAccountId(accountId, internalCallContext).size(), 1); try { accountDao.addEmail(accountEmailModelDao, internalCallContext); Assert.fail(); } catch (AccountApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.ACCOUNT_EMAIL_ALREADY_EXISTS.getCode()); } }
@Test(groups = "slow", description = "Test Account creation with External Key over limit") public void testCreateAccountWithExternalKeyOverLimit() throws Exception { AccountModelDao accountModelDao = createTestAccount(); // Set an externalKey of 256 characters (over limit) accountModelDao.setExternalKey("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis,."); final AccountData accountData = new DefaultAccount(accountModelDao); try { accountUserApi.createAccount(accountData, callContext); Assert.fail(); } catch (final AccountApiException e) { assertEquals(e.getCode(), ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED.getCode()); } }
@Test(groups = "slow", description = "Test Account creation with same External Key in different tenants") public void testCreateAccountWithSameExternalKeyInDifferentTenants() throws Exception { final AccountData accountData = createAccountData(); final Account account1 = accountUserApi.createAccount(accountData, callContext); try { // Same tenant accountUserApi.createAccount(accountData, callContext); Assert.fail(); } catch (final AccountApiException e) { assertEquals(e.getCode(), ErrorCode.ACCOUNT_ALREADY_EXISTS.getCode()); } final TenantSqlDao tenantSqlDao = dbi.onDemand(TenantSqlDao.class); final TenantModelDao tenant2 = new TenantModelDao(); tenantSqlDao.create(tenant2, internalCallContext); final CallContext callContext2 = new DefaultCallContext(account1.getId(), tenant2.getId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getUserToken(), clock); final Account account2 = accountUserApi.createAccount(accountData, callContext2); Assert.assertEquals(account1.getExternalKey(), account2.getExternalKey()); Assert.assertNotEquals(account1.getId(), account2.getId()); } }
public PaymentApiException(final AccountApiException e) { super(e, e.getCode(), e.getMessage()); }
public PaymentApiException(final AccountApiException e) { super(e, e.getCode(), e.getMessage()); }
@Override public Response toResponse(final AccountApiException exception) { if (exception.getCode() == ErrorCode.ACCOUNT_ALREADY_EXISTS.getCode()) { return buildConflictingRequestResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_CANNOT_CHANGE_EXTERNAL_KEY.getCode()) { return buildBadRequestResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_CANNOT_MAP_NULL_KEY.getCode()) { return buildBadRequestResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_CREATION_FAILED.getCode()) { return buildInternalErrorResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID.getCode()) { return buildNotFoundResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY.getCode()) { return buildNotFoundResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_INVALID_NAME.getCode()) { return buildBadRequestResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_UPDATE_FAILED.getCode()) { return buildInternalErrorResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_RECORD_ID.getCode()) { return buildNotFoundResponse(exception, uriInfo); } else { return fallback(exception, uriInfo); } } }