public GuicyKillbillTestModule(final KillbillConfigSource configSource, final ClockMock clock) { super(configSource); this.clock = clock; internalCallContext = new MutableInternalCallContext(InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, 1687L, DateTimeZone.UTC, clock.getUTCNow(), UUID.randomUUID(), UUID.randomUUID().toString(), CallOrigin.TEST, UserType.TEST, "Testing", "This is a test", clock.getUTCNow(), clock.getUTCNow()); callContext = new MutableCallContext(internalCallContext); }
protected void refreshCallContext() { refreshCallContext(callContext.getAccountId(), clock, internalCallContextFactory, callContext, internalCallContext); }
private void verifyInternalCallContext(final InternalCallContext context) { Assert.assertEquals(context.getCallOrigin(), callContext.getCallOrigin()); Assert.assertEquals(context.getComments(), callContext.getComments()); Assert.assertTrue(context.getCreatedDate().compareTo(callContext.getCreatedDate()) >= 0); Assert.assertEquals(context.getReasonCode(), callContext.getReasonCode()); Assert.assertTrue(context.getUpdatedDate().compareTo(callContext.getUpdatedDate()) >= 0); Assert.assertEquals(context.getCreatedBy(), callContext.getUserName()); Assert.assertEquals(context.getUserToken(), callContext.getUserToken()); Assert.assertEquals(context.getContextUserType(), callContext.getUserType()); // Our test callcontext doesn't have a tenant id Assert.assertEquals(context.getTenantRecordId(), (Long) InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID); } }
@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()); } }
testDBRouterAPI.reset(); final TenantContext tenantContext = new DefaultTenantContext(callContext.getAccountId(), callContext.getTenantId());
@Test(groups = "slow") public void testCustomFieldUpdate() throws Exception { final CustomField customField1 = new StringCustomField("gtqre", "value1", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); eventsListener.pushExpectedEvents(NextEvent.CUSTOM_FIELD); customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField1), callContext); assertListenerStatus(); final CustomField update1 = new StringCustomField(customField1.getId(), customField1.getFieldName(), "value2", customField1.getObjectType(), customField1.getObjectId(), callContext.getCreatedDate()); customFieldUserApi.updateCustomFields(ImmutableList.of(update1), callContext); List<CustomField> all = customFieldUserApi.getCustomFieldsForAccount(accountId, callContext); Assert.assertEquals(all.size(), 1); Assert.assertEquals(all.get(0).getId(), update1.getId()); Assert.assertEquals(all.get(0).getObjectType(), update1.getObjectType()); Assert.assertEquals(all.get(0).getObjectId(), update1.getObjectId()); Assert.assertEquals(all.get(0).getFieldName(), update1.getFieldName()); Assert.assertEquals(all.get(0).getFieldValue(), "value2"); try { customFieldUserApi.updateCustomFields(ImmutableList.<CustomField>of(new StringCustomField("gtqre", "value1", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate())), callContext); Assert.fail("Updating custom field should fail"); } catch (final CustomFieldApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CUSTOM_FIELD_DOES_NOT_EXISTS_FOR_ID.getCode()); } try { customFieldUserApi.updateCustomFields(ImmutableList.<CustomField>of(new StringCustomField(customField1.getId(), "wrongName", "value2", customField1.getObjectType(), customField1.getObjectId(), callContext.getCreatedDate())), callContext); Assert.fail("Updating custom field should fail"); } catch (final CustomFieldApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CUSTOM_FIELD_INVALID_UPDATE.getCode()); } }
@Test(groups = "slow") public void testCustomFieldBasic() throws Exception { final CustomField customField1 = new StringCustomField("some123", "some 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); final CustomField customField2 = new StringCustomField("other123", "other 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); eventsListener.pushExpectedEvents(NextEvent.CUSTOM_FIELD, NextEvent.CUSTOM_FIELD); customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField1, customField2), callContext); final CustomField customField3 = new StringCustomField("qrqrq123", "qrqrq 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); try { customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField3, customField1), callContext);
private void verifyInternalCallContext(final InternalCallContext context) { Assert.assertEquals(context.getCallOrigin(), callContext.getCallOrigin()); Assert.assertEquals(context.getComments(), callContext.getComments()); Assert.assertTrue(context.getCreatedDate().compareTo(callContext.getCreatedDate()) >= 0); Assert.assertEquals(context.getReasonCode(), callContext.getReasonCode()); Assert.assertTrue(context.getUpdatedDate().compareTo(callContext.getUpdatedDate()) >= 0); Assert.assertEquals(context.getCreatedBy(), callContext.getUserName()); Assert.assertEquals(context.getUserToken(), callContext.getUserToken()); Assert.assertEquals(context.getContextUserType(), callContext.getUserType()); // Our test callcontext doesn't have a tenant id Assert.assertEquals(context.getTenantRecordId(), (Long) InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID); } }
public GuicyKillbillTestModule(final KillbillConfigSource configSource, final ClockMock clock) { super(configSource); this.clock = clock; internalCallContext = new MutableInternalCallContext(InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, 1687L, DateTimeZone.UTC, clock.getUTCNow(), UUID.randomUUID(), UUID.randomUUID().toString(), CallOrigin.TEST, UserType.TEST, "Testing", "This is a test", clock.getUTCNow(), clock.getUTCNow()); callContext = new MutableCallContext(internalCallContext); }
protected void refreshCallContext() { refreshCallContext(callContext.getAccountId(), clock, internalCallContextFactory, callContext, internalCallContext); }
final CustomField customField = new StringCustomField(cfName, cfValue, ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD); customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField), callContext); final CustomField newCustomField = new StringCustomField(cfName, cfValue, ObjectType.ACCOUNT, accountId, callContext.getCreatedDate());
Mockito.when(accountData.getReferenceTime()).thenReturn(utcNow); final MutableCallContext mutableCallContext = new MutableCallContext(internalCallContext);
@Test(groups = "slow") public void testCustomFieldBasic() throws Exception { final CustomField customField1 = new StringCustomField("some123", "some 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); final CustomField customField2 = new StringCustomField("other123", "other 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); eventsListener.pushExpectedEvents(NextEvent.CUSTOM_FIELD, NextEvent.CUSTOM_FIELD); customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField1, customField2), callContext); final CustomField customField3 = new StringCustomField("qrqrq123", "qrqrq 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); try { customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField3, customField1), callContext);
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; }
@Test(groups = "slow") public void testCustomFieldUpdate() throws Exception { final CustomField customField1 = new StringCustomField("gtqre", "value1", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); eventsListener.pushExpectedEvents(NextEvent.CUSTOM_FIELD); customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField1), callContext); assertListenerStatus(); final CustomField update1 = new StringCustomField(customField1.getId(), customField1.getFieldName(), "value2", customField1.getObjectType(), customField1.getObjectId(), callContext.getCreatedDate()); customFieldUserApi.updateCustomFields(ImmutableList.of(update1), callContext); List<CustomField> all = customFieldUserApi.getCustomFieldsForAccount(accountId, callContext); Assert.assertEquals(all.size(), 1); Assert.assertEquals(all.get(0).getId(), update1.getId()); Assert.assertEquals(all.get(0).getObjectType(), update1.getObjectType()); Assert.assertEquals(all.get(0).getObjectId(), update1.getObjectId()); Assert.assertEquals(all.get(0).getFieldName(), update1.getFieldName()); Assert.assertEquals(all.get(0).getFieldValue(), "value2"); try { customFieldUserApi.updateCustomFields(ImmutableList.<CustomField>of(new StringCustomField("gtqre", "value1", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate())), callContext); Assert.fail("Updating custom field should fail"); } catch (final CustomFieldApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CUSTOM_FIELD_DOES_NOT_EXISTS_FOR_ID.getCode()); } try { customFieldUserApi.updateCustomFields(ImmutableList.<CustomField>of(new StringCustomField(customField1.getId(), "wrongName", "value2", customField1.getObjectType(), customField1.getObjectId(), callContext.getCreatedDate())), callContext); Assert.fail("Updating custom field should fail"); } catch (final CustomFieldApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CUSTOM_FIELD_INVALID_UPDATE.getCode()); } }
final CustomField customField = new StringCustomField(cfName, cfValue, ObjectType.ACCOUNT, accountId, callContext.getCreatedDate()); eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD); customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField), callContext); final CustomField newCustomField = new StringCustomField(cfName, cfValue, ObjectType.ACCOUNT, accountId, callContext.getCreatedDate());