killbill-uncached

analytics: add tests for tag SQL dao Signed-off-by: Pierre-Alexandre

6/21/2012 6:55:05 PM

Details

diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountTagSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountTagSqlDao.java
new file mode 100644
index 0000000..20ccfc8
--- /dev/null
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountTagSqlDao.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.analytics.dao;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.skife.jdbi.v2.IDBI;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.ning.billing.analytics.TestWithEmbeddedDB;
+import com.ning.billing.analytics.model.BusinessAccountTag;
+
+public class TestBusinessAccountTagSqlDao extends TestWithEmbeddedDB {
+    private BusinessAccountTagSqlDao accountTagSqlDao;
+
+    @BeforeMethod(groups = "slow")
+    public void setUp() throws Exception {
+        final IDBI dbi = helper.getDBI();
+        accountTagSqlDao = dbi.onDemand(BusinessAccountTagSqlDao.class);
+    }
+
+    @Test(groups = "slow")
+    public void testCRUD() throws Exception {
+        final String accountKey = UUID.randomUUID().toString();
+        final String name = UUID.randomUUID().toString().substring(0, 20);
+
+        // Verify initial state
+        Assert.assertEquals(accountTagSqlDao.getTagsForAccount(accountKey).size(), 0);
+        Assert.assertEquals(accountTagSqlDao.removeTag(accountKey, name), 0);
+
+        // Add an entry
+        Assert.assertEquals(accountTagSqlDao.addTag(accountKey, name), 1);
+        final List<BusinessAccountTag> tagsForAccount = accountTagSqlDao.getTagsForAccount(accountKey);
+        Assert.assertEquals(tagsForAccount.size(), 1);
+
+        // Retrieve it
+        final BusinessAccountTag accountTag = tagsForAccount.get(0);
+        Assert.assertEquals(accountTag.getAccountKey(), accountKey);
+        Assert.assertEquals(accountTag.getName(), name);
+
+        // Delete it
+        Assert.assertEquals(accountTagSqlDao.removeTag(accountKey, name), 1);
+        Assert.assertEquals(accountTagSqlDao.getTagsForAccount(accountKey).size(), 0);
+    }
+
+    @Test(groups = "slow")
+    public void testSegmentation() throws Exception {
+        final String accountKey1 = UUID.randomUUID().toString();
+        final String name1 = UUID.randomUUID().toString().substring(0, 20);
+        final String accountKey2 = UUID.randomUUID().toString();
+        final String name2 = UUID.randomUUID().toString().substring(0, 20);
+
+        // Add a tag to both accounts
+        Assert.assertEquals(accountTagSqlDao.addTag(accountKey1, name1), 1);
+        Assert.assertEquals(accountTagSqlDao.addTag(accountKey2, name2), 1);
+
+        Assert.assertEquals(accountTagSqlDao.getTagsForAccount(accountKey1).size(), 1);
+        Assert.assertEquals(accountTagSqlDao.getTagsForAccount(accountKey2).size(), 1);
+
+        // Remove the tag for the first account
+        Assert.assertEquals(accountTagSqlDao.removeTag(accountKey1, name1), 1);
+
+        Assert.assertEquals(accountTagSqlDao.getTagsForAccount(accountKey1).size(), 0);
+        Assert.assertEquals(accountTagSqlDao.getTagsForAccount(accountKey2).size(), 1);
+    }
+
+    @Test(groups = "slow")
+    public void testHealthCheck() throws Exception {
+        // HealthCheck test to make sure MySQL is setup properly
+        try {
+            accountTagSqlDao.test();
+        } catch (Throwable t) {
+            Assert.fail(t.toString());
+        }
+    }
+}
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentTagSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentTagSqlDao.java
new file mode 100644
index 0000000..5ae8f48
--- /dev/null
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentTagSqlDao.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.analytics.dao;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.skife.jdbi.v2.IDBI;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.ning.billing.analytics.TestWithEmbeddedDB;
+import com.ning.billing.analytics.model.BusinessInvoicePaymentTag;
+
+public class TestBusinessInvoicePaymentTagSqlDao extends TestWithEmbeddedDB {
+    private BusinessInvoicePaymentTagSqlDao invoicePaymentTagSqlDao;
+
+    @BeforeMethod(groups = "slow")
+    public void setUp() throws Exception {
+        final IDBI dbi = helper.getDBI();
+        invoicePaymentTagSqlDao = dbi.onDemand(BusinessInvoicePaymentTagSqlDao.class);
+    }
+
+    @Test(groups = "slow")
+    public void testCRUD() throws Exception {
+        final String paymentId = UUID.randomUUID().toString();
+        final String name = UUID.randomUUID().toString().substring(0, 20);
+
+        // Verify initial state
+        Assert.assertEquals(invoicePaymentTagSqlDao.getTagsForInvoicePayment(paymentId).size(), 0);
+        Assert.assertEquals(invoicePaymentTagSqlDao.removeTag(paymentId, name), 0);
+
+        // Add an entry
+        Assert.assertEquals(invoicePaymentTagSqlDao.addTag(paymentId, name), 1);
+        final List<BusinessInvoicePaymentTag> tagsForInvoicePayment = invoicePaymentTagSqlDao.getTagsForInvoicePayment(paymentId);
+        Assert.assertEquals(tagsForInvoicePayment.size(), 1);
+
+        // Retrieve it
+        final BusinessInvoicePaymentTag invoicePaymentTag = tagsForInvoicePayment.get(0);
+        Assert.assertEquals(invoicePaymentTag.getPaymentId().toString(), paymentId);
+        Assert.assertEquals(invoicePaymentTag.getName(), name);
+
+        // Delete it
+        Assert.assertEquals(invoicePaymentTagSqlDao.removeTag(paymentId, name), 1);
+        Assert.assertEquals(invoicePaymentTagSqlDao.getTagsForInvoicePayment(paymentId).size(), 0);
+    }
+
+    @Test(groups = "slow")
+    public void testSegmentation() throws Exception {
+        final String paymentId1 = UUID.randomUUID().toString();
+        final String name1 = UUID.randomUUID().toString().substring(0, 20);
+        final String paymentId2 = UUID.randomUUID().toString();
+        final String name2 = UUID.randomUUID().toString().substring(0, 20);
+
+        // Add a tag to both invoice payments
+        Assert.assertEquals(invoicePaymentTagSqlDao.addTag(paymentId1, name1), 1);
+        Assert.assertEquals(invoicePaymentTagSqlDao.addTag(paymentId2, name2), 1);
+
+        Assert.assertEquals(invoicePaymentTagSqlDao.getTagsForInvoicePayment(paymentId1).size(), 1);
+        Assert.assertEquals(invoicePaymentTagSqlDao.getTagsForInvoicePayment(paymentId2).size(), 1);
+
+        // Remove the tag for the first invoice payment
+        Assert.assertEquals(invoicePaymentTagSqlDao.removeTag(paymentId1, name1), 1);
+
+        Assert.assertEquals(invoicePaymentTagSqlDao.getTagsForInvoicePayment(paymentId1).size(), 0);
+        Assert.assertEquals(invoicePaymentTagSqlDao.getTagsForInvoicePayment(paymentId2).size(), 1);
+    }
+
+    @Test(groups = "slow")
+    public void testHealthCheck() throws Exception {
+        // HealthCheck test to make sure MySQL is setup properly
+        try {
+            invoicePaymentTagSqlDao.test();
+        } catch (Throwable t) {
+            Assert.fail(t.toString());
+        }
+    }
+}
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceTagSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceTagSqlDao.java
new file mode 100644
index 0000000..24ee93f
--- /dev/null
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceTagSqlDao.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.analytics.dao;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.skife.jdbi.v2.IDBI;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.ning.billing.analytics.TestWithEmbeddedDB;
+import com.ning.billing.analytics.model.BusinessInvoiceTag;
+
+public class TestBusinessInvoiceTagSqlDao extends TestWithEmbeddedDB {
+    private BusinessInvoiceTagSqlDao invoiceTagSqlDao;
+
+    @BeforeMethod(groups = "slow")
+    public void setUp() throws Exception {
+        final IDBI dbi = helper.getDBI();
+        invoiceTagSqlDao = dbi.onDemand(BusinessInvoiceTagSqlDao.class);
+    }
+
+    @Test(groups = "slow")
+    public void testCRUD() throws Exception {
+        final String invoiceId = UUID.randomUUID().toString();
+        final String name = UUID.randomUUID().toString().substring(0, 20);
+
+        // Verify initial state
+        Assert.assertEquals(invoiceTagSqlDao.getTagsForInvoice(invoiceId).size(), 0);
+        Assert.assertEquals(invoiceTagSqlDao.removeTag(invoiceId, name), 0);
+
+        // Add an entry
+        Assert.assertEquals(invoiceTagSqlDao.addTag(invoiceId, name), 1);
+        final List<BusinessInvoiceTag> tagsForInvoice = invoiceTagSqlDao.getTagsForInvoice(invoiceId);
+        Assert.assertEquals(tagsForInvoice.size(), 1);
+
+        // Retrieve it
+        final BusinessInvoiceTag invoiceTag = tagsForInvoice.get(0);
+        Assert.assertEquals(invoiceTag.getInvoiceId().toString(), invoiceId);
+        Assert.assertEquals(invoiceTag.getName(), name);
+
+        // Delete it
+        Assert.assertEquals(invoiceTagSqlDao.removeTag(invoiceId, name), 1);
+        Assert.assertEquals(invoiceTagSqlDao.getTagsForInvoice(invoiceId).size(), 0);
+    }
+
+    @Test(groups = "slow")
+    public void testSegmentation() throws Exception {
+        final String invoiceId1 = UUID.randomUUID().toString();
+        final String name1 = UUID.randomUUID().toString().substring(0, 20);
+        final String invoiceId2 = UUID.randomUUID().toString();
+        final String name2 = UUID.randomUUID().toString().substring(0, 20);
+
+        // Add a tag to both invoices
+        Assert.assertEquals(invoiceTagSqlDao.addTag(invoiceId1, name1), 1);
+        Assert.assertEquals(invoiceTagSqlDao.addTag(invoiceId2, name2), 1);
+
+        Assert.assertEquals(invoiceTagSqlDao.getTagsForInvoice(invoiceId1).size(), 1);
+        Assert.assertEquals(invoiceTagSqlDao.getTagsForInvoice(invoiceId2).size(), 1);
+
+        // Remove the tag for the first invoice
+        Assert.assertEquals(invoiceTagSqlDao.removeTag(invoiceId1, name1), 1);
+
+        Assert.assertEquals(invoiceTagSqlDao.getTagsForInvoice(invoiceId1).size(), 0);
+        Assert.assertEquals(invoiceTagSqlDao.getTagsForInvoice(invoiceId2).size(), 1);
+    }
+
+    @Test(groups = "slow")
+    public void testHealthCheck() throws Exception {
+        // HealthCheck test to make sure MySQL is setup properly
+        try {
+            invoiceTagSqlDao.test();
+        } catch (Throwable t) {
+            Assert.fail(t.toString());
+        }
+    }
+}
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionTagSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionTagSqlDao.java
new file mode 100644
index 0000000..8b4740f
--- /dev/null
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionTagSqlDao.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.analytics.dao;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.skife.jdbi.v2.IDBI;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.ning.billing.analytics.TestWithEmbeddedDB;
+import com.ning.billing.analytics.model.BusinessSubscriptionTransitionTag;
+
+public class TestBusinessSubscriptionTransitionTagSqlDao extends TestWithEmbeddedDB {
+    private BusinessSubscriptionTransitionTagSqlDao subscriptionTransitionTagSqlDao;
+
+    @BeforeMethod(groups = "slow")
+    public void setUp() throws Exception {
+        final IDBI dbi = helper.getDBI();
+        subscriptionTransitionTagSqlDao = dbi.onDemand(BusinessSubscriptionTransitionTagSqlDao.class);
+    }
+
+    @Test(groups = "slow")
+    public void testCRUD() throws Exception {
+        final String externalKey = UUID.randomUUID().toString();
+        final String name = UUID.randomUUID().toString().substring(0, 20);
+
+        // Verify initial state
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransition(externalKey).size(), 0);
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.removeTag(externalKey, name), 0);
+
+        // Add an entry
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.addTag(externalKey, name), 1);
+        final List<BusinessSubscriptionTransitionTag> tagsForBusinessSubscriptionTransition = subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransition(externalKey);
+        Assert.assertEquals(tagsForBusinessSubscriptionTransition.size(), 1);
+
+        // Retrieve it
+        final BusinessSubscriptionTransitionTag subscriptionTransitionTag = tagsForBusinessSubscriptionTransition.get(0);
+        Assert.assertEquals(subscriptionTransitionTag.getExternalKey(), externalKey);
+        Assert.assertEquals(subscriptionTransitionTag.getName(), name);
+
+        // Delete it
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.removeTag(externalKey, name), 1);
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransition(externalKey).size(), 0);
+    }
+
+    @Test(groups = "slow")
+    public void testSegmentation() throws Exception {
+        final String externalKey1 = UUID.randomUUID().toString();
+        final String name1 = UUID.randomUUID().toString().substring(0, 20);
+        final String externalKey2 = UUID.randomUUID().toString();
+        final String name2 = UUID.randomUUID().toString().substring(0, 20);
+
+        // Add a tag to both transitions
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.addTag(externalKey1, name1), 1);
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.addTag(externalKey2, name2), 1);
+
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransition(externalKey1).size(), 1);
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransition(externalKey2).size(), 1);
+
+        // Remove the tag for the first transition
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.removeTag(externalKey1, name1), 1);
+
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransition(externalKey1).size(), 0);
+        Assert.assertEquals(subscriptionTransitionTagSqlDao.getTagsForBusinessSubscriptionTransition(externalKey2).size(), 1);
+    }
+
+    @Test(groups = "slow")
+    public void testHealthCheck() throws Exception {
+        // HealthCheck test to make sure MySQL is setup properly
+        try {
+            subscriptionTransitionTagSqlDao.test();
+        } catch (Throwable t) {
+            Assert.fail(t.toString());
+        }
+    }
+}