Search in sources :

Example 1 with TagInternalEvent

use of org.killbill.billing.events.TagInternalEvent in project killbill by killbill.

the class TestTagEventBuilder method testNewUserTagCreationEvent.

@Test(groups = "fast")
public void testNewUserTagCreationEvent() throws Exception {
    final UUID tagId = UUID.randomUUID();
    final UUID objectId = UUID.randomUUID();
    final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = internalCallContext.getUserToken();
    final TagEventBuilder tagEventBuilder = new TagEventBuilder();
    final TagInternalEvent event = tagEventBuilder.newUserTagCreationEvent(tagId, objectId, objectType, new TagDefinitionModelDao(tagDefinition), 1L, 2L, UUID.randomUUID());
    Assert.assertTrue(event instanceof UserTagCreationInternalEvent);
    Assert.assertEquals(event, new DefaultUserTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID()));
    Assert.assertTrue(event.equals(new DefaultUserTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID())));
    verifyTagEvent(tagId, objectId, objectType, tagDefinitionId, tagDefinitionName, tagDefinitionDescription, tagDefinition, userToken, event);
}
Also used : ObjectType(org.killbill.billing.ObjectType) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) UserTagCreationInternalEvent(org.killbill.billing.events.UserTagCreationInternalEvent) UUID(java.util.UUID) TagInternalEvent(org.killbill.billing.events.TagInternalEvent) Test(org.testng.annotations.Test)

Example 2 with TagInternalEvent

use of org.killbill.billing.events.TagInternalEvent in project killbill by killbill.

the class TestTagEventBuilder method testNewUserTagDeletionEvent.

@Test(groups = "fast")
public void testNewUserTagDeletionEvent() throws Exception {
    final UUID tagId = UUID.randomUUID();
    final UUID objectId = UUID.randomUUID();
    final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = internalCallContext.getUserToken();
    final TagEventBuilder tagEventBuilder = new TagEventBuilder();
    final TagInternalEvent event = tagEventBuilder.newUserTagDeletionEvent(tagId, objectId, objectType, new TagDefinitionModelDao(tagDefinition), 1L, 2L, UUID.randomUUID());
    Assert.assertTrue(event instanceof UserTagDeletionInternalEvent);
    Assert.assertEquals(event, new DefaultUserTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID()));
    Assert.assertTrue(event.equals(new DefaultUserTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID())));
    verifyTagEvent(tagId, objectId, objectType, tagDefinitionId, tagDefinitionName, tagDefinitionDescription, tagDefinition, userToken, event);
}
Also used : ObjectType(org.killbill.billing.ObjectType) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UserTagDeletionInternalEvent(org.killbill.billing.events.UserTagDeletionInternalEvent) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) UUID(java.util.UUID) TagInternalEvent(org.killbill.billing.events.TagInternalEvent) Test(org.testng.annotations.Test)

Example 3 with TagInternalEvent

use of org.killbill.billing.events.TagInternalEvent in project killbill by killbill.

the class TestTagEventBuilder method testNewControlTagCreationEvent.

@Test(groups = "fast")
public void testNewControlTagCreationEvent() throws Exception {
    final UUID tagId = UUID.randomUUID();
    final UUID objectId = UUID.randomUUID();
    final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
    final UUID tagDefinitionId = ControlTagType.AUTO_PAY_OFF.getId();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = true;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = internalCallContext.getUserToken();
    final TagEventBuilder tagEventBuilder = new TagEventBuilder();
    final TagInternalEvent event = tagEventBuilder.newControlTagCreationEvent(tagId, objectId, objectType, new TagDefinitionModelDao(tagDefinition), 1L, 2L, UUID.randomUUID());
    Assert.assertTrue(event instanceof ControlTagCreationInternalEvent);
    Assert.assertEquals(event, new DefaultControlTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID()));
    Assert.assertTrue(event.equals(new DefaultControlTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID())));
    verifyTagEvent(tagId, objectId, objectType, tagDefinitionId, tagDefinitionName, tagDefinitionDescription, tagDefinition, userToken, event);
}
Also used : ObjectType(org.killbill.billing.ObjectType) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) UUID(java.util.UUID) TagInternalEvent(org.killbill.billing.events.TagInternalEvent) ControlTagCreationInternalEvent(org.killbill.billing.events.ControlTagCreationInternalEvent) Test(org.testng.annotations.Test)

