Search in sources :

Example 6 with TagDefinitionModelDao

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);
}
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 7 with TagDefinitionModelDao

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

Example 8 with TagDefinitionModelDao

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

Example 9 with TagDefinitionModelDao

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

Example 10 with TagDefinitionModelDao

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

TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)16 Test (org.testng.annotations.Test)15 UUID (java.util.UUID)12 TagDefinition (org.killbill.billing.util.tag.TagDefinition)9 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)8 TagModelDao (org.killbill.billing.util.tag.dao.TagModelDao)5 ObjectType (org.killbill.billing.ObjectType)4 TagDefinitionInternalEvent (org.killbill.billing.events.TagDefinitionInternalEvent)4 TagInternalEvent (org.killbill.billing.events.TagInternalEvent)4 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)2 Tag (org.killbill.billing.util.tag.Tag)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 ControlTagCreationInternalEvent (org.killbill.billing.events.ControlTagCreationInternalEvent)1 ControlTagDefinitionCreationInternalEvent (org.killbill.billing.events.ControlTagDefinitionCreationInternalEvent)1 ControlTagDefinitionDeletionInternalEvent (org.killbill.billing.events.ControlTagDefinitionDeletionInternalEvent)1 ControlTagDeletionInternalEvent (org.killbill.billing.events.ControlTagDeletionInternalEvent)1 UserTagCreationInternalEvent (org.killbill.billing.events.UserTagCreationInternalEvent)1 UserTagDefinitionCreationInternalEvent (org.killbill.billing.events.UserTagDefinitionCreationInternalEvent)1 UserTagDefinitionDeletionInternalEvent (org.killbill.billing.events.UserTagDefinitionDeletionInternalEvent)1 UserTagDeletionInternalEvent (org.killbill.billing.events.UserTagDeletionInternalEvent)1