killbill-memoizeit

payment: revisit test setup * Add logging around each test *

7/7/2012 4:57:22 PM

Details

diff --git a/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java b/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
index d634792..fd710e5 100644
--- a/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
+++ b/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
@@ -13,6 +13,7 @@
  * License for the specific language governing permissions and limitations
  * under the License.
  */
+
 package com.ning.billing.payment.api;
 
 import java.math.BigDecimal;
@@ -22,12 +23,13 @@ import org.joda.time.DateTime;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import com.ning.billing.payment.PaymentTestSuite;
 import com.ning.billing.util.jackson.ObjectMapper;
 
-public class TestEventJson {
+public class TestEventJson extends PaymentTestSuite {
     private final ObjectMapper mapper = new ObjectMapper();
 
-    @Test(groups = {"fast"})
+    @Test(groups = "fast")
     public void testPaymentErrorEvent() throws Exception {
         final PaymentErrorEvent e = new DefaultPaymentErrorEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), "no message", UUID.randomUUID());
         final String json = mapper.writeValueAsString(e);
@@ -37,7 +39,7 @@ public class TestEventJson {
         Assert.assertTrue(obj.equals(e));
     }
 
-    @Test(groups = {"fast"})
+    @Test(groups = "fast")
     public void testPaymentInfoEvent() throws Exception {
         final PaymentInfoEvent e = new DefaultPaymentInfoEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), new BigDecimal(12.9), new Integer(13), PaymentStatus.SUCCESS, "ext-ref-12345", UUID.randomUUID(), new DateTime());
         final String json = mapper.writeValueAsString(e);
diff --git a/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApi.java b/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApi.java
index 893544c..3d0d55a 100644
--- a/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApi.java
+++ b/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApi.java
@@ -42,6 +42,7 @@ import com.ning.billing.invoice.api.InvoicePaymentApi;
 import com.ning.billing.mock.glue.MockClockModule;
 import com.ning.billing.mock.glue.MockJunctionModule;
 import com.ning.billing.payment.MockRecurringInvoiceItem;
+import com.ning.billing.payment.PaymentTestSuite;
 import com.ning.billing.payment.TestHelper;
 import com.ning.billing.payment.api.Payment.PaymentAttempt;
 import com.ning.billing.payment.glue.PaymentTestModuleWithMocks;
