@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); }
protected Account createAccount(final AccountData accountData) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); refreshCallContext(account.getId()); return account; } }
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 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()); } }
public static Account createMockAccount(final AccountData accountData, final AccountUserApi accountUserApi, final AccountInternalApi accountInternalApi, final ImmutableAccountInternalApi immutableAccountInternalApi, final NonEntityDao nonEntityDao, final Clock clock, final InternalCallContextFactory internalCallContextFactory, final MutableCallContext callContext, final MutableInternalCallContext internalCallContext) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); Mockito.when(accountInternalApi.getAccountById(Mockito.<UUID>eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByKey(Mockito.<String>eq(account.getExternalKey()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(immutableAccountInternalApi.getImmutableAccountDataByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); ((MockNonEntityDao) nonEntityDao).addTenantRecordIdMapping(account.getId(), internalCallContext); ((MockNonEntityDao) nonEntityDao).addAccountRecordIdMapping(account.getId(), internalCallContext); refreshCallContext(account.getId(), clock, internalCallContextFactory, callContext, internalCallContext); return account; } }
@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()); } }
@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()); }
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);
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()); Account childAccount2 = accountUserApi.createAccount(new DefaultAccount(childAccountModelDao2), callContext); Assert.assertNull(childAccount2.getParentAccountId()); Assert.assertFalse(childAccount2.isPaymentDelegatedToParent());
@TimedResource @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Create account", response = AccountJson.class) @ApiResponses(value = {@ApiResponse(code = 201, message = "Account created successfully"), @ApiResponse(code = 400, message = "Invalid account data supplied")}) public Response createAccount(final AccountJson json, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws AccountApiException { verifyNonNullOrEmpty(json, "AccountJson body should be specified"); final AccountData data = json.toAccount(null); final Account account = accountUserApi.createAccount(data, context.createCallContextNoAccountId(createdBy, reason, comment, request)); return uriBuilder.buildResponse(uriInfo, AccountResource.class, "getAccount", account.getId(), request); }
private void setupAccount() throws Exception { final AccountData accountData = getAccountData(0); account = accountUserApi.createAccount(accountData, testCallContext); assertNotNull(account); final PaymentMethodPlugin info = createPaymentMethodPlugin(); paymentApi.addPaymentMethod(account, UUID.randomUUID().toString(), BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME, true, info, PLUGIN_PROPERTIES, testCallContext); }
protected Account createAccount(final AccountData accountData) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); refreshCallContext(account.getId()); return account; }
protected Account createAccount(final AccountData accountData) throws AccountApiException { final Account account = accountApi.createAccount(accountData, callContext); refreshCallContext(account.getId()); return account; }
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); }
public static Account createMockAccount(final AccountData accountData, final AccountUserApi accountUserApi, final AccountInternalApi accountInternalApi, final ImmutableAccountInternalApi immutableAccountInternalApi, final NonEntityDao nonEntityDao, final Clock clock, final InternalCallContextFactory internalCallContextFactory, final MutableCallContext callContext, final MutableInternalCallContext internalCallContext) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); Mockito.when(accountInternalApi.getAccountById(Mockito.<UUID>eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByKey(Mockito.<String>eq(account.getExternalKey()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(immutableAccountInternalApi.getImmutableAccountDataByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); ((MockNonEntityDao) nonEntityDao).addTenantRecordIdMapping(account.getId(), internalCallContext); ((MockNonEntityDao) nonEntityDao).addAccountRecordIdMapping(account.getId(), internalCallContext); refreshCallContext(account.getId(), clock, internalCallContextFactory, callContext, internalCallContext); return account; } }
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); }
account = GuicyKillbillTestSuiteNoDB.createMockAccount(accountData, accountApi, accountInternalApi, immutableAccountInternalApi, nonEntityDao, clock, internalCallContextFactory, mutableCallContext, internalCallContext); } else { account = accountApi.createAccount(accountData, context);
@Test(groups = "slow") public void testAuthSuccessWithPaymentControlNullPaymentMethodId() throws Exception { final AccountData accountData = getAccountData(1); final Account account = accountUserApi.createAccount(accountData, callContext); // Add non-default payment method final PaymentMethodPlugin info = createPaymentMethodPlugin(); final UUID paymentMethodId = paymentApi.addPaymentMethod(account, UUID.randomUUID().toString(), BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME, false, info, PLUGIN_PROPERTIES, callContext); testPaymentControlWithControl.setAdjustedPaymentMethodId(paymentMethodId); busHandler.pushExpectedEvents(NextEvent.PAYMENT); final Payment payment = paymentApi.createAuthorizationWithPaymentControl(account, null, null, BigDecimal.ONE, account.getCurrency(), null, null, null, properties, paymentOptions, callContext); assertListenerStatus(); final Payment paymentWithAttempts = paymentApi.getPayment(payment.getId(), false, true, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(paymentWithAttempts.getPaymentMethodId(), paymentMethodId); Assert.assertEquals(paymentWithAttempts.getPaymentAttempts().size(), 1); Assert.assertEquals(paymentWithAttempts.getPaymentAttempts().get(0).getPaymentMethodId(), paymentMethodId); Assert.assertEquals(paymentWithAttempts.getPaymentAttempts().get(0).getStateName(), "SUCCESS"); }
@Test(groups = "slow") public void testAuthFailureWithPaymentControlNullPaymentMethodId() throws Exception { final AccountData accountData = getAccountData(1); final Account account = accountUserApi.createAccount(accountData, callContext); // Add non-default payment method final PaymentMethodPlugin info = createPaymentMethodPlugin(); final UUID paymentMethodId = paymentApi.addPaymentMethod(account, UUID.randomUUID().toString(), BeatrixIntegrationModule.NON_OSGI_PLUGIN_NAME, false, info, PLUGIN_PROPERTIES, callContext); testPaymentControlWithControl.setAdjustedPaymentMethodId(paymentMethodId); paymentPlugin.makeNextPaymentFailWithError(); busHandler.pushExpectedEvents(NextEvent.PAYMENT_ERROR); final Payment payment = paymentApi.createAuthorizationWithPaymentControl(account, null, null, BigDecimal.ONE, account.getCurrency(), null, null, null, properties, paymentOptions, callContext); assertListenerStatus(); final Payment paymentWithAttempts = paymentApi.getPayment(payment.getId(), false, true, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(paymentWithAttempts.getPaymentMethodId(), paymentMethodId); Assert.assertEquals(paymentWithAttempts.getPaymentAttempts().size(), 1); Assert.assertEquals(paymentWithAttempts.getPaymentAttempts().get(0).getPaymentMethodId(), paymentMethodId); Assert.assertEquals(paymentWithAttempts.getPaymentAttempts().get(0).getStateName(), "ABORTED"); }
public Account createAccount(final CallContext callContext) throws AccountApiException { final Account accountData = new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)) .firstNameLength(6) .email(UUID.randomUUID().toString().substring(1, 8)) .phone(UUID.randomUUID().toString().substring(1, 8)) .migrated(false) .externalKey(UUID.randomUUID().toString().substring(1, 8)) .billingCycleDayLocal(31) .currency(accountCurrency) .paymentMethodId(UUID.randomUUID()) .timeZone(DateTimeZone.UTC) .createdDate(clock.getUTCNow()) .build(); final MutableCallContext mutableCallContext = new MutableCallContext(internalCallContext); final Account account; if (isFastTest()) { account = GuicyKillbillTestSuiteNoDB.createMockAccount(accountData, accountUserApi, accountApi, immutableAccountApi, nonEntityDao, clock, internalCallContextFactory, mutableCallContext, internalCallContext); } else { account = accountUserApi.createAccount(accountData, callContext); } GuicyKillbillTestSuite.refreshCallContext(account.getId(), clock, internalCallContextFactory, mutableCallContext, internalCallContext); return account; }