public MigrationCallContext(final CallContext context, final DateTime createdDate, final DateTime updatedDate) { super(context.getTenantId(), context.getUserName(), context.getCallOrigin(), context.getUserType()); this.createdDate = createdDate; this.updatedDate = updatedDate; }
/** * Create an internal call callcontext using an existing account to retrieve tenant and account record ids * <p/> * This is used for r/w operations - we need the account id to populate the account_record_id field * * @param accountId account id * @param context original call callcontext * @return internal call callcontext */ public InternalCallContext createInternalCallContext(final UUID accountId, final CallContext context) { return createInternalCallContext(accountId, ObjectType.ACCOUNT, context.getUserName(), context.getCallOrigin(), context.getUserType(), context.getUserToken(), context.getReasonCode(), context.getComments(), context.getCreatedDate(), context.getUpdatedDate()); }
private void verifyInternalCallContext(final InternalCallContext context) { Assert.assertEquals(context.getCallOrigin(), callContext.getCallOrigin()); Assert.assertEquals(context.getComments(), callContext.getComments()); Assert.assertEquals(context.getCreatedDate(), callContext.getCreatedDate()); Assert.assertEquals(context.getReasonCode(), callContext.getReasonCode()); Assert.assertEquals(context.getUpdatedDate(), callContext.getUpdatedDate()); 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); } }
/** * Create an internal call callcontext from a call callcontext, and retrieving the account_record_id from another table * * @param objectId the id of the row in the table pointed by object type where to look for account_record_id * @param objectType the object type pointed by this objectId * @param context original call callcontext * @return internal call callcontext from callcontext, with a non null account_record_id (if found) */ public InternalCallContext createInternalCallContext(final UUID objectId, final ObjectType objectType, final CallContext context) { // The callcontext may come from a user API - for security, check we're not doing cross-tenants operations //final Long tenantRecordIdFromObject = retrieveTenantRecordIdFromObject(objectId, objectType); //final Long tenantRecordIdFromContext = getTenantRecordId(callcontext); //Preconditions.checkState(tenantRecordIdFromContext.equals(tenantRecordIdFromObject), // "tenant of the pointed object (%s) and the callcontext (%s) don't match!", tenantRecordIdFromObject, tenantRecordIdFromContext); return createInternalCallContext(objectId, objectType, context.getUserName(), context.getCallOrigin(), context.getUserType(), context.getUserToken(), context.getReasonCode(), context.getComments(), context.getCreatedDate(), context.getUpdatedDate()); }
@Test(groups = "slow", enabled= false) 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 externalChargeInvoiceItem = invoiceUserApi.insertExternalChargeForInvoice(accountId, invoiceId, externalChargeAmount, UUID.randomUUID().toString(), clock.getUTCToday(), accountCurrency, newCallContextLater); 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); }