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());
}
}
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());
}
}
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);
}
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())));
}
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())));
}
Aggregations