Search in sources :

Example 1 with DescriptiveTag

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));
}
Also used : ObjectType(org.killbill.billing.ObjectType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultControlTag(org.killbill.billing.util.tag.DefaultControlTag) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BillingState(org.killbill.billing.overdue.config.api.BillingState) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with DescriptiveTag

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());
    }
}
Also used : ObjectType(org.killbill.billing.ObjectType) TagApiException(org.killbill.billing.util.api.TagApiException) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) AuditLog(org.killbill.billing.util.audit.AuditLog) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) Test(org.testng.annotations.Test)

Example 3 with DescriptiveTag

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());
    }
}
Also used : ObjectType(org.killbill.billing.ObjectType) TagApiException(org.killbill.billing.util.api.TagApiException) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) Test(org.testng.annotations.Test)

Example 4 with DescriptiveTag

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);
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) Tag(org.killbill.billing.util.tag.Tag) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) Test(org.testng.annotations.Test)

Example 5 with DescriptiveTag

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());
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) DescriptiveTag(org.killbill.billing.util.tag.DescriptiveTag)

Aggregations

DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)5 UUID (java.util.UUID)4 Tag (org.killbill.billing.util.tag.Tag)4 Test (org.testng.annotations.Test)4 ObjectType (org.killbill.billing.ObjectType)3 TagApiException (org.killbill.billing.util.api.TagApiException)2 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)2 TagModelDao (org.killbill.billing.util.tag.dao.TagModelDao)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 LocalDate (org.joda.time.LocalDate)1 BillingState (org.killbill.billing.overdue.config.api.BillingState)1 AuditLog (org.killbill.billing.util.audit.AuditLog)1 DefaultControlTag (org.killbill.billing.util.tag.DefaultControlTag)1