use of org.killbill.billing.util.tag.dao.TagDefinitionModelDao 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(), 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.dao.TagDefinitionModelDao in project killbill by killbill.
the class TestTagStore method testDeleteTagBeforeDeleteTagDefinition.
@Test(groups = "slow")
public void testDeleteTagBeforeDeleteTagDefinition() throws TagDefinitionApiException, TagApiException {
final String definitionName = "TestTag1234567";
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
tagDefinitionDao.create(definitionName, "Some test tag", internalCallContext);
assertListenerStatus();
final TagDefinitionModelDao tagDefinition = tagDefinitionDao.getByName(definitionName, internalCallContext);
assertNotNull(tagDefinition);
final UUID objectId = UUID.randomUUID();
final Tag tag = new DescriptiveTag(tagDefinition.getId(), ObjectType.ACCOUNT, objectId, internalCallContext.getCreatedDate());
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagDao.create(new TagModelDao(tag), internalCallContext);
assertListenerStatus();
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagDao.deleteTag(objectId, ObjectType.ACCOUNT, tagDefinition.getId(), internalCallContext);
assertListenerStatus();
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
tagDefinitionDao.deleteById(tagDefinition.getId(), internalCallContext);
assertListenerStatus();
}
use of org.killbill.billing.util.tag.dao.TagDefinitionModelDao in project killbill by killbill.
the class TestTagStore method testTagDefinitionDeletionForUnusedDefinition.
@Test(groups = "slow")
public void testTagDefinitionDeletionForUnusedDefinition() throws TagDefinitionApiException {
final String definitionName = "TestTag1234";
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
tagDefinitionDao.create(definitionName, "Some test tag", internalCallContext);
assertListenerStatus();
TagDefinitionModelDao tagDefinition = tagDefinitionDao.getByName(definitionName, internalCallContext);
assertNotNull(tagDefinition);
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
tagDefinitionDao.deleteById(tagDefinition.getId(), internalCallContext);
assertListenerStatus();
tagDefinition = tagDefinitionDao.getByName(definitionName, internalCallContext);
assertNull(tagDefinition);
}
use of org.killbill.billing.util.tag.dao.TagDefinitionModelDao in project killbill by killbill.
the class TestPagination method testTagDefinitionsPagination.
@Test(groups = "slow", description = "Test Pagination: basic SqlDAO and DAO calls")
public void testTagDefinitionsPagination() throws Exception {
final TagDefinitionSqlDao tagDefinitionSqlDao = dbi.onDemand(TagDefinitionSqlDao.class);
for (int i = 0; i < 10; i++) {
final String definitionName = "name-" + i;
final String description = "description-" + i;
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
tagDefinitionDao.create(definitionName, description, internalCallContext);
assertListenerStatus();
}
// Tests via SQL dao directly
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.getAll(internalCallContext)).size(), 10);
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, 100L, "record_id", "asc", internalCallContext)).size(), 10);
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(5L, 100L, "record_id", "asc", internalCallContext)).size(), 5);
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(5L, 10L, "record_id", "asc", internalCallContext)).size(), 5);
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, 5L, "record_id", "asc", internalCallContext)).size(), 5);
for (int i = 0; i < 10; i++) {
final List<TagDefinitionModelDao> tagDefinitions = ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, (long) i, "record_id", "asc", internalCallContext));
Assert.assertEquals(tagDefinitions.size(), i);
for (int j = 0; j < tagDefinitions.size(); j++) {
Assert.assertEquals(tagDefinitions.get(j).getName(), "name-" + j);
Assert.assertEquals(tagDefinitions.get(j).getDescription(), "description-" + j);
}
}
// Tests via DAO (to test EntityDaoBase)
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.getAll(internalCallContext)).size(), 10);
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(0L, 100L, internalCallContext)).size(), 10);
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(5L, 100L, internalCallContext)).size(), 5);
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(5L, 10L, internalCallContext)).size(), 5);
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(0L, 5L, internalCallContext)).size(), 5);
for (int i = 0; i < 10; i++) {
final List<TagDefinitionModelDao> tagDefinitions = ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionDao.get(0L, (long) i, internalCallContext));
Assert.assertEquals(tagDefinitions.size(), i);
for (int j = 0; j < tagDefinitions.size(); j++) {
Assert.assertEquals(tagDefinitions.get(j).getName(), "name-" + j);
Assert.assertEquals(tagDefinitions.get(j).getDescription(), "description-" + j);
}
}
}
use of org.killbill.billing.util.tag.dao.TagDefinitionModelDao 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), 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