Search in sources :

Example 1 with DefaultCallContext

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);
}
Also used : DefaultTenant(org.killbill.billing.tenant.api.DefaultTenant) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) UUID(java.util.UUID)

Example 2 with DefaultCallContext

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);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) ClockMock(org.killbill.clock.ClockMock) ExternalChargeInvoiceItem(org.killbill.billing.invoice.model.ExternalChargeInvoiceItem) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 3 with DefaultCallContext

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());
}
Also used : DefaultAccount(org.killbill.billing.account.api.DefaultAccount) AccountTestUtils.createTestAccount(org.killbill.billing.account.AccountTestUtils.createTestAccount) Account(org.killbill.billing.account.api.Account) DefaultMutableAccountData(org.killbill.billing.account.api.DefaultMutableAccountData) AccountTestUtils.createAccountData(org.killbill.billing.account.AccountTestUtils.createAccountData) MutableAccountData(org.killbill.billing.account.api.MutableAccountData) AccountData(org.killbill.billing.account.api.AccountData) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) AccountApiException(org.killbill.billing.account.api.AccountApiException) TenantModelDao(org.killbill.billing.tenant.dao.TenantModelDao) TenantSqlDao(org.killbill.billing.tenant.dao.TenantSqlDao) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) Test(org.testng.annotations.Test)

Example 4 with DefaultCallContext

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());
}
Also used : CallOrigin(org.killbill.billing.util.callcontext.CallOrigin) ClockMock(org.killbill.clock.ClockMock) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) EntityAudit(org.killbill.billing.util.dao.EntityAudit) TableName(org.killbill.billing.util.dao.TableName) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) AuditLogModelDao(org.killbill.billing.util.audit.dao.AuditLogModelDao) UUID(java.util.UUID) UserType(org.killbill.billing.util.callcontext.UserType) Test(org.testng.annotations.Test)

Example 5 with DefaultCallContext

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);
}
Also used : DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) AuditLogModelDao(org.killbill.billing.util.audit.dao.AuditLogModelDao) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) DefaultCallContext(org.killbill.billing.callcontext.DefaultCallContext) DateTime(org.joda.time.DateTime)

Aggregations

DefaultCallContext (org.killbill.billing.callcontext.DefaultCallContext)10 CallContext (org.killbill.billing.util.callcontext.CallContext)7 Test (org.testng.annotations.Test)7 UUID (java.util.UUID)6 DateTime (org.joda.time.DateTime)3 AuditLogModelDao (org.killbill.billing.util.audit.dao.AuditLogModelDao)3 ClockMock (org.killbill.clock.ClockMock)3 DefaultTenant (org.killbill.billing.tenant.api.DefaultTenant)2 Tenant (org.killbill.billing.tenant.api.Tenant)2 TenantData (org.killbill.billing.tenant.api.TenantData)2 CallOrigin (org.killbill.billing.util.callcontext.CallOrigin)2 UserType (org.killbill.billing.util.callcontext.UserType)2 EntityAudit (org.killbill.billing.util.dao.EntityAudit)2 TableName (org.killbill.billing.util.dao.TableName)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1