Search in sources :

Example 11 with ObjectType

use of org.killbill.billing.ObjectType 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 12 with ObjectType

use of org.killbill.billing.ObjectType 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 13 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class TestDefaultControlTagCreationEvent method testSerialization.

@Test(groups = "fast")
public void testSerialization() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    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 = UUID.randomUUID();
    final DefaultControlTagCreationEvent event = new DefaultControlTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultControlTagCreationEvent fromJson = objectMapper.readValue(json, DefaultControlTagCreationEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : ObjectType(org.killbill.billing.ObjectType) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 14 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class TestDefaultControlTagCreationEvent method testPojo.

@Test(groups = "fast")
public void testPojo() 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 = UUID.randomUUID();
    final DefaultControlTagCreationEvent event = new DefaultControlTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
    Assert.assertEquals(event.getBusEventType(), BusInternalEvent.BusInternalEventType.CONTROL_TAG_CREATION);
    Assert.assertEquals(event.getTagId(), tagId);
    Assert.assertEquals(event.getObjectId(), objectId);
    Assert.assertEquals(event.getObjectType(), objectType);
    Assert.assertEquals(event.getTagDefinition(), tagDefinition);
    Assert.assertEquals(event.getTagDefinition().getId(), tagDefinitionId);
    Assert.assertEquals(event.getTagDefinition().getName(), tagDefinitionName);
    Assert.assertEquals(event.getTagDefinition().getDescription(), tagDefinitionDescription);
    Assert.assertEquals(event, event);
    Assert.assertEquals(event, new DefaultControlTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID()));
    Assert.assertTrue(event.equals(event));
    Assert.assertTrue(event.equals(new DefaultControlTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID())));
}
Also used : ObjectType(org.killbill.billing.ObjectType) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 15 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class TestDefaultUserTagCreationEvent method testPojo.

@Test(groups = "fast")
public void testPojo() 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 = UUID.randomUUID();
    final DefaultUserTagCreationEvent event = new DefaultUserTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
    Assert.assertEquals(event.getBusEventType(), BusInternalEvent.BusInternalEventType.USER_TAG_CREATION);
    Assert.assertEquals(event.getTagId(), tagId);
    Assert.assertEquals(event.getObjectId(), objectId);
    Assert.assertEquals(event.getObjectType(), objectType);
    Assert.assertEquals(event.getTagDefinition(), tagDefinition);
    Assert.assertEquals(event.getTagDefinition().getId(), tagDefinitionId);
    Assert.assertEquals(event.getTagDefinition().getName(), tagDefinitionName);
    Assert.assertEquals(event.getTagDefinition().getDescription(), tagDefinitionDescription);
    Assert.assertEquals(event, event);
    Assert.assertEquals(event, new DefaultUserTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID()));
    Assert.assertTrue(event.equals(event));
    Assert.assertTrue(event.equals(new DefaultUserTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID())));
}
Also used : ObjectType(org.killbill.billing.ObjectType) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

ObjectType (org.killbill.billing.ObjectType)41 UUID (java.util.UUID)27 Test (org.testng.annotations.Test)25 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)12 TagDefinition (org.killbill.billing.util.tag.TagDefinition)12 CacheLoaderArgument (org.killbill.billing.util.cache.CacheLoaderArgument)11 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)9 ObjectMapper (org.killbill.billing.util.jackson.ObjectMapper)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 TagInternalEvent (org.killbill.billing.events.TagInternalEvent)3 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)3 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 DefaultPlan (org.killbill.billing.catalog.DefaultPlan)2 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)2 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)2 ControlTagCreationInternalEvent (org.killbill.billing.events.ControlTagCreationInternalEvent)2 ControlTagDeletionInternalEvent (org.killbill.billing.events.ControlTagDeletionInternalEvent)2