use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TestIntegrationWithCatalogUpdate method setupTenant.
private void setupTenant() throws TenantApiException {
final UUID uuid = UUID.randomUUID();
final String externalKey = uuid.toString();
final String apiKey = externalKey + "-Key";
final String apiSecret = externalKey + "-$3cr3t";
// Only place where we use callContext
tenant = tenantUserApi.createTenant(new DefaultTenant(uuid, init, init, externalKey, apiKey, apiSecret), callContext);
testCallContext = new DefaultCallContext(tenant.getId(), "tester", CallOrigin.EXTERNAL, UserType.TEST, "good reason", "trust me", uuid, clock);
}
use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TestDefaultInvoiceUserApi method testOriginalAmountCharged.
@Test(groups = "slow")
public void testOriginalAmountCharged() throws Exception {
final Invoice initialInvoice = invoiceUserApi.getInvoice(invoiceId, callContext);
final BigDecimal originalAmountCharged = initialInvoice.getOriginalChargedAmount();
final BigDecimal amountCharged = initialInvoice.getChargedAmount();
Assert.assertEquals(originalAmountCharged.compareTo(amountCharged), 0);
((ClockMock) clock).addDays(1);
// Sleep at least one sec to make sure created_date for the external charge is different than the created date for the invoice itself
CallContext newCallContextLater = new DefaultCallContext(callContext.getTenantId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getUserToken(), clock);
// Post an external charge
final BigDecimal externalChargeAmount = BigDecimal.TEN;
final InvoiceItem externalCharge = new ExternalChargeInvoiceItem(invoiceId, accountId, null, UUID.randomUUID().toString(), clock.getUTCToday(), externalChargeAmount, accountCurrency);
final InvoiceItem externalChargeInvoiceItem = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge), true, newCallContextLater).get(0);
final Invoice newInvoice = invoiceUserApi.getInvoice(invoiceId, callContext);
final BigDecimal newOriginalAmountCharged = newInvoice.getOriginalChargedAmount();
final BigDecimal newAmountCharged = newInvoice.getChargedAmount();
final BigDecimal expectedChargedAmount = newInvoice.getOriginalChargedAmount().add(externalChargeInvoiceItem.getAmount());
Assert.assertEquals(originalAmountCharged.compareTo(newOriginalAmountCharged), 0);
Assert.assertEquals(newAmountCharged.compareTo(expectedChargedAmount), 0);
}
use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TestDefaultAccountUserApi method testCreateAccountWithSameExternalKeyInDifferentTenants.
@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(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());
}
use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TestDefaultAuditLog method testGetters.
@Test(groups = "fast")
public void testGetters() throws Exception {
final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
final long recordId = Long.MAX_VALUE;
final ChangeType changeType = ChangeType.DELETE;
final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
final UUID tenantId = UUID.randomUUID();
final String userName = UUID.randomUUID().toString();
final CallOrigin callOrigin = CallOrigin.EXTERNAL;
final UserType userType = UserType.CUSTOMER;
final UUID userToken = UUID.randomUUID();
final ClockMock clock = new ClockMock();
final CallContext callContext = new DefaultCallContext(tenantId, userName, callOrigin, userType, userToken, clock);
final AuditLog auditLog = new DefaultAuditLog(new AuditLogModelDao(entityAudit, callContext), ObjectType.ACCOUNT_EMAIL, UUID.randomUUID());
Assert.assertEquals(auditLog.getChangeType(), changeType);
Assert.assertNull(auditLog.getComment());
Assert.assertNotNull(auditLog.getCreatedDate());
Assert.assertNull(auditLog.getReasonCode());
Assert.assertEquals(auditLog.getUserName(), userName);
Assert.assertEquals(auditLog.getUserToken(), userToken.toString());
}
use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class AuditLogModelDaoMapper method map.
@Override
public AuditLogModelDao map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException {
final UUID id = getUUID(r, "id");
final String tableName = r.getString("table_name");
final long targetRecordId = r.getLong("target_record_id");
final String changeType = r.getString("change_type");
final DateTime createdDate = getDateTime(r, "created_date");
final String createdBy = r.getString("created_by");
final String reasonCode = r.getString("reason_code");
final String comments = r.getString("comments");
final UUID userToken = getUUID(r, "user_token");
final EntityAudit entityAudit = new EntityAudit(id, TableName.valueOf(tableName), targetRecordId, ChangeType.valueOf(changeType), createdDate);
// TODO - we have the tenant_record_id but not the tenant id here
final CallContext callContext = new DefaultCallContext(null, createdBy, createdDate, reasonCode, comments, userToken);
return new AuditLogModelDao(entityAudit, callContext);
}
Aggregations