use of org.killbill.billing.util.tag.DescriptiveTag in project killbill by killbill.
the class TestCondition method testHasControlTag.
@Test(groups = "fast")
public void testHasControlTag() throws Exception {
final String xml = "<condition>" + " <controlTagInclusion>OVERDUE_ENFORCEMENT_OFF</controlTagInclusion>" + "</condition>";
final InputStream is = new ByteArrayInputStream(xml.getBytes());
final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
final UUID unpaidInvoiceId = UUID.randomUUID();
final LocalDate now = new LocalDate();
final ObjectType objectType = ObjectType.BUNDLE;
final UUID objectId = new UUID(0L, 1L);
final BillingState state0 = new BillingState(objectId, 0, BigDecimal.ZERO, null, unpaidInvoiceId, PaymentResponse.LOST_OR_STOLEN_CARD, new Tag[] { new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, objectType, objectId, clock.getUTCNow()), new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow()) });
final BillingState state1 = new BillingState(objectId, 1, new BigDecimal("100.00"), now.minusDays(10), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[] { new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow()) });
final BillingState state2 = new BillingState(objectId, 1, new BigDecimal("200.00"), now.minusDays(20), unpaidInvoiceId, PaymentResponse.DO_NOT_HONOR, new Tag[] { new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow()), new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, objectType, objectId, clock.getUTCNow()), new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow()) });
Assert.assertTrue(!c.evaluate(state0, now));
Assert.assertTrue(c.evaluate(state1, now));
Assert.assertTrue(c.evaluate(state2, now));
}
use of org.killbill.billing.util.tag.DescriptiveTag in project killbill by killbill.
the class TestDefaultTagDao method testCatchEventsOnCreateAndDelete.
@Test(groups = "slow")
public void testCatchEventsOnCreateAndDelete() throws Exception {
final String definitionName = UUID.randomUUID().toString().substring(0, 5);
final String description = UUID.randomUUID().toString().substring(0, 5);
final UUID objectId = UUID.randomUUID();
final ObjectType objectType = ObjectType.INVOICE_ITEM;
// Create a tag definition
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
final TagDefinitionModelDao createdTagDefinition = tagDefinitionDao.create(definitionName, description, ObjectType.ACCOUNT.name(), internalCallContext);
Assert.assertEquals(createdTagDefinition.getName(), definitionName);
Assert.assertEquals(createdTagDefinition.getDescription(), description);
assertListenerStatus();
final List<AuditLog> auditLogs1 = auditDao.getAuditLogsForId(TableName.TAG_DEFINITIONS, createdTagDefinition.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogs1.size(), 1);
Assert.assertEquals(auditLogs1.get(0).getChangeType(), ChangeType.INSERT);
// Make sure we can create a tag
eventsListener.pushExpectedEvent(NextEvent.TAG);
final Tag tag = new DescriptiveTag(createdTagDefinition.getId(), objectType, objectId, internalCallContext.getCreatedDate());
tagDao.create(new TagModelDao(tag), internalCallContext);
assertListenerStatus();
final List<AuditLog> auditLogs2 = auditDao.getAuditLogsForId(TableName.TAG, tag.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogs2.size(), 1);
Assert.assertEquals(auditLogs2.get(0).getChangeType(), ChangeType.INSERT);
// Make sure we can retrieve it via the DAO
final List<TagModelDao> foundTags = tagDao.getTagsForObject(objectId, objectType, false, internalCallContext);
Assert.assertEquals(foundTags.size(), 1);
Assert.assertEquals(foundTags.get(0).getTagDefinitionId(), createdTagDefinition.getId());
final List<TagModelDao> foundTagsForAccount = tagDao.getTagsForAccount(false, internalCallContext);
Assert.assertEquals(foundTagsForAccount.size(), 1);
Assert.assertEquals(foundTagsForAccount.get(0).getTagDefinitionId(), createdTagDefinition.getId());
// Delete the tag
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagDao.deleteTag(objectId, objectType, createdTagDefinition.getId(), internalCallContext);
assertListenerStatus();
final List<AuditLog> auditLogs3 = auditDao.getAuditLogsForId(TableName.TAG, tag.getId(), AuditLevel.FULL, internalCallContext);
Assert.assertEquals(auditLogs3.size(), 2);
Assert.assertEquals(auditLogs3.get(0).getChangeType(), ChangeType.INSERT);
Assert.assertEquals(auditLogs3.get(1).getChangeType(), ChangeType.DELETE);
// Make sure the tag is deleted
Assert.assertEquals(tagDao.getTagsForObject(objectId, objectType, false, internalCallContext).size(), 0);
Assert.assertEquals(tagDao.getTagsForAccount(false, internalCallContext).size(), 0);
Assert.assertEquals(tagDao.getTagsForObject(objectId, objectType, true, internalCallContext).size(), 1);
Assert.assertEquals(tagDao.getTagsForAccount(true, internalCallContext).size(), 1);
// Delete tag again, check correct error
try {
tagDao.deleteTag(objectId, objectType, createdTagDefinition.getId(), internalCallContext);
Assert.fail("Deleting same tag again should fail");
} catch (final TagApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.TAG_DOES_NOT_EXIST.getCode());
}
}
use of org.killbill.billing.util.tag.DescriptiveTag in project killbill by killbill.
the class TestDefaultTagDao method testInsertMultipleTags.
@Test(groups = "slow")
public void testInsertMultipleTags() throws TagApiException {
final UUID objectId = UUID.randomUUID();
final ObjectType objectType = ObjectType.ACCOUNT;
eventsListener.pushExpectedEvent(NextEvent.TAG);
final Tag tag = new DescriptiveTag(ControlTagType.AUTO_INVOICING_OFF.getId(), objectType, objectId, internalCallContext.getCreatedDate());
tagDao.create(new TagModelDao(tag), internalCallContext);
assertListenerStatus();
try {
final Tag tag2 = new DescriptiveTag(ControlTagType.AUTO_INVOICING_OFF.getId(), objectType, objectId, internalCallContext.getCreatedDate());
tagDao.create(new TagModelDao(tag2), internalCallContext);
Assert.fail("Should not be able to create twice the same tag");
assertListenerStatus();
} catch (final TagApiException e) {
Assert.assertEquals(ErrorCode.TAG_ALREADY_EXISTS.getCode(), e.getCode());
}
}
use of org.killbill.billing.util.tag.DescriptiveTag in project killbill by killbill.
the class TestAccountDao method testTags.
@Test(groups = "slow", description = "Test Account DAO: tags")
public void testTags() throws TagApiException, TagDefinitionApiException {
final AccountModelDao account = createTestAccount();
final TagDefinitionModelDao tagDefinition = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 4), UUID.randomUUID().toString(), ObjectType.ACCOUNT.name(), internalCallContext);
final Tag tag = new DescriptiveTag(tagDefinition.getId(), ObjectType.ACCOUNT, account.getId(), internalCallContext.getCreatedDate());
tagDao.create(new TagModelDao(tag), internalCallContext);
final List<TagModelDao> tags = tagDao.getTagsForObject(account.getId(), ObjectType.ACCOUNT, false, internalCallContext);
Assert.assertEquals(tags.size(), 1);
Assert.assertEquals(tags.get(0).getTagDefinitionId(), tagDefinition.getId());
Assert.assertEquals(tags.get(0).getObjectId(), account.getId());
Assert.assertEquals(tags.get(0).getObjectType(), ObjectType.ACCOUNT);
}
use of org.killbill.billing.util.tag.DescriptiveTag in project killbill by killbill.
the class TestDefaultAuditDao method addTag.
private void addTag() throws TagDefinitionApiException, TagApiException {
// Create a tag definition
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
final TagDefinitionModelDao tagDefinition = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 5), UUID.randomUUID().toString().substring(0, 5), ObjectType.ACCOUNT.name(), internalCallContext);
assertListenerStatus();
Assert.assertEquals(tagDefinitionDao.getById(tagDefinition.getId(), internalCallContext), tagDefinition);
// Create a tag
final UUID objectId = UUID.randomUUID();
final Tag theTag = new DescriptiveTag(tagDefinition.getId(), ObjectType.ACCOUNT, objectId, clock.getUTCNow());
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagDao.create(new TagModelDao(theTag), internalCallContext);
assertListenerStatus();
final List<TagModelDao> tags = tagDao.getTagsForObject(objectId, ObjectType.ACCOUNT, false, internalCallContext);
Assert.assertEquals(tags.size(), 1);
tag = tags.get(0);
Assert.assertEquals(tag.getTagDefinitionId(), tagDefinition.getId());
}
Aggregations