Search in sources :

Example 1 with TagModelDao

use of org.killbill.billing.util.tag.dao.TagModelDao 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 2 with TagModelDao

use of org.killbill.billing.util.tag.dao.TagModelDao 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 3 with TagModelDao

use of org.killbill.billing.util.tag.dao.TagModelDao in project killbill by killbill.

the class TestTagStore method testControlTagCreation.

@Test(groups = "slow")
public void testControlTagCreation() throws TagApiException {
    final UUID accountId = UUID.randomUUID();
    final ControlTag tag = new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF, ObjectType.ACCOUNT, accountId, clock.getUTCNow());
    eventsListener.pushExpectedEvent(NextEvent.TAG);
    tagDao.create(new TagModelDao(tag), internalCallContext);
    assertListenerStatus();
    final TagModelDao savedTag = tagDao.getById(tag.getId(), internalCallContext);
    assertEquals(savedTag.getTagDefinitionId(), tag.getTagDefinitionId());
    assertEquals(savedTag.getId(), tag.getId());
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 4 with TagModelDao

use of org.killbill.billing.util.tag.dao.TagModelDao in project killbill by killbill.

the class TestCache method testAllCachesAfterGetById.

@Test(groups = "slow")
public void testAllCachesAfterGetById() throws Exception {
    this.transactionalSqlDao = new EntitySqlDaoTransactionalJdbiWrapper(dbi, clock, controlCacheDispatcher, nonEntityDao, internalCallContextFactory);
    final TagModelDao tag = new TagModelDao(clock.getUTCNow(), UUID.randomUUID(), UUID.randomUUID(), ObjectType.TAG);
    insertTag(tag);
    // Verify we start with nothing in the cache
    Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 0);
    Assert.assertEquals(getCacheSize(CacheType.ACCOUNT_RECORD_ID), 0);
    Assert.assertEquals(getCacheSize(CacheType.TENANT_RECORD_ID), 0);
    Assert.assertEquals(getCacheSize(CacheType.OBJECT_ID), 0);
    final TagModelDao result = getById(tag.getId());
    Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 1);
    Assert.assertEquals(getCacheSize(CacheType.ACCOUNT_RECORD_ID), 1);
    Assert.assertEquals(getCacheSize(CacheType.TENANT_RECORD_ID), 1);
    Assert.assertEquals(getCacheSize(CacheType.OBJECT_ID), 1);
    final Long recordId = (Long) controlCacheDispatcher.getCacheController(CacheType.RECORD_ID).get(tag.getId().toString(), new CacheLoaderArgument(ObjectType.TAG));
    Assert.assertEquals(recordId, result.getRecordId());
    final Long tenantRecordId = (Long) controlCacheDispatcher.getCacheController(CacheType.TENANT_RECORD_ID).get(tag.getId().toString(), new CacheLoaderArgument(ObjectType.TAG));
    Assert.assertEquals(tenantRecordId, result.getTenantRecordId());
    final UUID objectId = (UUID) controlCacheDispatcher.getCacheController(CacheType.OBJECT_ID).get(TableName.TAG + CacheControllerDispatcher.CACHE_KEY_SEPARATOR + recordId, new CacheLoaderArgument(ObjectType.TAG));
    Assert.assertEquals(objectId, result.getId());
    final Long accountRecordId = (Long) controlCacheDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID).get(tag.getId().toString(), new CacheLoaderArgument(ObjectType.TAG));
    Assert.assertEquals(accountRecordId, result.getAccountRecordId());
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) EntitySqlDaoTransactionalJdbiWrapper(org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 5 with TagModelDao

use of org.killbill.billing.util.tag.dao.TagModelDao 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

TagModelDao (org.killbill.billing.util.tag.dao.TagModelDao)10 Test (org.testng.annotations.Test)7 UUID (java.util.UUID)6 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)5 EntitySqlDaoTransactionalJdbiWrapper (org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper)2 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)2 Tag (org.killbill.billing.util.tag.Tag)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 TagApiException (org.killbill.billing.util.api.TagApiException)1