diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestTagApi.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestTagApi.java
index 91249e5..d32c7c4 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestTagApi.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestTagApi.java
@@ -16,6 +16,7 @@
package com.ning.billing.beatrix.integration;
+import java.util.Collection;
import java.util.List;
import org.testng.Assert;
@@ -32,60 +33,50 @@ import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.entitlement.api.user.SubscriptionData;
import com.ning.billing.invoice.api.Invoice;
-import com.ning.billing.util.api.TagUserApi;
-import com.ning.billing.util.callcontext.CallContext;
-import com.ning.billing.util.callcontext.CallContextBase;
-import com.ning.billing.util.callcontext.DefaultCallContext;
import com.ning.billing.util.tag.ControlTagType;
import com.ning.billing.util.tag.Tag;
import com.ning.billing.util.tag.TagDefinition;
-import com.google.inject.Inject;
-
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
public class TestTagApi extends TestIntegrationBase {
-
private Account account;
- @Inject
- private TagUserApi tagApi;
-
@Override
- @BeforeMethod(groups = {"slow"})
+ @BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
super.beforeMethod();
account = createAccountWithNonOsgiPaymentMethod(getAccountData(25));
assertNotNull(account);
}
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testApiTagOnAccount() throws Exception {
-
busHandler.pushExpectedEvents(NextEvent.TAG);
- tagApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_INVOICING_OFF.getId(), callContext);
+ tagUserApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_INVOICING_OFF.getId(), callContext);
assertTrue(busHandler.isCompleted(DELAY));
busHandler.pushExpectedEvents(NextEvent.TAG);
- tagApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_PAY_OFF.getId(), callContext);
+ tagUserApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_PAY_OFF.getId(), callContext);
assertTrue(busHandler.isCompleted(DELAY));
- List<Tag> tags = tagApi.getTagsForAccount(account.getId(), callContext);
+ List<Tag> tags = tagUserApi.getTagsForAccount(account.getId(), callContext);
Assert.assertEquals(tags.size(), 2);
+ checkTagsExists(tags);
- tags = tagApi.getTagsForObject(account.getId(), ObjectType.ACCOUNT, callContext);
+ tags = tagUserApi.getTagsForObject(account.getId(), ObjectType.ACCOUNT, callContext);
Assert.assertEquals(tags.size(), 2);
+ checkTagsExists(tags);
- tags = tagApi.getTagsForAccountType(account.getId(), ObjectType.ACCOUNT, callContext);
+ tags = tagUserApi.getTagsForAccountType(account.getId(), ObjectType.ACCOUNT, callContext);
Assert.assertEquals(tags.size(), 2);
+ checkTagsExists(tags);
}
-
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testApiTagOnInvoice() throws Exception {
-
//
// Create necessary logic to end up with an Invoice object on that account.
//
@@ -115,48 +106,55 @@ public class TestTagApi extends TestIntegrationBase {
// Create a new tag definition
//
busHandler.pushExpectedEvents(NextEvent.TAG_DEFINITION);
- TagDefinition tagDefinition = tagApi.create("foo", "foo desc", callContext);
+ final TagDefinition tagDefinition = tagUserApi.create("foo", "foo desc", callContext);
assertTrue(busHandler.isCompleted(DELAY));
//
// Add 2 Tags on the invoice (1 control tag and 1 user tag)
//
busHandler.pushExpectedEvents(NextEvent.TAG);
- tagApi.addTag(invoice.getId(), ObjectType.INVOICE, ControlTagType.WRITTEN_OFF.getId(), callContext);
+ tagUserApi.addTag(invoice.getId(), ObjectType.INVOICE, ControlTagType.WRITTEN_OFF.getId(), callContext);
assertTrue(busHandler.isCompleted(DELAY));
busHandler.pushExpectedEvents(NextEvent.TAG);
- tagApi.addTag(invoice.getId(), ObjectType.INVOICE, tagDefinition.getId(), callContext);
+ tagUserApi.addTag(invoice.getId(), ObjectType.INVOICE, tagDefinition.getId(), callContext);
assertTrue(busHandler.isCompleted(DELAY));
- List<Tag> tags = tagApi.getTagsForAccount(account.getId(), callContext);
+ List<Tag> tags = tagUserApi.getTagsForAccount(account.getId(), callContext);
Assert.assertEquals(tags.size(), 2);
+ checkTagsExists(tags);
- tags = tagApi.getTagsForObject(invoice.getId(), ObjectType.INVOICE, callContext);
+ tags = tagUserApi.getTagsForObject(invoice.getId(), ObjectType.INVOICE, callContext);
Assert.assertEquals(tags.size(), 2);
+ checkTagsExists(tags);
- tags = tagApi.getTagsForAccountType(account.getId(), ObjectType.INVOICE, callContext);
+ tags = tagUserApi.getTagsForAccountType(account.getId(), ObjectType.INVOICE, callContext);
Assert.assertEquals(tags.size(), 2);
-
+ checkTagsExists(tags);
//
// Add a tag on the account itself and retry
//
busHandler.pushExpectedEvents(NextEvent.TAG);
- tagApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_PAY_OFF.getId(), callContext);
+ tagUserApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_PAY_OFF.getId(), callContext);
assertTrue(busHandler.isCompleted(DELAY));
- tags = tagApi.getTagsForAccount(account.getId(), callContext);
+ tags = tagUserApi.getTagsForAccount(account.getId(), callContext);
Assert.assertEquals(tags.size(), 3);
+ checkTagsExists(tags);
- tags = tagApi.getTagsForObject(invoice.getId(), ObjectType.INVOICE, callContext);
+ tags = tagUserApi.getTagsForObject(invoice.getId(), ObjectType.INVOICE, callContext);
Assert.assertEquals(tags.size(), 2);
+ checkTagsExists(tags);
- tags = tagApi.getTagsForAccountType(account.getId(), ObjectType.INVOICE, callContext);
+ tags = tagUserApi.getTagsForAccountType(account.getId(), ObjectType.INVOICE, callContext);
Assert.assertEquals(tags.size(), 2);
-
-
+ checkTagsExists(tags);
}
-
+ private void checkTagsExists(final Collection<Tag> tags) {
+ for (final Tag tag : tags) {
+ Assert.assertNotNull(recordIdApi.getRecordId(tag.getId(), ObjectType.TAG, callContext));
+ }
+ }
}
diff --git a/util/src/main/java/com/ning/billing/util/tag/api/DefaultTagUserApi.java b/util/src/main/java/com/ning/billing/util/tag/api/DefaultTagUserApi.java
index 0e4c188..61336ef 100644
--- a/util/src/main/java/com/ning/billing/util/tag/api/DefaultTagUserApi.java
+++ b/util/src/main/java/com/ning/billing/util/tag/api/DefaultTagUserApi.java
@@ -153,8 +153,8 @@ public class DefaultTagUserApi implements TagUserApi {
@Override
public Tag apply(final TagModelDao input) {
return TagModelDaoHelper.isControlTag(input.getTagDefinitionId()) ?
- new DefaultControlTag(ControlTagType.getTypeFromId(input.getTagDefinitionId()), input.getObjectType(), input.getObjectId(), input.getCreatedDate()) :
- new DescriptiveTag(input.getTagDefinitionId(), input.getObjectType(), input.getObjectId(), input.getCreatedDate());
+ new DefaultControlTag(input.getId(), ControlTagType.getTypeFromId(input.getTagDefinitionId()), input.getObjectType(), input.getObjectId(), input.getCreatedDate()) :
+ new DescriptiveTag(input.getId(), input.getTagDefinitionId(), input.getObjectType(), input.getObjectId(), input.getCreatedDate());
}
}));
}