killbill-uncached

Details

diff --git a/account/src/main/java/com/ning/billing/account/dao/DefaultAccountDao.java b/account/src/main/java/com/ning/billing/account/dao/DefaultAccountDao.java
index 1e00dba..623aa01 100644
--- a/account/src/main/java/com/ning/billing/account/dao/DefaultAccountDao.java
+++ b/account/src/main/java/com/ning/billing/account/dao/DefaultAccountDao.java
@@ -16,6 +16,7 @@
 
 package com.ning.billing.account.dao;
 
+import java.sql.DataTruncation;
 import java.util.List;
 import java.util.UUID;
 
@@ -89,7 +90,6 @@ public class DefaultAccountDao implements AccountDao {
     public void create(final Account account) throws AccountApiException {
         final String key = account.getExternalKey();
         try {
-
             accountSqlDao.inTransaction(new Transaction<Void, AccountSqlDao>() {
                 @Override
                 public Void inTransaction(final AccountSqlDao transactionalDao, final TransactionStatus status) throws AccountApiException, Bus.EventBusException {
@@ -109,6 +109,8 @@ public class DefaultAccountDao implements AccountDao {
         } catch (RuntimeException re) {
             if (re.getCause() instanceof AccountApiException) {
                 throw (AccountApiException) re.getCause();
+            } else if (re.getCause() instanceof DataTruncation) {
+                throw new AccountApiException(ErrorCode.DATA_TRUNCATION, re.getCause().getMessage());
             } else {
                 throw re;
             }
diff --git a/account/src/test/java/com/ning/billing/account/dao/AccountDaoTestBase.java b/account/src/test/java/com/ning/billing/account/dao/AccountDaoTestBase.java
index f4f530e..964eb6a 100644
--- a/account/src/test/java/com/ning/billing/account/dao/AccountDaoTestBase.java
+++ b/account/src/test/java/com/ning/billing/account/dao/AccountDaoTestBase.java
@@ -21,7 +21,10 @@ import static org.testng.Assert.fail;
 import java.io.IOException;
 
 import org.apache.commons.io.IOUtils;
+import org.skife.jdbi.v2.Handle;
 import org.skife.jdbi.v2.IDBI;
+import org.skife.jdbi.v2.TransactionCallback;
+import org.skife.jdbi.v2.TransactionStatus;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 
@@ -31,6 +34,7 @@ import com.google.inject.Stage;
 import com.ning.billing.account.glue.AccountModuleWithEmbeddedDb;
 import com.ning.billing.util.bus.DefaultBusService;
 import com.ning.billing.util.bus.BusService;
+import org.testng.annotations.BeforeMethod;
 
 public abstract class AccountDaoTestBase {
     protected AccountModuleWithEmbeddedDb module;
@@ -68,4 +72,29 @@ public abstract class AccountDaoTestBase {
     {
         module.stopDb();
     }
+
+    @BeforeMethod(alwaysRun = true)
+    public void cleanupData() {
+        dbi.inTransaction(new TransactionCallback<Void>() {
+            @Override
+            public Void inTransaction(Handle h, TransactionStatus status) throws Exception {
+                h.execute("truncate table accounts");
+                h.execute("truncate table entitlement_events");
+                h.execute("truncate table subscriptions");
+                h.execute("truncate table bundles");
+                h.execute("truncate table notifications");
+                h.execute("truncate table claimed_notifications");
+                h.execute("truncate table invoices");
+                h.execute("truncate table fixed_invoice_items");
+                h.execute("truncate table recurring_invoice_items");
+                h.execute("truncate table tag_definitions");
+                h.execute("truncate table tags");
+                h.execute("truncate table custom_fields");
+                h.execute("truncate table invoice_payments");
+                h.execute("truncate table payment_attempts");
+                h.execute("truncate table payments");
+                return null;
+            }
+        });
+    }
 }
diff --git a/account/src/test/java/com/ning/billing/account/dao/TestSimpleAccountDao.java b/account/src/test/java/com/ning/billing/account/dao/TestSimpleAccountDao.java
index f925247..3c726aa 100644
--- a/account/src/test/java/com/ning/billing/account/dao/TestSimpleAccountDao.java
+++ b/account/src/test/java/com/ning/billing/account/dao/TestSimpleAccountDao.java
@@ -42,7 +42,7 @@ import com.ning.billing.util.tag.dao.TagDefinitionSqlDao;
 
 @Test(groups = {"account-dao"})
 public class TestSimpleAccountDao extends AccountDaoTestBase {
-    private DefaultAccount createTestAccount() {
+    private AccountBuilder createTestAccountBuilder() {
         String thisKey = "test" + UUID.randomUUID().toString();
         String lastName = UUID.randomUUID().toString();
         String thisEmail = "me@me.com" + " " + UUID.randomUUID();
@@ -65,13 +65,12 @@ public class TestSimpleAccountDao extends AccountDaoTestBase {
                                    .locale(locale)
                                    .timeZone(timeZone)
                                    .createdDate(createdDate)
-                                   .updatedDate(updatedDate)
-                                   .build();
+                                   .updatedDate(updatedDate);
     }
 
+    @Test
     public void testBasic() throws AccountApiException {
-
-        Account a = createTestAccount();
+        Account a = createTestAccountBuilder().build();
         accountDao.create(a);
         String key = a.getExternalKey();
 
@@ -88,9 +87,26 @@ public class TestSimpleAccountDao extends AccountDaoTestBase {
         assertTrue(all.size() >= 1);
     }
 
+    // simple test to ensure long phone numbers can be stored
+    @Test
+    public void testLongPhoneNumber() throws AccountApiException {
+        Account account = createTestAccountBuilder().phone("123456789012345678901234").build();
+        accountDao.create(account);
+
+        Account saved = accountDao.getAccountByKey(account.getExternalKey());
+        assertNotNull(saved);
+    }
+
+    // simple test to ensure excessively long phone numbers cannot be stored
+    @Test(expectedExceptions = {AccountApiException.class})
+    public void testOverlyLongPhoneNumber() throws AccountApiException {
+        Account account = createTestAccountBuilder().phone("12345678901234567890123456").build();
+        accountDao.create(account);
+    }
+
     @Test
     public void testGetById() throws AccountApiException {
-        Account account = createTestAccount();
+        Account account = createTestAccountBuilder().build();
         UUID id = account.getId();
         String key = account.getExternalKey();
         String name = account.getName();
@@ -109,7 +125,7 @@ public class TestSimpleAccountDao extends AccountDaoTestBase {
 
     @Test
     public void testCustomFields() throws AccountApiException {
-        Account account = createTestAccount();
+        Account account = createTestAccountBuilder().build();
         String fieldName = "testField1";
         String fieldValue = "testField1_value";
         account.setFieldValue(fieldName, fieldValue);
@@ -124,7 +140,7 @@ public class TestSimpleAccountDao extends AccountDaoTestBase {
 
     @Test
     public void testTags() throws AccountApiException {
-        Account account = createTestAccount();
+        Account account = createTestAccountBuilder().build();
         TagDefinition definition = new DefaultTagDefinition("Test Tag", "For testing only", "Test System");
         TagDefinitionSqlDao tagDescriptionDao = dbi.onDemand(TagDefinitionSqlDao.class);
         tagDescriptionDao.create(definition);
@@ -146,7 +162,7 @@ public class TestSimpleAccountDao extends AccountDaoTestBase {
 
     @Test
     public void testGetIdFromKey() throws AccountApiException {
-        Account account = createTestAccount();
+        Account account = createTestAccountBuilder().build();
         accountDao.create(account);
 
         try {
@@ -159,12 +175,13 @@ public class TestSimpleAccountDao extends AccountDaoTestBase {
 
     @Test(expectedExceptions = AccountApiException.class)
     public void testGetIdFromKeyForNullKey() throws AccountApiException {
-        accountDao.getIdFromKey(null);
+        String key = null;
+        accountDao.getIdFromKey(key);
     }
 
     @Test
     public void testUpdate() throws Exception {
-        final Account account = createTestAccount();
+        final Account account = createTestAccountBuilder().build();
         accountDao.create(account);
 
         AccountData accountData = new AccountData() {
@@ -365,7 +382,7 @@ public class TestSimpleAccountDao extends AccountDaoTestBase {
     @Test(groups={"slow"},enabled=true)
     public void testDelete() throws AccountApiException {
 
-        Account a = createTestAccount();
+        Account a = createTestAccountBuilder().build();
         accountDao.create(a);
         String key = a.getExternalKey();
 
diff --git a/api/src/main/java/com/ning/billing/ErrorCode.java b/api/src/main/java/com/ning/billing/ErrorCode.java
index f7825e9..a90c6aa 100644
--- a/api/src/main/java/com/ning/billing/ErrorCode.java
+++ b/api/src/main/java/com/ning/billing/ErrorCode.java
@@ -22,7 +22,7 @@ public enum ErrorCode {
      * Range 0 : COMMON EXCEPTIONS
      */
     NOT_IMPLEMENTED(1, "Api not implemented yet"),
-
+    DATA_TRUNCATION(2, "Data truncation error. (%s)"),
     /*
      *
      * Range 1000 : ENTITLEMENTS