@Override public CallContext createCallContext(@Nullable final UUID tenantId, final String userName, final CallOrigin callOrigin, final UserType userType, final String reasonCode, final String comment, final UUID userToken) { return new DefaultCallContext(tenantId, userName, callOrigin, userType, reasonCode, comment, userToken, clock); }
@Test(groups = "fast") public void testGetters() throws Exception { final UUID tenantId = UUID.randomUUID(); final String userName = UUID.randomUUID().toString(); final DateTime createdDate = clock.getUTCNow(); final String reasonCode = UUID.randomUUID().toString(); final String comment = UUID.randomUUID().toString(); final UUID userToken = UUID.randomUUID(); final DefaultCallContext callContext = new DefaultCallContext(tenantId, userName, createdDate, reasonCode, comment, userToken); Assert.assertEquals(callContext.getTenantId(), tenantId); Assert.assertEquals(callContext.getCreatedDate(), createdDate); Assert.assertNull(callContext.getCallOrigin()); Assert.assertEquals(callContext.getComments(), comment); Assert.assertEquals(callContext.getReasonCode(), reasonCode); Assert.assertEquals(callContext.getUserName(), userName); Assert.assertEquals(callContext.getUpdatedDate(), createdDate); Assert.assertEquals(callContext.getUserToken(), userToken); Assert.assertNull(callContext.getUserType()); }
@Override public CallContext createCallContext(@Nullable final UUID tenantId, final String userName, final CallOrigin callOrigin, final UserType userType, @Nullable final UUID userToken) { return new DefaultCallContext(tenantId, userName, callOrigin, userType, userToken, clock); }
@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); } }
@Test(groups = "fast") public void testEquals() throws Exception { final UUID tenantId = UUID.randomUUID(); final String userName = UUID.randomUUID().toString(); final DateTime createdDate = clock.getUTCNow(); final String reasonCode = UUID.randomUUID().toString(); final String comment = UUID.randomUUID().toString(); final UUID userToken = UUID.randomUUID(); final DefaultCallContext callContext = new DefaultCallContext(tenantId, userName, createdDate, reasonCode, comment, userToken); Assert.assertEquals(callContext, callContext); final DefaultCallContext sameCallContext = new DefaultCallContext(tenantId, userName, createdDate, reasonCode, comment, userToken); Assert.assertEquals(sameCallContext, callContext); final DefaultCallContext otherCallContext = new DefaultCallContext(tenantId, UUID.randomUUID().toString(), createdDate, reasonCode, comment, userToken); Assert.assertNotEquals(otherCallContext, callContext); } }
@Test(groups = "fast") public void testEquals() 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 AuditLogModelDao auditLog = new AuditLogModelDao(entityAudit, callContext); Assert.assertEquals(auditLog, auditLog); final AuditLogModelDao sameAuditLog = new AuditLogModelDao(entityAudit, callContext); Assert.assertEquals(sameAuditLog, auditLog); clock.addMonths(1); final CallContext otherCallContext = new DefaultCallContext(tenantId, userName, callOrigin, userType, userToken, clock); final AuditLogModelDao otherAuditLog = new AuditLogModelDao(entityAudit, otherCallContext); Assert.assertNotEquals(otherAuditLog, auditLog); } }
@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()); }
@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); }