Example 4 with TagInternalEvent

use of org.killbill.billing.events.TagInternalEvent in project killbill by killbill.

the class DefaultTagDao method postBusEventFromTransaction.

@Override
protected void postBusEventFromTransaction(final TagModelDao tag, final TagModelDao savedTag, final ChangeType changeType, final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InternalCallContext context) throws BillingExceptionBase {
    final TagInternalEvent tagEvent;
    final TagDefinitionModelDao tagDefinition = getTagDefinitionFromTransaction(tag.getTagDefinitionId(), entitySqlDaoWrapperFactory, context);
    final boolean isControlTag = ControlTagType.getTypeFromId(tagDefinition.getId()) != null;
    switch(changeType) {
        case INSERT:
            tagEvent = (isControlTag) ? tagEventBuilder.newControlTagCreationEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()) : tagEventBuilder.newUserTagCreationEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken());
            break;
        case DELETE:
            tagEvent = (isControlTag) ? tagEventBuilder.newControlTagDeletionEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()) : tagEventBuilder.newUserTagDeletionEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken());
            break;
        default:
            return;
    }
    try {
        bus.postFromTransaction(tagEvent, entitySqlDaoWrapperFactory.getHandle().getConnection());
    } catch (final PersistentBus.EventBusException e) {
        log.warn("Failed to post tag event for tagId='{}'", tag.getId().toString(), e);
    }
}
Also used : TagInternalEvent(org.killbill.billing.events.TagInternalEvent) PersistentBus(org.killbill.bus.api.PersistentBus)

Example 5 with TagInternalEvent

use of org.killbill.billing.events.TagInternalEvent in project killbill by killbill.

the class TestTagEventBuilder method testNewControlTagDeletionEvent.

@Test(groups = "fast")
public void testNewControlTagDeletionEvent() throws Exception {
    final UUID tagId = UUID.randomUUID();
    final UUID objectId = UUID.randomUUID();
    final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
    final UUID tagDefinitionId = ControlTagType.AUTO_PAY_OFF.getId();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = true;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = internalCallContext.getUserToken();
    final TagEventBuilder tagEventBuilder = new TagEventBuilder();
    final TagInternalEvent event = tagEventBuilder.newControlTagDeletionEvent(tagId, objectId, objectType, new TagDefinitionModelDao(tagDefinition), 1L, 2L, UUID.randomUUID());
    Assert.assertTrue(event instanceof ControlTagDeletionInternalEvent);
    Assert.assertEquals(event, new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID()));
    Assert.assertTrue(event.equals(new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID())));
    verifyTagEvent(tagId, objectId, objectType, tagDefinitionId, tagDefinitionName, tagDefinitionDescription, tagDefinition, userToken, event);
}
Also used : ObjectType(org.killbill.billing.ObjectType) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) ControlTagDeletionInternalEvent(org.killbill.billing.events.ControlTagDeletionInternalEvent) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) UUID(java.util.UUID) TagInternalEvent(org.killbill.billing.events.TagInternalEvent) Test(org.testng.annotations.Test)

Aggregations

TagInternalEvent (org.killbill.billing.events.TagInternalEvent)5 UUID (java.util.UUID)4 ObjectType (org.killbill.billing.ObjectType)4 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)4 TagDefinition (org.killbill.billing.util.tag.TagDefinition)4 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)4 Test (org.testng.annotations.Test)4 ControlTagCreationInternalEvent (org.killbill.billing.events.ControlTagCreationInternalEvent)1 ControlTagDeletionInternalEvent (org.killbill.billing.events.ControlTagDeletionInternalEvent)1 UserTagCreationInternalEvent (org.killbill.billing.events.UserTagCreationInternalEvent)1 UserTagDeletionInternalEvent (org.killbill.billing.events.UserTagDeletionInternalEvent)1 PersistentBus (org.killbill.bus.api.PersistentBus)1