killbill-memoizeit

fixed pro-ration rounding issues; modified MysqlTestingHelper

2/21/2012 10:22:16 PM

Changes

Details

diff --git a/account/src/main/resources/com/ning/billing/account/ddl.sql b/account/src/main/resources/com/ning/billing/account/ddl.sql
index 58b47f0..fd2f6f8 100644
--- a/account/src/main/resources/com/ning/billing/account/ddl.sql
+++ b/account/src/main/resources/com/ning/billing/account/ddl.sql
@@ -17,7 +17,7 @@ CREATE TABLE accounts (
     state_or_province varchar(50) DEFAULT NULL,
     country varchar(50) DEFAULT NULL,
     postal_code varchar(11) DEFAULT NULL,
-    phone varchar(13) DEFAULT NULL,
+    phone varchar(25) DEFAULT NULL,
     created_dt datetime,
     updated_dt datetime,
     PRIMARY KEY(id)
@@ -25,3 +25,48 @@ CREATE TABLE accounts (
 CREATE UNIQUE INDEX accounts_external_key ON accounts(external_key);
 CREATE UNIQUE INDEX accounts_email ON accounts(email);
 
+DROP TABLE IF EXISTS account_history;
+CREATE TABLE account_history (
+    id char(36) NOT NULL,
+    external_key varchar(128) NULL,
+    email varchar(50) NOT NULL,
+    name varchar(100) NOT NULL,
+    first_name_length int NOT NULL,
+    currency char(3) DEFAULT NULL,
+    billing_cycle_day int DEFAULT NULL,
+    payment_provider_name varchar(20) DEFAULT NULL,
+    time_zone varchar(50) DEFAULT NULL,
+    locale varchar(5) DEFAULT NULL,
+    address1 varchar(100) DEFAULT NULL,
+    address2 varchar(100) DEFAULT NULL,
+    company_name varchar(50) DEFAULT NULL,
+    city varchar(50) DEFAULT NULL,
+    state_or_province varchar(50) DEFAULT NULL,
+    country varchar(50) DEFAULT NULL,
+    postal_code varchar(11) DEFAULT NULL,
+    phone varchar(25) DEFAULT NULL,
+    date datetime
+) ENGINE=innodb;
+CREATE INDEX account_id ON account_history(id);
+
+CREATE TRIGGER store_account_history_on_insert AFTER INSERT ON accounts
+    FOR EACH ROW
+        INSERT INTO account_history (id, external_key, email, name, first_name_length, currency,
+                                    billing_cycle_day, payment_provider_name, time_zone, locale, 
+                                    address1, address2, company_name, city, state_or_province, 
+                                    country, postal_code, phone, date)
+        VALUES (NEW.id, NEW.external_key, NEW.email, NEW.name, NEW.first_name_length, NEW.currency,
+                NEW.billing_cycle_day, NEW.payment_provider_name, NEW.time_zone, NEW.locale, 
+                NEW.address1, NEW.address2, NEW.company_name, NEW.city, NEW.state_or_province, 
+                NEW.country, NEW.postal_code, NEW.phone, NEW.created_dt);
+
+CREATE TRIGGER store_account_history_on_update AFTER UPDATE ON accounts
+    FOR EACH ROW
+        INSERT INTO account_history (id, external_key, email, name, first_name_length, currency,
+                                    billing_cycle_day, payment_provider_name, time_zone, locale, 
+                                    address1, address2, company_name, city, state_or_province, 
+                                    country, postal_code, phone, date)
+        VALUES (NEW.id, NEW.external_key, NEW.email, NEW.name, NEW.first_name_length, NEW.currency,
+                NEW.billing_cycle_day, NEW.payment_provider_name, NEW.time_zone, NEW.locale, 
+                NEW.address1, NEW.address2, NEW.company_name, NEW.city, NEW.state_or_province, 
+                NEW.country, NEW.postal_code, NEW.phone, NEW.updated_dt);
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 1c118a9..f925247 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
@@ -125,7 +125,7 @@ public class TestSimpleAccountDao extends AccountDaoTestBase {
     @Test
     public void testTags() throws AccountApiException {
         Account account = createTestAccount();
-        TagDefinition definition = new DefaultTagDefinition("Test Tag", "For testing only", "Test System", new DateTime());
+        TagDefinition definition = new DefaultTagDefinition("Test Tag", "For testing only", "Test System");
         TagDefinitionSqlDao tagDescriptionDao = dbi.onDemand(TagDefinitionSqlDao.class);
         tagDescriptionDao.create(definition);
 
diff --git a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
index 6054529..528abb5 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
@@ -74,8 +74,8 @@ public class TestAnalyticsService
 {
     private static final String KEY = "12345";
     private static final String ACCOUNT_KEY = "pierre-12345";
-    private static final DefaultTagDefinition TAG_ONE = new DefaultTagDefinition("batch20", "something", "pierre", new DateTime(DateTimeZone.UTC));
-    private static final DefaultTagDefinition TAG_TWO = new DefaultTagDefinition("awesome", "something", "pierre", new DateTime(DateTimeZone.UTC));
+    private static final DefaultTagDefinition TAG_ONE = new DefaultTagDefinition("batch20", "something", "pierre");
+    private static final DefaultTagDefinition TAG_TWO = new DefaultTagDefinition("awesome", "something", "pierre");
 
     @Inject
     private AccountUserApi accountApi;
diff --git a/api/src/main/java/com/ning/billing/util/tag/TagDefinition.java b/api/src/main/java/com/ning/billing/util/tag/TagDefinition.java
index d5cc5c1..1e17866 100644
--- a/api/src/main/java/com/ning/billing/util/tag/TagDefinition.java
+++ b/api/src/main/java/com/ning/billing/util/tag/TagDefinition.java
@@ -24,7 +24,5 @@ public interface TagDefinition extends Entity {
 
     String getCreatedBy();
 
-    DateTime getCreationDate();
-
     String getDescription();
 }
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
index eb7b72a..cdd7464 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
@@ -22,7 +22,6 @@ import static org.testng.Assert.assertTrue;
 
 import java.io.IOException;
 import java.math.BigDecimal;
-import java.util.Iterator;
 import java.util.List;
 import java.util.UUID;
 
@@ -267,7 +266,7 @@ public class TestBasic {
         Thread.sleep(600000);
     }
 
-    @Test(groups = "stress", enabled = true)
+    @Test(groups = "stress", enabled = false)
     public void stressTest() throws Exception {
         final int maxIterations = 7;
         for (int curIteration = 0; curIteration < maxIterations; curIteration++) {
@@ -289,7 +288,7 @@ public class TestBasic {
 
     private void testBasePlanComplete(DateTime initialCreationDate, int billingDay,
                                       boolean proRationExpected) throws Exception {
-        long DELAY = 2000;
+        long DELAY = 5000;
 
         log.info("Beginning test with BCD of " + billingDay);
         Account account = accountUserApi.createAccount(getAccountData(billingDay), null, null);
@@ -297,7 +296,7 @@ public class TestBasic {
         assertNotNull(account);
 
         // set clock to the initial start date
-        clock.setDeltaFromReality(initialCreationDate.getMillis() - DateTime.now().getMillis());
+        clock.setDeltaFromReality(initialCreationDate.getMillis() - clock.getUTCNow().getMillis());
         SubscriptionBundle bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever");
 
         String productName = "Shotgun";
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
index 0f5375b..9168e17 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
@@ -68,7 +68,7 @@ public class Engine implements EventListener, EntitlementService {
     private final EntitlementConfig config;
     private final NotificationQueueService notificationQueueService;
 
-    private NotificationQueue subscritionEventQueue;
+    private NotificationQueue subscriptionEventQueue;
 
     @Inject
     public Engine(Clock clock, EntitlementDao dao, PlanAligner planAligner,
@@ -97,7 +97,7 @@ public class Engine implements EventListener, EntitlementService {
     public void initialize() {
 
         try {
-            subscritionEventQueue = notificationQueueService.createNotificationQueue(ENTITLEMENT_SERVICE_NAME,
+            subscriptionEventQueue = notificationQueueService.createNotificationQueue(ENTITLEMENT_SERVICE_NAME,
                     NOTIFICATION_QUEUE_NAME,
                     new NotificationQueueHandler() {
                 @Override
@@ -135,13 +135,13 @@ public class Engine implements EventListener, EntitlementService {
 
     @LifecycleHandlerType(LifecycleLevel.START_SERVICE)
     public void start() {
-        subscritionEventQueue.startQueue();
+        subscriptionEventQueue.startQueue();
     }
 
     @LifecycleHandlerType(LifecycleLevel.STOP_SERVICE)
     public void stop() {
-        if (subscritionEventQueue != null) {
-            subscritionEventQueue.stopQueue();
+        if (subscriptionEventQueue != null) {
+            subscriptionEventQueue.stopQueue();
          }
     }
 
diff --git a/invoice/src/main/java/com/ning/billing/invoice/glue/InvoiceModule.java b/invoice/src/main/java/com/ning/billing/invoice/glue/InvoiceModule.java
index 1dfac5b..7c6e5cc 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/glue/InvoiceModule.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/glue/InvoiceModule.java
@@ -52,10 +52,6 @@ public class InvoiceModule extends AbstractModule {
         bind(InvoicePaymentApi.class).to(DefaultInvoicePaymentApi.class).asEagerSingleton();
     }
 
-    protected void installClock() {
-    	install(new ClockModule());
-    }
-
     protected void installConfig() {
         final InvoiceConfig config = new ConfigurationObjectFactory(System.getProperties()).build(InvoiceConfig.class);
         bind(InvoiceConfig.class).toInstance(config);
diff --git a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoice.java b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoice.java
index 6d419de..b11bfe2 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoice.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoice.java
@@ -184,7 +184,7 @@ public class DefaultInvoice implements Invoice {
             return true;
         }
 
-        return lastPaymentAttempt.plusDays(numberOfDays).isBefore(targetDate);
+        return !lastPaymentAttempt.plusDays(numberOfDays).isAfter(targetDate);
     }
 
     @Override
diff --git a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
index 039f305..a8a1ecc 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
@@ -233,34 +233,4 @@ public class DefaultInvoiceGenerator implements InvoiceGenerator {
             return fixedPriceInvoiceItem;
         }
     }
-
-//    // assumption: startDate is in the user's time zone
-//    private DateTime calculateSegmentEndDate(final DateTime startDate, final DateTime nextEndDate,
-//                                             final int billCycleDay, final BillingPeriod billingPeriod) {
-//        int dayOfMonth = startDate.getDayOfMonth();
-//        int maxDayOfMonth = startDate.dayOfMonth().getMaximumValue();
-//
-//        DateTime nextBillingDate;
-//
-//        // if the start date is not on the bill cycle day, move it to the nearest following date that works
-//        if ((billCycleDay > maxDayOfMonth) || (dayOfMonth == billCycleDay)) {
-//            nextBillingDate = startDate.plusMonths(billingPeriod.getNumberOfMonths());
-//        } else {
-//            MutableDateTime proposedDate = startDate.toMutableDateTime();
-//
-//            if (dayOfMonth < billCycleDay) {
-//                // move the end date forward to the bill cycle date (same month)
-//                int effectiveBillCycleDay = (billCycleDay > maxDayOfMonth) ? maxDayOfMonth : billCycleDay;
-//                nextBillingDate = proposedDate.dayOfMonth().set(effectiveBillCycleDay).toDateTime();
-//            } else {
-//                // go to the next month
-//                proposedDate = proposedDate.monthOfYear().add(1);
-//                maxDayOfMonth = proposedDate.dayOfMonth().getMaximumValue();
-//                int effectiveBillCycleDay = (billCycleDay > maxDayOfMonth) ? maxDayOfMonth : billCycleDay;
-//                nextBillingDate = proposedDate.dayOfMonth().set(effectiveBillCycleDay).toDateTime();
-//            }
-//        }
-//
-//        return nextBillingDate.isAfter(nextEndDate) ? nextEndDate : nextBillingDate;
-//    }
 }
\ No newline at end of file
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
index 6957ba0..9d7805a 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
@@ -21,8 +21,13 @@ import static org.testng.Assert.fail;
 
 import java.io.IOException;
 
+import com.google.inject.Inject;
 import com.ning.billing.invoice.tests.InvoicingTestBase;
 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;
 
@@ -32,6 +37,7 @@ import com.google.inject.Stage;
 import com.ning.billing.invoice.glue.InvoiceModuleWithEmbeddedDb;
 import com.ning.billing.util.bus.BusService;
 import com.ning.billing.util.bus.DefaultBusService;
+import org.testng.annotations.BeforeMethod;
 
 public abstract class InvoiceDaoTestBase extends InvoicingTestBase {
     protected InvoiceDao invoiceDao;
@@ -70,6 +76,32 @@ public abstract class InvoiceDaoTestBase extends InvoicingTestBase {
         }
     }
 
+    @BeforeMethod(alwaysRun = true)
+    public void cleanupData() {
+        module.getDbi().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;
+            }
+        });
+    }
+
     @AfterClass(alwaysRun = true)
     protected void tearDown() {
         module.stopDb();
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTests.java b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTests.java
index 4e07a39..711665a 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTests.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTests.java
@@ -169,7 +169,7 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
     @Test
     public void testGetInvoicesForPayment() {
         List<UUID> invoices;
-        DateTime notionalDate = new DateTime();
+        DateTime notionalDate = clock.getUTCNow();
 
         // create a new invoice with one item
         UUID accountId = UUID.randomUUID();
diff --git a/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithEmbeddedDb.java b/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithEmbeddedDb.java
index 4ab3495..bb9094e 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithEmbeddedDb.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithEmbeddedDb.java
@@ -23,6 +23,7 @@ import com.ning.billing.invoice.api.test.DefaultInvoiceTestApi;
 import com.ning.billing.invoice.dao.InvoicePaymentSqlDao;
 import com.ning.billing.invoice.dao.RecurringInvoiceItemSqlDao;
 import com.ning.billing.util.glue.GlobalLockerModule;
+import com.ning.billing.util.notificationq.NotificationConfig;
 import org.skife.jdbi.v2.IDBI;
 import com.ning.billing.account.glue.AccountModule;
 import com.ning.billing.catalog.glue.CatalogModule;
@@ -50,6 +51,10 @@ public class InvoiceModuleWithEmbeddedDb extends InvoiceModule {
         helper.stopMysql();
     }
 
+    public IDBI getDbi() {
+        return dbi;
+    }
+
     public RecurringInvoiceItemSqlDao getInvoiceItemSqlDao() {
         return dbi.onDemand(RecurringInvoiceItemSqlDao.class);
     }
@@ -80,4 +85,23 @@ public class InvoiceModuleWithEmbeddedDb extends InvoiceModule {
 
         install(new BusModule());
     }
+
+    private class TestNotificationConfig implements NotificationConfig {
+        @Override
+        public boolean isNotificationProcessingOff() {
+            return false;
+        }
+        @Override
+        public long getNotificationSleepTimeMs() {
+            return 10;
+        }
+        @Override
+        public int getDaoMaxReadyEvents() {
+            return 1;
+        }
+        @Override
+        public long getDaoClaimTimeMs() {
+            return 60000;
+        }
+    }
 }
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java b/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
index 18a3df3..136eeb5 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
@@ -59,8 +59,6 @@ import static org.testng.Assert.assertNull;
 
 @Test(groups = {"fast", "invoicing", "invoiceGenerator"})
 public class DefaultInvoiceGeneratorTests extends InvoicingTestBase {
-
-
     private final InvoiceGenerator generator = new DefaultInvoiceGenerator(new DefaultClock());
 
     @Test
@@ -192,14 +190,14 @@ public class DefaultInvoiceGeneratorTests extends InvoicingTestBase {
         assertEquals(invoice.getNumberOfItems(), 4);
 
         BigDecimal numberOfCyclesEvent1;
-        numberOfCyclesEvent1 = ONE.add(FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        numberOfCyclesEvent1 = ONE.add(FOURTEEN.divide(THIRTY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
 
         BigDecimal numberOfCyclesEvent2 = TWO;
 
         BigDecimal expectedValue;
         expectedValue = numberOfCyclesEvent1.multiply(rate1);
         expectedValue = expectedValue.add(numberOfCyclesEvent2.multiply(rate2));
-        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS);
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         assertEquals(invoice.getTotalAmount(), expectedValue);
     }
@@ -391,8 +389,8 @@ public class DefaultInvoiceGeneratorTests extends InvoicingTestBase {
         // on 7/31/2011, convert subscription 3 to annual
         events.add(createBillingEvent(subscriptionId3, plan3UpgradeToAnnualDate, plan3, plan3Phase2, 31));
         expectedAmount = ONE_HUNDRED.subtract(TEN);
-        expectedAmount = expectedAmount.add(TEN.multiply(ELEVEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD)));
-        expectedAmount = expectedAmount.setScale(NUMBER_OF_DECIMALS);
+        expectedAmount = expectedAmount.add(TEN.multiply(ELEVEN.divide(THIRTY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD)));
+        expectedAmount = expectedAmount.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         testInvoiceGeneration(events, invoiceItems, plan3UpgradeToAnnualDate, 3, expectedAmount);
 
         // on 8/7/2011, invoice subscription 4 (plan 2)
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/DoubleProRationTests.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/DoubleProRationTests.java
index 64fa95c..fd37599 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/DoubleProRationTests.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/DoubleProRationTests.java
@@ -81,9 +81,10 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2012, 1, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
-        expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
@@ -95,9 +96,10 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2012, 1, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
-        expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
@@ -109,9 +111,10 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2012, 1, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
-        expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
@@ -123,9 +126,10 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2012, 1, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
-        expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/DoubleProRationTests.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/DoubleProRationTests.java
index c1d6085..184f5d5 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/DoubleProRationTests.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/DoubleProRationTests.java
@@ -37,7 +37,8 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime targetDate = buildDateTime(2011, 1, 1);
         DateTime endDate = buildDateTime(2011, 4, 27);
 
-        BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
 
@@ -47,7 +48,8 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime targetDate = buildDateTime(2011, 1, 7);
         DateTime endDate = buildDateTime(2011, 4, 27);
 
-        BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
 
@@ -57,7 +59,8 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime targetDate = buildDateTime(2011, 1, 15);
         DateTime endDate = buildDateTime(2011, 4, 27);
 
-        BigDecimal expectedValue = ONE.add(FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        BigDecimal expectedValue = ONE.add(FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
 
@@ -68,8 +71,9 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2011, 4, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
@@ -81,9 +85,10 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2011, 4, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
-        expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
@@ -95,9 +100,10 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2011, 4, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
-        expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
@@ -109,9 +115,10 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2011, 4, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
-        expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
@@ -123,9 +130,10 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2011, 4, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(ONE);
-        expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
@@ -137,8 +145,9 @@ public class DoubleProRationTests extends ProRationInAdvanceTestBase {
         DateTime endDate = buildDateTime(2011, 8, 27);
 
         BigDecimal expectedValue;
-        expectedValue = FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+        expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
         expectedValue = expectedValue.add(TWO);
+        expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
 
         testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
     }
diff --git a/payment/src/test/java/com/ning/billing/payment/TestHelper.java b/payment/src/test/java/com/ning/billing/payment/TestHelper.java
index ac05da4..4430eb2 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestHelper.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestHelper.java
@@ -53,7 +53,7 @@ public class TestHelper {
                                                                      .firstNameLength(name.length())
                                                                      .externalKey(externalKey)
                                                                      .phone("123-456-7890")
-                                                                     .email("ccuser@example.com")
+                                                                     .email("ccuser" + RandomStringUtils.randomAlphanumeric(8) + "@example.com")
                                                                      .currency(Currency.USD)
                                                                      .billingCycleDay(1)
                                                                      .build();
diff --git a/payment/src/test/java/com/ning/billing/payment/TestPaymentInvoiceIntegration.java b/payment/src/test/java/com/ning/billing/payment/TestPaymentInvoiceIntegration.java
index 8768117..c1e62d8 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestPaymentInvoiceIntegration.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestPaymentInvoiceIntegration.java
@@ -90,7 +90,7 @@ public class TestPaymentInvoiceIntegration {
 
     @AfterClass(alwaysRun = true)
     public void stopMysql() {
-        helper.stopMysql();
+        if (helper != null) helper.stopMysql();
     }
 
     @BeforeMethod(alwaysRun = true)
@@ -116,9 +116,11 @@ public class TestPaymentInvoiceIntegration {
 
     @AfterMethod(alwaysRun = true)
     public void tearDown() throws EventBusException {
-        eventBus.unregister(invoiceProcessor);
-        eventBus.unregister(paymentInfoReceiver);
-        eventBus.stop();
+        if (eventBus != null) {
+            eventBus.unregister(invoiceProcessor);
+            eventBus.unregister(paymentInfoReceiver);
+            eventBus.stop();
+        }
     }
 
     @Test
diff --git a/util/src/main/java/com/ning/billing/util/customfield/dao/FieldStoreDao.java b/util/src/main/java/com/ning/billing/util/customfield/dao/FieldStoreDao.java
index 14c123a..a766982 100644
--- a/util/src/main/java/com/ning/billing/util/customfield/dao/FieldStoreDao.java
+++ b/util/src/main/java/com/ning/billing/util/customfield/dao/FieldStoreDao.java
@@ -48,8 +48,8 @@ public interface FieldStoreDao extends EntityCollectionDao<CustomField>, Transac
     @Override
     @SqlBatch(transactional=false)
     public void batchSaveFromTransaction(@Bind("objectId") final String objectId,
-                     @Bind("objectType") final String objectType,
-                     @CustomFieldBinder final List<CustomField> entities);
+                                         @Bind("objectType") final String objectType,
+                                         @CustomFieldBinder final List<CustomField> entities);
 
 
     public class CustomFieldMapper implements ResultSetMapper<CustomField> {
diff --git a/util/src/main/java/com/ning/billing/util/tag/dao/DefaultTagDefinitionDao.java b/util/src/main/java/com/ning/billing/util/tag/dao/DefaultTagDefinitionDao.java
index 57ca679..baaf9cd 100644
--- a/util/src/main/java/com/ning/billing/util/tag/dao/DefaultTagDefinitionDao.java
+++ b/util/src/main/java/com/ning/billing/util/tag/dao/DefaultTagDefinitionDao.java
@@ -46,7 +46,7 @@ public class DefaultTagDefinitionDao implements TagDefinitionDao {
 
         // add control tag definitions
         for (ControlTagType controlTag : ControlTagType.values()) {
-            definitionList.add(new DefaultTagDefinition(controlTag.toString(), controlTag.getDescription(), null, null));
+            definitionList.add(new DefaultTagDefinition(controlTag.toString(), controlTag.getDescription(), null));
         }
 
         return definitionList;
@@ -69,7 +69,7 @@ public class DefaultTagDefinitionDao implements TagDefinitionDao {
             throw new TagDefinitionApiException(ErrorCode.TAG_DEFINITION_ALREADY_EXISTS, definitionName);
         }
 
-        TagDefinition definition = new DefaultTagDefinition(definitionName, description, createdBy, clock.getUTCNow());
+        TagDefinition definition = new DefaultTagDefinition(definitionName, description, createdBy);
         dao.create(definition);
         return definition;
     }
diff --git a/util/src/main/java/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.java b/util/src/main/java/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.java
index f13daff..b2e7dab 100644
--- a/util/src/main/java/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.java
@@ -70,8 +70,7 @@ public interface TagDefinitionSqlDao extends EntityDao<TagDefinition> {
             String name = result.getString("name");
             String description = result.getString("description");
             String createdBy = result.getString("created_by");
-            DateTime creationDate = new DateTime(result.getTimestamp("creation_date"));
-            return new DefaultTagDefinition(id, name, description, createdBy, creationDate);
+            return new DefaultTagDefinition(id, name, description, createdBy);
         }
     }
 
@@ -86,7 +85,6 @@ public interface TagDefinitionSqlDao extends EntityDao<TagDefinition> {
                         q.bind("id", tagDefinition.getId().toString());
                         q.bind("name", tagDefinition.getName());
                         q.bind("createdBy", tagDefinition.getCreatedBy());
-                        q.bind("creationDate", tagDefinition.getCreationDate().toDate());
                         q.bind("description", tagDefinition.getDescription());
                     }
                 };
diff --git a/util/src/main/java/com/ning/billing/util/tag/dao/TagMapper.java b/util/src/main/java/com/ning/billing/util/tag/dao/TagMapper.java
index 1296083..fadf98c 100644
--- a/util/src/main/java/com/ning/billing/util/tag/dao/TagMapper.java
+++ b/util/src/main/java/com/ning/billing/util/tag/dao/TagMapper.java
@@ -45,10 +45,9 @@ public class TagMapper implements ResultSetMapper<Tag> {
         } catch (Throwable t) {
             String description = result.getString("tag_description");
             String createdBy = result.getString("created_by");
-            DateTime creationDate = new DateTime(result.getDate("creation_date"));
 
             UUID tagDefinitionId = UUID.fromString(result.getString("tag_definition_id"));
-            TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, name, description, createdBy, creationDate);
+            TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, name, description, createdBy);
             tag = new DescriptiveTag(id, tagDefinition, addedBy, addedDate);
         }
 
diff --git a/util/src/main/java/com/ning/billing/util/tag/DefaultTagDefinition.java b/util/src/main/java/com/ning/billing/util/tag/DefaultTagDefinition.java
index bfce619..482e56d 100644
--- a/util/src/main/java/com/ning/billing/util/tag/DefaultTagDefinition.java
+++ b/util/src/main/java/com/ning/billing/util/tag/DefaultTagDefinition.java
@@ -17,27 +17,24 @@
 package com.ning.billing.util.tag;
 
 import java.util.UUID;
-import org.joda.time.DateTime;
 import com.ning.billing.util.entity.EntityBase;
 
 public class DefaultTagDefinition extends EntityBase implements TagDefinition {
     private String name;
     private String description;
     private String createdBy;
-    private DateTime creationDate;
 
     public DefaultTagDefinition(String name, String description,
-                                String createdBy, DateTime creationDate) {
-        this(UUID.randomUUID(), name, description, createdBy, creationDate);
+                                String createdBy) {
+        this(UUID.randomUUID(), name, description, createdBy);
     }
 
     public DefaultTagDefinition(UUID id, String name, String description,
-                                String createdBy, DateTime creationDate) {
+                                String createdBy) {
         super(id);
         this.name = name;
         this.description = description;
         this.createdBy = createdBy;
-        this.creationDate = creationDate;
     }
     
     @Override
@@ -51,11 +48,6 @@ public class DefaultTagDefinition extends EntityBase implements TagDefinition {
     }
 
     @Override
-    public DateTime getCreationDate() {
-        return creationDate;
-    }
-
-    @Override
     public String getDescription() {
         return description;
     }
diff --git a/util/src/main/resources/com/ning/billing/util/customfield/dao/FieldStoreDao.sql.stg b/util/src/main/resources/com/ning/billing/util/customfield/dao/FieldStoreDao.sql.stg
index 9d3e96e..c9ee046 100644
--- a/util/src/main/resources/com/ning/billing/util/customfield/dao/FieldStoreDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/customfield/dao/FieldStoreDao.sql.stg
@@ -1,8 +1,8 @@
 group FieldStoreDao;
 
 batchSaveFromTransaction() ::= <<
-  INSERT INTO custom_fields(id, object_id, object_type, field_name, field_value)
-  VALUES (:id, :objectId, :objectType, :fieldName, :fieldValue)
+  INSERT INTO custom_fields(id, object_id, object_type, field_name, field_value, created_date, updated_date)
+  VALUES (:id, :objectId, :objectType, :fieldName, :fieldValue, NOW(), NOW())
   ON DUPLICATE KEY UPDATE
     field_value = :fieldValue;
 >>
diff --git a/util/src/main/resources/com/ning/billing/util/ddl.sql b/util/src/main/resources/com/ning/billing/util/ddl.sql
index a0ef302..389efa7 100644
--- a/util/src/main/resources/com/ning/billing/util/ddl.sql
+++ b/util/src/main/resources/com/ning/billing/util/ddl.sql
@@ -5,19 +5,44 @@ CREATE TABLE custom_fields (
   object_type varchar(30) NOT NULL,
   field_name varchar(30) NOT NULL,
   field_value varchar(255) NOT NULL,
+  created_date datetime NOT NULL,
+  updated_date datetime NOT NULL,
   PRIMARY KEY(id)
 ) ENGINE=innodb;
 CREATE INDEX custom_fields_object_id_object_type ON custom_fields(object_id, object_type);
 CREATE UNIQUE INDEX custom_fields_unique ON custom_fields(object_id, object_type, field_name);
 
+DROP TABLE IF EXISTS custom_field_history;
+CREATE TABLE custom_field_history (
+  id char(36) NOT NULL,
+  object_id char(36) NOT NULL,
+  object_type varchar(30) NOT NULL,
+  field_name varchar(30) NOT NULL,
+  field_value varchar(255) NOT NULL,
+  change_type char(6) NOT NULL,
+  date datetime NOT NULL
+) ENGINE=innodb;
+CREATE INDEX custom_field_history_object_id_object_type ON custom_fields(object_id, object_type);
+
+CREATE TRIGGER store_custom_field_history_on_insert AFTER INSERT ON custom_fields
+    FOR EACH ROW
+        INSERT INTO custom_field_history (id, object_id, object_type, field_name, field_value, change_type, date)
+        VALUES (NEW.id, NEW.object_id, NEW.object_type, NEW.field_name, NEW.field_value, 'CREATE', NEW.created_date);
+
+CREATE TRIGGER store_custom_field_history_on_update AFTER UPDATE ON custom_fields
+    FOR EACH ROW
+        INSERT INTO custom_field_history (id, object_id, object_type, field_name, field_value, change_type, date)
+        VALUES (NEW.id, NEW.object_id, NEW.object_type, NEW.field_name, NEW.field_value, 'UPDATE', NEW.updated_date);
+
 DROP TABLE IF EXISTS tag_descriptions;
 DROP TABLE IF EXISTS tag_definitions;
 CREATE TABLE tag_definitions (
   id char(36) NOT NULL,
   name varchar(20) NOT NULL,
   created_by varchar(50) NOT NULL,
-  creation_date datetime NOT NULL,
   description varchar(200) NOT NULL,
+  created_date datetime NOT NULL,
+  updated_date datetime NOT NULL,
   PRIMARY KEY(id)
 ) ENGINE=innodb;
 CREATE UNIQUE INDEX tag_definitions_name ON tag_definitions(name);
diff --git a/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
index 72268d0..333da26 100644
--- a/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/tag/dao/TagDefinitionSqlDao.sql.stg
@@ -1,24 +1,32 @@
 group TagDefinitionDao;
 
+fields(prefix) ::= <<
+    <prefix>id,
+    <prefix>name,
+    <prefix>created_by,
+    <prefix>description,
+    <prefix>created_date,
+    <prefix>updated_date
+>>
+
 get() ::= <<
-  SELECT id, name, created_by, creation_date, description
+  SELECT <fields()>
   FROM tag_definitions;
 >>
 
 create() ::= <<
-  INSERT INTO tag_definitions(id, name, created_by, creation_date, description)
-  VALUES(:id, :name, :createdBy, :creationDate, :description);
+  INSERT INTO tag_definitions(<fields()>)
+  VALUES(:id, :name, :createdBy, :description, NOW(), NOW());
 >>
 
 update() ::= <<
   UPDATE tag_definitions
-  SET name = :name, created_by = :createdBy, creation_date = :creationDate,
-      description = :description)
+  SET name = :name, created_by = :createdBy, description = :description, updated_date = NOW())
   WHERE id = :id;
 >>
 
 load() ::= <<
-  SELECT id, name, created_by, creation_date, description
+  SELECT <fields()>
   FROM tag_definitions
   WHERE id = :id;
 >>
@@ -40,7 +48,7 @@ tagDefinitionUsageCount() ::= <<
 >>
 
 getByName() ::= <<
-  SELECT id, name, created_by, creation_date, description
+  SELECT <fields()>
   FROM tag_definitions
   WHERE name = :name;
 >>
diff --git a/util/src/main/resources/com/ning/billing/util/tag/dao/TagStoreSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/tag/dao/TagStoreSqlDao.sql.stg
index 9d7ce5c..4cad04c 100644
--- a/util/src/main/resources/com/ning/billing/util/tag/dao/TagStoreSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/tag/dao/TagStoreSqlDao.sql.stg
@@ -13,7 +13,7 @@ load() ::= <<
            td.id AS tag_definition_id,
            t.tag_definition_name AS tag_definition_name,
            td.description AS tag_description,
-           td.created_by, td.creation_date
+           td.created_by
     FROM tags t
     LEFT JOIN tag_definitions td ON t.tag_definition_name = td.name
     WHERE t.object_id = :objectId AND t.object_type = :objectType;
diff --git a/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java b/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java
index 5ee7e88..93814f3 100644
--- a/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java
+++ b/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java
@@ -46,7 +46,7 @@ public class MysqlTestingHelper
 
     private static final String DB_NAME = "test_killbill";
     private static final String USERNAME = "root";
-    private static final String PASSWORD = "";
+    private static final String PASSWORD = "root";
 
     private File dbDir;
     private MysqldResource mysqldResource;
@@ -77,7 +77,6 @@ public class MysqlTestingHelper
 
     public void startMysql() throws IOException
     {
-
         if (isUsingLocalInstance()) {
             return;
         }
@@ -90,6 +89,7 @@ public class MysqlTestingHelper
         final Map<String, String> dbOpts = new HashMap<String, String>();
         dbOpts.put(MysqldResourceI.PORT, Integer.toString(port));
         dbOpts.put(MysqldResourceI.INITIALIZE_USER, "true");
+        dbOpts.put(MysqldResourceI.INITIALIZE_PASSWORD, PASSWORD);
         dbOpts.put(MysqldResourceI.INITIALIZE_USER_NAME, USERNAME);
         dbOpts.put("default-time-zone", "+00:00");