@@ -61,8 +62,7 @@ import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 @Guice(modules = {PaymentTestModuleWithMocks.class, MockClockModule.class, MockJunctionModule.class, CallContextModule.class})
-@Test(groups = "fast")
-public class TestPaymentApi {
+public class TestPaymentApi extends PaymentTestSuite {
     private static final Logger log = LoggerFactory.getLogger(TestPaymentApi.class);
 
     @Inject
@@ -85,22 +85,22 @@ public class TestPaymentApi {
         context = new DefaultCallContext("Payment Tests", CallOrigin.INTERNAL, UserType.SYSTEM, clock);
     }
 
-    @BeforeClass
+    @BeforeClass(groups = "fast")
     public void setupClass() throws Exception {
         account = testHelper.createTestAccount("yoyo.yahoo.com");
     }
 
-    @BeforeMethod(alwaysRun = true)
+    @BeforeMethod(groups = "fast")
     public void setUp() throws EventBusException {
         eventBus.start();
     }
 
-    @AfterMethod(alwaysRun = true)
+    @AfterMethod(groups = "fast")
     public void tearDown() throws EventBusException {
         eventBus.stop();
     }
 
-    @Test
+    @Test(groups = "fast")
     public void testSimplePaymentWithNoAmount() throws Exception {
         final BigDecimal invoiceAmount = new BigDecimal("10.0011");
         final BigDecimal requestedAmount = null;
@@ -109,7 +109,7 @@ public class TestPaymentApi {
         testSimplePayment(invoiceAmount, requestedAmount, expectedAmount);
     }
 
-    @Test
+    @Test(groups = "fast")
     public void testSimplePaymentWithInvoiceAmount() throws Exception {
         final BigDecimal invoiceAmount = new BigDecimal("10.0011");
         final BigDecimal requestedAmount = invoiceAmount;
@@ -118,7 +118,7 @@ public class TestPaymentApi {
         testSimplePayment(invoiceAmount, requestedAmount, expectedAmount);
     }
 
-    @Test
+    @Test(groups = "fast")
     public void testSimplePaymentWithLowerAmount() throws Exception {
         final BigDecimal invoiceAmount = new BigDecimal("10.0011");
         final BigDecimal requestedAmount = new BigDecimal("8.0091");
@@ -127,7 +127,7 @@ public class TestPaymentApi {
         testSimplePayment(invoiceAmount, requestedAmount, expectedAmount);
     }
 
-    @Test
+    @Test(groups = "fast")
     public void testSimplePaymentWithInvalidAmount() throws Exception {
         final BigDecimal invoiceAmount = new BigDecimal("10.0011");
         final BigDecimal requestedAmount = new BigDecimal("80.0091");
@@ -179,7 +179,7 @@ public class TestPaymentApi {
         }
     }
 
-    @Test
+    @Test(groups = "fast")
     public void testPaymentMethods() throws Exception {
         List<PaymentMethod> methods = paymentApi.getPaymentMethods(account, false);
         assertEquals(methods.size(), 1);
diff --git a/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java b/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
index 1af7d2c..74cd804 100644
--- a/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
+++ b/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
@@ -13,6 +13,7 @@
  * License for the specific language governing permissions and limitations
  * under the License.
  */
+
 package com.ning.billing.payment.dao;
 
 import java.io.IOException;
@@ -24,30 +25,30 @@ import java.util.UUID;
 import org.joda.time.DateTime;
 import org.skife.config.ConfigurationObjectFactory;
 import org.skife.jdbi.v2.IDBI;
-import org.testng.Assert;
 import org.testng.annotations.AfterSuite;
 import org.testng.annotations.BeforeSuite;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
 import com.ning.billing.catalog.api.Currency;
 import com.ning.billing.dbi.DBIProvider;
 import com.ning.billing.dbi.DbiConfig;
 import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.payment.PaymentTestSuiteWithEmbeddedDB;
 import com.ning.billing.payment.api.PaymentStatus;
 import com.ning.billing.payment.dao.RefundModelDao.RefundStatus;
 import com.ning.billing.util.callcontext.CallContext;
 import com.ning.billing.util.callcontext.TestCallContext;
 import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.clock.DefaultClock;
-import com.ning.billing.util.io.IOUtils;
 
-import static junit.framework.Assert.assertNull;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
 import static org.testng.Assert.fail;
 
-public class TestPaymentDao {
+public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
     private static final CallContext context = new TestCallContext("PaymentTests");
 
     private PaymentDao paymentDao;
@@ -55,24 +56,17 @@ public class TestPaymentDao {
     private IDBI dbi;
     private Clock clock;
 
-    @BeforeSuite(groups = {"slow"})
-    public void startMysql() throws IOException {
-        final String paymentddl = IOUtils.toString(MysqlTestingHelper.class.getResourceAsStream("/com/ning/billing/payment/ddl.sql"));
-        final String utilddl = IOUtils.toString(MysqlTestingHelper.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
+    @BeforeSuite(groups = "slow")
+    public void setup() throws IOException {
         clock = new DefaultClock();
 
         setupDb();
 
-        helper.startMysql();
-        helper.initDb(paymentddl);
-        helper.initDb(utilddl);
-
         paymentDao = new AuditedPaymentDao(dbi, null);
     }
 
     private void setupDb() {
-        helper = new MysqlTestingHelper();
+        helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
         if (helper.isUsingLocalInstance()) {
             final DbiConfig config = new ConfigurationObjectFactory(System.getProperties()).build(DbiConfig.class);
             final DBIProvider provider = new DBIProvider(config);
@@ -82,28 +76,14 @@ public class TestPaymentDao {
         }
     }
 
-    @AfterSuite(groups = {"slow"})
-    public void stopMysql() {
-        helper.stopMysql();
-    }
-
-    @BeforeTest(groups = {"slow"})
-    public void cleanupDb() {
-        helper.cleanupAllTables();
-    }
-
-
-
-
-    @Test(groups = {"slow"})
+    @Test(groups = "slow")
     public void testRefund() {
-
         final UUID accountId = UUID.randomUUID();
         final UUID paymentId1 = UUID.randomUUID();
         final BigDecimal amount1 = new BigDecimal(13);
         final Currency currency = Currency.USD;
 
-        RefundModelDao refund1 =  new RefundModelDao(accountId, paymentId1, amount1, currency, true);
+        RefundModelDao refund1 = new RefundModelDao(accountId, paymentId1, amount1, currency, true);
 
         paymentDao.insertRefund(refund1, context);
         RefundModelDao refundCheck = paymentDao.getRefund(refund1.getId());
@@ -118,7 +98,7 @@ public class TestPaymentDao {
         final BigDecimal amount2 = new BigDecimal(7.00);
         final UUID paymentId2 = UUID.randomUUID();
 
-        RefundModelDao refund2 =  new RefundModelDao(accountId, paymentId2, amount2, currency, true);
+        RefundModelDao refund2 = new RefundModelDao(accountId, paymentId2, amount2, currency, true);
         paymentDao.insertRefund(refund2, context);
         paymentDao.updateRefundStatus(refund2.getId(), RefundStatus.COMPLETED, context);
 
@@ -143,7 +123,6 @@ public class TestPaymentDao {
         }
     }
 
-
     @Test(groups = "slow")
     public void testUpdateStatus() {
         final UUID accountId = UUID.randomUUID();
@@ -208,7 +187,6 @@ public class TestPaymentDao {
         assertEquals(savedPayment.getEffectiveDate().compareTo(effectiveDate), 0);
         assertEquals(savedPayment.getPaymentStatus(), PaymentStatus.UNKNOWN);
 
-
         PaymentAttemptModelDao savedAttempt = paymentDao.getPaymentAttempt(attempt.getId());
         assertEquals(savedAttempt.getId(), attempt.getId());
         assertEquals(savedAttempt.getPaymentId(), payment.getId());
@@ -239,7 +217,7 @@ public class TestPaymentDao {
 
     }
 
-    @Test(groups = {"slow"})
+    @Test(groups = "slow")
     public void testNewAttempt() {
         final UUID accountId = UUID.randomUUID();
         final UUID invoiceId = UUID.randomUUID();
@@ -278,7 +256,6 @@ public class TestPaymentDao {
         assertEquals(savedAttempt1.getPaymentError(), null);
         assertEquals(savedAttempt1.getRequestedAmount().compareTo(amount), 0);
 
-
         final PaymentAttemptModelDao savedAttempt2 = attempts.get(1);
         assertEquals(savedAttempt2.getPaymentId(), payment.getId());
         assertEquals(savedAttempt2.getAccountId(), accountId);
@@ -288,7 +265,7 @@ public class TestPaymentDao {
         assertEquals(savedAttempt2.getRequestedAmount().compareTo(newAmount), 0);
     }
 
-    @Test(groups = {"slow"})
+    @Test(groups = "slow")
     public void testPaymentMethod() {
 
         final UUID paymentMethodId = UUID.randomUUID();
@@ -318,7 +295,5 @@ public class TestPaymentDao {
 
         final PaymentMethodModelDao deletedPaymentMethod = paymentDao.getPaymentMethod(paymentMethodId);
         assertNull(deletedPaymentMethod);
-
-
     }
 }
diff --git a/payment/src/test/java/com/ning/billing/payment/PaymentTestSuite.java b/payment/src/test/java/com/ning/billing/payment/PaymentTestSuite.java
new file mode 100644
index 0000000..1baac9d
--- /dev/null
+++ b/payment/src/test/java/com/ning/billing/payment/PaymentTestSuite.java
@@ -0,0 +1,22 @@
+/*
+ * 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.payment;
+
+import com.ning.billing.KillbillTestSuite;
+
+public abstract class PaymentTestSuite extends KillbillTestSuite {
+}
diff --git a/payment/src/test/java/com/ning/billing/payment/PaymentTestSuiteWithEmbeddedDB.java b/payment/src/test/java/com/ning/billing/payment/PaymentTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..50e82a6
--- /dev/null
+++ b/payment/src/test/java/com/ning/billing/payment/PaymentTestSuiteWithEmbeddedDB.java
@@ -0,0 +1,22 @@
+/*
+ * 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.payment;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class PaymentTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
index 3fa67e0..e8e1580 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
@@ -64,7 +64,7 @@ import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 @Guice(modules = {PaymentTestModuleWithMocks.class, MockClockModule.class, MockJunctionModule.class, CallContextModule.class})
-public class TestRetryService {
+public class TestRetryService extends PaymentTestSuite {
     @Inject
     private PaymentConfig paymentConfig;
     @Inject