killbill-memoizeit

util: fix error when fetching tags The wrong constructors

4/18/2013 8:22:51 PM

Details

diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
index bdef87f..12bc382 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
@@ -83,6 +83,7 @@ import com.ning.billing.payment.api.PaymentApiException;
 import com.ning.billing.payment.api.PaymentMethodPlugin;
 import com.ning.billing.payment.api.TestPaymentMethodPluginBase;
 import com.ning.billing.payment.provider.MockPaymentProviderPlugin;
+import com.ning.billing.util.api.RecordIdApi;
 import com.ning.billing.util.api.TagUserApi;
 import com.ning.billing.util.config.OSGIConfig;
 import com.ning.billing.util.svcapi.account.AccountInternalApi;
@@ -201,6 +202,8 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implemen
     @Inject
     protected OSGIConfig osgiConfig;
 
+    @Inject
+    protected RecordIdApi recordIdApi;
 
     protected TestApiListener busHandler;
 
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());
             }
         }));
     }