killbill-uncached
Changes
analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentFieldSqlDao.java 4(+2 -2)
analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentSqlDao.java 4(+2 -2)
analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentTagSqlDao.java 4(+2 -2)
analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessOverdueStatusSqlDao.java 4(+2 -2)
analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionFieldSqlDao.java 4(+2 -2)
analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionTagSqlDao.java 4(+2 -2)
catalog/pom.xml 5(+5 -0)
entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java 3(+2 -1)
entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationMemory.java 10(+4 -6)
entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestApiBaseRepair.java 13(+3 -10)
entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java 45(+7 -38)
entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java 61(+11 -50)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelMemory.java 10(+4 -6)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java 38(+0 -38)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanMemory.java 15(+6 -9)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanSql.java 16(+7 -9)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java 13(+5 -8)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateMemory.java 6(+2 -4)
entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateSql.java 5(+2 -3)
entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoMemory.java 21(+5 -16)
entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java 48(+1 -47)
entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java 22(+22 -0)
invoice/src/main/java/com/ning/billing/invoice/api/migration/DefaultInvoiceMigrationApi.java 21(+19 -2)
invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java 46(+21 -25)
invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java 19(+15 -4)
invoice/src/test/java/com/ning/billing/invoice/api/migration/MockModuleNoEntitlement.java 31(+4 -27)
invoice/src/test/java/com/ning/billing/invoice/api/migration/TestDefaultInvoiceMigrationApi.java 98(+28 -70)
invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java 81(+40 -41)
invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java 238(+117 -121)
invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java 53(+15 -38)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java 18(+9 -9)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java 20(+10 -10)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java 13(+6 -7)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java 30(+15 -15)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java 18(+9 -9)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java 21(+10 -11)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java 36(+18 -18)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java 12(+6 -6)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java 19(+9 -10)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java 20(+10 -10)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java 36(+18 -18)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java 12(+6 -6)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java 12(+6 -6)
junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBlockingCalculator.java 69(+25 -44)
junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultBillingEvent.java 22(+9 -13)
overdue/pom.xml 5(+5 -0)
overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java 64(+32 -32)
overdue/src/test/java/com/ning/billing/overdue/applicator/TestOverdueStateApplicator.java 36(+12 -24)
overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculator.java 32(+13 -19)
overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java 96(+46 -50)
overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java 52(+15 -37)
payment/pom.xml 5(+5 -0)
util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java 4(+2 -2)
util/src/main/resources/com/ning/billing/util/notificationq/dao/NotificationSqlDao.sql.stg 32(+32 -0)
util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagCreationEvent.java 3(+2 -1)
util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionCreationEvent.java 3(+2 -1)
util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionDeletionEvent.java 3(+2 -1)
util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDeletionEvent.java 3(+2 -1)
util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionCreationEvent.java 3(+2 -1)
util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionDeletionEvent.java 3(+2 -1)
Details
diff --git a/account/src/test/java/com/ning/billing/account/AccountTestSuite.java b/account/src/test/java/com/ning/billing/account/AccountTestSuite.java
new file mode 100644
index 0000000..aa2eb9e
--- /dev/null
+++ b/account/src/test/java/com/ning/billing/account/AccountTestSuite.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.account;
+
+import com.ning.billing.KillbillTestSuite;
+
+public abstract class AccountTestSuite extends KillbillTestSuite {
+}
diff --git a/account/src/test/java/com/ning/billing/account/AccountTestSuiteWithEmbeddedDB.java b/account/src/test/java/com/ning/billing/account/AccountTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..24fb47f
--- /dev/null
+++ b/account/src/test/java/com/ning/billing/account/AccountTestSuiteWithEmbeddedDB.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.account;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class AccountTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/account/src/test/java/com/ning/billing/account/api/user/TestDefaultAccountUserApi.java b/account/src/test/java/com/ning/billing/account/api/user/TestDefaultAccountUserApi.java
index 5d4657b..6de32f6 100644
--- a/account/src/test/java/com/ning/billing/account/api/user/TestDefaultAccountUserApi.java
+++ b/account/src/test/java/com/ning/billing/account/api/user/TestDefaultAccountUserApi.java
@@ -24,6 +24,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.ning.billing.account.AccountTestSuite;
import com.ning.billing.account.api.Account;
import com.ning.billing.account.api.AccountData;
import com.ning.billing.account.api.DefaultAccount;
@@ -37,7 +38,7 @@ import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.callcontext.CallContext;
import com.ning.billing.util.callcontext.CallContextFactory;
-public class TestDefaultAccountUserApi {
+public class TestDefaultAccountUserApi extends AccountTestSuite {
private final CallContextFactory factory = Mockito.mock(CallContextFactory.class);
private final CallContext callContext = Mockito.mock(CallContext.class);
diff --git a/account/src/test/java/com/ning/billing/account/api/user/TestEventJson.java b/account/src/test/java/com/ning/billing/account/api/user/TestEventJson.java
index 8853ad6..a15d101 100644
--- a/account/src/test/java/com/ning/billing/account/api/user/TestEventJson.java
+++ b/account/src/test/java/com/ning/billing/account/api/user/TestEventJson.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.account.api.user;
import java.util.ArrayList;
@@ -22,18 +23,18 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.account.AccountTestSuite;
import com.ning.billing.account.api.AccountChangeEvent;
import com.ning.billing.account.api.ChangedField;
import com.ning.billing.account.api.DefaultChangedField;
import com.ning.billing.account.api.user.DefaultAccountCreationEvent.DefaultAccountData;
import com.ning.billing.util.jackson.ObjectMapper;
-public class TestEventJson {
+public class TestEventJson extends AccountTestSuite {
private final ObjectMapper mapper = new ObjectMapper();
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDefaultAccountChangeEvent() throws Exception {
-
final List<ChangedField> changes = new ArrayList<ChangedField>();
changes.add(new DefaultChangedField("fieldXX", "valueX", "valueXXX"));
changes.add(new DefaultChangedField("fieldYY", "valueY", "valueYYY"));
@@ -46,17 +47,15 @@ public class TestEventJson {
Assert.assertTrue(obj.equals(e));
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testAccountCreationEvent() throws Exception {
-
final DefaultAccountData data = new DefaultAccountData("dsfdsf", "bobo", 3, "bobo@yahoo.com", 12, "USD", UUID.randomUUID(),
- "UTC", "US", "21 avenue", "", "Gling", "San Franciso", "CA", "94110", "USA", "4126789887", false, false);
+ "UTC", "US", "21 avenue", "", "Gling", "San Franciso", "CA", "94110", "USA", "4126789887", false, false);
final DefaultAccountCreationEvent e = new DefaultAccountCreationEvent(data, UUID.randomUUID(), UUID.randomUUID());
final String json = mapper.writeValueAsString(e);
final Class<?> claz = Class.forName(DefaultAccountCreationEvent.class.getName());
final Object obj = mapper.readValue(json, claz);
Assert.assertTrue(obj.equals(e));
-
}
}
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 0635c4e..463afe7 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
@@ -18,15 +18,10 @@ package com.ning.billing.account.dao;
import java.io.IOException;
-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;
-import org.testng.annotations.BeforeMethod;
-import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.account.AccountTestSuiteWithEmbeddedDB;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.BusService;
import com.ning.billing.util.bus.DefaultBusService;
@@ -37,14 +32,11 @@ import com.ning.billing.util.callcontext.DefaultCallContextFactory;
import com.ning.billing.util.callcontext.UserType;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
-import com.ning.billing.util.io.IOUtils;
import com.ning.billing.util.tag.api.user.TagEventBuilder;
import static org.testng.Assert.fail;
-public abstract class AccountDaoTestBase {
- private final MysqlTestingHelper helper = new MysqlTestingHelper();
-
+public abstract class AccountDaoTestBase extends AccountTestSuiteWithEmbeddedDB {
protected final TagEventBuilder tagEventBuilder = new TagEventBuilder();
protected AccountDao accountDao;
@@ -53,17 +45,9 @@ public abstract class AccountDaoTestBase {
protected Bus bus;
protected CallContext context;
- @BeforeClass(alwaysRun = true)
+ @BeforeClass(groups = "slow")
protected void setup() throws IOException {
- // Health check test to make sure MySQL is setup properly
try {
- final String accountDdl = IOUtils.toString(AccountSqlDao.class.getResourceAsStream("/com/ning/billing/account/ddl.sql"));
- final String utilDdl = IOUtils.toString(AccountSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
- helper.startMysql();
- helper.initDb(accountDdl);
- helper.initDb(utilDdl);
-
dbi = helper.getDBI();
bus = new InMemoryBus();
@@ -71,9 +55,11 @@ public abstract class AccountDaoTestBase {
((DefaultBusService) busService).startBus();
accountDao = new AuditedAccountDao(dbi, bus);
+ // Health check test to make sure MySQL is setup properly
accountDao.test();
accountEmailDao = new AuditedAccountEmailDao(dbi);
+ // Health check test to make sure MySQL is setup properly
accountEmailDao.test();
final Clock clock = new ClockMock();
@@ -82,27 +68,4 @@ public abstract class AccountDaoTestBase {
fail(t.toString());
}
}
-
- @AfterClass(alwaysRun = true)
- public void stopMysql() {
- helper.stopMysql();
- }
-
- @BeforeMethod(alwaysRun = true)
- public void cleanupData() {
- dbi.inTransaction(new TransactionCallback<Void>() {
- @Override
- public Void inTransaction(final Handle h, final TransactionStatus status) throws Exception {
- h.execute("truncate table accounts");
- h.execute("truncate table notifications");
- h.execute("truncate table bus_events");
- h.execute("truncate table claimed_bus_events");
- h.execute("truncate table claimed_notifications");
- h.execute("truncate table tag_definitions");
- h.execute("truncate table tags");
- h.execute("truncate table custom_fields");
- return null;
- }
- });
- }
}
diff --git a/account/src/test/java/com/ning/billing/account/dao/TestAccountDao.java b/account/src/test/java/com/ning/billing/account/dao/TestAccountDao.java
index b3105c3..5d457e2 100644
--- a/account/src/test/java/com/ning/billing/account/dao/TestAccountDao.java
+++ b/account/src/test/java/com/ning/billing/account/dao/TestAccountDao.java
@@ -126,7 +126,6 @@ public class TestAccountDao extends AccountDaoTestBase {
assertEquals(account.getExternalKey(), key);
assertEquals(account.getName(), name);
assertEquals(account.getFirstNameLength(), firstNameLength);
-
}
@Test
@@ -359,9 +358,9 @@ public class TestAccountDao extends AccountDaoTestBase {
final String buggyKey = "extKey1338";
final DefaultAccount updatedAccountData = new DefaultAccount(accountId, buggyKey, "myemail1337@glam.com",
- "John Smith", 4, Currency.USD, 15, null,
- null, null, null, null, null, null, null, null, null, null,
- false, false);
+ "John Smith", 4, Currency.USD, 15, null,
+ null, null, null, null, null, null, null, null, null, null,
+ false, false);
accountDao.update(updatedAccountData, context);
Assert.assertNull(accountDao.getAccountByKey(buggyKey));
}
diff --git a/account/src/test/java/com/ning/billing/account/glue/AccountModuleWithMocks.java b/account/src/test/java/com/ning/billing/account/glue/AccountModuleWithMocks.java
index f806309..b224a46 100644
--- a/account/src/test/java/com/ning/billing/account/glue/AccountModuleWithMocks.java
+++ b/account/src/test/java/com/ning/billing/account/glue/AccountModuleWithMocks.java
@@ -16,10 +16,11 @@
package com.ning.billing.account.glue;
+import org.mockito.Mockito;
+
import com.ning.billing.account.dao.AccountDao;
import com.ning.billing.account.dao.AccountEmailDao;
import com.ning.billing.account.dao.MockAccountDao;
-import com.ning.billing.mock.BrainDeadProxyFactory;
import com.ning.billing.mock.glue.MockClockModule;
import com.ning.billing.util.glue.CallContextModule;
@@ -27,7 +28,7 @@ public class AccountModuleWithMocks extends AccountModule {
@Override
protected void installAccountDao() {
bind(MockAccountDao.class).asEagerSingleton();
- final AccountEmailDao accountEmailDao = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountEmailDao.class);
+ final AccountEmailDao accountEmailDao = Mockito.mock(AccountEmailDao.class);
bind(AccountEmailDao.class).toInstance(accountEmailDao);
bind(AccountDao.class).to(MockAccountDao.class);
}
diff --git a/analytics/src/main/java/com/ning/billing/analytics/AnalyticsListener.java b/analytics/src/main/java/com/ning/billing/analytics/AnalyticsListener.java
index 6337422..a5ad78f 100644
--- a/analytics/src/main/java/com/ning/billing/analytics/AnalyticsListener.java
+++ b/analytics/src/main/java/com/ning/billing/analytics/AnalyticsListener.java
@@ -25,7 +25,7 @@ import com.ning.billing.entitlement.api.timeline.RepairEntitlementEvent;
import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.RequestedSubscriptionEvent;
-import com.ning.billing.invoice.api.EmptyInvoiceEvent;
+import com.ning.billing.invoice.api.NullInvoiceEvent;
import com.ning.billing.invoice.api.InvoiceCreationEvent;
import com.ning.billing.overdue.OverdueChangeEvent;
import com.ning.billing.payment.api.PaymentErrorEvent;
@@ -101,7 +101,7 @@ public class AnalyticsListener {
}
@Subscribe
- public void handleNullInvoice(final EmptyInvoiceEvent event) {
+ public void handleNullInvoice(final NullInvoiceEvent event) {
// Ignored for now
}
diff --git a/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestModule.java b/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestModule.java
index e7c167e..d710c9f 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestModule.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestModule.java
@@ -62,7 +62,7 @@ public class AnalyticsTestModule extends AnalyticsModule {
install(new DefaultJunctionModule());
// Install the Dao layer
- final MysqlTestingHelper helper = TestWithEmbeddedDB.getMysqlTestingHelper();
+ final MysqlTestingHelper helper = AnalyticsTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
diff --git a/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestSuite.java b/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestSuite.java
index 489f5a1..e388f51 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestSuite.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestSuite.java
@@ -16,27 +16,7 @@
package com.ning.billing.analytics;
-import java.lang.reflect.Method;
+import com.ning.billing.KillbillTestSuite;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-
-public abstract class AnalyticsTestSuite {
- private static final Logger log = LoggerFactory.getLogger(AnalyticsTestSuite.class);
-
- @BeforeMethod(alwaysRun = true)
- public void startTest(final Method method) throws Exception {
- log.info("***************************************************************************************************");
- log.info("*** Starting test {}:{}", method.getDeclaringClass().getName(), method.getName());
- log.info("***************************************************************************************************");
- }
-
- @AfterMethod(alwaysRun = true)
- public void endTest(final Method method) throws Exception {
- log.info("***************************************************************************************************");
- log.info("*** Ending test {}:{}", method.getDeclaringClass().getName(), method.getName());
- log.info("***************************************************************************************************");
- }
+public abstract class AnalyticsTestSuite extends KillbillTestSuite {
}
diff --git a/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestSuiteWithEmbeddedDB.java b/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..8f6bd92
--- /dev/null
+++ b/analytics/src/test/java/com/ning/billing/analytics/AnalyticsTestSuiteWithEmbeddedDB.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.analytics;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class AnalyticsTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
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 405c431..2e71aa4 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
@@ -39,7 +39,7 @@ import com.ning.billing.analytics.AnalyticsTestModule;
import com.ning.billing.analytics.MockDuration;
import com.ning.billing.analytics.MockPhase;
import com.ning.billing.analytics.MockProduct;
-import com.ning.billing.analytics.TestWithEmbeddedDB;
+import com.ning.billing.analytics.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.dao.BusinessAccountSqlDao;
import com.ning.billing.analytics.dao.BusinessSubscriptionTransitionSqlDao;
import com.ning.billing.analytics.model.BusinessSubscription;
@@ -88,7 +88,7 @@ import com.ning.billing.util.clock.DefaultClock;
import static org.testng.Assert.fail;
@Guice(modules = {AnalyticsTestModule.class})
-public class TestAnalyticsService extends TestWithEmbeddedDB {
+public class TestAnalyticsService extends AnalyticsTestSuiteWithEmbeddedDB {
final Product product = new MockProduct("platinum", "subscription", ProductCategory.BASE);
final Plan plan = new MockPlan("platinum-monthly", product);
final PlanPhase phase = new MockPhase(PhaseType.EVERGREEN, plan, MockDuration.UNLIMITED(), 25.95);
@@ -225,7 +225,7 @@ public class TestAnalyticsService extends TestWithEmbeddedDB {
INVOICE_AMOUNT, ACCOUNT_CURRENCY);
invoice.addInvoiceItem(invoiceItem);
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, invoice.getTargetDate().getDayOfMonth(), context);
final List<Invoice> invoices = invoiceDao.getInvoicesByAccount(account.getId());
Assert.assertEquals(invoices.size(), 1);
Assert.assertEquals(invoices.get(0).getInvoiceItems().size(), 1);
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestAnalyticsDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestAnalyticsDao.java
index b083b48..67fec93 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestAnalyticsDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestAnalyticsDao.java
@@ -33,7 +33,7 @@ import org.testng.annotations.Test;
import com.ning.billing.analytics.MockDuration;
import com.ning.billing.analytics.MockPhase;
import com.ning.billing.analytics.MockProduct;
-import com.ning.billing.analytics.TestWithEmbeddedDB;
+import com.ning.billing.analytics.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessAccount;
import com.ning.billing.analytics.model.BusinessSubscription;
import com.ning.billing.analytics.model.BusinessSubscriptionEvent;
@@ -51,7 +51,7 @@ import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.mock.MockPlan;
-public class TestAnalyticsDao extends TestWithEmbeddedDB {
+public class TestAnalyticsDao extends AnalyticsTestSuiteWithEmbeddedDB {
private static final Long TOTAL_ORDERING = 1L;
private static final UUID BUNDLE_ID = UUID.randomUUID();
private static final String EXTERNAL_KEY = "23456";
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountFieldSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountFieldSqlDao.java
index 2c44668..196da64 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountFieldSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountFieldSqlDao.java
@@ -24,10 +24,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessAccountField;
-public class TestBusinessAccountFieldSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessAccountFieldSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessAccountFieldSqlDao accountFieldSqlDao;
@BeforeMethod(groups = "slow")
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
index 01e50a4..1a55220 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountTagSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessAccountTagSqlDao.java
@@ -24,10 +24,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessAccountTag;
-public class TestBusinessAccountTagSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessAccountTagSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessAccountTagSqlDao accountTagSqlDao;
@BeforeMethod(groups = "slow")
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceFieldSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceFieldSqlDao.java
index 9553dfa..910fe74 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceFieldSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceFieldSqlDao.java
@@ -24,10 +24,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessInvoiceField;
-public class TestBusinessInvoiceFieldSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessInvoiceFieldSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessInvoiceFieldSqlDao invoiceFieldSqlDao;
@BeforeMethod(groups = "slow")
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceItemSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceItemSqlDao.java
index 4d4a324..de6aa69 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceItemSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceItemSqlDao.java
@@ -26,11 +26,11 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessInvoiceItem;
import com.ning.billing.catalog.api.Currency;
-public class TestBusinessInvoiceItemSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessInvoiceItemSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessInvoiceItemSqlDao invoiceItemSqlDao;
@BeforeMethod(groups = "slow")
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentFieldSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentFieldSqlDao.java
index b97849d..c898a7f 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentFieldSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentFieldSqlDao.java
@@ -24,10 +24,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessInvoicePaymentField;
-public class TestBusinessInvoicePaymentFieldSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessInvoicePaymentFieldSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessInvoicePaymentFieldSqlDao invoicePaymentFieldSqlDao;
@BeforeMethod(groups = "slow")
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentSqlDao.java
index 9ec7696..7aed3b6 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentSqlDao.java
@@ -26,11 +26,11 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessInvoicePayment;
import com.ning.billing.catalog.api.Currency;
-public class TestBusinessInvoicePaymentSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessInvoicePaymentSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessInvoicePaymentSqlDao invoicePaymentSqlDao;
@BeforeMethod(groups = "slow")
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
index 5ae8f48..2fa6025 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentTagSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoicePaymentTagSqlDao.java
@@ -24,10 +24,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessInvoicePaymentTag;
-public class TestBusinessInvoicePaymentTagSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessInvoicePaymentTagSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessInvoicePaymentTagSqlDao invoicePaymentTagSqlDao;
@BeforeMethod(groups = "slow")
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceSqlDao.java
index b66e4ad..226c058 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceSqlDao.java
@@ -26,11 +26,11 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessInvoice;
import com.ning.billing.catalog.api.Currency;
-public class TestBusinessInvoiceSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessInvoiceSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessInvoiceSqlDao invoiceSqlDao;
@BeforeMethod(groups = "slow")
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
index 24ee93f..2c30a46 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceTagSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessInvoiceTagSqlDao.java
@@ -24,10 +24,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessInvoiceTag;
-public class TestBusinessInvoiceTagSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessInvoiceTagSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessInvoiceTagSqlDao invoiceTagSqlDao;
@BeforeMethod(groups = "slow")
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessOverdueStatusSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessOverdueStatusSqlDao.java
index ead1a4b..5db58e3 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessOverdueStatusSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessOverdueStatusSqlDao.java
@@ -25,10 +25,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessOverdueStatus;
-public class TestBusinessOverdueStatusSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessOverdueStatusSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessOverdueStatusSqlDao overdueStatusSqlDao;
@BeforeMethod(groups = "slow")
diff --git a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionFieldSqlDao.java b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionFieldSqlDao.java
index 528dc65..aac2fde 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionFieldSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionFieldSqlDao.java
@@ -24,10 +24,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessSubscriptionTransitionField;
-public class TestBusinessSubscriptionTransitionFieldSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessSubscriptionTransitionFieldSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessSubscriptionTransitionFieldSqlDao subscriptionTransitionFieldSqlDao;
@BeforeMethod(groups = "slow")
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
index 4ab67ad..60209fd 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionTagSqlDao.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/dao/TestBusinessSubscriptionTransitionTagSqlDao.java
@@ -24,10 +24,10 @@ 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.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.analytics.model.BusinessSubscriptionTransitionTag;
-public class TestBusinessSubscriptionTransitionTagSqlDao extends TestWithEmbeddedDB {
+public class TestBusinessSubscriptionTransitionTagSqlDao extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessSubscriptionTransitionTagSqlDao subscriptionTransitionTagSqlDao;
@BeforeMethod(groups = "slow")
diff --git a/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java b/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
index e2d9242..f693718 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
@@ -60,7 +60,7 @@ import com.ning.billing.util.clock.DefaultClock;
import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
-public class TestBusinessTagRecorder extends TestWithEmbeddedDB {
+public class TestBusinessTagRecorder extends AnalyticsTestSuiteWithEmbeddedDB {
private BusinessAccountTagSqlDao accountTagSqlDao;
private BusinessSubscriptionTransitionTagSqlDao subscriptionTransitionTagSqlDao;
private InMemoryBus eventBus;
diff --git a/api/src/main/java/com/ning/billing/BillingExceptionBase.java b/api/src/main/java/com/ning/billing/BillingExceptionBase.java
index a074d3e..85761ab 100644
--- a/api/src/main/java/com/ning/billing/BillingExceptionBase.java
+++ b/api/src/main/java/com/ning/billing/BillingExceptionBase.java
@@ -16,12 +16,12 @@
package com.ning.billing;
+import javax.annotation.Nullable;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public class BillingExceptionBase extends Exception {
-
private static final Logger log = LoggerFactory.getLogger(BillingExceptionBase.class);
private static final long serialVersionUID = 165720101383L;
@@ -42,9 +42,8 @@ public class BillingExceptionBase extends Exception {
this.cause = cause;
}
-
- public BillingExceptionBase(final Throwable cause, final ErrorCode code, final Object... args) {
- String tmp = null;
+ public BillingExceptionBase(@Nullable final Throwable cause, final ErrorCode code, final Object... args) {
+ final String tmp;
try {
tmp = String.format(code.getFormat(), args);
} catch (RuntimeException e) {
@@ -74,4 +73,14 @@ public class BillingExceptionBase extends Exception {
return code;
}
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("BillingExceptionBase");
+ sb.append("{cause=").append(cause);
+ sb.append(", code=").append(code);
+ sb.append(", formattedMsg='").append(formattedMsg).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
}
diff --git a/api/src/main/java/com/ning/billing/glue/InvoiceModule.java b/api/src/main/java/com/ning/billing/glue/InvoiceModule.java
index 7e55895..f513edd 100644
--- a/api/src/main/java/com/ning/billing/glue/InvoiceModule.java
+++ b/api/src/main/java/com/ning/billing/glue/InvoiceModule.java
@@ -17,13 +17,9 @@
package com.ning.billing.glue;
public interface InvoiceModule {
-
public abstract void installInvoiceUserApi();
public abstract void installInvoicePaymentApi();
public abstract void installInvoiceMigrationApi();
-
- public abstract void installInvoiceTestApi();
-
-}
\ No newline at end of file
+}
diff --git a/api/src/main/java/com/ning/billing/invoice/api/InvoiceCreationEvent.java b/api/src/main/java/com/ning/billing/invoice/api/InvoiceCreationEvent.java
index 0385827..5fb8964 100644
--- a/api/src/main/java/com/ning/billing/invoice/api/InvoiceCreationEvent.java
+++ b/api/src/main/java/com/ning/billing/invoice/api/InvoiceCreationEvent.java
@@ -22,12 +22,10 @@ import java.util.UUID;
import org.joda.time.DateTime;
import com.ning.billing.catalog.api.Currency;
-import com.ning.billing.util.bus.BusEvent;
-public interface InvoiceCreationEvent extends BusEvent {
- public UUID getInvoiceId();
+public interface InvoiceCreationEvent extends InvoiceEvent {
- public UUID getAccountId();
+ public UUID getInvoiceId();
public BigDecimal getAmountOwed();
diff --git a/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApiException.java b/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApiException.java
index d201a27..81f1946 100644
--- a/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApiException.java
+++ b/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentPluginApiException.java
@@ -13,10 +13,10 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.payment.plugin.api;
public class PaymentPluginApiException extends Exception {
-
private static final long serialVersionUID = 15642965L;
private final String errorType;
@@ -34,4 +34,14 @@ public class PaymentPluginApiException extends Exception {
public String getErrorMessage() {
return errorMessage;
}
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("PaymentPluginApiException");
+ sb.append("{errorMessage='").append(errorMessage).append('\'');
+ sb.append(", errorType='").append(errorType).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
}
diff --git a/api/src/main/java/com/ning/billing/util/userrequest/CompletionUserRequestWaiter.java b/api/src/main/java/com/ning/billing/util/userrequest/CompletionUserRequestWaiter.java
index 19f1b65..b7c308d 100644
--- a/api/src/main/java/com/ning/billing/util/userrequest/CompletionUserRequestWaiter.java
+++ b/api/src/main/java/com/ning/billing/util/userrequest/CompletionUserRequestWaiter.java
@@ -21,7 +21,7 @@ import java.util.concurrent.TimeoutException;
import com.ning.billing.account.api.AccountChangeEvent;
import com.ning.billing.account.api.AccountCreationEvent;
import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
-import com.ning.billing.invoice.api.EmptyInvoiceEvent;
+import com.ning.billing.invoice.api.NullInvoiceEvent;
import com.ning.billing.invoice.api.InvoiceCreationEvent;
import com.ning.billing.payment.api.PaymentErrorEvent;
import com.ning.billing.payment.api.PaymentInfoEvent;
@@ -39,7 +39,7 @@ public interface CompletionUserRequestWaiter {
public void onInvoiceCreation(final InvoiceCreationEvent curEvent);
- public void onEmptyInvoice(final EmptyInvoiceEvent curEvent);
+ public void onEmptyInvoice(final NullInvoiceEvent curEvent);
public void onPaymentInfo(final PaymentInfoEvent curEvent);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/BeatrixTestSuiteWithEmbeddedDB.java b/beatrix/src/test/java/com/ning/billing/beatrix/BeatrixTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..b6a8d20
--- /dev/null
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/BeatrixTestSuiteWithEmbeddedDB.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.beatrix;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class BeatrixTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixModule.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixModule.java
index c26fac5..96fcca7 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixModule.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixModule.java
@@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.account.api.AccountService;
import com.ning.billing.account.glue.AccountModule;
import com.ning.billing.analytics.setup.AnalyticsModule;
@@ -65,7 +66,6 @@ import static org.testng.Assert.assertNotNull;
public class BeatrixModule extends AbstractModule {
-
public static final String PLUGIN_NAME = "yoyo";
@Override
@@ -77,7 +77,7 @@ public class BeatrixModule extends AbstractModule {
bind(ClockMock.class).asEagerSingleton();
bind(Lifecycle.class).to(SubsetDefaultLifecycle.class).asEagerSingleton();
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
final IDBI dbi;
if (helper.isUsingLocalInstance()) {
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestAnalytics.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestAnalytics.java
index adc0fc6..27dddf5 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestAnalytics.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestAnalytics.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -52,6 +53,7 @@ import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.invoice.generator.InvoiceDateUtils;
import com.ning.billing.overdue.config.OverdueConfig;
import com.ning.billing.payment.api.PaymentStatus;
import com.ning.billing.util.api.TagApiException;
@@ -447,8 +449,9 @@ public class TestAnalytics extends TestIntegrationBase {
// No billing period for the trial item
Assert.assertEquals(invoiceItem.getBillingPeriod(), subscription.getCurrentPhase().getBillingPeriod().toString());
Assert.assertEquals(invoiceItem.getCurrency(), account.getCurrency());
- // The subscription end date is null (evergreen)
- Assert.assertEquals(invoiceItem.getEndDate(), subscription.getStartDate().plus(subscription.getCurrentPhase().getDuration().toJodaPeriod()));
+ final DateTime subscriptionEndDate = subscription.getStartDate().plus(subscription.getCurrentPhase().getDuration().toJodaPeriod());
+ final DateTime roundedSubscriptionEndDate = InvoiceDateUtils.roundDateTimeToDate(subscriptionEndDate, DateTimeZone.UTC);
+ Assert.assertEquals(invoiceItem.getEndDate(), roundedSubscriptionEndDate);
Assert.assertEquals(invoiceItem.getExternalKey(), bundle.getKey());
Assert.assertEquals(invoiceItem.getInvoiceId(), invoice.getInvoiceId());
Assert.assertEquals(invoiceItem.getItemType(), "FIXED");
@@ -457,7 +460,9 @@ public class TestAnalytics extends TestIntegrationBase {
Assert.assertEquals(invoiceItem.getProductName(), subscription.getCurrentPlan().getProduct().getName());
Assert.assertEquals(invoiceItem.getProductType(), subscription.getCurrentPlan().getProduct().getCatalogName());
Assert.assertEquals(invoiceItem.getSlug(), subscription.getCurrentPhase().getName());
- Assert.assertEquals(invoiceItem.getStartDate(), subscription.getStartDate());
+ final DateTime subscriptionStartDate = subscription.getStartDate();
+ final DateTime roundedSubscriptionStartDate = InvoiceDateUtils.roundDateTimeToDate(subscriptionStartDate, DateTimeZone.UTC);
+ Assert.assertEquals(invoiceItem.getStartDate(), roundedSubscriptionStartDate);
return subscription;
}
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
index 15910a3..9139a3e 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
@@ -41,123 +41,91 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
-@Test(groups = "slow")
@Guice(modules = {BeatrixModule.class})
public class TestIntegration extends TestIntegrationBase {
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "slow")
public void testBasePlanCompleteWithBillingDayInPast() throws Exception {
log.info("Starting testBasePlanCompleteWithBillingDayInPast");
- final DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ final DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
testBasePlanComplete(startDate, 31, false);
}
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "slow")
public void testBasePlanCompleteWithBillingDayPresent() throws Exception {
log.info("Starting testBasePlanCompleteWithBillingDayPresent");
- final DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ final DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
testBasePlanComplete(startDate, 1, false);
}
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "slow")
public void testBasePlanCompleteWithBillingDayAlignedWithTrial() throws Exception {
log.info("Starting testBasePlanCompleteWithBillingDayAlignedWithTrial");
- final DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ final DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
testBasePlanComplete(startDate, 2, false);
}
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "slow")
public void testBasePlanCompleteWithBillingDayInFuture() throws Exception {
log.info("Starting testBasePlanCompleteWithBillingDayInFuture");
- final DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ final DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
testBasePlanComplete(startDate, 3, true);
}
- @Test(groups = {"slow", "stress"}, enabled = false)
+ @Test(groups = {"stress"})
public void stressTest() throws Exception {
- final int maxIterations = 7;
+ final int maxIterations = 100;
for (int curIteration = 0; curIteration < maxIterations; curIteration++) {
+ if (curIteration != 0) {
+ setupTest();
+ }
+
log.info("################################ ITERATION " + curIteration + " #########################");
Thread.sleep(1000);
- setupTest();
testBasePlanCompleteWithBillingDayPresent();
Thread.sleep(1000);
+ cleanupTest();
setupTest();
testBasePlanCompleteWithBillingDayInPast();
Thread.sleep(1000);
+ cleanupTest();
setupTest();
testBasePlanCompleteWithBillingDayAlignedWithTrial();
Thread.sleep(1000);
+ cleanupTest();
setupTest();
testBasePlanCompleteWithBillingDayInFuture();
+ if (curIteration < maxIterations - 1) {
+ cleanupTest();
+ Thread.sleep(1000);
+ }
+
}
}
-// // STEPH set to disabled until test written properly and fixed
-// @Test(groups = "slow", enabled = true)
-// public void testRepairChangeBPWithAddonIncluded() throws Exception {
-//
-// log.info("Starting testRepairChangeBPWithAddonIncluded");
-//
-// DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
-// clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
-//
-// Account account = createAccountWithPaymentMethod(getAccountData(25));
-// assertNotNull(account);
-//
-// SubscriptionBundle bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", context);
-//
-// String productName = "Shotgun";
-// BillingPeriod term = BillingPeriod.MONTHLY;
-// String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
-//
-// busHandler.pushExpectedEvent(NextEvent.CREATE);
-// busHandler.pushExpectedEvent(NextEvent.INVOICE);
-// SubscriptionData baseSubscription = subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
-// new PlanPhaseSpecifier(productName, ProductCategory.BASE, term, planSetName, null), null, context));
-// assertNotNull(baseSubscription);
-// assertTrue(busHandler.isCompleted(DELAY));
-//
-// // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
-// Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3));
-// clock.addDeltaFromReality(it.toDurationMillis());
-//
-// busHandler.pushExpectedEvent(NextEvent.CREATE);
-// busHandler.pushExpectedEvent(NextEvent.INVOICE);
-// busHandler.pushExpectedEvent(NextEvent.PAYMENT);
-// subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
-// new PlanPhaseSpecifier("Telescopic-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null), null, context));
-// assertTrue(busHandler.isCompleted(DELAY));
-//
-// busHandler.pushExpectedEvent(NextEvent.CREATE);
-// busHandler.pushExpectedEvent(NextEvent.INVOICE);
-// busHandler.pushExpectedEvent(NextEvent.PAYMENT);
-// subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
-// new PlanPhaseSpecifier("Laser-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null), null, context));
-// assertTrue(busHandler.isCompleted(DELAY));
-//
-//
-// // 26 / 5
-// int duration = 28;
-// it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(duration));
-// busHandler.pushExpectedEvent(NextEvent.PHASE);
-// busHandler.pushExpectedEvent(NextEvent.PHASE);
-// busHandler.pushExpectedEvent(NextEvent.PHASE);
-// busHandler.pushExpectedEvent(NextEvent.INVOICE);
-// busHandler.pushExpectedEvent(NextEvent.PAYMENT);
-// clock.addDeltaFromReality(it.toDurationMillis());
-// assertTrue(busHandler.isCompleted(DELAY));
-//
-// assertListenerStatus();
-// }
-
- // STEPH set to disabled until test written properly and fixed
- @Test(groups = "slow", enabled = false)
- public void testRepairChangeBPWithAddonIncluded() throws Exception {
+ @Test(groups = {"stress"})
+ public void stressTestDebug() throws Exception {
+ final int maxIterations = 100;
+ for (int curIteration = 0; curIteration < maxIterations; curIteration++) {
+ log.info("################################ ITERATION " + curIteration + " #########################");
+ if (curIteration != 0) {
+ setupTest();
+ }
+ testAddonsWithMultipleAlignments();
+ if (curIteration < maxIterations - 1) {
+ cleanupTest();
+ Thread.sleep(1000);
+ }
+ }
+ }
+
+
+ @Test(groups = "slow")
+ public void testAddonsWithMultipleAlignments() throws Exception {
log.info("Starting testRepairChangeBPWithAddonIncluded");
- final DateTime initialDate = new DateTime(2012, 4, 25, 0, 13, 42, 0);
+ final DateTime initialDate = new DateTime(2012, 4, 25, 0, 13, 42, 0, testTimeZone);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithPaymentMethod(getAccountData(25));
@@ -199,19 +167,16 @@ public class TestIntegration extends TestIntegrationBase {
assertTrue(busHandler.isCompleted(DELAY));
assertListenerStatus();
- // MOVE CLOCK A LITTLE BIT MORE -- EITHER STAY IN TRIAL OR GET OUT
+ // MOVE CLOCK A LITTLE BIT MORE -- EITHER STAY IN TRIAL OR GET OUT
busHandler.pushExpectedEvent(NextEvent.PHASE);
busHandler.pushExpectedEvent(NextEvent.PHASE);
- busHandler.pushExpectedEvent(NextEvent.INVOICE);
busHandler.pushExpectedEvent(NextEvent.PAYMENT);
busHandler.pushExpectedEvent(NextEvent.INVOICE);
- busHandler.pushExpectedEvent(NextEvent.PAYMENT);
log.info("Moving clock from" + clock.getUTCNow() + " to " + clock.getUTCNow().plusDays(28));
clock.addDays(28);// 26 / 5
assertTrue(busHandler.isCompleted(DELAY));
assertListenerStatus();
-
busHandler.pushExpectedEvent(NextEvent.PHASE);
busHandler.pushExpectedEvent(NextEvent.INVOICE);
busHandler.pushExpectedEvent(NextEvent.PAYMENT);
@@ -220,13 +185,11 @@ public class TestIntegration extends TestIntegrationBase {
assertTrue(busHandler.isCompleted(DELAY));
assertListenerStatus();
-
log.info("Moving clock from" + clock.getUTCNow() + " to " + clock.getUTCNow().plusDays(10));
clock.addDays(10);// 8 / 6
assertTrue(busHandler.isCompleted(DELAY));
assertListenerStatus();
-
busHandler.pushExpectedEvent(NextEvent.INVOICE);
busHandler.pushExpectedEvent(NextEvent.PAYMENT);
log.info("Moving clock from" + clock.getUTCNow() + " to " + clock.getUTCNow().plusDays(18));
@@ -238,8 +201,6 @@ public class TestIntegration extends TestIntegrationBase {
clock.addDays(3);
assertTrue(busHandler.isCompleted(DELAY));
assertListenerStatus();
-
-
}
@@ -252,7 +213,7 @@ public class TestIntegration extends TestIntegrationBase {
final UUID accountId = account.getId();
assertNotNull(account);
- final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
+ final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0, testTimeZone);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final SubscriptionBundle bundle = entitlementUserApi.createBundleForAccount(account.getId(), "someBundle", context);
@@ -275,12 +236,12 @@ public class TestIntegration extends TestIntegrationBase {
// TODO: Jeff implement repair
}
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "slow")
public void testWithRecreatePlan() throws Exception {
log.info("Starting testWithRecreatePlan");
- final DateTime initialDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ final DateTime initialDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
final int billingDay = 2;
log.info("Beginning test with BCD of " + billingDay);
@@ -351,7 +312,6 @@ public class TestIntegration extends TestIntegrationBase {
private void testBasePlanComplete(final DateTime initialCreationDate, final int billingDay,
final boolean proRationExpected) throws Exception {
-
log.info("Beginning test with BCD of " + billingDay);
final Account account = createAccountWithPaymentMethod(getAccountData(billingDay));
final UUID accountId = account.getId();
@@ -554,7 +514,7 @@ public class TestIntegration extends TestIntegrationBase {
log.info("Starting testForMultipleRecurringPhases");
- final DateTime initialCreationDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ final DateTime initialCreationDate = new DateTime(2012, 2, 1, 0, 3, 42, 0, testTimeZone);
clock.setDeltaFromReality(initialCreationDate.getMillis() - clock.getUTCNow().getMillis());
final Account account = createAccountWithPaymentMethod(getAccountData(2));
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 7aeaa80..f20ac76 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
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.beatrix.integration;
import java.io.IOException;
@@ -42,6 +43,7 @@ import com.ning.billing.analytics.AnalyticsListener;
import com.ning.billing.analytics.api.user.DefaultAnalyticsUserApi;
import com.ning.billing.api.TestApiListener;
import com.ning.billing.api.TestListenerStatus;
+import com.ning.billing.beatrix.BeatrixTestSuiteWithEmbeddedDB;
import com.ning.billing.beatrix.lifecycle.Lifecycle;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.dbi.MysqlTestingHelper;
@@ -55,6 +57,7 @@ import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceService;
import com.ning.billing.invoice.api.InvoiceUserApi;
+import com.ning.billing.invoice.generator.InvoiceDateUtils;
import com.ning.billing.invoice.model.InvoicingConfiguration;
import com.ning.billing.junction.plumbing.api.BlockingSubscription;
import com.ning.billing.overdue.wrapper.OverdueWrapperFactory;
@@ -75,7 +78,9 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-public class TestIntegrationBase implements TestListenerStatus {
+public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implements TestListenerStatus {
+ protected static final DateTimeZone testTimeZone = DateTimeZone.UTC;
+
protected static final int NUMBER_OF_DECIMALS = InvoicingConfiguration.getNumberOfDecimals();
protected static final int ROUNDING_METHOD = InvoicingConfiguration.getRoundingMode();
@@ -87,7 +92,6 @@ public class TestIntegrationBase implements TestListenerStatus {
protected static final Logger log = LoggerFactory.getLogger(TestIntegration.class);
protected static long AT_LEAST_ONE_MONTH_MS = 31L * 24L * 3600L * 1000L;
-
protected static final long DELAY = 5000;
@Inject
@@ -148,7 +152,6 @@ public class TestIntegrationBase implements TestListenerStatus {
protected TestApiListener busHandler;
-
private boolean isListenerFailed;
private String listenerFailedMsg;
@@ -164,7 +167,6 @@ public class TestIntegrationBase implements TestListenerStatus {
listenerFailedMsg = null;
}
-
protected void assertListenerStatus() {
if (isListenerFailed) {
log.error(listenerFailedMsg);
@@ -172,52 +174,17 @@ public class TestIntegrationBase implements TestListenerStatus {
}
}
- protected void setupMySQL() throws IOException {
- final String accountDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/account/ddl.sql"));
- final String analyticsDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/analytics/ddl.sql"));
- final String entitlementDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/entitlement/ddl.sql"));
- final String invoiceDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/invoice/ddl.sql"));
- final String paymentDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/payment/ddl.sql"));
- final String utilDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- final String junctionDb = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/junction/ddl.sql"));
-
- helper.startMysql();
-
- helper.initDb(accountDdl);
- helper.initDb(analyticsDdl);
- helper.initDb(entitlementDdl);
- helper.initDb(invoiceDdl);
- helper.initDb(paymentDdl);
- helper.initDb(utilDdl);
- helper.initDb(junctionDb);
- }
-
-
@BeforeClass(groups = "slow")
public void setup() throws Exception {
-
- setupMySQL();
-
context = new DefaultCallContextFactory(clock).createCallContext("Integration Test", CallOrigin.TEST, UserType.TEST);
busHandler = new TestApiListener(this);
-
- }
-
- @AfterClass(groups = "slow")
- public void tearDown() throws Exception {
- helper.stopMysql();
}
-
@BeforeMethod(groups = "slow")
public void setupTest() throws Exception {
-
log.warn("\n");
log.warn("RESET TEST FRAMEWORK\n\n");
- // Pre test cleanup
- helper.cleanupAllTables();
-
clock.resetDeltaFromReality();
resetTestListenerStatus();
@@ -236,7 +203,6 @@ public class TestIntegrationBase implements TestListenerStatus {
log.warn("DONE WITH TEST\n");
}
-
protected void verifyTestResult(final UUID accountId, final UUID subscriptionId,
final DateTime startDate, final DateTime endDate,
final BigDecimal amount, final DateTime chargeThroughDate,
@@ -252,9 +218,12 @@ public class TestIntegrationBase implements TestListenerStatus {
boolean wasFound = false;
+ // Make sure to round the dates in the comparisons as the invoice items dates are rounded
+ final DateTime roundedStartDate = InvoiceDateUtils.roundDateTimeToDate(startDate, testTimeZone);
+ final DateTime roundedEndDate = InvoiceDateUtils.roundDateTimeToDate(endDate, testTimeZone);
for (final InvoiceItem item : invoiceItems) {
- if (item.getStartDate().compareTo(startDate) == 0) {
- if (item.getEndDate().compareTo(endDate) == 0) {
+ if (item.getStartDate().compareTo(roundedStartDate) == 0) {
+ if (item.getEndDate().compareTo(roundedEndDate) == 0) {
if (item.getAmount().compareTo(amount) == 0) {
wasFound = true;
break;
@@ -271,7 +240,8 @@ public class TestIntegrationBase implements TestListenerStatus {
assertNotNull(ctd);
log.info("Checking CTD: " + ctd.toString() + "; clock is " + clock.getUTCNow().toString());
assertTrue(clock.getUTCNow().isBefore(ctd));
- assertTrue(ctd.compareTo(chargeThroughDate) == 0);
+ // The CTD is rounded too
+ assertTrue(ctd.compareTo(InvoiceDateUtils.roundDateTimeToDate(chargeThroughDate, testTimeZone)) == 0);
}
protected SubscriptionData subscriptionDataFromSubscription(final Subscription sub) {
@@ -303,11 +273,11 @@ public class TestIntegrationBase implements TestListenerStatus {
return UUID.randomUUID().toString();
}
};
+
paymentApi.addPaymentMethod(BeatrixModule.PLUGIN_NAME, account, true, info, context);
return accountUserApi.getAccountById(account.getId());
}
-
protected AccountData getAccountData(final int billingDay) {
final String someRandomKey = UUID.randomUUID().toString();
return new AccountData() {
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/lifecycle/TestLifecycle.java b/beatrix/src/test/java/com/ning/billing/beatrix/lifecycle/TestLifecycle.java
index ac41b0e..649297c 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/lifecycle/TestLifecycle.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/lifecycle/TestLifecycle.java
@@ -27,13 +27,12 @@ import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Stage;
+import com.ning.billing.beatrix.BeatrixTestSuite;
import com.ning.billing.lifecycle.KillbillService;
import com.ning.billing.lifecycle.LifecycleHandlerType;
import com.ning.billing.lifecycle.LifecycleHandlerType.LifecycleLevel;
-
-public class TestLifecycle {
-
+public class TestLifecycle extends BeatrixTestSuite {
private static final Logger log = LoggerFactory.getLogger(TestLifecycle.class);
private Service1 s1;
@@ -42,7 +41,6 @@ public class TestLifecycle {
private DefaultLifecycle lifecycle;
public static class ServiceBase {
-
private int count = 0;
public ServiceBase() {
@@ -63,7 +61,6 @@ public class TestLifecycle {
}
public static class Service1 extends ServiceBase implements KillbillService {
-
@LifecycleHandlerType(LifecycleLevel.INIT_BUS)
public void initBus() {
log.info("Service1 : got INIT_BUS");
@@ -89,7 +86,6 @@ public class TestLifecycle {
}
public static class Service2 extends ServiceBase implements KillbillService {
-
@LifecycleHandlerType(LifecycleLevel.LOAD_CATALOG)
public void loadCatalog() {
log.info("Service2 : got LOAD_CATALOG");
@@ -120,8 +116,7 @@ public class TestLifecycle {
}
}
-
- @BeforeClass(alwaysRun = true)
+ @BeforeClass(groups = "fast")
public void setup() {
final Injector g = Guice.createInjector(Stage.DEVELOPMENT, new TestLifecycleModule());
s1 = g.getInstance(Service1.class);
@@ -129,7 +124,7 @@ public class TestLifecycle {
lifecycle = g.getInstance(DefaultLifecycle.class);
}
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testLifecycle() {
s1.reset();
s2.reset();
@@ -153,7 +148,6 @@ public class TestLifecycle {
}
public static class LifecycleNoWarn extends DefaultLifecycle {
-
@Inject
public LifecycleNoWarn(final Injector injector) {
super(injector);
@@ -165,14 +159,12 @@ public class TestLifecycle {
}
public static class TestLifecycleModule extends AbstractModule {
-
@Override
protected void configure() {
bind(DefaultLifecycle.class).to(LifecycleNoWarn.class).asEagerSingleton();
bind(Service1.class).asEagerSingleton();
bind(Service2.class).asEagerSingleton();
}
-
}
}
catalog/pom.xml 5(+5 -0)
diff --git a/catalog/pom.xml b/catalog/pom.xml
index bc40a07..e7dd393 100644
--- a/catalog/pom.xml
+++ b/catalog/pom.xml
@@ -39,6 +39,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
diff --git a/catalog/src/test/java/com/ning/billing/catalog/io/TestVersionedCatalogLoader.java b/catalog/src/test/java/com/ning/billing/catalog/io/TestVersionedCatalogLoader.java
index dc2b28b..ac30ca3 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/io/TestVersionedCatalogLoader.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/io/TestVersionedCatalogLoader.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.catalog.io;
import javax.xml.bind.JAXBException;
@@ -26,47 +27,43 @@ import java.util.Iterator;
import java.util.List;
import org.joda.time.DateTime;
+import org.testng.Assert;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;
import com.google.common.io.Resources;
+import com.ning.billing.catalog.CatalogTestSuite;
import com.ning.billing.catalog.StandaloneCatalog;
import com.ning.billing.catalog.VersionedCatalog;
import com.ning.billing.catalog.api.InvalidConfigException;
import com.ning.billing.lifecycle.KillbillService.ServiceException;
import com.ning.billing.util.clock.DefaultClock;
-import static org.testng.AssertJUnit.assertEquals;
-
-public class TestVersionedCatalogLoader {
+public class TestVersionedCatalogLoader extends CatalogTestSuite {
private final VersionedCatalogLoader loader = new VersionedCatalogLoader(new DefaultClock());
-
- @Test(enabled = true)
- public void testAppendToURI() throws MalformedURLException, IOException, URISyntaxException {
+ @Test(groups = "fast")
+ public void testAppendToURI() throws IOException, URISyntaxException {
final URL u1 = new URL("http://www.ning.com/foo");
- assertEquals("http://www.ning.com/foo/bar", loader.appendToURI(u1, "bar").toString());
+ Assert.assertEquals(loader.appendToURI(u1, "bar").toString(), "http://www.ning.com/foo/bar");
final URL u2 = new URL("http://www.ning.com/foo/");
- assertEquals("http://www.ning.com/foo/bar", loader.appendToURI(u2, "bar").toString());
-
+ Assert.assertEquals(loader.appendToURI(u2, "bar").toString(), "http://www.ning.com/foo/bar");
}
-
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testFindXmlFileReferences() throws MalformedURLException, URISyntaxException {
final String page = "dg.xml\n" +
"replica.foo\n" +
"snv1/\n" +
"viking.xml\n";
final List<URI> urls = loader.findXmlFileReferences(page, new URL("http://ning.com/"));
- assertEquals(2, urls.size());
- assertEquals("http://ning.com/dg.xml", urls.get(0).toString());
- assertEquals("http://ning.com/viking.xml", urls.get(1).toString());
-
+ Assert.assertEquals(urls.size(), 2);
+ Assert.assertEquals(urls.get(0).toString(), "http://ning.com/dg.xml");
+ Assert.assertEquals(urls.get(1).toString(), "http://ning.com/viking.xml");
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testExtractHrefs() {
final String page = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" +
"<html>" +
@@ -86,12 +83,12 @@ public class TestVersionedCatalogLoader {
"<address>Apache/2.2.3 (CentOS) Server at <a href=\"mailto:kate@ning.com\">gepo.ningops.net</a> Port 80</address>" +
"</body></html>";
final List<String> hrefs = loader.extractHrefs(page);
- assertEquals(8, hrefs.size());
- assertEquals("/config/trunk/", hrefs.get(0));
- assertEquals("dg.xml", hrefs.get(1));
+ Assert.assertEquals(hrefs.size(), 8);
+ Assert.assertEquals(hrefs.get(0), "/config/trunk/");
+ Assert.assertEquals(hrefs.get(1), "dg.xml");
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testFindXmlUrlReferences() throws MalformedURLException, URISyntaxException {
final String page = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" +
"<html>" +
@@ -111,22 +108,21 @@ public class TestVersionedCatalogLoader {
"<address>Apache/2.2.3 (CentOS) Server at <a href=\"mailto:kate@ning.com\">gepo.ningops.net</a> Port 80</address>" +
"</body></html>";
final List<URI> uris = loader.findXmlUrlReferences(page, new URL("http://ning.com/"));
- assertEquals(2, uris.size());
- assertEquals("http://ning.com/dg.xml", uris.get(0).toString());
- assertEquals("http://ning.com/viking.xml", uris.get(1).toString());
-
+ Assert.assertEquals(uris.size(), 2);
+ Assert.assertEquals(uris.get(0).toString(), "http://ning.com/dg.xml");
+ Assert.assertEquals(uris.get(1).toString(), "http://ning.com/viking.xml");
}
- @Test(enabled = true)
- public void testLoad() throws MalformedURLException, IOException, SAXException, InvalidConfigException, JAXBException, TransformerException, URISyntaxException, ServiceException {
+ @Test(groups = "fast")
+ public void testLoad() throws IOException, SAXException, InvalidConfigException, JAXBException, TransformerException, URISyntaxException, ServiceException {
final VersionedCatalog c = loader.load(Resources.getResource("versionedCatalog").toString());
- assertEquals(3, c.size());
+ Assert.assertEquals(c.size(), 3);
final Iterator<StandaloneCatalog> it = c.iterator();
DateTime dt = new DateTime("2011-01-01T00:00:00+00:00");
- assertEquals(dt.toDate(), it.next().getEffectiveDate());
+ Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate());
dt = new DateTime("2011-02-02T00:00:00+00:00");
- assertEquals(dt.toDate(), it.next().getEffectiveDate());
+ Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate());
dt = new DateTime("2011-03-03T00:00:00+00:00");
- assertEquals(dt.toDate(), it.next().getEffectiveDate());
+ Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate());
}
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/io/TestXMLReader.java b/catalog/src/test/java/com/ning/billing/catalog/io/TestXMLReader.java
index b03f18b..8d91c8e 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/io/TestXMLReader.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/io/TestXMLReader.java
@@ -16,18 +16,22 @@
package com.ning.billing.catalog.io;
+import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.common.io.Resources;
+import com.ning.billing.catalog.CatalogTestSuite;
import com.ning.billing.catalog.StandaloneCatalog;
import com.ning.billing.util.config.XMLLoader;
-public class TestXMLReader {
-
- @Test(enabled = true)
- public void testCatalogLoad() throws Exception {
- XMLLoader.getObjectFromString(Resources.getResource("WeaponsHire.xml").toExternalForm(), StandaloneCatalog.class);
- XMLLoader.getObjectFromString(Resources.getResource("WeaponsHireSmall.xml").toExternalForm(), StandaloneCatalog.class);
+public class TestXMLReader extends CatalogTestSuite {
+ @Test(groups = "fast")
+ public void testCatalogLoad() {
+ try {
+ XMLLoader.getObjectFromString(Resources.getResource("WeaponsHire.xml").toExternalForm(), StandaloneCatalog.class);
+ XMLLoader.getObjectFromString(Resources.getResource("WeaponsHireSmall.xml").toExternalForm(), StandaloneCatalog.class);
+ } catch (Exception e) {
+ Assert.fail(e.toString());
+ }
}
-
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/MockCatalogModule.java b/catalog/src/test/java/com/ning/billing/catalog/MockCatalogModule.java
index 4af0136..30435bb 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/MockCatalogModule.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/MockCatalogModule.java
@@ -16,24 +16,20 @@
package com.ning.billing.catalog;
+import org.mockito.Mockito;
+
import com.google.inject.AbstractModule;
import com.ning.billing.catalog.api.Catalog;
import com.ning.billing.catalog.api.CatalogService;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
public class MockCatalogModule extends AbstractModule {
-
@Override
protected void configure() {
- CatalogService catalogService = BrainDeadProxyFactory.createBrainDeadProxyFor(CatalogService.class);
- ((ZombieControl) catalogService).addResult("getCurrentCatalog", new MockCatalog());
-
- catalogService = BrainDeadProxyFactory.createBrainDeadProxyFor(CatalogService.class);
- final Catalog catalog = BrainDeadProxyFactory.createBrainDeadProxyFor(Catalog.class);
-
- ((ZombieControl) catalogService).addResult("getFullCatalog", catalog);
+ final Catalog catalog = Mockito.mock(Catalog.class);
+ final CatalogService catalogService = Mockito.mock(CatalogService.class);
+ Mockito.when(catalogService.getCurrentCatalog()).thenReturn(new MockCatalog());
+ Mockito.when(catalogService.getFullCatalog()).thenReturn(catalog);
bind(CatalogService.class).toInstance(catalogService);
}
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
index 5ae3793..50c1186 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCase.java
@@ -23,6 +23,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.ning.billing.ErrorCode;
+import com.ning.billing.catalog.CatalogTestSuite;
import com.ning.billing.catalog.DefaultPriceList;
import com.ning.billing.catalog.DefaultProduct;
import com.ning.billing.catalog.MockCatalog;
@@ -33,13 +34,8 @@ import com.ning.billing.catalog.api.PlanSpecifier;
import com.ning.billing.catalog.api.PriceListSet;
import com.ning.billing.catalog.api.ProductCategory;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-
-public class TestCase {
-
+public class TestCase extends CatalogTestSuite {
protected class CaseResult extends Case<Result> {
-
@XmlElement(required = true)
private final Result policy;
@@ -107,14 +103,13 @@ public class TestCase {
}
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testBasic() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
-
final CaseResult cr = new CaseResult(
product,
ProductCategory.BASE,
@@ -129,14 +124,13 @@ public class TestCase {
assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardProduct() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
-
final CaseResult cr = new CaseResult(
null,
ProductCategory.BASE,
@@ -152,14 +146,13 @@ public class TestCase {
assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardProductCategory() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
-
final CaseResult cr = new CaseResult(
product,
null,
@@ -175,14 +168,13 @@ public class TestCase {
assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardBillingPeriod() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
-
final CaseResult cr = new CaseResult(
product,
ProductCategory.BASE,
@@ -198,14 +190,13 @@ public class TestCase {
assertionException(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, "dipsy", cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardPriceList() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
-
final CaseResult cr = new CaseResult(
product,
ProductCategory.BASE,
@@ -228,7 +219,6 @@ public class TestCase {
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
-
final CaseResult cr0 = new CaseResult(
product,
ProductCategory.BASE,
@@ -258,17 +248,16 @@ public class TestCase {
Result.LALA);
final Result r1 = Case.getResult(new CaseResult[]{cr0, cr1, cr2, cr3},
- new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName()), cat);
- assertEquals(Result.FOO, r1);
+ new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName()), cat);
+ Assert.assertEquals(r1, Result.FOO);
final Result r2 = Case.getResult(new CaseResult[]{cr0, cr1, cr2},
- new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName()), cat);
- assertEquals(Result.DIPSY, r2);
+ new PlanSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName()), cat);
+ Assert.assertEquals(r2, Result.DIPSY);
}
-
protected void assertionNull(final CaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final StandaloneCatalog cat) throws CatalogApiException {
- assertNull(cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
+ Assert.assertNull(cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
}
protected void assertionException(final CaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final StandaloneCatalog cat) {
@@ -281,8 +270,6 @@ public class TestCase {
}
protected void assertion(final Result result, final CaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final StandaloneCatalog cat) throws CatalogApiException {
- assertEquals(result, cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
+ Assert.assertEquals(result, cr.getResult(new PlanSpecifier(productName, productCategory, bp, priceListName), cat));
}
-
-
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
index a52b02c..e29d713 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCaseChange.java
@@ -22,6 +22,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.ning.billing.ErrorCode;
+import com.ning.billing.catalog.CatalogTestSuite;
import com.ning.billing.catalog.DefaultPriceList;
import com.ning.billing.catalog.DefaultProduct;
import com.ning.billing.catalog.MockCatalog;
@@ -34,12 +35,8 @@ import com.ning.billing.catalog.api.PlanSpecifier;
import com.ning.billing.catalog.api.PriceListSet;
import com.ning.billing.catalog.api.ProductCategory;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-
-public class TestCaseChange {
+public class TestCaseChange extends CatalogTestSuite {
protected static class CaseChangeResult extends CaseChange<Result> {
-
@XmlElement(required = true)
private final Result result;
@@ -68,7 +65,7 @@ public class TestCaseChange {
}
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testBasic() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -78,7 +75,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, product2,
ProductCategory.BASE, ProductCategory.BASE,
@@ -158,7 +154,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildcardFromProduct() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -168,7 +164,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
null, product2,
ProductCategory.BASE, ProductCategory.BASE,
@@ -241,7 +236,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildcardToProduct() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -251,7 +246,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, null,
ProductCategory.BASE, ProductCategory.BASE,
@@ -331,7 +325,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildcardFromProductCategory() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -341,7 +335,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, product2,
null, ProductCategory.BASE,
@@ -421,7 +414,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildcardToProductCategory() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -431,7 +424,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, product2,
ProductCategory.BASE, null,
@@ -511,7 +503,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildcardFromBillingPeriod() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -521,7 +513,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, product2,
ProductCategory.BASE, ProductCategory.BASE,
@@ -601,8 +592,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
-
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardToBillingPeriod() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -612,7 +602,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, product2,
ProductCategory.BASE, ProductCategory.BASE,
@@ -692,7 +681,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardFromPriceList() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -702,7 +691,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, product2,
ProductCategory.BASE, ProductCategory.BASE,
@@ -782,7 +770,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildcardToPriceList() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -792,7 +780,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, product2,
ProductCategory.BASE, ProductCategory.BASE,
@@ -872,7 +859,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildcardPlanPhase() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -882,7 +869,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr = new CaseChangeResult(
product1, product2,
ProductCategory.BASE, ProductCategory.BASE,
@@ -962,8 +948,7 @@ public class TestCaseChange {
PhaseType.TRIAL, cat);
}
-
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testOrder() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
@@ -973,7 +958,6 @@ public class TestCaseChange {
final DefaultProduct product2 = cat.getCurrentProducts()[2];
final DefaultPriceList priceList2 = cat.getPriceLists().getChildPriceLists()[1];
-
final CaseChangeResult cr0 = new CaseChangeResult(
product1, product2,
ProductCategory.BASE, ProductCategory.BASE,
@@ -1015,20 +999,18 @@ public class TestCaseChange {
Result.LALA);
final Result r1 = CaseChange.getResult(new CaseChangeResult[]{cr0, cr1, cr2, cr3, cr4},
- new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN),
- new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.MONTHLY, priceList2.getName()), cat);
+ new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN),
+ new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.MONTHLY, priceList2.getName()), cat);
- assertEquals(Result.FOO, r1);
+ Assert.assertEquals(r1, Result.FOO);
final Result r2 = CaseChange.getResult(new CaseChangeResult[]{cr0, cr1, cr2, cr3, cr4},
- new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN),
- new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.ANNUAL, priceList2.getName()), cat);
-
- assertEquals(Result.DIPSY, r2);
+ new PlanPhaseSpecifier(product1.getName(), product1.getCategory(), BillingPeriod.MONTHLY, priceList1.getName(), PhaseType.EVERGREEN),
+ new PlanSpecifier(product2.getName(), product2.getCategory(), BillingPeriod.ANNUAL, priceList2.getName()), cat);
+ Assert.assertEquals(r2, Result.DIPSY);
}
-
protected void assertionNull(final CaseChangeResult cr,
final String fromProductName, final String toProductName,
final ProductCategory fromProductCategory, final ProductCategory toProductCategory,
@@ -1036,8 +1018,8 @@ public class TestCaseChange {
final String fromPriceListName, final String toPriceListName,
final PhaseType phaseType, final StandaloneCatalog cat) {
try {
- assertNull(cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType),
- new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName), cat));
+ Assert.assertNull(cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType),
+ new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName), cat));
} catch (CatalogApiException e) {
Assert.fail("", e);
}
@@ -1065,11 +1047,10 @@ public class TestCaseChange {
final String fromPriceListName, final String toPriceListName,
final PhaseType phaseType, final StandaloneCatalog cat) {
try {
- assertEquals(result, cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType),
- new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName), cat));
+ Assert.assertEquals(result, cr.getResult(new PlanPhaseSpecifier(fromProductName, fromProductCategory, fromBp, fromPriceListName, phaseType),
+ new PlanSpecifier(toProductName, toProductCategory, toBp, toPriceListName), cat));
} catch (CatalogApiException e) {
Assert.fail("", e);
}
}
-
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
index 26dfc5c..e7ae6a8 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestCasePhase.java
@@ -22,6 +22,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.ning.billing.ErrorCode;
+import com.ning.billing.catalog.CatalogTestSuite;
import com.ning.billing.catalog.DefaultPriceList;
import com.ning.billing.catalog.DefaultProduct;
import com.ning.billing.catalog.MockCatalog;
@@ -32,9 +33,8 @@ import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.ProductCategory;
-public class TestCasePhase {
+public class TestCasePhase extends CatalogTestSuite {
protected class CaseResult extends CasePhase<Result> {
-
@XmlElement(required = true)
private final Result policy;
@@ -55,14 +55,13 @@ public class TestCasePhase {
}
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testBasic() {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
-
final CaseResult cr = new CaseResult(
product,
ProductCategory.BASE,
@@ -79,14 +78,13 @@ public class TestCasePhase {
assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardProduct() {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
-
final CaseResult cr = new CaseResult(
null,
ProductCategory.BASE,
@@ -103,14 +101,13 @@ public class TestCasePhase {
assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardProductCategory() {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
-
final CaseResult cr = new CaseResult(
product,
null,
@@ -127,14 +124,13 @@ public class TestCasePhase {
assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardBillingPeriod() {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
-
final CaseResult cr = new CaseResult(
product,
ProductCategory.BASE,
@@ -151,14 +147,13 @@ public class TestCasePhase {
assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardPriceList() {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
-
final CaseResult cr = new CaseResult(
product,
ProductCategory.BASE,
@@ -175,14 +170,13 @@ public class TestCasePhase {
assertionNull(cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testWildCardPhaseType() {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
-
final CaseResult cr = new CaseResult(
product,
ProductCategory.BASE,
@@ -199,14 +193,13 @@ public class TestCasePhase {
assertion(Result.FOO, cr, product.getName(), ProductCategory.BASE, BillingPeriod.MONTHLY, priceList.getName(), PhaseType.TRIAL, cat);
}
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testOrder() throws CatalogApiException {
final MockCatalog cat = new MockCatalog();
final DefaultProduct product = cat.getCurrentProducts()[0];
final DefaultPriceList priceList = cat.getPriceLists().getDefaultPricelist();
-
final CaseResult cr0 = new CaseResult(
product,
ProductCategory.BASE,
@@ -248,18 +241,17 @@ public class TestCasePhase {
Result.LALA);
final Result r1 = CasePhase.getResult(new CaseResult[]{cr0, cr1, cr2, cr3, cr4},
- new PlanPhaseSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN), cat);
+ new PlanPhaseSpecifier(product.getName(), product.getCategory(), BillingPeriod.MONTHLY, priceList.getName(), PhaseType.EVERGREEN), cat);
Assert.assertEquals(Result.FOO, r1);
final Result r2 = CasePhase.getResult(new CaseResult[]{cr0, cr1, cr2, cr3, cr4},
- new PlanPhaseSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN), cat);
+ new PlanPhaseSpecifier(product.getName(), product.getCategory(), BillingPeriod.ANNUAL, priceList.getName(), PhaseType.EVERGREEN), cat);
Assert.assertEquals(Result.DIPSY, r2);
}
-
protected void assertionNull(final CaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final PhaseType phaseType, final StandaloneCatalog cat) {
try {
Assert.assertNull(cr.getResult(new PlanPhaseSpecifier(productName, productCategory, bp, priceListName, phaseType), cat));
@@ -268,7 +260,6 @@ public class TestCasePhase {
}
}
-
protected void assertionException(final CaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final PhaseType phaseType, final StandaloneCatalog cat) {
try {
Assert.assertNull(cr.getResult(new PlanPhaseSpecifier(productName, productCategory, bp, priceListName, phaseType), cat));
@@ -285,6 +276,4 @@ public class TestCasePhase {
Assert.fail("", e);
}
}
-
-
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestLoadRules.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestLoadRules.java
index 0e8b04e..27cf7d1 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestLoadRules.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestLoadRules.java
@@ -16,11 +16,13 @@
package com.ning.billing.catalog.rules;
-import java.io.File;
+import java.net.URI;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.google.common.io.Resources;
+import com.ning.billing.catalog.CatalogTestSuite;
import com.ning.billing.catalog.StandaloneCatalog;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.PlanAlignmentCreate;
@@ -28,22 +30,22 @@ import com.ning.billing.catalog.api.PlanSpecifier;
import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.util.config.XMLLoader;
-public class TestLoadRules {
-
- @Test
+public class TestLoadRules extends CatalogTestSuite {
+ @Test(groups = "fast")
public void test() throws Exception {
- final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(new File("src/test/resources/WeaponsHireSmall.xml").toURI(), StandaloneCatalog.class);
+ final URI uri = new URI(Resources.getResource("WeaponsHireSmall.xml").toExternalForm());
+ final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(uri, StandaloneCatalog.class);
Assert.assertNotNull(catalog);
final PlanRules rules = catalog.getPlanRules();
final PlanSpecifier specifier = new PlanSpecifier("Laser-Scope", ProductCategory.ADD_ON, BillingPeriod.MONTHLY,
- "DEFAULT");
+ "DEFAULT");
final PlanAlignmentCreate alignment = rules.getPlanCreateAlignment(specifier, catalog);
Assert.assertEquals(alignment, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
final PlanSpecifier specifier2 = new PlanSpecifier("Extra-Ammo", ProductCategory.ADD_ON, BillingPeriod.MONTHLY,
- "DEFAULT");
+ "DEFAULT");
final PlanAlignmentCreate alignment2 = rules.getPlanCreateAlignment(specifier2, catalog);
Assert.assertEquals(alignment2, PlanAlignmentCreate.START_OF_BUNDLE);
diff --git a/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java b/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
index bc876d3..2795dc1 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/rules/TestPlanRules.java
@@ -22,6 +22,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
+import com.ning.billing.catalog.CatalogTestSuite;
import com.ning.billing.catalog.DefaultPriceList;
import com.ning.billing.catalog.DefaultProduct;
import com.ning.billing.catalog.MockCatalog;
@@ -36,12 +37,11 @@ import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.PlanSpecifier;
import com.ning.billing.catalog.api.PriceListSet;
-public class TestPlanRules {
- Logger log = LoggerFactory.getLogger(TestPlanRules.class);
-
+public class TestPlanRules extends CatalogTestSuite {
+ private final Logger log = LoggerFactory.getLogger(TestPlanRules.class);
private MockCatalog cat = null;
- @BeforeTest
+ @BeforeTest(groups = "fast")
public void setup() {
cat = new MockCatalog();
@@ -57,7 +57,7 @@ public class TestPlanRules {
setPriceListCase(new CasePriceList[]{casePriceList});
}
- @Test
+ @Test(groups = "fast")
public void testCannotChangeToSamePlan() throws CatalogApiException {
final DefaultProduct product1 = cat.getCurrentProducts()[0];
final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
@@ -73,10 +73,9 @@ public class TestPlanRules {
} catch (CatalogApiException e) {
Assert.fail("", e);
}
-
}
- @Test
+ @Test(groups = "fast")
public void testExistingPriceListIsKept() throws CatalogApiException {
final DefaultProduct product1 = cat.getCurrentProducts()[0];
final DefaultPriceList priceList1 = cat.findCurrentPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
@@ -97,11 +96,9 @@ public class TestPlanRules {
Assert.assertEquals(result.getPolicy(), ActionPolicy.END_OF_TERM);
Assert.assertEquals(result.getAlignment(), PlanAlignmentChange.START_OF_SUBSCRIPTION);
Assert.assertEquals(result.getNewPriceList(), priceList1);
-
}
-
- @Test
+ @Test(groups = "fast")
public void testBaseCase() throws CatalogApiException {
final DefaultProduct product1 = cat.getCurrentProducts()[0];
final DefaultProduct product2 = cat.getCurrentProducts()[1];
@@ -124,8 +121,5 @@ public class TestPlanRules {
Assert.assertEquals(result.getPolicy(), ActionPolicy.END_OF_TERM);
Assert.assertEquals(result.getAlignment(), PlanAlignmentChange.START_OF_SUBSCRIPTION);
Assert.assertEquals(result.getNewPriceList(), priceList2);
-
}
-
-
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestCatalogService.java b/catalog/src/test/java/com/ning/billing/catalog/TestCatalogService.java
index 38c21e2..3fa6949 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestCatalogService.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestCatalogService.java
@@ -24,9 +24,8 @@ import com.ning.billing.config.CatalogConfig;
import com.ning.billing.lifecycle.KillbillService.ServiceException;
import com.ning.billing.util.clock.DefaultClock;
-public class TestCatalogService {
-
- @Test
+public class TestCatalogService extends CatalogTestSuite {
+ @Test(groups = "fast")
public void testCatalogServiceDirectory() throws ServiceException {
final DefaultCatalogService service = new DefaultCatalogService(new CatalogConfig() {
@Override
@@ -40,7 +39,7 @@ public class TestCatalogService {
Assert.assertEquals(service.getFullCatalog().getCatalogName(), "WeaponsHireSmall");
}
- @Test
+ @Test(groups = "fast")
public void testCatalogServiceFile() throws ServiceException {
final DefaultCatalogService service = new DefaultCatalogService(new CatalogConfig() {
@Override
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestInternationalPrice.java b/catalog/src/test/java/com/ning/billing/catalog/TestInternationalPrice.java
index 62fbe6c..f543071 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestInternationalPrice.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestInternationalPrice.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.catalog;
import java.math.BigDecimal;
@@ -28,10 +29,10 @@ import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.util.config.ValidationErrors;
-public class TestInternationalPrice {
+public class TestInternationalPrice extends CatalogTestSuite {
private static final Logger log = LoggerFactory.getLogger(TestInternationalPrice.class);
- @Test
+ @Test(groups = "fast")
public void testZeroValue() throws URISyntaxException, CatalogApiException {
final StandaloneCatalog c = new MockCatalog();
c.setSupportedCurrencies(new Currency[]{Currency.GBP, Currency.EUR, Currency.USD, Currency.BRL, Currency.MXN});
@@ -59,10 +60,9 @@ public class TestInternationalPrice {
Assert.assertEquals(p1.getPrice(Currency.USD), new BigDecimal(1));
Assert.assertEquals(p1.getPrice(Currency.BRL), new BigDecimal(1));
Assert.assertEquals(p1.getPrice(Currency.MXN), new BigDecimal(1));
-
}
- @Test
+ @Test(groups = "fast")
public void testPriceInitialization() throws URISyntaxException, CatalogApiException {
final StandaloneCatalog c = new MockCatalog();
c.setSupportedCurrencies(new Currency[]{Currency.GBP, Currency.EUR, Currency.USD, Currency.BRL, Currency.MXN});
@@ -71,7 +71,7 @@ public class TestInternationalPrice {
Assert.assertEquals(c.getCurrentPlans()[0].getFinalPhase().getRecurringPrice().getPrice(Currency.GBP), new BigDecimal(0));
}
- @Test
+ @Test(groups = "fast")
public void testNegativeValuePrices() {
final StandaloneCatalog c = new MockCatalog();
c.setSupportedCurrencies(new Currency[]{Currency.GBP, Currency.EUR, Currency.USD, Currency.BRL, Currency.MXN});
@@ -89,6 +89,4 @@ public class TestInternationalPrice {
errors.log(log);
Assert.assertEquals(errors.size(), 3);
}
-
-
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestPlan.java b/catalog/src/test/java/com/ning/billing/catalog/TestPlan.java
index 2aad0a6..cf2987e 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestPlan.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestPlan.java
@@ -27,12 +27,11 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.util.config.ValidationErrors;
-public class TestPlan {
+public class TestPlan extends CatalogTestSuite {
private static final Logger log = LoggerFactory.getLogger(TestPlan.class);
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testDateValidation() {
-
final StandaloneCatalog c = new MockCatalog();
c.setSupportedCurrencies(new Currency[]{Currency.GBP, Currency.EUR, Currency.USD, Currency.BRL, Currency.MXN});
final DefaultPlan p1 = MockPlan.createBicycleTrialEvergreen1USD();
@@ -40,10 +39,9 @@ public class TestPlan {
final ValidationErrors errors = p1.validate(c, new ValidationErrors());
Assert.assertEquals(errors.size(), 1);
errors.log(log);
-
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testDataCalc() {
final DefaultPlan p0 = MockPlan.createBicycleTrialEvergreen1USD();
@@ -55,6 +53,5 @@ public class TestPlan {
Assert.assertEquals(p0.dateOfFirstRecurringNonZeroCharge(requestedDate).compareTo(requestedDate.plusDays(30)), 0);
Assert.assertEquals(p1.dateOfFirstRecurringNonZeroCharge(requestedDate).compareTo(requestedDate.plusDays(100)), 0);
Assert.assertEquals(p2.dateOfFirstRecurringNonZeroCharge(requestedDate).compareTo(requestedDate.plusDays(0)), 0);
-
}
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestPlanPhase.java b/catalog/src/test/java/com/ning/billing/catalog/TestPlanPhase.java
index ee3f11e..600a620 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestPlanPhase.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestPlanPhase.java
@@ -26,10 +26,10 @@ import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.util.config.ValidationErrors;
-public class TestPlanPhase {
- Logger log = LoggerFactory.getLogger(TestPlanPhase.class);
+public class TestPlanPhase extends CatalogTestSuite {
+ private final Logger log = LoggerFactory.getLogger(TestPlanPhase.class);
- @Test(enabled = true)
+ @Test(groups = "fast")
public void testValidation() {
log.info("Testing Plan Phase Validation");
@@ -42,15 +42,15 @@ public class TestPlanPhase {
pp = MockPlanPhase.createUSDMonthlyEvergreen("1.00", null).setBillCycleDuration(BillingPeriod.NO_BILLING_PERIOD).setPlan(MockPlan.createBicycleNoTrialEvergreen1USD());// new MockPlanPhase().setBillCycleDuration(BillingPeriod.NO_BILLING_PERIOD).setRecurringPrice(new MockInternationalPrice());
errors = pp.validate(new MockCatalog(), new ValidationErrors());
errors.log(log);
- Assert.assertEquals(errors.size(), 1);
+ Assert.assertEquals(errors.size(), 2);
pp = MockPlanPhase.createUSDMonthlyEvergreen(null, null).setBillCycleDuration(BillingPeriod.NO_BILLING_PERIOD).setPlan(MockPlan.createBicycleNoTrialEvergreen1USD());//new MockPlanPhase().setRecurringPrice(null).setFixedPrice(null).setBillCycleDuration(BillingPeriod.NO_BILLING_PERIOD);
errors = pp.validate(new MockCatalog(), new ValidationErrors());
errors.log(log);
- Assert.assertEquals(errors.size(), 1);
+ Assert.assertEquals(errors.size(), 2);
}
- @Test
+ @Test(groups = "fast")
public void testPhaseNames() throws CatalogApiException {
final String planName = "Foo";
final String planNameExt = planName + "-";
@@ -71,12 +71,9 @@ public class TestPlanPhase {
Assert.assertEquals(ppnFixedTerm, planNameExt + "fixedterm");
Assert.assertEquals(ppnDiscount, planNameExt + "discount");
-
Assert.assertEquals(DefaultPlanPhase.planName(ppnDiscount), planName);
Assert.assertEquals(DefaultPlanPhase.planName(ppnTrial), planName);
Assert.assertEquals(DefaultPlanPhase.planName(ppnEvergreen), planName);
Assert.assertEquals(DefaultPlanPhase.planName(ppnFixedTerm), planName);
-
-
}
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestPriceListSet.java b/catalog/src/test/java/com/ning/billing/catalog/TestPriceListSet.java
index 107283d..2f54295 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestPriceListSet.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestPriceListSet.java
@@ -30,8 +30,8 @@ import static com.ning.billing.catalog.api.BillingPeriod.MONTHLY;
import static com.ning.billing.catalog.api.PhaseType.DISCOUNT;
import static com.ning.billing.catalog.api.PhaseType.EVERGREEN;
-public class TestPriceListSet {
- @Test(enabled = true)
+public class TestPriceListSet extends CatalogTestSuite {
+ @Test(groups = "fast")
public void testOverriding() throws CatalogApiException {
final DefaultProduct foo = new DefaultProduct("Foo", ProductCategory.BASE);
final DefaultProduct bar = new DefaultProduct("Bar", ProductCategory.BASE);
@@ -57,6 +57,7 @@ public class TestPriceListSet {
Assert.assertEquals(set.getPlanFrom("child", foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
}
+ @Test(groups = "fast")
public void testForNullBillingPeriod() throws CatalogApiException {
final DefaultProduct foo = new DefaultProduct("Foo", ProductCategory.BASE);
final DefaultProduct bar = new DefaultProduct("Bar", ProductCategory.BASE);
@@ -82,5 +83,4 @@ public class TestPriceListSet {
Assert.assertEquals(set.getPlanFrom(PriceListSet.DEFAULT_PRICELIST_NAME, foo, BillingPeriod.ANNUAL).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
Assert.assertEquals(set.getPlanFrom(PriceListSet.DEFAULT_PRICELIST_NAME, foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
}
-
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestStandaloneCatalog.java b/catalog/src/test/java/com/ning/billing/catalog/TestStandaloneCatalog.java
index edca7f1..3f5cca3 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestStandaloneCatalog.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestStandaloneCatalog.java
@@ -22,9 +22,8 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.PhaseType;
-public class TestStandaloneCatalog {
-
- @Test
+public class TestStandaloneCatalog extends CatalogTestSuite {
+ @Test(groups = "fast")
public void testFindPhase() throws CatalogApiException {
final DefaultPlanPhase phaseTrial1 = new MockPlanPhase().setPhaseType(PhaseType.TRIAL);
final DefaultPlanPhase phaseTrial2 = new MockPlanPhase().setPhaseType(PhaseType.TRIAL);
@@ -44,9 +43,5 @@ public class TestStandaloneCatalog {
Assert.assertEquals(cat.findCurrentPhase("TestPlan2-discount"), phaseDiscount2);
Assert.assertEquals(cat.findCurrentPhase("TestPlan1-trial"), phaseTrial1);
Assert.assertEquals(cat.findCurrentPhase("TestPlan2-trial"), phaseTrial2);
-
-
}
-
-
}
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestVersionedCatalog.java b/catalog/src/test/java/com/ning/billing/catalog/TestVersionedCatalog.java
index a972fd5..2f0f873 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestVersionedCatalog.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestVersionedCatalog.java
@@ -13,13 +13,13 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.catalog;
import javax.xml.bind.JAXBException;
import javax.xml.transform.TransformerException;
import java.io.IOException;
import java.math.BigDecimal;
-import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Date;
@@ -41,26 +41,23 @@ import com.ning.billing.catalog.io.VersionedCatalogLoader;
import com.ning.billing.lifecycle.KillbillService.ServiceException;
import com.ning.billing.util.clock.DefaultClock;
-import static org.testng.AssertJUnit.assertEquals;
-
-public class TestVersionedCatalog {
+public class TestVersionedCatalog extends CatalogTestSuite {
private static final Logger log = LoggerFactory.getLogger(TestVersionedCatalog.class);
private final VersionedCatalogLoader loader = new VersionedCatalogLoader(new DefaultClock());
private VersionedCatalog vc;
- @BeforeClass(groups = {"fast"})
+ @BeforeClass(groups = "fast")
public void setUp() throws ServiceException {
vc = loader.load(Resources.getResource("versionedCatalog").toString());
}
- @Test(groups = {"fast"}, enabled = true)
- public void testAddCatalog() throws MalformedURLException, IOException, SAXException, InvalidConfigException, JAXBException, TransformerException, URISyntaxException, ServiceException, CatalogApiException {
+ @Test(groups = "fast")
+ public void testAddCatalog() throws IOException, SAXException, InvalidConfigException, JAXBException, TransformerException, URISyntaxException, ServiceException, CatalogApiException {
vc.add(new StandaloneCatalog(new Date()));
- assertEquals(4, vc.size());
+ Assert.assertEquals(vc.size(), 4);
}
-
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testFindPlanWithDates() throws Exception {
final DateTime dt0 = new DateTime("2010-01-01T00:00:00+00:00");
final DateTime dt1 = new DateTime("2011-01-01T00:01:00+00:00");
@@ -99,7 +96,7 @@ public class TestVersionedCatalog {
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testErrorOnDateTooEarly() {
final DateTime dt0 = new DateTime("1977-01-01T00:00:00+00:00");
try {
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
index 24c7cca..ab0cd11 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
@@ -625,6 +625,7 @@ public class AuditedEntitlementDao implements EntitlementDao {
});
}
+ @Override
public void repair(final UUID accountId, final UUID bundleId, final List<SubscriptionDataRepair> inRepair, final CallContext context) {
subscriptionsDao.inTransaction(new Transaction<Void, SubscriptionSqlDao>() {
@Override
@@ -673,7 +674,7 @@ public class AuditedEntitlementDao implements EntitlementDao {
try {
final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(Engine.ENTITLEMENT_SERVICE_NAME,
Engine.NOTIFICATION_QUEUE_NAME);
- subscriptionEventQueue.recordFutureNotificationFromTransaction(transactionalDao, effectiveDate, notificationKey);
+ subscriptionEventQueue.recordFutureNotificationFromTransaction(transactionalDao, effectiveDate, null, notificationKey);
} catch (NoSuchNotificationQueue e) {
throw new RuntimeException(e);
} catch (IOException e) {
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestPlanAligner.java b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestPlanAligner.java
index 6579baa..65df594 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestPlanAligner.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestPlanAligner.java
@@ -28,6 +28,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.ning.billing.KillbillTestSuite;
import com.ning.billing.catalog.DefaultCatalogService;
import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.PhaseType;
@@ -39,7 +40,6 @@ import com.ning.billing.entitlement.api.user.DefaultSubscriptionFactory;
import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.SubscriptionData;
-import com.ning.billing.entitlement.api.user.SubscriptionTransitionData;
import com.ning.billing.entitlement.events.EntitlementEvent;
import com.ning.billing.entitlement.events.user.ApiEventBase;
import com.ning.billing.entitlement.events.user.ApiEventBuilder;
@@ -47,7 +47,7 @@ import com.ning.billing.entitlement.events.user.ApiEventType;
import com.ning.billing.entitlement.exceptions.EntitlementError;
import com.ning.billing.util.clock.DefaultClock;
-public class TestPlanAligner {
+public class TestPlanAligner extends KillbillTestSuite {
private static final String priceList = PriceListSet.DEFAULT_PRICELIST_NAME;
private final DefaultClock clock = new DefaultClock();
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java
index 09740d2..6be543d 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java
@@ -24,12 +24,13 @@ import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.KillbillTestSuite;
import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.entitlement.events.EntitlementEvent;
import com.ning.billing.entitlement.events.user.ApiEventType;
-public class TestTimedMigration {
+public class TestTimedMigration extends KillbillTestSuite {
@Test(groups = "fast")
public void testConstructor() throws Exception {
final DateTime eventTime = new DateTime(DateTimeZone.UTC);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedPhase.java b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedPhase.java
index 75831fa..c75b6c2 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedPhase.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedPhase.java
@@ -22,9 +22,10 @@ import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.KillbillTestSuite;
import com.ning.billing.catalog.api.PlanPhase;
-public class TestTimedPhase {
+public class TestTimedPhase extends KillbillTestSuite {
@Test(groups = "fast")
public void testConstructor() throws Exception {
final PlanPhase planPhase = Mockito.mock(PlanPhase.class);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
index 961923f..a15cd77 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigration.java
@@ -47,11 +47,7 @@ import static org.testng.Assert.assertTrue;
public abstract class TestMigration extends TestApiBase {
public void testSingleBasePlan() {
-
try {
-
- log.info("Starting testSingleBasePlan");
-
final DateTime startDate = clock.getUTCNow().minusMonths(2);
final DateTime beforeMigration = clock.getUTCNow();
final EntitlementAccountMigration toBeMigrated = createAccountWithRegularBasePlan(startDate);
@@ -84,7 +80,6 @@ public abstract class TestMigration extends TestApiBase {
public void testPlanWithAddOn() {
try {
- log.info("Starting testPlanWithAddOn");
final DateTime beforeMigration = clock.getUTCNow();
final DateTime initalBPStart = clock.getUTCNow().minusMonths(3);
final DateTime initalAddonStart = clock.getUTCNow().minusMonths(1).plusDays(7);
@@ -134,7 +129,6 @@ public abstract class TestMigration extends TestApiBase {
public void testSingleBasePlanFutureCancelled() {
try {
- log.info("Starting testSingleBasePlanFutureCancelled");
final DateTime startDate = clock.getUTCNow().minusMonths(1);
final DateTime beforeMigration = clock.getUTCNow();
final EntitlementAccountMigration toBeMigrated = createAccountWithRegularBasePlanFutreCancelled(startDate);
@@ -159,7 +153,6 @@ public abstract class TestMigration extends TestApiBase {
assertEquals(subscription.getCurrentPlan().getName(), "assault-rifle-annual");
assertEquals(subscription.getChargedThroughDate(), startDate.plusYears(1));
-
testListener.pushExpectedEvent(NextEvent.MIGRATE_BILLING);
testListener.pushExpectedEvent(NextEvent.CANCEL);
@@ -176,17 +169,13 @@ public abstract class TestMigration extends TestApiBase {
assertNull(subscription.getCurrentPlan());
assertListenerStatus();
-
} catch (EntitlementMigrationApiException e) {
Assert.fail("", e);
}
}
public void testSingleBasePlanWithPendingPhase() {
-
try {
-
- log.info("Starting testSingleBasePlanWithPendingPhase");
final DateTime trialDate = clock.getUTCNow().minusDays(10);
final EntitlementAccountMigration toBeMigrated = createAccountFuturePendingPhase(trialDate);
@@ -226,16 +215,13 @@ public abstract class TestMigration extends TestApiBase {
assertEquals(subscription.getCurrentPhase().getName(), "assault-rifle-monthly-evergreen");
assertListenerStatus();
-
} catch (EntitlementMigrationApiException e) {
Assert.fail("", e);
}
}
public void testSingleBasePlanWithPendingChange() {
-
try {
- log.info("Starting testSingleBasePlanWithPendingChange");
final DateTime beforeMigration = clock.getUTCNow();
final EntitlementAccountMigration toBeMigrated = createAccountFuturePendingChange();
final DateTime afterMigration = clock.getUTCNow();
@@ -279,25 +265,19 @@ public abstract class TestMigration extends TestApiBase {
}
}
-
private EntitlementAccountMigration createAccountTest(final List<List<EntitlementSubscriptionMigrationCaseWithCTD>> cases) {
-
return new EntitlementAccountMigration() {
-
private final UUID accountId = UUID.randomUUID();
@Override
public EntitlementBundleMigration[] getBundles() {
final List<EntitlementBundleMigration> bundles = new ArrayList<EntitlementBundleMigration>();
final EntitlementBundleMigration bundle0 = new EntitlementBundleMigration() {
-
@Override
public EntitlementSubscriptionMigration[] getSubscriptions() {
-
final EntitlementSubscriptionMigration[] result = new EntitlementSubscriptionMigration[cases.size()];
for (int i = 0; i < cases.size(); i++) {
-
final List<EntitlementSubscriptionMigrationCaseWithCTD> curCases = cases.get(i);
final EntitlementSubscriptionMigration subscription = new EntitlementSubscriptionMigration() {
@Override
@@ -362,7 +342,6 @@ public abstract class TestMigration extends TestApiBase {
null,
null));
-
final List<List<EntitlementSubscriptionMigrationCaseWithCTD>> input = new ArrayList<List<EntitlementSubscriptionMigrationCaseWithCTD>>();
input.add(cases);
input.add(firstAddOnCases);
@@ -393,7 +372,6 @@ public abstract class TestMigration extends TestApiBase {
return createAccountTest(input);
}
-
private EntitlementAccountMigration createAccountFuturePendingPhase(final DateTime trialDate) {
final List<EntitlementSubscriptionMigrationCaseWithCTD> cases = new LinkedList<EntitlementSubscriptionMigrationCaseWithCTD>();
cases.add(new EntitlementSubscriptionMigrationCaseWithCTD(
@@ -429,9 +407,7 @@ public abstract class TestMigration extends TestApiBase {
return createAccountTest(input);
}
-
public static class EntitlementSubscriptionMigrationCaseWithCTD implements EntitlementSubscriptionMigrationCase {
-
private final PlanPhaseSpecifier pps;
private final DateTime effDt;
private final DateTime cancelDt;
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationMemory.java
index 81c12cd..e07e1c1 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationMemory.java
@@ -23,7 +23,6 @@ import com.google.inject.Injector;
import com.google.inject.Stage;
import com.ning.billing.entitlement.glue.MockEngineModuleMemory;
-@Test(groups = "fast")
public class TestMigrationMemory extends TestMigration {
@Override
protected Injector getInjector() {
@@ -31,26 +30,25 @@ public class TestMigrationMemory extends TestMigration {
}
@Override
- @Test(enabled = true, groups = "fast")
+ @Test(groups = "fast")
public void testSingleBasePlan() {
super.testSingleBasePlan();
}
@Override
- @Test(enabled = true, groups = "fast")
+ @Test(groups = "fast")
public void testSingleBasePlanFutureCancelled() {
super.testSingleBasePlanFutureCancelled();
}
@Override
- @Test(enabled = true, groups = "fast")
+ @Test(groups = "fast")
public void testPlanWithAddOn() {
super.testPlanWithAddOn();
}
-
@Override
- @Test(enabled = true, groups = "fast")
+ @Test(groups = "fast")
public void testSingleBasePlanWithPendingPhase() {
super.testSingleBasePlanWithPendingPhase();
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationSql.java
index 82fc7e7..2d0b100 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/migration/TestMigrationSql.java
@@ -30,25 +30,25 @@ public class TestMigrationSql extends TestMigration {
}
@Override
- @Test(enabled = true, groups = "slow")
+ @Test(groups = "slow")
public void testSingleBasePlan() {
super.testSingleBasePlan();
}
@Override
- @Test(enabled = true, groups = "slow")
+ @Test(groups = "slow")
public void testPlanWithAddOn() {
super.testPlanWithAddOn();
}
@Override
- @Test(enabled = true, groups = "slow")
+ @Test(groups = "slow")
public void testSingleBasePlanFutureCancelled() {
super.testSingleBasePlanFutureCancelled();
}
@Override
- @Test(enabled = true, groups = "slow")
+ @Test(groups = "slow")
public void testSingleBasePlanWithPendingPhase() {
super.testSingleBasePlanWithPendingPhase();
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
index 1c68f2f..55115be 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
@@ -51,6 +51,7 @@ import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.catalog.api.TimeUnit;
import com.ning.billing.config.EntitlementConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.entitlement.EntitlementTestSuiteWithEmbeddedDB;
import com.ning.billing.entitlement.api.billing.ChargeThruApi;
import com.ning.billing.entitlement.api.migration.EntitlementMigrationApi;
import com.ning.billing.entitlement.api.timeline.EntitlementTimelineApi;
@@ -61,7 +62,6 @@ import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.entitlement.api.user.SubscriptionData;
import com.ning.billing.entitlement.engine.core.Engine;
import com.ning.billing.entitlement.engine.dao.EntitlementDao;
-import com.ning.billing.entitlement.engine.dao.MockEntitlementDao;
import com.ning.billing.entitlement.engine.dao.MockEntitlementDaoMemory;
import com.ning.billing.entitlement.events.EntitlementEvent;
import com.ning.billing.entitlement.events.phase.PhaseEvent;
@@ -74,14 +74,13 @@ import com.ning.billing.util.callcontext.TestCallContext;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
import com.ning.billing.util.glue.RealImplementation;
-import com.ning.billing.util.io.IOUtils;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
-public abstract class TestApiBase implements TestListenerStatus {
+public abstract class TestApiBase extends EntitlementTestSuiteWithEmbeddedDB implements TestListenerStatus {
protected static final Logger log = LoggerFactory.getLogger(TestApiBase.class);
protected EntitlementService entitlementService;
@@ -114,7 +113,6 @@ public abstract class TestApiBase implements TestListenerStatus {
//
protected DateTime testStartDate = new DateTime(2012, 5, 7, 0, 3, 42, 0);
-
public static void loadSystemPropertiesFromClasspath(final String resource) {
final URL url = TestApiBase.class.getResource(resource);
assertNotNull(url);
@@ -132,15 +130,11 @@ public abstract class TestApiBase implements TestListenerStatus {
public void tearDown() {
try {
((DefaultBusService) busService).stopBus();
- if (helper != null) {
- helper.stopMysql();
- }
} catch (Exception e) {
log.warn("Failed to tearDown test properly ", e);
}
}
-
@Override
public void failed(final String msg) {
this.isListenerFailed = true;
@@ -155,13 +149,11 @@ public abstract class TestApiBase implements TestListenerStatus {
@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
-
loadSystemPropertiesFromClasspath("/entitlement.properties");
final Injector g = getInjector();
entitlementService = g.getInstance(EntitlementService.class);
- final EntitlementUserApi entApi = (EntitlementUserApi) g.getInstance(Key.get(EntitlementUserApi.class, RealImplementation.class));
- entitlementApi = entApi;
+ entitlementApi = g.getInstance(Key.get(EntitlementUserApi.class, RealImplementation.class));
billingApi = g.getInstance(ChargeThruApi.class);
migrationApi = g.getInstance(EntitlementMigrationApi.class);
repairApi = g.getInstance(EntitlementTimelineApi.class);
@@ -175,9 +167,6 @@ public abstract class TestApiBase implements TestListenerStatus {
}
private void init() throws Exception {
-
- setupDao();
-
((DefaultCatalogService) catalogService).loadCatalog();
accountData = getAccountData();
@@ -187,27 +176,19 @@ public abstract class TestApiBase implements TestListenerStatus {
testListener = new TestApiListener(this);
}
- private void setupDao() throws IOException {
- if (helper != null) {
- final String entitlementDdl = IOUtils.toString(TestApiBase.class.getResourceAsStream("/com/ning/billing/entitlement/ddl.sql"));
- final String utilDdl = IOUtils.toString(TestApiBase.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- helper.startMysql();
- helper.initDb(entitlementDdl);
- helper.initDb(utilDdl);
- }
- }
-
private static boolean isSqlTest(final EntitlementDao theDao) {
return (!(theDao instanceof MockEntitlementDaoMemory));
}
@BeforeMethod(alwaysRun = true)
public void setupTest() throws Exception {
-
- log.warn("RESET TEST FRAMEWORK\n\n");
+ log.warn("RESET TEST FRAMEWORK");
// CLEANUP ALL DB TABLES OR IN MEMORY STRUCTURES
- cleanupDao();
+ if (!isSqlTest(dao)) {
+ // The MySQL testing helper will clean the tables between each test
+ ((MockEntitlementDaoMemory) dao).reset();
+ }
// RESET LIST OF EXPECTED EVENTS
if (testListener != null) {
@@ -237,7 +218,6 @@ public abstract class TestApiBase implements TestListenerStatus {
@AfterMethod(alwaysRun = true)
public void cleanupTest() throws Exception {
-
// UNREGISTER TEST LISTENER AND STOP BUS
busService.getBus().unregister(testListener);
busService.getBus().stop();
@@ -245,7 +225,7 @@ public abstract class TestApiBase implements TestListenerStatus {
// STOP NOTIFICATION QUEUE
((Engine) entitlementService).stop();
- log.warn("DONE WITH TEST\n");
+ log.warn("DONE WITH TEST");
}
protected void assertListenerStatus() {
@@ -255,14 +235,6 @@ public abstract class TestApiBase implements TestListenerStatus {
}
}
- private void cleanupDao() {
- if (helper != null) {
- helper.cleanupAllTables();
- } else {
- ((MockEntitlementDao) dao).reset();
- }
- }
-
protected SubscriptionData createSubscription(final String productName, final BillingPeriod term, final String planSet, final DateTime requestedDate)
throws EntitlementUserApiException {
return createSubscriptionWithBundle(bundle.getId(), productName, term, planSet, requestedDate);
@@ -275,7 +247,6 @@ public abstract class TestApiBase implements TestListenerStatus {
protected SubscriptionData createSubscriptionWithBundle(final UUID bundleId, final String productName, final BillingPeriod term, final String planSet, final DateTime requestedDate)
throws EntitlementUserApiException {
-
testListener.pushExpectedEvent(NextEvent.CREATE);
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundleId,
new PlanPhaseSpecifier(productName, ProductCategory.BASE, term, planSet, null),
@@ -286,7 +257,6 @@ public abstract class TestApiBase implements TestListenerStatus {
}
protected void checkNextPhaseChange(final SubscriptionData subscription, final int expPendingEvents, final DateTime expPhaseChange) {
-
final List<EntitlementEvent> events = dao.getPendingEventsForSubscription(subscription.getId());
assertNotNull(events);
printEvents(events);
@@ -367,7 +337,6 @@ public abstract class TestApiBase implements TestListenerStatus {
return result;
}
-
protected Duration getDurationYear(final int years) {
final Duration result = new Duration() {
@Override
@@ -510,5 +479,4 @@ public abstract class TestApiBase implements TestListenerStatus {
log.debug("Transition " + cur);
}
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEventJson.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEventJson.java
index e53115f..53c266b 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEventJson.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestEventJson.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.entitlement.api;
import java.util.UUID;
@@ -21,6 +22,7 @@ import org.joda.time.DateTime;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.entitlement.EntitlementTestSuite;
import com.ning.billing.entitlement.api.timeline.DefaultRepairEntitlementEvent;
import com.ning.billing.entitlement.api.timeline.RepairEntitlementEvent;
import com.ning.billing.entitlement.api.user.DefaultEffectiveSubscriptionEvent;
@@ -28,25 +30,23 @@ import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
import com.ning.billing.entitlement.api.user.Subscription.SubscriptionState;
import com.ning.billing.util.jackson.ObjectMapper;
-public class TestEventJson {
+public class TestEventJson extends EntitlementTestSuite {
private final ObjectMapper mapper = new ObjectMapper();
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSubscriptionEvent() throws Exception {
-
final EffectiveSubscriptionEvent e = new DefaultEffectiveSubscriptionEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), new DateTime(), new DateTime(),
- SubscriptionState.ACTIVE, "pro", "TRIAL", "DEFAULT", SubscriptionState.CANCELLED, null, null, null, 3L, UUID.randomUUID(), SubscriptionTransitionType.CANCEL, 0, new DateTime());
+ SubscriptionState.ACTIVE, "pro", "TRIAL", "DEFAULT", SubscriptionState.CANCELLED, null, null, null, 3L, UUID.randomUUID(), SubscriptionTransitionType.CANCEL, 0, new DateTime());
final String json = mapper.writeValueAsString(e);
final Class<?> claz = Class.forName(DefaultEffectiveSubscriptionEvent.class.getName());
final Object obj = mapper.readValue(json, claz);
Assert.assertTrue(obj.equals(e));
-
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testRepairEntitlementEvent() throws Exception {
final RepairEntitlementEvent e = new DefaultRepairEntitlementEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), new DateTime());
@@ -56,6 +56,4 @@ public class TestEventJson {
final Object obj = mapper.readValue(json, claz);
Assert.assertTrue(obj.equals(e));
}
-
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestApiBaseRepair.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestApiBaseRepair.java
index 292dc37..449d1e7 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestApiBaseRepair.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestApiBaseRepair.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.entitlement.api.timeline;
import java.util.Collections;
@@ -39,9 +40,7 @@ import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import static org.testng.Assert.assertEquals;
-
public abstract class TestApiBaseRepair extends TestApiBase {
-
protected static final Logger log = LoggerFactory.getLogger(TestApiBaseRepair.class);
public interface TestWithExceptionCallback {
@@ -59,7 +58,6 @@ public abstract class TestApiBaseRepair extends TestApiBase {
}
}
-
protected SubscriptionTimeline createSubscriptionRepair(final UUID id, final List<DeletedEvent> deletedEvents, final List<NewEvent> newEvents) {
return new SubscriptionTimeline() {
@Override
@@ -111,9 +109,8 @@ public abstract class TestApiBaseRepair extends TestApiBase {
protected ExistingEvent createExistingEventForAssertion(final SubscriptionTransitionType type,
final String productName, final PhaseType phaseType, final ProductCategory category, final String priceListName, final BillingPeriod billingPeriod,
final DateTime effectiveDateTime) {
-
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(productName, category, billingPeriod, priceListName, phaseType);
- final ExistingEvent ev = new ExistingEvent() {
+ return new ExistingEvent() {
@Override
public SubscriptionTransitionType getSubscriptionTransitionType() {
return type;
@@ -139,7 +136,6 @@ public abstract class TestApiBaseRepair extends TestApiBase {
return effectiveDateTime;
}
};
- return ev;
}
protected SubscriptionTimeline getSubscriptionRepair(final UUID id, final BundleTimeline bundleRepair) {
@@ -148,12 +144,11 @@ public abstract class TestApiBaseRepair extends TestApiBase {
return cur;
}
}
- Assert.fail("Failed to find SubscriptionReapir " + id);
+ Assert.fail("Failed to find SubscriptionRepair " + id);
return null;
}
protected void validateExistingEventForAssertion(final ExistingEvent expected, final ExistingEvent input) {
-
log.info(String.format("Got %s -> Expected %s", input.getPlanPhaseSpecifier().getProductName(), expected.getPlanPhaseSpecifier().getProductName()));
assertEquals(input.getPlanPhaseSpecifier().getProductName(), expected.getPlanPhaseSpecifier().getProductName());
log.info(String.format("Got %s -> Expected %s", input.getPlanPhaseSpecifier().getPhaseType(), expected.getPlanPhaseSpecifier().getPhaseType()));
@@ -178,7 +173,6 @@ public abstract class TestApiBaseRepair extends TestApiBase {
}
protected NewEvent createNewEvent(final SubscriptionTransitionType type, final DateTime requestedDate, final PlanPhaseSpecifier spec) {
-
return new NewEvent() {
@Override
public SubscriptionTransitionType getSubscriptionTransitionType() {
@@ -228,5 +222,4 @@ public abstract class TestApiBaseRepair extends TestApiBase {
}
});
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairBP.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairBP.java
index af685e4..a81d71b 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairBP.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairBP.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.entitlement.api.timeline;
import java.util.Collections;
@@ -53,17 +54,13 @@ import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
public class TestRepairBP extends TestApiBaseRepair {
-
@Override
public Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testFetchBundleRepair() throws Exception {
-
- log.info("Starting testFetchBundleRepair");
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -126,11 +123,8 @@ public class TestRepairBP extends TestApiBaseRepair {
}
//TODO MDW: Temporary disable need to look at this with Stephane
- @Test(groups = {"slow"}, enabled = false)
+ @Test(groups = "slow", enabled = false)
public void testBPRepairWithCancellationOnstart() throws Exception {
-
- log.info("Starting testBPRepairWithCancellationOnstart");
-
final String baseProduct = "Shotgun";
final DateTime startDate = clock.getUTCNow();
@@ -205,7 +199,6 @@ public class TestRepairBP extends TestApiBaseRepair {
final SubscriptionData realRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId());
assertEquals(realRunBaseSubscription.getAllTransitions().size(), 2);
-
assertEquals(realRunBaseSubscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION + 1);
assertEquals(realRunBaseSubscription.getBundleId(), bundle.getId());
assertEquals(realRunBaseSubscription.getStartDate(), startDate);
@@ -215,11 +208,8 @@ public class TestRepairBP extends TestApiBaseRepair {
assertListenerStatus();
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testBPRepairReplaceCreateBeforeTrial() throws Exception {
-
- log.info("Starting testBPRepairReplaceCreateBeforeTrial");
-
final String baseProduct = "Shotgun";
final String newBaseProduct = "Assault-Rifle";
@@ -237,11 +227,8 @@ public class TestRepairBP extends TestApiBaseRepair {
assertListenerStatus();
}
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testBPRepairReplaceCreateInTrial() throws Exception {
-
- log.info("Starting testBPRepairReplaceCreateInTrial");
-
final String baseProduct = "Shotgun";
final String newBaseProduct = "Assault-Rifle";
@@ -283,12 +270,8 @@ public class TestRepairBP extends TestApiBaseRepair {
assertListenerStatus();
}
-
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testBPRepairReplaceCreateAfterTrial() throws Exception {
-
- log.info("Starting testBPRepairReplaceCreateAfterTrial");
-
final String baseProduct = "Shotgun";
final String newBaseProduct = "Assault-Rifle";
@@ -306,12 +289,8 @@ public class TestRepairBP extends TestApiBaseRepair {
assertListenerStatus();
}
-
private UUID testBPRepairCreate(final boolean inTrial, final DateTime startDate, final int clockShift,
final String baseProduct, final String newBaseProduct, final List<ExistingEvent> expectedEvents) throws Exception {
-
- log.info("Starting testBPRepairCreate");
-
// CREATE BP
final Subscription baseSubscription = createSubscription(baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
@@ -400,7 +379,6 @@ public class TestRepairBP extends TestApiBaseRepair {
final SubscriptionData realRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId());
assertEquals(realRunBaseSubscription.getAllTransitions().size(), 2);
-
assertEquals(realRunBaseSubscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION + 1);
assertEquals(realRunBaseSubscription.getBundleId(), bundle.getId());
assertEquals(realRunBaseSubscription.getStartDate(), newCreateTime);
@@ -418,11 +396,8 @@ public class TestRepairBP extends TestApiBaseRepair {
return baseSubscription.getId();
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testBPRepairAddChangeInTrial() throws Exception {
-
- log.info("Starting testBPRepairAddChangeInTrial");
-
final String baseProduct = "Shotgun";
final String newBaseProduct = "Assault-Rifle";
@@ -465,11 +440,8 @@ public class TestRepairBP extends TestApiBaseRepair {
assertListenerStatus();
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testBPRepairAddChangeAfterTrial() throws Exception {
-
- log.info("Starting testBPRepairAddChangeAfterTrial");
-
final String baseProduct = "Shotgun";
final String newBaseProduct = "Assault-Rifle";
@@ -489,11 +461,8 @@ public class TestRepairBP extends TestApiBaseRepair {
assertListenerStatus();
}
-
private UUID testBPRepairAddChange(final boolean inTrial, final DateTime startDate, final int clockShift,
final String baseProduct, final String newBaseProduct, final List<ExistingEvent> expectedEvents, final int expectedTransitions) throws Exception {
-
-
// CREATE BP
final Subscription baseSubscription = createSubscription(baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
@@ -559,7 +528,6 @@ public class TestRepairBP extends TestApiBaseRepair {
assertEquals(currentPhase.getPhaseType(), PhaseType.EVERGREEN);
}
-
// SECOND RE-ISSUE CALL-- NON DRY RUN
dryRun = false;
testListener.pushExpectedEvent(NextEvent.REPAIR_BUNDLE);
@@ -580,7 +548,6 @@ public class TestRepairBP extends TestApiBaseRepair {
final SubscriptionData realRunBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId());
assertEquals(realRunBaseSubscription.getAllTransitions().size(), expectedTransitions);
-
assertEquals(realRunBaseSubscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION + 1);
assertEquals(realRunBaseSubscription.getBundleId(), bundle.getId());
assertEquals(realRunBaseSubscription.getStartDate(), baseSubscription.getStartDate());
@@ -601,11 +568,8 @@ public class TestRepairBP extends TestApiBaseRepair {
return baseSubscription.getId();
}
- @Test(groups = {"slow"})
- public void testRepairWithFurureCancelEvent() throws Exception {
-
- log.info("Starting testRepairWithFurureCancelEvent");
-
+ @Test(groups = "slow")
+ public void testRepairWithFutureCancelEvent() throws Exception {
final DateTime startDate = clock.getUTCNow();
// CREATE BP
@@ -623,11 +587,9 @@ public class TestRepairBP extends TestApiBaseRepair {
billingApi.setChargedThroughDate(baseSubscription.getId(), newChargedThroughDate, context);
baseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId());
-
final DateTime requestedChange = clock.getUTCNow();
baseSubscription.changePlan("Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, requestedChange, context);
-
// CHECK CHANGE DID NOT OCCUR YET
Plan currentPlan = baseSubscription.getCurrentPlan();
assertNotNull(currentPlan);
@@ -635,7 +597,6 @@ public class TestRepairBP extends TestApiBaseRepair {
assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE);
assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
-
final DateTime repairTime = clock.getUTCNow().minusDays(1);
final BundleTimeline bundleRepair = repairApi.getBundleRepair(bundle.getId());
sortEventsOnBundle(bundleRepair);
@@ -675,13 +636,9 @@ public class TestRepairBP extends TestApiBaseRepair {
assertListenerStatus();
}
-
// Needs real SQL backend to be tested properly
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testENT_REPAIR_VIEW_CHANGED_newEvent() throws Exception {
-
- log.info("Starting testENT_REPAIR_VIEW_CHANGED_newEvent");
-
final TestWithException test = new TestWithException();
final DateTime startDate = clock.getUTCNow();
@@ -713,11 +670,8 @@ public class TestRepairBP extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_VIEW_CHANGED);
}
- @Test(groups = {"slow"}, enabled = false)
+ @Test(groups = "slow", enabled = false)
public void testENT_REPAIR_VIEW_CHANGED_ctd() throws Exception {
-
- log.info("Starting testENT_REPAIR_VIEW_CHANGED_ctd");
-
final TestWithException test = new TestWithException();
final DateTime startDate = clock.getUTCNow();
@@ -748,5 +702,4 @@ public class TestRepairBP extends TestApiBaseRepair {
}
}, ErrorCode.ENT_REPAIR_VIEW_CHANGED);
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java
index 85116a3..7757cec 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithAO.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.entitlement.api.timeline;
import java.util.Collections;
@@ -48,17 +49,13 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
public class TestRepairWithAO extends TestApiBaseRepair {
-
@Override
public Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testRepairChangeBPWithAddonIncluded() throws Exception {
-
- log.info("Starting testRepairChangeBPWithAddonIncluded");
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -149,7 +146,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
validateExistingEventForAssertion(e, bpRepair.getExistingEvents().get(index++));
}
-
SubscriptionData newAoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId());
assertEquals(newAoSubscription.getState(), SubscriptionState.ACTIVE);
assertEquals(newAoSubscription.getAllTransitions().size(), 2);
@@ -160,7 +156,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
assertEquals(newAoSubscription2.getAllTransitions().size(), 2);
assertEquals(newAoSubscription2.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
-
SubscriptionData newBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId());
assertEquals(newBaseSubscription.getState(), SubscriptionState.ACTIVE);
assertEquals(newBaseSubscription.getAllTransitions().size(), 2);
@@ -171,7 +166,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final BundleTimeline realRunBundleRepair = repairApi.repairBundle(bundleRepair, dryRun, context);
assertTrue(testListener.isCompleted(5000));
-
aoRepair = getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
@@ -203,18 +197,14 @@ public class TestRepairWithAO extends TestApiBaseRepair {
assertEquals(newAoSubscription2.getAllTransitions().size(), 2);
assertEquals(newAoSubscription2.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION + 1);
-
newBaseSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(baseSubscription.getId());
assertEquals(newBaseSubscription.getState(), SubscriptionState.ACTIVE);
assertEquals(newBaseSubscription.getAllTransitions().size(), 3);
assertEquals(newBaseSubscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION + 1);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testRepairChangeBPWithAddonNonAvailable() throws Exception {
-
- log.info("Starting testRepairChangeBPWithAddonNonAvailable");
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -332,11 +322,8 @@ public class TestRepairWithAO extends TestApiBaseRepair {
assertEquals(newBaseSubscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION + 1);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testRepairCancelBP_EOT_WithAddons() throws Exception {
-
- log.info("Starting testRepairCancelBP_EOT_WithAddons");
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -348,7 +335,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
-
final SubscriptionData aoSubscription = createSubscription("Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
// MOVE CLOCK A LITTLE BIT MORE -- AFTER TRIAL
@@ -475,12 +461,8 @@ public class TestRepairWithAO extends TestApiBaseRepair {
assertEquals(newBaseSubscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION + 1);
}
-
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testRepairCancelAO() throws Exception {
-
- log.info("Starting testRepairCancelAO");
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -508,7 +490,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
-
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
final DateTime aoCancelDate = aoSubscription.getStartDate().plusDays(1);
@@ -552,7 +533,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
final BundleTimeline realRunBundleRepair = repairApi.repairBundle(bRepair, dryRun, context);
assertTrue(testListener.isCompleted(5000));
-
aoRepair = getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
index = 0;
@@ -571,12 +551,8 @@ public class TestRepairWithAO extends TestApiBaseRepair {
assertEquals(newBaseSubscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
}
-
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testRepairRecreateAO() throws Exception {
-
- log.info("Starting testRepairRecreateAO");
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -604,7 +580,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
-
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
des.add(createDeletedEvent(aoRepair.getExistingEvents().get(0).getEventId()));
des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
@@ -623,7 +598,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
aoRepair = getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
-
final List<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoRecreateDate));
@@ -668,11 +642,8 @@ public class TestRepairWithAO extends TestApiBaseRepair {
// . Both multi phase
// . Telescopic-Scope (bundle align) and Laser-Scope is Subscription align
//
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testRepairChangeAOOK() throws Exception {
-
- log.info("Starting testRepairChangeAOOK");
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -716,7 +687,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
aoRepair = getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 3);
-
final List<ExistingEvent> expected = new LinkedList<SubscriptionTimeline.ExistingEvent>();
expected.add(createExistingEventForAssertion(SubscriptionTransitionType.CREATE, "Telescopic-Scope", PhaseType.DISCOUNT,
ProductCategory.ADD_ON, PriceListSet.DEFAULT_PRICELIST_NAME, BillingPeriod.MONTHLY, aoSubscription.getStartDate()));
@@ -751,7 +721,6 @@ public class TestRepairWithAO extends TestApiBaseRepair {
assertEquals(newAoSubscription.getState(), SubscriptionState.ACTIVE);
assertEquals(newAoSubscription.getAllTransitions().size(), 3);
-
assertEquals(newAoSubscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION + 1);
assertEquals(newAoSubscription.getBundleId(), bundle.getId());
assertEquals(newAoSubscription.getStartDate(), aoSubscription.getStartDate());
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java
index 7c61f4f..6c1d506 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/timeline/TestRepairWithError.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.entitlement.api.timeline;
import java.util.Collections;
@@ -47,7 +48,6 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
public class TestRepairWithError extends TestApiBaseRepair {
-
private static final String baseProduct = "Shotgun";
private TestWithException test;
private Subscription baseSubscription;
@@ -65,15 +65,11 @@ public class TestRepairWithError extends TestApiBaseRepair {
baseSubscription = createSubscription(baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testENT_REPAIR_NEW_EVENT_BEFORE_LAST_BP_REMAINING() throws Exception {
-
- log.info("Starting testENT_REPAIR_NEW_EVENT_BEFORE_LAST_BP_REMAINING");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException {
-
// MOVE AFTER TRIAL
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -96,11 +92,8 @@ public class TestRepairWithError extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_NEW_EVENT_BEFORE_LAST_BP_REMAINING);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testENT_REPAIR_INVALID_DELETE_SET() throws Exception {
-
- log.info("Starting testENT_REPAIR_INVALID_DELETE_SET");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException, EntitlementUserApiException {
@@ -133,11 +126,8 @@ public class TestRepairWithError extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_INVALID_DELETE_SET);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testENT_REPAIR_NON_EXISTENT_DELETE_EVENT() throws Exception {
-
- log.info("Starting testENT_REPAIR_NON_EXISTENT_DELETE_EVENT");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException {
@@ -156,11 +146,8 @@ public class TestRepairWithError extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_NON_EXISTENT_DELETE_EVENT);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testENT_REPAIR_SUB_RECREATE_NOT_EMPTY() throws Exception {
-
- log.info("Starting testENT_REPAIR_SUB_RECREATE_NOT_EMPTY");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException {
@@ -187,11 +174,8 @@ public class TestRepairWithError extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_SUB_RECREATE_NOT_EMPTY);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testENT_REPAIR_SUB_EMPTY() throws Exception {
-
- log.info("Starting testENT_REPAIR_SUB_EMPTY");
-
test.withException(new TestWithExceptionCallback() {
@Override
@@ -219,16 +203,11 @@ public class TestRepairWithError extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_SUB_EMPTY);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testENT_REPAIR_AO_CREATE_BEFORE_BP_START() throws Exception {
-
- log.info("Starting testENT_REPAIR_AO_CREATE_BEFORE_BP_START");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException, EntitlementUserApiException {
-
-
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
@@ -248,7 +227,6 @@ public class TestRepairWithError extends TestApiBaseRepair {
final SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
-
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
des.add(createDeletedEvent(aoRepair.getExistingEvents().get(0).getEventId()));
des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
@@ -267,16 +245,12 @@ public class TestRepairWithError extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_AO_CREATE_BEFORE_BP_START);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testENT_REPAIR_NEW_EVENT_BEFORE_LAST_AO_REMAINING() throws Exception {
-
- log.info("Starting testENT_REPAIR_NEW_EVENT_BEFORE_LAST_AO_REMAINING");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException, EntitlementUserApiException {
-
// MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4));
clock.addDeltaFromReality(it.toDurationMillis());
@@ -296,7 +270,6 @@ public class TestRepairWithError extends TestApiBaseRepair {
final SubscriptionTimeline aoRepair = getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
assertEquals(aoRepair.getExistingEvents().size(), 2);
-
final List<DeletedEvent> des = new LinkedList<SubscriptionTimeline.DeletedEvent>();
//des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
final DateTime aoCancelDate = aoSubscription.getStartDate().plusDays(10);
@@ -313,12 +286,8 @@ public class TestRepairWithError extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_NEW_EVENT_BEFORE_LAST_AO_REMAINING);
}
-
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testENT_REPAIR_BP_RECREATE_MISSING_AO() throws Exception {
-
- log.info("Starting testENT_REPAIR_BP_RECREATE_MISSING_AO");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException, EntitlementUserApiException {
@@ -357,11 +326,8 @@ public class TestRepairWithError extends TestApiBaseRepair {
//
// CAN'T seem to trigger such case easily, other errors trigger before...
//
- @Test(groups = {"fast"}, enabled = false)
+ @Test(groups = "fast", enabled = false)
public void testENT_REPAIR_BP_RECREATE_MISSING_AO_CREATE() throws Exception {
-
- log.info("Starting testENT_REPAIR_BP_RECREATE_MISSING_AO_CREATE");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException, EntitlementUserApiException {
@@ -406,16 +372,12 @@ public class TestRepairWithError extends TestApiBaseRepair {
}, ErrorCode.ENT_REPAIR_BP_RECREATE_MISSING_AO_CREATE);
}
- @Test(groups = {"fast"}, enabled = false)
+ @Test(groups = "fast", enabled = false)
public void testENT_REPAIR_MISSING_AO_DELETE_EVENT() throws Exception {
-
- log.info("Starting testENT_REPAIR_MISSING_AO_DELETE_EVENT");
-
test.withException(new TestWithExceptionCallback() {
@Override
public void doTest() throws EntitlementRepairException, EntitlementUserApiException {
-
/*
// MOVE CLOCK -- JUST BEFORE END OF TRIAL
*
@@ -460,5 +422,4 @@ public class TestRepairWithError extends TestApiBaseRepair {
}
}, ErrorCode.ENT_REPAIR_MISSING_AO_DELETE_EVENT);
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiAddOn.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiAddOn.java
index 182974b..2571b6f 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiAddOn.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiAddOn.java
@@ -49,17 +49,13 @@ import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
public class TestUserApiAddOn extends TestApiBase {
-
@Override
public Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
}
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testCreateCancelAddon() {
-
- log.info("Starting testCreateCancelAddon");
-
try {
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
@@ -89,13 +85,9 @@ public class TestUserApiAddOn extends TestApiBase {
}
}
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testCancelBPWithAddon() {
-
- log.info("Starting testCancelBPWithAddon");
-
try {
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -154,14 +146,9 @@ public class TestUserApiAddOn extends TestApiBase {
}
}
-
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testChangeBPWithAddonIncluded() {
-
- log.info("Starting testChangeBPWithAddonIncluded");
-
try {
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -221,13 +208,9 @@ public class TestUserApiAddOn extends TestApiBase {
}
}
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testChangeBPWithAddonNonAvailable() {
-
- log.info("Starting testChangeBPWithAddonNonAvailable");
-
try {
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -286,7 +269,6 @@ public class TestUserApiAddOn extends TestApiBase {
clock.addDeltaFromReality(it.toDurationMillis());
assertTrue(testListener.isCompleted(5000));
-
// REFETCH AO SUBSCRIPTION AND CHECK THIS CANCELLED
aoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId());
assertEquals(aoSubscription.getState(), SubscriptionState.CANCELLED);
@@ -297,12 +279,8 @@ public class TestUserApiAddOn extends TestApiBase {
}
}
-
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testAddonCreateWithBundleAlign() {
-
- log.info("Starting testAddonCreateWithBundleAlign");
-
try {
final String aoProduct = "Telescopic-Scope";
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
@@ -310,9 +288,9 @@ public class TestUserApiAddOn extends TestApiBase {
// This is just to double check our test catalog gives us what we want before we start the test
final PlanSpecifier planSpecifier = new PlanSpecifier(aoProduct,
- ProductCategory.ADD_ON,
- aoTerm,
- aoPriceList);
+ ProductCategory.ADD_ON,
+ aoTerm,
+ aoPriceList);
final PlanAlignmentCreate alignement = catalog.planCreateAlignment(planSpecifier, clock.getUTCNow());
assertEquals(alignement, PlanAlignmentCreate.START_OF_BUNDLE);
@@ -324,11 +302,8 @@ public class TestUserApiAddOn extends TestApiBase {
}
}
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testAddonCreateWithSubscriptionAlign() {
-
- log.info("Starting testAddonCreateWithSubscriptionAlign");
-
try {
final String aoProduct = "Laser-Scope";
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
@@ -336,9 +311,9 @@ public class TestUserApiAddOn extends TestApiBase {
// This is just to double check our test catalog gives us what we want before we start the test
final PlanSpecifier planSpecifier = new PlanSpecifier(aoProduct,
- ProductCategory.ADD_ON,
- aoTerm,
- aoPriceList);
+ ProductCategory.ADD_ON,
+ aoTerm,
+ aoPriceList);
final PlanAlignmentCreate alignement = catalog.planCreateAlignment(planSpecifier, clock.getUTCNow());
assertEquals(alignement, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
@@ -350,11 +325,8 @@ public class TestUserApiAddOn extends TestApiBase {
}
}
-
private void testAddonCreateInternal(final String aoProduct, final BillingPeriod aoTerm, final String aoPriceList, final PlanAlignmentCreate expAlignement) {
-
try {
-
final String baseProduct = "Shotgun";
final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -404,7 +376,6 @@ public class TestUserApiAddOn extends TestApiBase {
clock.addDeltaFromReality(it.toDurationMillis());
assertTrue(testListener.isCompleted(5000));
-
// CHECK EVERYTHING AGAIN
aoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId());
@@ -418,11 +389,9 @@ public class TestUserApiAddOn extends TestApiBase {
assertNotNull(aoCurrentPhase);
assertEquals(aoCurrentPhase.getPhaseType(), PhaseType.EVERGREEN);
-
aoSubscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(aoSubscription.getId());
aoPendingTranstion = aoSubscription.getPendingTransition();
assertNull(aoPendingTranstion);
-
} catch (EntitlementUserApiException e) {
Assert.fail(e.getMessage());
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancel.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancel.java
index 879bb90..af1b2f4 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancel.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancel.java
@@ -37,13 +37,8 @@ import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
public abstract class TestUserApiCancel extends TestApiBase {
-
protected void testCancelSubscriptionIMM() {
-
- log.info("Starting testCancelSubscriptionIMM");
-
try {
-
final DateTime init = clock.getUTCNow();
final String prod = "Shotgun";
@@ -76,12 +71,8 @@ public abstract class TestUserApiCancel extends TestApiBase {
}
}
-
protected void testCancelSubscriptionEOTWithChargeThroughDate() throws EntitlementBillingApiException {
- log.info("Starting testCancelSubscriptionEOTWithChargeThroughDate");
-
try {
-
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -139,13 +130,8 @@ public abstract class TestUserApiCancel extends TestApiBase {
}
}
-
protected void testCancelSubscriptionEOTWithNoChargeThroughDate() {
-
- log.info("Starting testCancelSubscriptionEOTWithNoChargeThroughDate");
-
try {
-
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -188,11 +174,7 @@ public abstract class TestUserApiCancel extends TestApiBase {
// are as they used to be and we can move forward without hitting cancellation
//
protected void testUncancel() throws EntitlementBillingApiException {
-
- log.info("Starting testUncancel");
-
try {
-
final String prod = "Shotgun";
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSet = PriceListSet.DEFAULT_PRICELIST_NAME;
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelMemory.java
index 4b3f54a..60d978f 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelMemory.java
@@ -25,33 +25,31 @@ import com.ning.billing.entitlement.api.billing.EntitlementBillingApiException;
import com.ning.billing.entitlement.glue.MockEngineModuleMemory;
public class TestUserApiCancelMemory extends TestUserApiCancel {
-
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.PRODUCTION, new MockEngineModuleMemory());
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelSubscriptionIMM() {
super.testCancelSubscriptionIMM();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelSubscriptionEOTWithChargeThroughDate() throws EntitlementBillingApiException {
super.testCancelSubscriptionEOTWithChargeThroughDate();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelSubscriptionEOTWithNoChargeThroughDate() {
super.testCancelSubscriptionEOTWithNoChargeThroughDate();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testUncancel() throws EntitlementBillingApiException {
super.testUncancel();
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelSql.java
index 2bd3299..535add2 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCancelSql.java
@@ -25,14 +25,12 @@ import com.ning.billing.entitlement.api.billing.EntitlementBillingApiException;
import com.ning.billing.entitlement.glue.MockEngineModuleSql;
public class TestUserApiCancelSql extends TestUserApiCancel {
-
-
@Override
public Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
}
- @Test(enabled = false, groups = {"stress"})
+ @Test(enabled = false, groups = {"slow, stress"})
public void stressTest() throws Exception {
final int MAX_STRESS_ITERATIONS = 10;
for (int i = 0; i < MAX_STRESS_ITERATIONS; i++) {
@@ -49,27 +47,26 @@ public class TestUserApiCancelSql extends TestUserApiCancel {
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testCancelSubscriptionIMM() {
super.testCancelSubscriptionIMM();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testCancelSubscriptionEOTWithChargeThroughDate() throws EntitlementBillingApiException {
super.testCancelSubscriptionEOTWithChargeThroughDate();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testCancelSubscriptionEOTWithNoChargeThroughDate() {
super.testCancelSubscriptionEOTWithNoChargeThroughDate();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testUncancel() throws EntitlementBillingApiException {
super.testUncancel();
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java
index 59db4d7..72573e3 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlan.java
@@ -43,8 +43,6 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
public abstract class TestUserApiChangePlan extends TestApiBase {
-
-
private void checkChangePlan(final SubscriptionData subscription, final String expProduct, final ProductCategory expCategory,
final BillingPeriod expBillingPeriod, final PhaseType expPhase) {
@@ -59,19 +57,13 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
assertEquals(currentPhase.getPhaseType(), expPhase);
}
-
protected void testChangePlanBundleAlignEOTWithNoChargeThroughDate() {
tChangePlanBundleAlignEOTWithNoChargeThroughDate("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, "Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
}
-
private void tChangePlanBundleAlignEOTWithNoChargeThroughDate(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet,
final String toProd, final BillingPeriod toTerm, final String toPlanSet) {
-
- log.info("Starting testChangePlanBundleAlignEOTWithNoChargeThroughDate");
-
try {
-
// CREATE
final SubscriptionData subscription = createSubscription(fromProd, fromTerm, fromPlanSet);
@@ -102,25 +94,19 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
-
protected void testChangePlanBundleAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
- log.info("Starting testChangePlanBundleAlignEOTWithChargeThroughDate");
testChangePlanBundleAlignEOTWithChargeThroughDate("Shotgun", BillingPeriod.ANNUAL, "gunclubDiscount", "Pistol", BillingPeriod.ANNUAL, "gunclubDiscount");
}
private void testChangePlanBundleAlignEOTWithChargeThroughDate(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet,
final String toProd, final BillingPeriod toTerm, final String toPlanSet) throws EntitlementBillingApiException {
-
-
try {
-
// CREATE
SubscriptionData subscription = createSubscription(fromProd, fromTerm, fromPlanSet);
final PlanPhase trialPhase = subscription.getCurrentPhase();
final DateTime expectedPhaseTrialChange = DefaultClock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
-
// MOVE TO NEXT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31));
@@ -129,7 +115,6 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
PlanPhase currentPhase = subscription.getCurrentPhase();
assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
-
// SET CTD
final Duration ctd = getDurationMonth(1);
final DateTime newChargedThroughDate = DefaultClock.addDuration(expectedPhaseTrialChange, ctd);
@@ -155,7 +140,6 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
final List<EntitlementEvent> events = dao.getPendingEventsForSubscription(subscription.getId());
assertTrue(events.get(0) instanceof ApiEvent);
-
// MOVE TO EOT
testListener.pushExpectedEvent(NextEvent.CHANGE);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
@@ -172,19 +156,14 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
-
protected void testChangePlanBundleAlignIMM() {
tChangePlanBundleAlignIMM("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, "Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
}
-
private void tChangePlanBundleAlignIMM(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet,
final String toProd, final BillingPeriod toTerm, final String toPlanSet) {
- log.info("Starting testChangePlanBundleAlignIMM");
-
try {
-
final SubscriptionData subscription = createSubscription(fromProd, fromTerm, fromPlanSet);
testListener.pushExpectedEvent(NextEvent.CHANGE);
@@ -217,17 +196,13 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
-
protected void testChangePlanChangePlanAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
- log.info("Starting testChangePlanChangePlanAlignEOTWithChargeThroughDate");
tChangePlanChangePlanAlignEOTWithChargeThroughDate("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, "Assault-Rifle", BillingPeriod.ANNUAL, "rescue");
}
private void tChangePlanChangePlanAlignEOTWithChargeThroughDate(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet,
final String toProd, final BillingPeriod toTerm, final String toPlanSet) throws EntitlementBillingApiException {
-
try {
-
DateTime currentTime = clock.getUTCNow();
SubscriptionData subscription = createSubscription(fromProd, fromTerm, fromPlanSet);
@@ -308,8 +283,6 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
protected void testMultipleChangeLastIMM() throws EntitlementBillingApiException {
-
- log.info("Starting testMultipleChangeLastIMM");
try {
SubscriptionData subscription = createSubscription("Assault-Rifle", BillingPeriod.MONTHLY, "gunclubDiscount");
final PlanPhase trialPhase = subscription.getCurrentPhase();
@@ -361,10 +334,7 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
protected void testMultipleChangeLastEOT() throws EntitlementBillingApiException {
-
- log.info("Starting testMultipleChangeLastEOT");
try {
-
SubscriptionData subscription = createSubscription("Assault-Rifle", BillingPeriod.ANNUAL, "gunclubDiscount");
final PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
@@ -425,7 +395,6 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
assertNotNull(currentPhase);
assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
-
// MOVE TO NEXT PHASE
testListener.pushExpectedEvent(NextEvent.PHASE);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(6));
@@ -449,13 +418,8 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
}
}
-
protected void testCorrectPhaseAlignmentOnChange() {
-
- log.info("Starting testCorrectPhaseAlignmentOnChange");
-
try {
-
SubscriptionData subscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
PlanPhase trialPhase = subscription.getCurrentPhase();
assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
@@ -464,7 +428,6 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(2));
clock.addDeltaFromReality(it.toDurationMillis());
-
// CHANGE IMMEDIATE TO A 3 PHASES PLAN
testListener.reset();
testListener.pushExpectedEvent(NextEvent.CHANGE);
@@ -506,5 +469,4 @@ public abstract class TestUserApiChangePlan extends TestApiBase {
Assert.fail(e.getMessage());
}
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanMemory.java
index 6bc6864..1bf654b 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanMemory.java
@@ -25,46 +25,43 @@ import com.ning.billing.entitlement.api.billing.EntitlementBillingApiException;
import com.ning.billing.entitlement.glue.MockEngineModuleMemory;
public class TestUserApiChangePlanMemory extends TestUserApiChangePlan {
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.PRODUCTION, new MockEngineModuleMemory());
}
-
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testChangePlanBundleAlignEOTWithNoChargeThroughDate() {
super.testChangePlanBundleAlignEOTWithNoChargeThroughDate();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testChangePlanBundleAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
super.testChangePlanBundleAlignEOTWithChargeThroughDate();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testChangePlanBundleAlignIMM() {
super.testChangePlanBundleAlignIMM();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testMultipleChangeLastIMM() throws EntitlementBillingApiException {
super.testMultipleChangeLastIMM();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testMultipleChangeLastEOT() throws EntitlementBillingApiException {
super.testMultipleChangeLastEOT();
}
-
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCorrectPhaseAlignmentOnChange() {
super.testCorrectPhaseAlignmentOnChange();
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanSql.java
index bec359b..406b575 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiChangePlanSql.java
@@ -25,13 +25,12 @@ import com.ning.billing.entitlement.api.billing.EntitlementBillingApiException;
import com.ning.billing.entitlement.glue.MockEngineModuleSql;
public class TestUserApiChangePlanSql extends TestUserApiChangePlan {
-
@Override
public Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
}
- @Test(enabled = false, groups = {"stress"})
+ @Test(enabled = false, groups = {"slow", "stress"})
public void stressTest() throws Exception {
final int MAX_STRESS_ITERATIONS = 10;
for (int i = 0; i < MAX_STRESS_ITERATIONS; i++) {
@@ -54,37 +53,37 @@ public class TestUserApiChangePlanSql extends TestUserApiChangePlan {
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testCorrectPhaseAlignmentOnChange() {
super.testCorrectPhaseAlignmentOnChange();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testChangePlanBundleAlignEOTWithNoChargeThroughDate() {
super.testChangePlanBundleAlignEOTWithNoChargeThroughDate();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testChangePlanBundleAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
super.testChangePlanBundleAlignEOTWithChargeThroughDate();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testChangePlanBundleAlignIMM() {
super.testChangePlanBundleAlignIMM();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testMultipleChangeLastIMM() throws EntitlementBillingApiException {
super.testMultipleChangeLastIMM();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testMultipleChangeLastEOT() throws EntitlementBillingApiException {
super.testMultipleChangeLastEOT();
}
@@ -95,5 +94,4 @@ public class TestUserApiChangePlanSql extends TestUserApiChangePlan {
public void testChangePlanChangePlanAlignEOTWithChargeThroughDate() throws EntitlementBillingApiException {
super.testChangePlanChangePlanAlignEOTWithChargeThroughDate();
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
index 510f55b..9ab3af1 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreate.java
@@ -16,7 +16,6 @@
package com.ning.billing.entitlement.api.user;
-
import java.util.List;
import org.joda.time.DateTime;
@@ -42,13 +41,10 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
public abstract class TestUserApiCreate extends TestApiBase {
-
private static final Logger log = LoggerFactory.getLogger(TestUserApiCreate.class);
public void testCreateWithRequestedDate() {
- log.info("Starting testCreateWithRequestedDate");
try {
-
final DateTime init = clock.getUTCNow();
final DateTime requestedDate = init.minusYears(1);
@@ -56,13 +52,11 @@ public abstract class TestUserApiCreate extends TestApiBase {
final BillingPeriod term = BillingPeriod.MONTHLY;
final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
-
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.CREATE);
-
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null), requestedDate, context);
+ getProductSpecifier(productName, planSetName, term, null), requestedDate, context);
assertNotNull(subscription);
assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
@@ -80,12 +74,8 @@ public abstract class TestUserApiCreate extends TestApiBase {
}
}
-
protected void testCreateWithInitialPhase() {
- log.info("Starting testCreateWithInitialPhase");
try {
-
-
final DateTime init = clock.getUTCNow();
final String productName = "Shotgun";
@@ -95,7 +85,7 @@ public abstract class TestUserApiCreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.CREATE);
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, PhaseType.EVERGREEN), clock.getUTCNow(), context);
+ getProductSpecifier(productName, planSetName, term, PhaseType.EVERGREEN), clock.getUTCNow(), context);
assertNotNull(subscription);
assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
@@ -122,10 +112,7 @@ public abstract class TestUserApiCreate extends TestApiBase {
}
protected void testSimpleCreateSubscription() {
-
- log.info("Starting testSimpleCreateSubscription");
try {
-
final DateTime init = clock.getUTCNow();
final String productName = "Shotgun";
@@ -135,8 +122,8 @@ public abstract class TestUserApiCreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.CREATE);
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null),
- clock.getUTCNow(), context);
+ getProductSpecifier(productName, planSetName, term, null),
+ clock.getUTCNow(), context);
assertNotNull(subscription);
assertEquals(subscription.getActiveVersion(), SubscriptionEvents.INITIAL_VERSION);
@@ -180,12 +167,8 @@ public abstract class TestUserApiCreate extends TestApiBase {
}
}
-
protected void testSimpleSubscriptionThroughPhases() {
-
- log.info("Starting testSimpleSubscriptionThroughPhases");
try {
-
final String productName = "Pistol";
final BillingPeriod term = BillingPeriod.ANNUAL;
final String planSetName = "gunclubDiscount";
@@ -211,7 +194,6 @@ public abstract class TestUserApiCreate extends TestApiBase {
assertNotNull(currentPhase);
assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
-
// MOVE TO EVERGREEN PHASE + RE-READ SUBSCRIPTION
testListener.pushExpectedEvent(NextEvent.PHASE);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusYears(1));
@@ -230,10 +212,7 @@ public abstract class TestUserApiCreate extends TestApiBase {
}
protected void testSubscriptionWithAddOn() {
-
- log.info("Starting testSubscriptionWithAddOn");
try {
-
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.ANNUAL;
final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
@@ -241,7 +220,7 @@ public abstract class TestUserApiCreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.CREATE);
final SubscriptionData subscription = (SubscriptionData) entitlementApi.createSubscription(bundle.getId(),
- getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), context);
+ getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), context);
assertNotNull(subscription);
assertListenerStatus();
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java
index d671d2a..a7cd464 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateMemory.java
@@ -24,41 +24,38 @@ import com.google.inject.Stage;
import com.ning.billing.entitlement.glue.MockEngineModuleMemory;
public class TestUserApiCreateMemory extends TestUserApiCreate {
-
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.PRODUCTION, new MockEngineModuleMemory());
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCreateWithRequestedDate() {
super.testCreateWithRequestedDate();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCreateWithInitialPhase() {
super.testSimpleSubscriptionThroughPhases();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testSimpleCreateSubscription() {
super.testSimpleCreateSubscription();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
protected void testSimpleSubscriptionThroughPhases() {
super.testSimpleSubscriptionThroughPhases();
}
@Override
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
protected void testSubscriptionWithAddOn() {
super.testSubscriptionWithAddOn();
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java
index 135e98c..526d3b2 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiCreateSql.java
@@ -24,32 +24,31 @@ import com.google.inject.Stage;
import com.ning.billing.entitlement.glue.MockEngineModuleSql;
public class TestUserApiCreateSql extends TestUserApiCreate {
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testCreateWithRequestedDate() {
super.testCreateWithRequestedDate();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testCreateWithInitialPhase() {
super.testCreateWithInitialPhase();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
public void testSimpleCreateSubscription() {
super.testSimpleCreateSubscription();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
protected void testSimpleSubscriptionThroughPhases() {
super.testSimpleSubscriptionThroughPhases();
}
@@ -59,5 +58,4 @@ public class TestUserApiCreateSql extends TestUserApiCreate {
protected void testSubscriptionWithAddOn() {
super.testSubscriptionWithAddOn();
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiDemos.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiDemos.java
index 49e7a59..d2d33c4 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiDemos.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiDemos.java
@@ -46,7 +46,6 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
public class TestUserApiDemos extends TestApiBase {
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
@@ -67,10 +66,8 @@ public class TestUserApiDemos extends TestApiBase {
* 7. Move to next Phase
* 8. Cancel EOT
*/
- @Test(enabled = true, groups = "demos")
+ @Test(enabled = false, groups = {"slow", "demos"})
public void testDemo1() throws EntitlementBillingApiException {
-
- log.info("Starting testSubscriptionWithAddOn");
try {
System.out.println("DEMO 1 START");
@@ -173,15 +170,12 @@ public class TestUserApiDemos extends TestApiBase {
}
-
private void displayState(final UUID subscriptionId, final String stepMsg) {
-
System.out.println("");
System.out.println("******\t STEP " + stepMsg + " **************");
try {
final SubscriptionData subscription = (SubscriptionData) entitlementApi.getSubscriptionFromId(subscriptionId);
-
final Plan currentPlan = subscription.getCurrentPlan();
final PlanPhase currentPhase = subscription.getCurrentPhase();
final String priceList = subscription.getCurrentPriceList().getName();
@@ -203,7 +197,7 @@ public class TestUserApiDemos extends TestApiBase {
}
- @Test(enabled = true, groups = {"stress"})
+ @Test(enabled = false, groups = {"slow", "stress"})
public void stressTest() throws Exception {
for (int i = 0; i < 100; i++) {
cleanupTest();
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiError.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiError.java
index fa947f1..afa82d0 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiError.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiError.java
@@ -42,24 +42,17 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
public class TestUserApiError extends TestApiBase {
-
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleMemory());
}
-
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCreateSubscriptionBadCatalog() {
-
- log.info("Starting testCreateSubscriptionBadCatalog");
-
// WRONG PRODUCTS
tCreateSubscriptionInternal(bundle.getId(), null, BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.CAT_NULL_PRODUCT_NAME);
tCreateSubscriptionInternal(bundle.getId(), "Whatever", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.CAT_NO_SUCH_PRODUCT);
-
// TODO: MARTIN TO FIX WITH CORRECT ERROR CODE. RIGHT NOW NPE
// WRONG BILLING PERIOD
@@ -69,33 +62,28 @@ public class TestUserApiError extends TestApiBase {
}
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCreateSubscriptionNoBundle() {
- log.info("Starting testCreateSubscriptionNoBundle");
tCreateSubscriptionInternal(null, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.ENT_CREATE_NO_BUNDLE);
}
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCreateSubscriptionNoBP() {
- log.info("Starting testCreateSubscriptionNoBP");
tCreateSubscriptionInternal(bundle.getId(), "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.ENT_CREATE_NO_BP);
}
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCreateSubscriptionBPExists() {
- log.info("Starting testCreateSubscriptionBPExists");
try {
createSubscription("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
tCreateSubscriptionInternal(bundle.getId(), "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.ENT_CREATE_BP_EXISTS);
} catch (Exception e) {
- e.printStackTrace();
- Assert.assertFalse(true);
+ Assert.fail(e.toString());
}
}
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testRecreateSubscriptionBPNotCancelled() {
- log.info("Starting testRecreateSubscriptionBPNotCancelled");
try {
final SubscriptionData subscription = createSubscription("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
try {
@@ -105,26 +93,23 @@ public class TestUserApiError extends TestApiBase {
assertEquals(e.getCode(), ErrorCode.ENT_RECREATE_BAD_STATE.getCode());
}
} catch (Exception e) {
- e.printStackTrace();
- Assert.assertFalse(true);
+ Assert.fail(e.toString());
}
}
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCreateSubscriptionAddOnNotAvailable() {
- log.info("Starting testCreateSubscriptionAddOnNotAvailable");
try {
final UUID accountId = UUID.randomUUID();
final SubscriptionBundle aoBundle = entitlementApi.createBundleForAccount(accountId, "myAOBundle", context);
createSubscriptionWithBundle(aoBundle.getId(), "Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
tCreateSubscriptionInternal(aoBundle.getId(), "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.ENT_CREATE_AO_NOT_AVAILABLE);
} catch (Exception e) {
- e.printStackTrace();
- Assert.assertFalse(true);
+ Assert.fail(e.toString());
}
}
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testCreateSubscriptionAddOnIncluded() {
log.info("Starting testCreateSubscriptionAddOnIncluded");
try {
@@ -133,12 +118,10 @@ public class TestUserApiError extends TestApiBase {
createSubscriptionWithBundle(aoBundle.getId(), "Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
tCreateSubscriptionInternal(aoBundle.getId(), "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.ENT_CREATE_AO_ALREADY_INCLUDED);
} catch (Exception e) {
- e.printStackTrace();
- Assert.assertFalse(true);
+ Assert.fail(e.toString());
}
}
-
private void tCreateSubscriptionInternal(@Nullable final UUID bundleId, @Nullable final String productName,
@Nullable final BillingPeriod term, final String planSet, final ErrorCode expected) {
try {
@@ -156,10 +139,8 @@ public class TestUserApiError extends TestApiBase {
}
}
-
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testChangeSubscriptionNonActive() {
- log.info("Starting testChangeSubscriptionNonActive");
try {
final Subscription subscription = createSubscription("Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME);
@@ -176,15 +157,12 @@ public class TestUserApiError extends TestApiBase {
}
}
} catch (Exception e) {
- e.printStackTrace();
- Assert.assertFalse(true);
+ Assert.fail(e.toString());
}
}
-
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testChangeSubscriptionFutureCancelled() {
- log.info("Starting testChangeSubscriptionFutureCancelled");
try {
Subscription subscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
final PlanPhase trialPhase = subscription.getCurrentPhase();
@@ -196,7 +174,6 @@ public class TestUserApiError extends TestApiBase {
clock.addDeltaFromReality(it.toDurationMillis());
assertTrue(testListener.isCompleted(5000));
-
// SET CTD TO CANCEL IN FUTURE
final DateTime expectedPhaseTrialChange = DefaultClock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
final Duration ctd = getDurationMonth(1);
@@ -219,20 +196,16 @@ public class TestUserApiError extends TestApiBase {
assertListenerStatus();
} catch (Exception e) {
- e.printStackTrace();
- Assert.assertFalse(true);
+ Assert.fail(e.toString());
}
}
-
- @Test(enabled = false, groups = {"fast"})
+ @Test(enabled = false, groups = "fast")
public void testCancelBadState() {
- log.info("Starting testCancelBadState");
}
- @Test(enabled = true, groups = {"fast"})
+ @Test(groups = "fast")
public void testUncancelBadState() {
- log.info("Starting testUncancelBadState");
try {
final Subscription subscription = createSubscription("Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME);
@@ -248,10 +221,7 @@ public class TestUserApiError extends TestApiBase {
}
assertListenerStatus();
} catch (Exception e) {
- e.printStackTrace();
- Assert.assertFalse(true);
+ Assert.fail(e.toString());
}
-
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiPriceList.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiPriceList.java
index 36d699d..f2d7f22 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiPriceList.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiPriceList.java
@@ -20,18 +20,14 @@ import com.google.inject.Injector;
import com.ning.billing.entitlement.api.TestApiBase;
public class TestUserApiPriceList extends TestApiBase {
-
@Override
protected Injector getInjector() {
return null;
}
protected void testChangeDefaultToDiscountToDefault() {
-
}
protected void testChangeDiscountToDefaultoDiscount() {
-
}
-
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreate.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreate.java
index cd09fdf..d35c9f3 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreate.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreate.java
@@ -31,12 +31,9 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
public abstract class TestUserApiRecreate extends TestApiBase {
-
private static final Logger log = LoggerFactory.getLogger(TestUserApiRecreate.class);
-
protected void testRecreateWithBPCanceledThroughSubscription() {
- log.info("Starting testRecreateWithBPCanceledThroughSubscription");
try {
testCreateAndRecreate(false);
assertListenerStatus();
@@ -47,7 +44,6 @@ public abstract class TestUserApiRecreate extends TestApiBase {
}
protected void testCreateWithBPCanceledFromUserApi() {
- log.info("Starting testCreateWithBPCanceledFromUserApi");
try {
testCreateAndRecreate(true);
assertListenerStatus();
@@ -57,9 +53,7 @@ public abstract class TestUserApiRecreate extends TestApiBase {
}
}
-
private SubscriptionData testCreateAndRecreate(final boolean fromUserAPi) throws EntitlementUserApiException {
-
final DateTime init = clock.getUTCNow();
final DateTime requestedDate = init.minusYears(1);
@@ -103,12 +97,11 @@ public abstract class TestUserApiRecreate extends TestApiBase {
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.RE_CREATE);
- // Avoid ordering issue for events at exact same date; this is actually a real good test, we
+ // Avoid ordering issue for events at exact same date; this is actually a real good test,
// we test it at Beatrix level. At this level that would work for sql tests but not for in memory.
try {
Thread.sleep(1000);
- } catch (InterruptedException e) {
-
+ } catch (InterruptedException ignored) {
}
if (fromUserAPi) {
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateMemory.java
index b164d65..fa808b6 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateMemory.java
@@ -24,21 +24,19 @@ import com.google.inject.Stage;
import com.ning.billing.entitlement.glue.MockEngineModuleMemory;
public class TestUserApiRecreateMemory extends TestUserApiRecreate {
-
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.PRODUCTION, new MockEngineModuleMemory());
}
@Override
- @Test(enabled = false, groups = {"fast"})
+ @Test(enabled = false, groups = "fast")
protected void testRecreateWithBPCanceledThroughSubscription() {
super.testRecreateWithBPCanceledThroughSubscription();
}
@Override
- @Test(enabled = false, groups = {"fast"})
+ @Test(enabled = false, groups = "fast")
protected void testCreateWithBPCanceledFromUserApi() {
super.testRecreateWithBPCanceledThroughSubscription();
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateSql.java
index 7b6217c..5dfcea1 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiRecreateSql.java
@@ -24,20 +24,19 @@ import com.google.inject.Stage;
import com.ning.billing.entitlement.glue.MockEngineModuleSql;
public class TestUserApiRecreateSql extends TestUserApiRecreate {
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
protected void testRecreateWithBPCanceledThroughSubscription() {
super.testRecreateWithBPCanceledThroughSubscription();
}
@Override
- @Test(enabled = true, groups = {"slow"})
+ @Test(groups = "slow")
protected void testCreateWithBPCanceledFromUserApi() {
super.testRecreateWithBPCanceledThroughSubscription();
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiScenarios.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiScenarios.java
index 81aa23b..f679b73 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiScenarios.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiScenarios.java
@@ -39,17 +39,13 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
public class TestUserApiScenarios extends TestApiBase {
-
@Override
protected Injector getInjector() {
return Guice.createInjector(Stage.DEVELOPMENT, new MockEngineModuleSql());
}
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testChangeIMMCancelUncancelChangeEOT() throws EntitlementBillingApiException {
-
- log.info("Starting testChangeIMMCancelUncancelChangeEOT");
-
try {
SubscriptionData subscription = createSubscription("Assault-Rifle", BillingPeriod.MONTHLY, "gunclubDiscount");
final PlanPhase trialPhase = subscription.getCurrentPhase();
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoMemory.java
index 06032f7..3479d0e 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoMemory.java
@@ -35,7 +35,6 @@ import com.google.inject.Inject;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.catalog.api.TimeUnit;
-import com.ning.billing.config.EntitlementConfig;
import com.ning.billing.entitlement.api.SubscriptionFactory;
import com.ning.billing.entitlement.api.migration.AccountMigrationData;
import com.ning.billing.entitlement.api.migration.AccountMigrationData.BundleMigrationData;
@@ -59,8 +58,7 @@ import com.ning.billing.util.notificationq.NotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService;
import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
-public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlementDao {
-
+public class MockEntitlementDaoMemory implements EntitlementDao {
protected static final Logger log = LoggerFactory.getLogger(EntitlementDao.class);
private final List<SubscriptionBundle> bundles;
@@ -71,12 +69,11 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
private final CatalogService catalogService;
@Inject
- public MockEntitlementDaoMemory(final Clock clock, final EntitlementConfig config,
+ public MockEntitlementDaoMemory(final Clock clock,
final NotificationQueueService notificationQueueService,
final CatalogService catalogService) {
super();
this.clock = clock;
- final EntitlementConfig config1 = config;
this.catalogService = catalogService;
this.notificationQueueService = notificationQueueService;
this.bundles = new ArrayList<SubscriptionBundle>();
@@ -84,7 +81,6 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
this.events = new TreeSet<EntitlementEvent>();
}
- @Override
public void reset() {
bundles.clear();
subscriptions.clear();
@@ -154,7 +150,6 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
return Collections.emptyList();
}
-
@Override
public void createSubscription(final SubscriptionData subscription, final List<EntitlementEvent> initialEvents,
final CallContext context) {
@@ -220,7 +215,6 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
}
}
-
@Override
public Subscription getBaseSubscription(final SubscriptionFactory factory, final UUID bundleId) {
for (final Subscription cur : subscriptions) {
@@ -239,7 +233,6 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
insertEvent(nextPhase);
}
-
private Subscription buildSubscription(final SubscriptionFactory factory, final SubscriptionData in) {
if (factory != null) {
return factory.createSubscription(new SubscriptionBuilder(in), getEventsForSubscription(in.getId()));
@@ -299,7 +292,6 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
}
}
-
private void cancelNextPhaseEvent(final UUID subscriptionId) {
final Subscription curSubscription = getSubscriptionFromId(null, subscriptionId);
@@ -326,7 +318,6 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
}
}
-
private void cancelNextChangeEvent(final UUID subscriptionId) {
synchronized (events) {
@@ -374,7 +365,6 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
}
}
-
@Override
public void migrate(final UUID accountId, final AccountMigrationData accountData, final CallContext context) {
synchronized (events) {
@@ -410,18 +400,17 @@ public class MockEntitlementDaoMemory implements EntitlementDao, MockEntitlement
private void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao, final DateTime effectiveDate, final NotificationKey notificationKey) {
try {
final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(Engine.ENTITLEMENT_SERVICE_NAME,
- Engine.NOTIFICATION_QUEUE_NAME);
- subscriptionEventQueue.recordFutureNotificationFromTransaction(transactionalDao, effectiveDate, notificationKey);
+ Engine.NOTIFICATION_QUEUE_NAME);
+ subscriptionEventQueue.recordFutureNotificationFromTransaction(transactionalDao, effectiveDate, null, notificationKey);
} catch (NoSuchNotificationQueue e) {
throw new RuntimeException(e);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new RuntimeException(e);
}
}
@Override
public Map<UUID, List<EntitlementEvent>> getEventsForBundle(final UUID bundleId) {
- // TODO Auto-generated method stub
return null;
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java
index 6a93d3c..0c104fc 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java
@@ -17,11 +17,6 @@
package com.ning.billing.entitlement.engine.dao;
import org.skife.jdbi.v2.IDBI;
-import org.skife.jdbi.v2.Transaction;
-import org.skife.jdbi.v2.TransactionStatus;
-import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.mixins.CloseMe;
-import org.skife.jdbi.v2.sqlobject.mixins.Transactional;
import com.google.inject.Inject;
import com.ning.billing.catalog.api.CatalogService;
@@ -30,51 +25,10 @@ import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.notificationq.NotificationQueueService;
-public class MockEntitlementDaoSql extends AuditedEntitlementDao implements MockEntitlementDao {
-
- private final ResetSqlDao resetDao;
-
+public class MockEntitlementDaoSql extends AuditedEntitlementDao {
@Inject
public MockEntitlementDaoSql(final IDBI dbi, final Clock clock, final AddonUtils addonUtils, final NotificationQueueService notificationQueueService,
final Bus eventBus, final CatalogService catalogService) {
super(dbi, clock, addonUtils, notificationQueueService, eventBus, catalogService);
- this.resetDao = dbi.onDemand(ResetSqlDao.class);
- }
-
-
- @Override
- public void reset() {
- resetDao.inTransaction(new Transaction<Void, ResetSqlDao>() {
-
- @Override
- public Void inTransaction(final ResetSqlDao dao, final TransactionStatus status)
- throws Exception {
- resetDao.resetEvents();
- resetDao.resetSubscriptions();
- resetDao.resetBundles();
- resetDao.resetClaimedNotifications();
- resetDao.resetNotifications();
- return null;
- }
- });
- }
-
- public static interface ResetSqlDao extends Transactional<ResetSqlDao>, CloseMe {
-
- @SqlUpdate("truncate table subscription_events")
- public void resetEvents();
-
- @SqlUpdate("truncate table subscriptions")
- public void resetSubscriptions();
-
- @SqlUpdate("truncate table bundles")
- public void resetBundles();
-
- @SqlUpdate("truncate table notifications")
- public void resetNotifications();
-
- @SqlUpdate("truncate table claimed_notifications")
- public void resetClaimedNotifications();
-
}
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuite.java b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuite.java
new file mode 100644
index 0000000..e839150
--- /dev/null
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuite.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.entitlement;
+
+import com.ning.billing.KillbillTestSuite;
+
+public abstract class EntitlementTestSuite extends KillbillTestSuite {
+}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..0537107
--- /dev/null
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.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.entitlement;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class EntitlementTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
index 844bf90..dd48560 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModule.java
@@ -16,20 +16,19 @@
package com.ning.billing.entitlement.glue;
+import org.mockito.Mockito;
+
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.catalog.glue.CatalogModule;
-import com.ning.billing.mock.BrainDeadProxyFactory;
import com.ning.billing.mock.glue.MockClockModule;
import com.ning.billing.util.glue.CallContextModule;
public class MockEngineModule extends DefaultEntitlementModule {
-
-
@Override
protected void configure() {
super.configure();
install(new CatalogModule());
- bind(AccountUserApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class));
+ bind(AccountUserApi.class).toInstance(Mockito.mock(AccountUserApi.class));
install(new MockClockModule());
install(new CallContextModule());
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
index 148b62d..13a9012 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
@@ -16,7 +16,6 @@
package com.ning.billing.entitlement.glue;
-
import com.google.inject.name.Names;
import com.ning.billing.entitlement.api.timeline.RepairEntitlementLifecycleDao;
import com.ning.billing.entitlement.engine.dao.EntitlementDao;
@@ -28,7 +27,6 @@ import com.ning.billing.util.notificationq.MockNotificationQueueService;
import com.ning.billing.util.notificationq.NotificationQueueService;
public class MockEngineModuleMemory extends MockEngineModule {
-
@Override
protected void installEntitlementDao() {
bind(EntitlementDao.class).to(MockEntitlementDaoMemory.class).asEagerSingleton();
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleSql.java
index 51a55a0..fd3d266 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleSql.java
@@ -16,11 +16,11 @@
package com.ning.billing.entitlement.glue;
-
import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
import com.google.inject.name.Names;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.DBIProvider;
import com.ning.billing.dbi.DbiConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
@@ -34,8 +34,6 @@ import com.ning.billing.util.glue.CustomFieldModule;
import com.ning.billing.util.glue.NotificationQueueModule;
public class MockEngineModuleSql extends MockEngineModule {
-
-
@Override
protected void installEntitlementDao() {
bind(EntitlementDao.class).to(MockEntitlementDaoSql.class).asEagerSingleton();
@@ -44,9 +42,8 @@ public class MockEngineModuleSql extends MockEngineModule {
bind(RepairEntitlementDao.class).asEagerSingleton();
}
-
protected void installDBI() {
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
if (helper.isUsingLocalInstance()) {
bind(IDBI.class).toProvider(DBIProvider.class).asEagerSingleton();
diff --git a/invoice/src/main/java/com/ning/billing/invoice/api/migration/DefaultInvoiceMigrationApi.java b/invoice/src/main/java/com/ning/billing/invoice/api/migration/DefaultInvoiceMigrationApi.java
index 9e9b95c..67d3c77 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/api/migration/DefaultInvoiceMigrationApi.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/api/migration/DefaultInvoiceMigrationApi.java
@@ -20,8 +20,13 @@ import java.math.BigDecimal;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
+import com.ning.billing.account.api.Account;
+import com.ning.billing.account.api.AccountApiException;
+import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceItem;
@@ -35,23 +40,35 @@ import com.ning.billing.util.callcontext.UserType;
import com.ning.billing.util.clock.Clock;
public class DefaultInvoiceMigrationApi implements InvoiceMigrationApi {
+ private static final Logger log = LoggerFactory.getLogger(DefaultInvoiceMigrationApi.class);
+ private final AccountUserApi accountUserApi;
private final DefaultInvoiceDao dao;
private final Clock clock;
@Inject
- public DefaultInvoiceMigrationApi(final DefaultInvoiceDao dao, final Clock clock) {
+ public DefaultInvoiceMigrationApi(final AccountUserApi accountUserApi, final DefaultInvoiceDao dao, final Clock clock) {
+ this.accountUserApi = accountUserApi;
this.dao = dao;
this.clock = clock;
}
@Override
public UUID createMigrationInvoice(final UUID accountId, final DateTime targetDate, final BigDecimal balance, final Currency currency) {
+ final Account account;
+ try {
+ account = accountUserApi.getAccountById(accountId);
+ } catch (AccountApiException e) {
+ log.warn("Unable to find account for id {}", accountId);
+ return null;
+ }
+
final CallContext context = new DefaultCallContextFactory(clock).createMigrationCallContext("Migration", CallOrigin.INTERNAL, UserType.MIGRATION, clock.getUTCNow(), clock.getUTCNow());
final Invoice migrationInvoice = new MigrationInvoice(accountId, clock.getUTCNow(), targetDate, currency);
final InvoiceItem migrationInvoiceItem = new MigrationInvoiceItem(migrationInvoice.getId(), accountId, targetDate, balance, currency);
migrationInvoice.addInvoiceItem(migrationInvoiceItem);
- dao.create(migrationInvoice, context);
+
+ dao.create(migrationInvoice, account.getBillCycleDay(), context);
return migrationInvoice.getId();
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
index 08b359f..fe88a63 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
@@ -19,19 +19,14 @@ package com.ning.billing.invoice.dao;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
-import javax.annotation.Nullable;
-
import org.joda.time.DateTime;
-import org.joda.time.field.ZeroIsMaxDateTimeField;
import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.Transaction;
import org.skife.jdbi.v2.TransactionStatus;
-import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.inject.Inject;
@@ -47,7 +42,6 @@ import com.ning.billing.invoice.model.CreditAdjInvoiceItem;
import com.ning.billing.invoice.model.CreditBalanceAdjInvoiceItem;
import com.ning.billing.invoice.model.DefaultInvoice;
import com.ning.billing.invoice.model.DefaultInvoicePayment;
-import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.model.RecurringInvoiceItem;
import com.ning.billing.invoice.model.RefundAdjInvoiceItem;
import com.ning.billing.invoice.notification.NextBillingDatePoster;
@@ -65,7 +59,6 @@ public class DefaultInvoiceDao implements InvoiceDao {
private final InvoicePaymentSqlDao invoicePaymentSqlDao;
private final TagUserApi tagUserApi;
private final NextBillingDatePoster nextBillingDatePoster;
-
private final InvoiceItemSqlDao invoiceItemSqlDao;
@Inject
@@ -146,13 +139,11 @@ public class DefaultInvoiceDao implements InvoiceDao {
}
@Override
- public void create(final Invoice invoice, final CallContext context) {
+ public void create(final Invoice invoice, final int billCycleDay, final CallContext context) {
invoiceSqlDao.inTransaction(new Transaction<Void, InvoiceSqlDao>() {
@Override
public Void inTransaction(final InvoiceSqlDao transactional, final TransactionStatus status) throws Exception {
-
final Invoice currentInvoice = transactional.getById(invoice.getId().toString());
-
if (currentInvoice == null) {
final List<EntityAudit> audits = new ArrayList<EntityAudit>();
@@ -168,9 +159,8 @@ public class DefaultInvoiceDao implements InvoiceDao {
recordIdList = transInvoiceItemSqlDao.getRecordIds(invoice.getId().toString());
audits.addAll(createAudits(TableName.INVOICE_ITEMS, recordIdList));
- List<InvoiceItem> recurringInvoiceItems = invoice.getInvoiceItems(RecurringInvoiceItem.class);
-
- notifyOfFutureBillingEvents(transactional, recurringInvoiceItems);
+ final List<InvoiceItem> recurringInvoiceItems = invoice.getInvoiceItems(RecurringInvoiceItem.class);
+ notifyOfFutureBillingEvents(transactional, invoice.getAccountId(), billCycleDay, recurringInvoiceItems);
final List<InvoicePayment> invoicePayments = invoice.getPayments();
final InvoicePaymentSqlDao invoicePaymentSqlDao = transactional.become(InvoicePaymentSqlDao.class);
@@ -180,7 +170,6 @@ public class DefaultInvoiceDao implements InvoiceDao {
transactional.insertAuditFromTransaction(audits, context);
}
-
return null;
}
});
@@ -215,12 +204,11 @@ public class DefaultInvoiceDao implements InvoiceDao {
return invoiceSqlDao.inTransaction(new Transaction<BigDecimal, InvoiceSqlDao>() {
@Override
public BigDecimal inTransaction(final InvoiceSqlDao transactional, final TransactionStatus status) throws Exception {
-
BigDecimal cba = BigDecimal.ZERO;
BigDecimal accountBalance = BigDecimal.ZERO;
- List<Invoice> invoices = getAllInvoicesByAccountFromTransaction(accountId, transactional);
- for (Invoice cur : invoices) {
+ final List<Invoice> invoices = getAllInvoicesByAccountFromTransaction(accountId, transactional);
+ for (final Invoice cur : invoices) {
accountBalance = accountBalance.add(cur.getBalance());
cba = cba.add(cur.getCBAAmount());
}
@@ -239,7 +227,6 @@ public class DefaultInvoiceDao implements InvoiceDao {
});
}
-
@Override
public void notifyOfPayment(final InvoicePayment invoicePayment, final CallContext context) {
invoicePaymentSqlDao.inTransaction(new Transaction<Void, InvoicePaymentSqlDao>() {
@@ -295,11 +282,9 @@ public class DefaultInvoiceDao implements InvoiceDao {
tagUserApi.removeTag(invoiceId, ObjectType.INVOICE, ControlTagType.WRITTEN_OFF.toTagDefinition(), context);
}
-
@Override
- public InvoicePayment createRefund(final UUID paymentId, final BigDecimal amount, final boolean isInvoiceAdjusted, final UUID paymentCookieId, final CallContext context)
+ public InvoicePayment createRefund(final UUID paymentId, final BigDecimal amount, final boolean isInvoiceAdjusted, final UUID paymentCookieId, final CallContext context)
throws InvoiceApiException {
-
return invoicePaymentSqlDao.inTransaction(new Transaction<InvoicePayment, InvoicePaymentSqlDao>() {
@Override
public InvoicePayment inTransaction(final InvoicePaymentSqlDao transactional, final TransactionStatus status) throws Exception {
@@ -327,34 +312,36 @@ public class DefaultInvoiceDao implements InvoiceDao {
}
final InvoicePayment refund = new DefaultInvoicePayment(UUID.randomUUID(), InvoicePaymentType.REFUND, paymentId,
- payment.getInvoiceId(), context.getCreatedDate(), requestedPositiveAmount.negate(), payment.getCurrency(), paymentCookieId, payment.getId());
+ payment.getInvoiceId(), context.getCreatedDate(), requestedPositiveAmount.negate(),
+ payment.getCurrency(), paymentCookieId, payment.getId());
transactional.create(refund, context);
// Retrieve invoice after the Refund
- InvoiceSqlDao transInvoiceDao = transactional.become(InvoiceSqlDao.class);
- Invoice invoice = transInvoiceDao.getById(payment.getInvoiceId().toString());
+ final InvoiceSqlDao transInvoiceDao = transactional.become(InvoiceSqlDao.class);
+ final Invoice invoice = transInvoiceDao.getById(payment.getInvoiceId().toString());
if (invoice != null) {
populateChildren(invoice, transInvoiceDao);
+ } else {
+ throw new IllegalStateException("Invoice shouldn't be null for payment " + payment.getId());
}
final BigDecimal invoiceBalanceAfterRefund = invoice.getBalance();
- InvoiceItemSqlDao transInvoiceItemDao = transInvoiceDao.become(InvoiceItemSqlDao.class);
+ final InvoiceItemSqlDao transInvoiceItemDao = transInvoiceDao.become(InvoiceItemSqlDao.class);
// If we have an existing CBA > 0, we need to adjust it
//final BigDecimal cbaAmountAfterRefund = invoice.getCBAAmount();
final BigDecimal accountCbaAvailable = getAccountCBAFromTransaction(invoice.getAccountId(), transInvoiceDao);
BigDecimal cbaAdjAmount = BigDecimal.ZERO;
if (accountCbaAvailable.compareTo(BigDecimal.ZERO) > 0) {
- cbaAdjAmount = (requestedPositiveAmount.compareTo(accountCbaAvailable) > 0) ? accountCbaAvailable.negate() : requestedPositiveAmount.negate();
+ cbaAdjAmount = (requestedPositiveAmount.compareTo(accountCbaAvailable) > 0) ? accountCbaAvailable.negate() : requestedPositiveAmount.negate();
final InvoiceItem cbaAdjItem = new CreditBalanceAdjInvoiceItem(invoice.getId(), invoice.getAccountId(), context.getCreatedDate(), cbaAdjAmount, invoice.getCurrency());
transInvoiceItemDao.create(cbaAdjItem, context);
}
final BigDecimal requestedPositiveAmountAfterCbaAdj = requestedPositiveAmount.add(cbaAdjAmount);
if (isInvoiceAdjusted) {
-
- BigDecimal maxBalanceToAdjust = (invoiceBalanceAfterRefund.compareTo(BigDecimal.ZERO) <= 0) ? BigDecimal.ZERO : invoiceBalanceAfterRefund;
- BigDecimal requestedPositiveAmountToAdjust = requestedPositiveAmountAfterCbaAdj.compareTo(maxBalanceToAdjust) > 0 ? maxBalanceToAdjust : requestedPositiveAmountAfterCbaAdj;
+ final BigDecimal maxBalanceToAdjust = (invoiceBalanceAfterRefund.compareTo(BigDecimal.ZERO) <= 0) ? BigDecimal.ZERO : invoiceBalanceAfterRefund;
+ final BigDecimal requestedPositiveAmountToAdjust = requestedPositiveAmountAfterCbaAdj.compareTo(maxBalanceToAdjust) > 0 ? maxBalanceToAdjust : requestedPositiveAmountAfterCbaAdj;
if (requestedPositiveAmountToAdjust.compareTo(BigDecimal.ZERO) > 0) {
final InvoiceItem adjItem = new RefundAdjInvoiceItem(invoice.getId(), invoice.getAccountId(), context.getCreatedDate(), requestedPositiveAmountToAdjust.negate(), invoice.getCurrency());
transInvoiceItemDao.create(adjItem, context);
@@ -365,14 +352,12 @@ public class DefaultInvoiceDao implements InvoiceDao {
});
}
-
@Override
public InvoicePayment postChargeback(final UUID invoicePaymentId, final BigDecimal amount, final CallContext context) throws InvoiceApiException {
return invoicePaymentSqlDao.inTransaction(new Transaction<InvoicePayment, InvoicePaymentSqlDao>() {
@Override
public InvoicePayment inTransaction(final InvoicePaymentSqlDao transactional, final TransactionStatus status) throws Exception {
-
final BigDecimal maxChargedBackAmount = getRemainingAmountPaidFromTransaction(invoicePaymentId, transactional);
final BigDecimal requestedChargedBackAmout = (amount == null) ? maxChargedBackAmount : amount;
if (requestedChargedBackAmout.compareTo(BigDecimal.ZERO) <= 0) {
@@ -387,7 +372,7 @@ public class DefaultInvoiceDao implements InvoiceDao {
throw new InvoiceApiException(ErrorCode.INVOICE_PAYMENT_NOT_FOUND, invoicePaymentId.toString());
} else {
final InvoicePayment chargeBack = new DefaultInvoicePayment(UUID.randomUUID(), InvoicePaymentType.CHARGED_BACK, null,
- payment.getInvoiceId(), context.getCreatedDate(), requestedChargedBackAmout.negate(), payment.getCurrency(), null, payment.getId());
+ payment.getInvoiceId(), context.getCreatedDate(), requestedChargedBackAmout.negate(), payment.getCurrency(), null, payment.getId());
invoicePaymentSqlDao.create(chargeBack, context);
return chargeBack;
}
@@ -437,8 +422,8 @@ public class DefaultInvoiceDao implements InvoiceDao {
@Override
public InvoiceItem insertCredit(final UUID accountId, final UUID invoiceId, final BigDecimal amount,
- final DateTime effectiveDate, final Currency currency,
- final CallContext context) {
+ final DateTime effectiveDate, final Currency currency,
+ final CallContext context) {
return invoiceSqlDao.inTransaction(new Transaction<InvoiceItem, InvoiceSqlDao>() {
@Override
@@ -449,8 +434,9 @@ public class DefaultInvoiceDao implements InvoiceDao {
transactional.create(invoiceForRefund, context);
invoiceIdForRefund = invoiceForRefund.getId();
}
+
final InvoiceItem credit = new CreditAdjInvoiceItem(invoiceIdForRefund, accountId, effectiveDate, amount, currency);
- InvoiceItemSqlDao transInvoiceItemDao = transactional.become(InvoiceItemSqlDao.class);
+ final InvoiceItemSqlDao transInvoiceItemDao = transactional.become(InvoiceItemSqlDao.class);
transInvoiceItemDao.create(credit, context);
return credit;
}
@@ -464,14 +450,14 @@ public class DefaultInvoiceDao implements InvoiceDao {
private BigDecimal getAccountCBAFromTransaction(final UUID accountId, final InvoiceSqlDao transactional) {
BigDecimal cba = BigDecimal.ZERO;
- List<Invoice> invoices = getAllInvoicesByAccountFromTransaction(accountId, transactional);
- for (Invoice cur : invoices) {
+ final List<Invoice> invoices = getAllInvoicesByAccountFromTransaction(accountId, transactional);
+ for (final Invoice cur : invoices) {
cba = cba.add(cur.getCBAAmount());
}
+
return cba;
}
-
private void populateChildren(final Invoice invoice, final InvoiceSqlDao invoiceSqlDao) {
getInvoiceItemsWithinTransaction(invoice, invoiceSqlDao);
getInvoicePaymentsWithinTransaction(invoice, invoiceSqlDao);
@@ -488,14 +474,11 @@ public class DefaultInvoiceDao implements InvoiceDao {
return invoices;
}
-
private BigDecimal getRemainingAmountPaidFromTransaction(final UUID invoicePaymentId, final InvoicePaymentSqlDao transactional) {
final BigDecimal amount = transactional.getRemainingAmountPaid(invoicePaymentId.toString());
return amount == null ? BigDecimal.ZERO : amount;
}
-
-
private void getInvoiceItemsWithinTransaction(final List<Invoice> invoices, final InvoiceSqlDao invoiceDao) {
for (final Invoice invoice : invoices) {
getInvoiceItemsWithinTransaction(invoice, invoiceDao);
@@ -523,16 +506,36 @@ public class DefaultInvoiceDao implements InvoiceDao {
invoice.addPayments(invoicePayments);
}
- private void notifyOfFutureBillingEvents(final InvoiceSqlDao dao, final List<InvoiceItem> invoiceItems) {
+ private void notifyOfFutureBillingEvents(final InvoiceSqlDao dao, final UUID accountId, final int billCycleDay, final List<InvoiceItem> invoiceItems) {
+ DateTime nextBCD = null;
+ UUID subscriptionForNextBCD = null;
for (final InvoiceItem item : invoiceItems) {
if (item.getInvoiceItemType() == InvoiceItemType.RECURRING) {
final RecurringInvoiceItem recurringInvoiceItem = (RecurringInvoiceItem) item;
if ((recurringInvoiceItem.getEndDate() != null) &&
(recurringInvoiceItem.getAmount() == null ||
recurringInvoiceItem.getAmount().compareTo(BigDecimal.ZERO) >= 0)) {
- nextBillingDatePoster.insertNextBillingNotification(dao, item.getSubscriptionId(), recurringInvoiceItem.getEndDate());
+ if (nextBCD == null || nextBCD.compareTo(recurringInvoiceItem.getEndDate()) > 0) {
+ nextBCD = recurringInvoiceItem.getEndDate();
+ subscriptionForNextBCD = recurringInvoiceItem.getSubscriptionId();
+ }
}
}
}
+ // We need to be notified if and only if the maximum end date of the invoiced recurring items is equal
+ // to the next bill cycle day.
+ // We take the maximum because we're guaranteed to have invoiced all subscriptions up until that date
+ // (and no further processing is needed).
+ // Also, we only need to get notified on the BDC. For other invoice events (e.g. phase changes),
+ // we'll be notified by entitlement.
+ if (subscriptionForNextBCD != null && nextBCD != null) {
+ final int lastDayOfMonth = nextBCD.dayOfMonth().withMaximumValue().getDayOfMonth();
+ final int nextBCDDay = nextBCD.getDayOfMonth();
+ // Small trick here in case the bill cycle day doesn't exist for that month, e.g. the bill cycle day
+ // is on the 31st, but the month has only 30 days
+ if (nextBCDDay == billCycleDay || (lastDayOfMonth == nextBCDDay && billCycleDay > lastDayOfMonth)) {
+ nextBillingDatePoster.insertNextBillingNotification(dao, accountId, subscriptionForNextBCD, nextBCD);
+ }
+ }
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceDao.java
index 9c2403b..1812ed1 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceDao.java
@@ -31,7 +31,7 @@ import com.ning.billing.util.api.TagApiException;
import com.ning.billing.util.callcontext.CallContext;
public interface InvoiceDao {
- void create(Invoice invoice, CallContext context);
+ void create(final Invoice invoice, final int billCycleDay, final CallContext context);
Invoice getById(final UUID id);
diff --git a/invoice/src/main/java/com/ning/billing/invoice/generator/DefaultInvoiceGenerator.java b/invoice/src/main/java/com/ning/billing/invoice/generator/DefaultInvoiceGenerator.java
index 118bf8a..7d34da2 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/generator/DefaultInvoiceGenerator.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/generator/DefaultInvoiceGenerator.java
@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
import org.joda.time.Months;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -296,31 +297,38 @@ public class DefaultInvoiceGenerator implements InvoiceGenerator {
return items;
}
+ // Turn a set of events into a list of invoice items. Note that the dates on the invoice items will be rounded (granularity of a day)
List<InvoiceItem> processEvents(final UUID invoiceId, final UUID accountId, final BillingEvent thisEvent, @Nullable final BillingEvent nextEvent,
final DateTime targetDate, final Currency currency) throws InvoiceApiException {
final List<InvoiceItem> items = new ArrayList<InvoiceItem>();
- final InvoiceItem fixedPriceInvoiceItem = generateFixedPriceItem(invoiceId, accountId, thisEvent, targetDate, currency);
+
+ final DateTime roundedTargetDate = InvoiceDateUtils.roundDateTimeToDate(targetDate, thisEvent.getTimeZone());
+
+ // Handle fixed price items
+ final InvoiceItem fixedPriceInvoiceItem = generateFixedPriceItem(invoiceId, accountId, thisEvent, roundedTargetDate, currency);
if (fixedPriceInvoiceItem != null) {
items.add(fixedPriceInvoiceItem);
}
+ // Handle recurring items
final BillingPeriod billingPeriod = thisEvent.getBillingPeriod();
if (billingPeriod != BillingPeriod.NO_BILLING_PERIOD) {
-
final BillingMode billingMode = instantiateBillingMode(thisEvent.getBillingMode());
+ // Invoice granularity is day; (if not some comparison might fail)
final DateTime startDate = thisEvent.getEffectiveDate();
- final DateTime tzAdjustedStartDate = startDate.toDateTime(thisEvent.getTimeZone());
- final DateTime roundedStartDate = new DateTime(tzAdjustedStartDate.getYear(), tzAdjustedStartDate.getMonthOfYear(), tzAdjustedStartDate.getDayOfMonth(), 0, 0, thisEvent.getTimeZone());
- log.info(String.format("start = %s, rounded = %s, target = %s, in = %s", startDate, roundedStartDate, targetDate, (!roundedStartDate.isAfter(targetDate)) ? "in" : "out"));
- if (!roundedStartDate.isAfter(targetDate)) {
+ final DateTime roundedStartDate = InvoiceDateUtils.roundDateTimeToDate(startDate, thisEvent.getTimeZone());
+
+ if (!roundedStartDate.isAfter(roundedTargetDate)) {
final DateTime endDate = (nextEvent == null) ? null : nextEvent.getEffectiveDate();
+
+ final DateTime roundedEndDate = InvoiceDateUtils.roundDateTimeToDate(endDate, thisEvent.getTimeZone());
final int billCycleDay = thisEvent.getBillCycleDay();
final List<RecurringInvoiceItemData> itemData;
try {
- itemData = billingMode.calculateInvoiceItemData(startDate, endDate, targetDate, billCycleDay, billingPeriod);
+ itemData = billingMode.calculateInvoiceItemData(roundedStartDate, roundedEndDate, roundedTargetDate, billCycleDay, billingPeriod);
} catch (InvalidDateSequenceException e) {
- throw new InvoiceApiException(ErrorCode.INVOICE_INVALID_DATE_SEQUENCE, startDate, endDate, targetDate);
+ throw new InvoiceApiException(ErrorCode.INVOICE_INVALID_DATE_SEQUENCE, startDate, endDate, roundedTargetDate);
}
for (final RecurringInvoiceItemData itemDatum : itemData) {
@@ -356,20 +364,23 @@ public class DefaultInvoiceGenerator implements InvoiceGenerator {
}
InvoiceItem generateFixedPriceItem(final UUID invoiceId, final UUID accountId, final BillingEvent thisEvent,
- final DateTime targetDate, final Currency currency) {
- if (thisEvent.getEffectiveDate().isAfter(targetDate)) {
+ final DateTime roundedTargetDate, final Currency currency) {
+ final DateTime roundedStartDate = InvoiceDateUtils.roundDateTimeToDate(thisEvent.getEffectiveDate(), thisEvent.getTimeZone());
+
+ if (roundedStartDate.isAfter(roundedTargetDate)) {
return null;
} else {
final BigDecimal fixedPrice = thisEvent.getFixedPrice();
if (fixedPrice != null) {
final Duration duration = thisEvent.getPlanPhase().getDuration();
- final DateTime endDate = duration.addToDateTime(thisEvent.getEffectiveDate());
+ final DateTime endDate = InvoiceDateUtils.roundDateTimeToDate(duration.addToDateTime(roundedStartDate), thisEvent.getTimeZone());
return new FixedPriceInvoiceItem(invoiceId, accountId, thisEvent.getSubscription().getBundleId(),
- thisEvent.getSubscription().getId(),
- thisEvent.getPlan().getName(), thisEvent.getPlanPhase().getName(),
- thisEvent.getEffectiveDate(), endDate, fixedPrice, currency);
+ thisEvent.getSubscription().getId(),
+ thisEvent.getPlan().getName(), thisEvent.getPlanPhase().getName(),
+ roundedStartDate, endDate,
+ fixedPrice, currency);
} else {
return null;
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java b/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java
new file mode 100644
index 0000000..5f7f86a
--- /dev/null
+++ b/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java
@@ -0,0 +1,31 @@
+/*
+ * 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.invoice.generator;
+
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+
+public class InvoiceDateUtils {
+ public static DateTime roundDateTimeToDate(final DateTime input, final DateTimeZone timeZone) {
+ if (input == null) {
+ return null;
+ }
+ final DateTime tzAdjustedStartDate = input.toDateTime(timeZone);
+
+ return new DateTime(tzAdjustedStartDate.getYear(), tzAdjustedStartDate.getMonthOfYear(), tzAdjustedStartDate.getDayOfMonth(), 0, 0, timeZone);
+ }
+}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/glue/DefaultInvoiceModule.java b/invoice/src/main/java/com/ning/billing/invoice/glue/DefaultInvoiceModule.java
index 7ed75e1..1f2507b 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/glue/DefaultInvoiceModule.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/glue/DefaultInvoiceModule.java
@@ -31,8 +31,6 @@ import com.ning.billing.invoice.api.InvoiceUserApi;
import com.ning.billing.invoice.api.formatters.InvoiceFormatterFactory;
import com.ning.billing.invoice.api.invoice.DefaultInvoicePaymentApi;
import com.ning.billing.invoice.api.migration.DefaultInvoiceMigrationApi;
-import com.ning.billing.invoice.api.test.DefaultInvoiceTestApi;
-import com.ning.billing.invoice.api.test.InvoiceTestApi;
import com.ning.billing.invoice.api.user.DefaultInvoiceUserApi;
import com.ning.billing.invoice.dao.DefaultInvoiceDao;
import com.ning.billing.invoice.dao.InvoiceDao;
@@ -44,7 +42,6 @@ import com.ning.billing.invoice.notification.EmailInvoiceNotifier;
import com.ning.billing.invoice.notification.NextBillingDateNotifier;
import com.ning.billing.invoice.notification.NextBillingDatePoster;
import com.ning.billing.invoice.notification.NullInvoiceNotifier;
-import com.ning.billing.invoice.template.formatters.DefaultInvoiceFormatterFactory;
import com.ning.billing.util.template.translation.TranslatorConfig;
public class DefaultInvoiceModule extends AbstractModule implements InvoiceModule {
@@ -60,11 +57,6 @@ public class DefaultInvoiceModule extends AbstractModule implements InvoiceModul
}
@Override
- public void installInvoiceTestApi() {
- bind(InvoiceTestApi.class).to(DefaultInvoiceTestApi.class).asEagerSingleton();
- }
-
- @Override
public void installInvoicePaymentApi() {
bind(InvoicePaymentApi.class).to(DefaultInvoicePaymentApi.class).asEagerSingleton();
}
@@ -120,6 +112,5 @@ public class DefaultInvoiceModule extends AbstractModule implements InvoiceModul
installInvoiceUserApi();
installInvoicePaymentApi();
installInvoiceMigrationApi();
- installInvoiceTestApi();
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java b/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java
index 1f747e5..1fdb6f7 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java
@@ -41,7 +41,7 @@ import com.ning.billing.invoice.api.InvoiceApiException;
import com.ning.billing.invoice.api.InvoiceCreationEvent;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceNotifier;
-import com.ning.billing.invoice.api.user.DefaultEmptyInvoiceEvent;
+import com.ning.billing.invoice.api.user.DefaultNullInvoiceEvent;
import com.ning.billing.invoice.api.user.DefaultInvoiceCreationEvent;
import com.ning.billing.invoice.dao.InvoiceDao;
import com.ning.billing.invoice.generator.InvoiceGenerator;
@@ -159,7 +159,7 @@ public class InvoiceDispatcher {
log.info("Generated null invoice.");
outputDebugData(billingEvents, invoices);
if (!dryRun) {
- final BusEvent event = new DefaultEmptyInvoiceEvent(accountId, clock.getUTCNow(), context.getUserToken());
+ final BusEvent event = new DefaultNullInvoiceEvent(accountId, clock.getUTCNow(), context.getUserToken());
postEvent(event, accountId);
}
} else {
@@ -172,7 +172,7 @@ public class InvoiceDispatcher {
}
outputDebugData(billingEvents, invoices);
if (!dryRun) {
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, account.getBillCycleDay(), context);
final List<InvoiceItem> fixedPriceInvoiceItems = invoice.getInvoiceItems(FixedPriceInvoiceItem.class);
final List<InvoiceItem> recurringInvoiceItems = invoice.getInvoiceItems(RecurringInvoiceItem.class);
diff --git a/invoice/src/main/java/com/ning/billing/invoice/model/InAdvanceBillingMode.java b/invoice/src/main/java/com/ning/billing/invoice/model/InAdvanceBillingMode.java
index e6132d4..117df30 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/model/InAdvanceBillingMode.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/model/InAdvanceBillingMode.java
@@ -77,7 +77,6 @@ public class InAdvanceBillingMode implements BillingMode {
results.add(new RecurringInvoiceItemData(lastBillingCycleDate, effectiveEndDate, trailingProRationPeriods));
}
}
-
return results;
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
index 5c03f01..99e4f28 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
@@ -38,7 +38,6 @@ import com.ning.billing.util.notificationq.NotificationQueueService.Notification
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier {
-
private static final Logger log = LoggerFactory.getLogger(DefaultNextBillingDateNotifier.class);
public static final String NEXT_BILLING_DATE_NOTIFIER_QUEUE = "next-billing-date-queue";
@@ -47,13 +46,12 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier {
private final InvoiceConfig config;
private final EntitlementUserApi entitlementUserApi;
-
private NotificationQueue nextBillingQueue;
private final InvoiceListener listener;
@Inject
public DefaultNextBillingDateNotifier(final NotificationQueueService notificationQueueService,
- final InvoiceConfig config, final EntitlementUserApi entitlementUserApi, final InvoiceListener listener) {
+ final InvoiceConfig config, final EntitlementUserApi entitlementUserApi, final InvoiceListener listener) {
this.notificationQueueService = notificationQueueService;
this.config = config;
this.entitlementUserApi = entitlementUserApi;
@@ -62,17 +60,27 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier {
@Override
public void initialize() throws NotificationQueueAlreadyExists {
- nextBillingQueue = notificationQueueService.createNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
- NEXT_BILLING_DATE_NOTIFIER_QUEUE,
- new NotificationQueueHandler() {
+ final NotificationConfig notificationConfig = new NotificationConfig() {
+ @Override
+ public long getSleepTimeMs() {
+ return config.getSleepTimeMs();
+ }
+
+ @Override
+ public boolean isNotificationProcessingOff() {
+ return config.isNotificationProcessingOff();
+ }
+ };
+
+ final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() {
@Override
public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDate) {
try {
-
- if (! (notificationKey instanceof NextBillingDateNotificationKey)) {
+ if (!(notificationKey instanceof NextBillingDateNotificationKey)) {
log.error("Invoice service received an unexpected event type {}", notificationKey.getClass().getName());
return;
}
+
final NextBillingDateNotificationKey key = (NextBillingDateNotificationKey) notificationKey;
try {
final Subscription subscription = entitlementUserApi.getSubscriptionFromId(key.getUuidKey());
@@ -87,23 +95,13 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier {
} catch (IllegalArgumentException e) {
log.error("The key returned from the NextBillingNotificationQueue is not a valid UUID", e);
}
-
}
- },
- new NotificationConfig() {
-
- @Override
- public long getSleepTimeMs() {
- return config.getSleepTimeMs();
- }
-
- @Override
- public boolean isNotificationProcessingOff() {
- return config.isNotificationProcessingOff();
- }
- }
- );
+ };
+ nextBillingQueue = notificationQueueService.createNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
+ NEXT_BILLING_DATE_NOTIFIER_QUEUE,
+ notificationQueueHandler,
+ notificationConfig);
}
@Override
@@ -122,6 +120,4 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier {
private void processEvent(final UUID subscriptionId, final DateTime eventDateTime) {
listener.handleNextBillingDateEvent(subscriptionId, eventDateTime);
}
-
-
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java
index f2521de..5f1c8e4 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java
@@ -17,6 +17,7 @@
package com.ning.billing.invoice.notification;
import java.io.IOException;
+import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
@@ -26,7 +27,7 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.ning.billing.invoice.api.DefaultInvoiceService;
-import com.ning.billing.util.notificationq.NotificationKey;
+import com.ning.billing.util.notificationq.Notification;
import com.ning.billing.util.notificationq.NotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService;
import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
@@ -45,18 +46,28 @@ public class DefaultNextBillingDatePoster implements NextBillingDatePoster {
}
@Override
- public void insertNextBillingNotification(final Transmogrifier transactionalDao, final UUID subscriptionId, final DateTime futureNotificationTime) {
+ public void insertNextBillingNotification(final Transmogrifier transactionalDao, final UUID accountId, final UUID subscriptionId, final DateTime futureNotificationTime) {
final NotificationQueue nextBillingQueue;
try {
+
+
nextBillingQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE);
log.info("Queuing next billing date notification. id: {}, timestamp: {}", subscriptionId.toString(), futureNotificationTime.toString());
- nextBillingQueue.recordFutureNotificationFromTransaction(transactionalDao, futureNotificationTime, new NextBillingDateNotificationKey(subscriptionId));
+
+ List<Notification> existingNotifications = nextBillingQueue.getNotificationForAccountAndDate(accountId, futureNotificationTime);
+ if (existingNotifications.size() > 0) {
+ log.info(String.format("%s : notification for account %s and date %s already exist, skip...",
+ DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE, accountId, futureNotificationTime));
+ return;
+ }
+
+ nextBillingQueue.recordFutureNotificationFromTransaction(transactionalDao, futureNotificationTime, accountId, new NextBillingDateNotificationKey(subscriptionId));
} catch (NoSuchNotificationQueue e) {
log.error("Attempting to put items on a non-existent queue (NextBillingDateNotifier).", e);
} catch (IOException e) {
- log.error("Failed to serialize notficationKey for subscriptionId {}", subscriptionId);
+ log.error("Failed to serialize notficationKey for subscriptionId {}", subscriptionId);
}
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDatePoster.java b/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDatePoster.java
index 279c61a..60f8ec4 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDatePoster.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDatePoster.java
@@ -23,7 +23,7 @@ import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
public interface NextBillingDatePoster {
- void insertNextBillingNotification(Transmogrifier transactionalDao,
+ void insertNextBillingNotification(Transmogrifier transactionalDao, UUID accountId,
UUID subscriptionId, DateTime futureNotificationTime);
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/api/migration/MockModuleNoEntitlement.java b/invoice/src/test/java/com/ning/billing/invoice/api/migration/MockModuleNoEntitlement.java
index a315a2c..ecae293 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/api/migration/MockModuleNoEntitlement.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/api/migration/MockModuleNoEntitlement.java
@@ -16,11 +16,7 @@
package com.ning.billing.invoice.api.migration;
-import static org.testng.Assert.assertNotNull;
-
-import java.io.IOException;
-import java.net.URL;
-
+import org.mockito.Mockito;
import org.skife.config.ConfigurationObjectFactory;
import com.ning.billing.invoice.MockModule;
@@ -29,44 +25,25 @@ import com.ning.billing.invoice.glue.DefaultInvoiceModule;
import com.ning.billing.invoice.notification.NextBillingDateNotifier;
import com.ning.billing.invoice.notification.NextBillingDatePoster;
import com.ning.billing.invoice.notification.NullInvoiceNotifier;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.email.templates.TemplateModule;
import com.ning.billing.util.template.translation.TranslatorConfig;
public class MockModuleNoEntitlement extends MockModule {
-// @Override
-// protected void installEntitlementModule() {
-// BillingApi entitlementApi = BrainDeadProxyFactory.createBrainDeadProxyFor(BillingApi.class);
-// ((ZombieControl)entitlementApi).addResult("setChargedThroughDateFromTransaction", BrainDeadProxyFactory.ZOMBIE_VOID);
-// ((ZombieControl)entitlementApi).addResult("getBillingEventsForAccountAndUpdateAccountBCD", BrainDeadProxyFactory.ZOMBIE_VOID);
-// //bind(BillingApi.class).toInstance(entitlementApi);
-//// bind(EntitlementUserApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class));
-// ChargeThruApi cta = BrainDeadProxyFactory.createBrainDeadProxyFor(ChargeThruApi.class);
-// bind(ChargeThruApi.class).toInstance(cta);
-// ((ZombieControl)cta).addResult("setChargedThroughDateFromTransaction", BrainDeadProxyFactory.ZOMBIE_VOID);
-// }
-
@Override
protected void installInvoiceModule() {
install(new DefaultInvoiceModule() {
-
@Override
protected void installNotifiers() {
- bind(NextBillingDateNotifier.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(NextBillingDateNotifier.class));
- final NextBillingDatePoster poster = BrainDeadProxyFactory.createBrainDeadProxyFor(NextBillingDatePoster.class);
- ((ZombieControl) poster).addResult("insertNextBillingNotification", BrainDeadProxyFactory.ZOMBIE_VOID);
+ bind(NextBillingDateNotifier.class).toInstance(Mockito.mock(NextBillingDateNotifier.class));
+ final NextBillingDatePoster poster = Mockito.mock(NextBillingDatePoster.class);
bind(NextBillingDatePoster.class).toInstance(poster);
bind(InvoiceNotifier.class).to(NullInvoiceNotifier.class).asEagerSingleton();
final TranslatorConfig config = new ConfigurationObjectFactory(System.getProperties()).build(TranslatorConfig.class);
bind(TranslatorConfig.class).toInstance(config);
}
-
-
});
- install(new TemplateModule());
-
+ install(new TemplateModule());
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/api/migration/TestDefaultInvoiceMigrationApi.java b/invoice/src/test/java/com/ning/billing/invoice/api/migration/TestDefaultInvoiceMigrationApi.java
index 7bbeb76..5ce310f 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/api/migration/TestDefaultInvoiceMigrationApi.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/api/migration/TestDefaultInvoiceMigrationApi.java
@@ -22,18 +22,13 @@ import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
-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.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
-import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
-import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -46,13 +41,11 @@ import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
-import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.billing.BillingModeType;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.invoice.InvoiceDispatcher;
import com.ning.billing.invoice.MockBillingEventSet;
-import com.ning.billing.invoice.TestInvoiceDispatcher;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceMigrationApi;
import com.ning.billing.invoice.api.InvoiceNotifier;
@@ -64,8 +57,6 @@ import com.ning.billing.invoice.notification.NullInvoiceNotifier;
import com.ning.billing.invoice.tests.InvoicingTestBase;
import com.ning.billing.junction.api.BillingApi;
import com.ning.billing.junction.api.BillingEventSet;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.bus.BusService;
import com.ning.billing.util.bus.DefaultBusService;
import com.ning.billing.util.callcontext.CallContext;
@@ -75,11 +66,10 @@ import com.ning.billing.util.callcontext.UserType;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
import com.ning.billing.util.globallocker.GlobalLocker;
-import com.ning.billing.util.io.IOUtils;
@Guice(modules = {MockModuleNoEntitlement.class})
public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
- final Logger log = LoggerFactory.getLogger(TestDefaultInvoiceMigrationApi.class);
+ private final Logger log = LoggerFactory.getLogger(TestDefaultInvoiceMigrationApi.class);
@Inject
InvoiceUserApi invoiceUserApi;
@@ -89,13 +79,12 @@ public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
@Inject
private InvoiceGenerator generator;
+
@Inject
private InvoiceDao invoiceDao;
- @Inject
- private GlobalLocker locker;
@Inject
- private MysqlTestingHelper helper;
+ private GlobalLocker locker;
@Inject
private BusService busService;
@@ -106,6 +95,10 @@ public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
@Inject
private BillingApi billingApi;
+ @Inject
+ private AccountUserApi accountUserApi;
+
+ private Account account;
private UUID accountId;
private UUID subscriptionId;
private DateTime date_migrated;
@@ -114,61 +107,37 @@ public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
private UUID migrationInvoiceId;
private UUID regularInvoiceId;
- private IDBI dbi;
-
-
private static final BigDecimal MIGRATION_INVOICE_AMOUNT = new BigDecimal("100.00");
private static final Currency MIGRATION_INVOICE_CURRENCY = Currency.USD;
private final Clock clock = new ClockMock();
- //@BeforeTest(groups = {"slow"})
- public void cleanup() {
- if (dbi != null) {
- dbi.inTransaction(new TransactionCallback<Void>() {
- @Override
- public Void inTransaction(final Handle h, final TransactionStatus status)
- throws Exception {
- h.execute("truncate table invoices");
- h.execute("truncate table invoice_items");
- h.execute("truncate table invoice_payments");
- return null;
- }
- });
- }
+ @BeforeSuite(groups = "slow")
+ public void setup() throws Exception {
+ busService.getBus().start();
}
-
- @BeforeSuite(groups = {"slow"})
- public void setup() throws Exception {
- log.info("Starting set up");
+ @BeforeMethod(groups = "slow")
+ public void setupMethod() throws Exception {
accountId = UUID.randomUUID();
subscriptionId = UUID.randomUUID();
date_migrated = clock.getUTCNow().minusYears(1);
date_regular = clock.getUTCNow();
- final String invoiceDdl = IOUtils.toString(TestInvoiceDispatcher.class.getResourceAsStream("/com/ning/billing/invoice/ddl.sql"));
- final String utilDdl = IOUtils.toString(TestInvoiceDispatcher.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
- helper.startMysql();
-
- helper.initDb(invoiceDdl);
- helper.initDb(utilDdl);
- dbi = helper.getDBI();
- cleanup();
- busService.getBus().start();
+ account = Mockito.mock(Account.class);
+ Mockito.when(accountUserApi.getAccountById(accountId)).thenReturn(account);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getId()).thenReturn(accountId);
+ Mockito.when(account.isNotifiedForInvoices()).thenReturn(true);
- ((ZombieControl) billingApi).addResult("setChargedThroughDate", BrainDeadProxyFactory.ZOMBIE_VOID);
migrationInvoiceId = createAndCheckMigrationInvoice();
regularInvoiceId = generateRegularInvoice();
-
}
- @AfterSuite(groups = {"slow"})
+ @AfterSuite(groups = "slow")
public void tearDown() {
try {
((DefaultBusService) busService).stopBus();
- helper.stopMysql();
} catch (Exception e) {
log.warn("Failed to tearDown test properly ", e);
}
@@ -195,16 +164,9 @@ public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
}
private UUID generateRegularInvoice() throws Exception {
- final AccountUserApi accountUserApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) accountUserApi).addResult("getAccountById", account);
- ((ZombieControl) account).addResult("getCurrency", Currency.USD);
- ((ZombieControl) account).addResult("getId", accountId);
- ((ZombieControl) account).addResult("isNotifiedForInvoices", true);
-
- final Subscription subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) subscription).addResult("getId", subscriptionId);
- ((ZombieControl) subscription).addResult("getBundleId", new UUID(0L, 0L));
+ final Subscription subscription = Mockito.mock(Subscription.class);
+ Mockito.when(subscription.getId()).thenReturn(subscriptionId);
+ Mockito.when(subscription.getBundleId()).thenReturn(new UUID(0L, 0L));
final BillingEventSet events = new MockBillingEventSet();
final Plan plan = MockPlan.createBicycleNoTrialEvergreen1USD();
final PlanPhase planPhase = MockPlanPhase.create1USDMonthlyEvergreen();
@@ -215,7 +177,7 @@ public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
fixedPrice, BigDecimal.ONE, currency, BillingPeriod.MONTHLY, 1,
BillingModeType.IN_ADVANCE, "", 1L, SubscriptionTransitionType.CREATE));
- ((ZombieControl) billingApi).addResult("getBillingEventsForAccountAndUpdateAccountBCD", events);
+ Mockito.when(billingApi.getBillingEventsForAccountAndUpdateAccountBCD(accountId)).thenReturn(events);
final InvoiceNotifier invoiceNotifier = new NullInvoiceNotifier();
final InvoiceDispatcher dispatcher = new InvoiceDispatcher(generator, accountUserApi, billingApi,
@@ -237,7 +199,7 @@ public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
return invoice.getId();
}
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testUserApiAccess() {
final List<Invoice> byAccount = invoiceUserApi.getInvoicesByAccount(accountId);
Assert.assertEquals(byAccount.size(), 1);
@@ -251,9 +213,8 @@ public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
Assert.assertEquals(unpaid.size(), 2);
}
-
// Check migration invoice IS returned for payment api calls
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testPaymentApi() {
final List<Invoice> allByAccount = invoicePaymentApi.getAllInvoicesByAccount(accountId);
Assert.assertEquals(allByAccount.size(), 2);
@@ -261,19 +222,16 @@ public class TestDefaultInvoiceMigrationApi extends InvoicingTestBase {
Assert.assertTrue(checkContains(allByAccount, migrationInvoiceId));
}
-
// ACCOUNT balance should reflect total of migration and non-migration invoices
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testBalance() {
final Invoice migrationInvoice = invoiceDao.getById(migrationInvoiceId);
final Invoice regularInvoice = invoiceDao.getById(regularInvoiceId);
final BigDecimal balanceOfAllInvoices = migrationInvoice.getBalance().add(regularInvoice.getBalance());
final BigDecimal accountBalance = invoiceUserApi.getAccountBalance(accountId);
- System.out.println("ACCOUNT balance: " + accountBalance + " should equal the Balance Of All Invoices: " + balanceOfAllInvoices);
+ log.info("ACCOUNT balance: " + accountBalance + " should equal the Balance Of All Invoices: " + balanceOfAllInvoices);
Assert.assertEquals(accountBalance.compareTo(balanceOfAllInvoices), 0);
-
-
}
private boolean checkContains(final List<Invoice> invoices, final UUID invoiceId) {
diff --git a/invoice/src/test/java/com/ning/billing/invoice/api/MockInvoicePaymentApi.java b/invoice/src/test/java/com/ning/billing/invoice/api/MockInvoicePaymentApi.java
index dbd1f08..87183b4 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/api/MockInvoicePaymentApi.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/api/MockInvoicePaymentApi.java
@@ -170,7 +170,6 @@ public class MockInvoicePaymentApi implements InvoicePaymentApi {
public InvoicePayment createRefund(UUID paymentId,
BigDecimal amount, boolean isInvoiceAdjusted, UUID paymentCookieId, CallContext context)
throws InvoiceApiException {
- // TODO Auto-generated method stub
return null;
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/api/user/TestEventJson.java b/invoice/src/test/java/com/ning/billing/invoice/api/user/TestEventJson.java
index 404255b..848a8e6 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/api/user/TestEventJson.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/api/user/TestEventJson.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.invoice.api.user;
import java.math.BigDecimal;
@@ -23,14 +24,15 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.ning.billing.catalog.api.Currency;
-import com.ning.billing.invoice.api.EmptyInvoiceEvent;
+import com.ning.billing.invoice.InvoiceTestSuite;
import com.ning.billing.invoice.api.InvoiceCreationEvent;
+import com.ning.billing.invoice.api.NullInvoiceEvent;
import com.ning.billing.util.jackson.ObjectMapper;
-public class TestEventJson {
+public class TestEventJson extends InvoiceTestSuite {
private final ObjectMapper mapper = new ObjectMapper();
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testInvoiceCreationEvent() throws Exception {
final InvoiceCreationEvent e = new DefaultInvoiceCreationEvent(UUID.randomUUID(), UUID.randomUUID(), new BigDecimal(12.0), Currency.USD, new DateTime(), UUID.randomUUID());
@@ -42,14 +44,14 @@ public class TestEventJson {
Assert.assertTrue(obj.equals(e));
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testEmptyInvoiceEvent() throws Exception {
- final EmptyInvoiceEvent e = new DefaultEmptyInvoiceEvent(UUID.randomUUID(), new DateTime(), UUID.randomUUID());
+ final NullInvoiceEvent e = new DefaultNullInvoiceEvent(UUID.randomUUID(), new DateTime(), UUID.randomUUID());
final String json = mapper.writeValueAsString(e);
- final Class<?> claz = Class.forName(DefaultEmptyInvoiceEvent.class.getName());
+ final Class<?> claz = Class.forName(DefaultNullInvoiceEvent.class.getName());
final Object obj = mapper.readValue(json, claz);
Assert.assertTrue(obj.equals(e));
}
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 c1c40af..78db034 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
@@ -27,6 +27,7 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.config.InvoiceConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.invoice.generator.DefaultInvoiceGenerator;
@@ -42,7 +43,6 @@ 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.ClockMock;
-import com.ning.billing.util.io.IOUtils;
import com.ning.billing.util.tag.api.DefaultTagUserApi;
import com.ning.billing.util.tag.api.user.TagEventBuilder;
import com.ning.billing.util.tag.dao.AuditedTagDao;
@@ -57,7 +57,6 @@ public class InvoiceDaoTestBase extends InvoicingTestBase {
protected final TagEventBuilder tagEventBuilder = new TagEventBuilder();
protected IDBI dbi;
- private MysqlTestingHelper mysqlTestingHelper;
protected InvoiceDao invoiceDao;
protected InvoiceItemSqlDao invoiceItemSqlDao;
protected InvoicePaymentSqlDao invoicePaymentDao;
@@ -98,23 +97,16 @@ public class InvoiceDaoTestBase extends InvoicingTestBase {
}
}
- @BeforeClass(groups={"slow"})
+ @BeforeClass(groups = "slow")
protected void setup() throws IOException {
loadSystemPropertiesFromClasspath("/resource.properties");
- mysqlTestingHelper = new MysqlTestingHelper();
+ final MysqlTestingHelper mysqlTestingHelper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
dbi = mysqlTestingHelper.getDBI();
- final String invoiceDdl = IOUtils.toString(DefaultInvoiceDao.class.getResourceAsStream("/com/ning/billing/invoice/ddl.sql"));
- final String utilDdl = IOUtils.toString(DefaultInvoiceDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
clock = new ClockMock();
- mysqlTestingHelper.startMysql();
- mysqlTestingHelper.initDb(invoiceDdl);
- mysqlTestingHelper.initDb(utilDdl);
-
bus = new InMemoryBus();
bus.start();
@@ -128,34 +120,15 @@ public class InvoiceDaoTestBase extends InvoicingTestBase {
invoiceItemSqlDao = dbi.onDemand(InvoiceItemSqlDao.class);
invoicePaymentDao = dbi.onDemand(InvoicePaymentSqlDao.class);
-
-
context = new TestCallContext("Invoice Dao Tests");
generator = new DefaultInvoiceGenerator(clock, invoiceConfig);
-
-
assertTrue(true);
}
- @BeforeMethod(groups={"slow"})
- public void cleanupData() {
- dbi.inTransaction(new TransactionCallback<Void>() {
- @Override
- public Void inTransaction(final Handle h, final TransactionStatus status)
- throws Exception {
- h.execute("truncate table invoices");
- h.execute("truncate table invoice_items");
- h.execute("truncate table invoice_payments");
- return null;
- }
- });
- }
-
- @AfterClass(groups={"slow"})
+ @AfterClass(groups = "slow")
protected void tearDown() {
bus.stop();
- mysqlTestingHelper.stopMysql();
assertTrue(true);
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/MockInvoiceDao.java b/invoice/src/test/java/com/ning/billing/invoice/dao/MockInvoiceDao.java
index 310b24b..a81485f 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/MockInvoiceDao.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/MockInvoiceDao.java
@@ -46,7 +46,7 @@ public class MockInvoiceDao implements InvoiceDao {
}
@Override
- public void create(final Invoice invoice, final CallContext context) {
+ public void create(final Invoice invoice, final int billCycleDay, final CallContext context) {
synchronized (monitor) {
invoices.put(invoice.getId(), invoice);
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/TestDefaultInvoiceDao.java b/invoice/src/test/java/com/ning/billing/invoice/dao/TestDefaultInvoiceDao.java
index 169f2ff..e0f3ea0 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/TestDefaultInvoiceDao.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/TestDefaultInvoiceDao.java
@@ -25,6 +25,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.ning.billing.invoice.InvoiceTestSuite;
import com.ning.billing.invoice.notification.NextBillingDatePoster;
import com.ning.billing.util.api.TagUserApi;
import com.ning.billing.util.callcontext.CallContext;
@@ -37,7 +38,7 @@ import com.ning.billing.util.tag.dao.MockTagDefinitionDao;
import com.ning.billing.util.tag.dao.TagDao;
import com.ning.billing.util.tag.dao.TagDefinitionDao;
-public class TestDefaultInvoiceDao {
+public class TestDefaultInvoiceDao extends InvoiceTestSuite {
private TagUserApi tagUserApi;
private DefaultInvoiceDao dao;
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceDao.java b/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceDao.java
index 626cb2f..fb7bf9c 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceDao.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceDao.java
@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.mockito.Mockito;
import org.testng.annotations.Test;
import com.ning.billing.catalog.DefaultPrice;
@@ -54,8 +55,6 @@ import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.model.RecurringInvoiceItem;
import com.ning.billing.invoice.model.RepairAdjInvoiceItem;
import com.ning.billing.junction.api.BillingEventSet;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.api.TagApiException;
import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.tag.ControlTagType;
@@ -70,13 +69,13 @@ import static org.testng.Assert.assertTrue;
public class TestInvoiceDao extends InvoiceDaoTestBase {
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testCreationAndRetrievalByAccount() {
final UUID accountId = UUID.randomUUID();
final Invoice invoice = new DefaultInvoice(accountId, clock.getUTCNow(), clock.getUTCNow(), Currency.USD);
final DateTime invoiceDate = invoice.getInvoiceDate();
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, invoice.getTargetDate().getDayOfMonth(), context);
final List<Invoice> invoices = invoiceDao.getInvoicesByAccount(accountId);
assertNotNull(invoices);
@@ -89,7 +88,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertTrue(thisInvoice.getBalance().compareTo(BigDecimal.ZERO) == 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testInvoicePayment() {
final UUID accountId = UUID.randomUUID();
final Invoice invoice = new DefaultInvoice(accountId, clock.getUTCNow(), clock.getUTCNow(), Currency.USD);
@@ -99,10 +98,10 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime startDate = new DateTime(2010, 1, 1, 0, 0, 0, 0);
final DateTime endDate = new DateTime(2010, 4, 1, 0, 0, 0, 0);
final InvoiceItem invoiceItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, "test plan", "test phase", startDate, endDate,
- new BigDecimal("21.00"), new BigDecimal("7.00"), Currency.USD);
+ new BigDecimal("21.00"), new BigDecimal("7.00"), Currency.USD);
invoice.addInvoiceItem(invoiceItem);
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, invoice.getTargetDate().getDayOfMonth(), context);
final Invoice savedInvoice = invoiceDao.getById(invoiceId);
assertNotNull(savedInvoice);
@@ -113,7 +112,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final BigDecimal paymentAmount = new BigDecimal("11.00");
final UUID paymentId = UUID.randomUUID();
- invoiceDao.notifyOfPayment(new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT,paymentId, invoiceId, clock.getUTCNow().plusDays(12), paymentAmount, Currency.USD), context);
+ invoiceDao.notifyOfPayment(new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoiceId, clock.getUTCNow().plusDays(12), paymentAmount, Currency.USD), context);
final Invoice retrievedInvoice = invoiceDao.getById(invoiceId);
assertNotNull(retrievedInvoice);
@@ -123,13 +122,13 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(retrievedInvoice.getPaidAmount().compareTo(new BigDecimal("11.00")), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testRetrievalForNonExistentInvoiceId() {
final Invoice invoice = invoiceDao.getById(UUID.randomUUID());
assertNull(invoice);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAddPayment1() {
final UUID accountId = UUID.randomUUID();
final DateTime targetDate = new DateTime(2011, 10, 6, 0, 0, 0, 0);
@@ -139,7 +138,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime paymentDate = new DateTime(2011, 6, 24, 12, 14, 36, 0);
final BigDecimal paymentAmount = new BigDecimal("14.0");
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, invoice.getTargetDate().getDayOfMonth(), context);
invoiceDao.notifyOfPayment(new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, paymentId, invoice.getId(), paymentDate, paymentAmount, Currency.USD), context);
invoice = invoiceDao.getById(invoice.getId());
@@ -148,7 +147,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(invoice.getNumberOfPayments(), 1);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAddPayment2() {
final UUID accountId = UUID.randomUUID();
final DateTime targetDate = new DateTime(2011, 10, 6, 0, 0, 0, 0);
@@ -156,13 +155,13 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime paymentDate = new DateTime(2011, 6, 24, 12, 14, 36, 0);
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, invoice.getTargetDate().getDayOfMonth(), context);
invoiceDao.notifyOfPayment(new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice.getId(), paymentDate, invoice.getBalance(), Currency.USD), context);
invoice = invoiceDao.getById(invoice.getId());
assertEquals(invoice.getLastPaymentDate().compareTo(paymentDate), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetInvoicesBySubscriptionForRecurringItems() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
@@ -180,7 +179,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
// Create invoice 1 (subscriptions 1-4)
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final UUID invoiceId1 = invoice1.getId();
@@ -188,24 +187,24 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
DateTime endDate = startDate.plusMonths(1);
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId1, "test plan", "test A", startDate, endDate,
- rate1, rate1, Currency.USD);
+ rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item1, context);
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId2, "test plan", "test B", startDate, endDate,
- rate2, rate2, Currency.USD);
+ rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(item2, context);
final RecurringInvoiceItem item3 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId3, "test plan", "test C", startDate, endDate,
- rate3, rate3, Currency.USD);
+ rate3, rate3, Currency.USD);
invoiceItemSqlDao.create(item3, context);
final RecurringInvoiceItem item4 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId4, "test plan", "test D", startDate, endDate,
- rate4, rate4, Currency.USD);
+ rate4, rate4, Currency.USD);
invoiceItemSqlDao.create(item4, context);
// Create invoice 2 (subscriptions 1-3)
final DefaultInvoice invoice2 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate, Currency.USD);
- invoiceDao.create(invoice2, context);
+ invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
final UUID invoiceId2 = invoice2.getId();
@@ -213,15 +212,15 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
endDate = startDate.plusMonths(1);
final RecurringInvoiceItem item5 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId1, "test plan", "test phase A", startDate, endDate,
- rate1, rate1, Currency.USD);
+ rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item5, context);
final RecurringInvoiceItem item6 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId2, "test plan", "test phase B", startDate, endDate,
- rate2, rate2, Currency.USD);
+ rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(item6, context);
final RecurringInvoiceItem item7 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId3, "test plan", "test phase C", startDate, endDate,
- rate3, rate3, Currency.USD);
+ rate3, rate3, Currency.USD);
invoiceItemSqlDao.create(item7, context);
// Check that each subscription returns the correct number of invoices
@@ -238,7 +237,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(items4.size(), 1);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetInvoicesBySubscriptionForFixedItems() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
@@ -256,7 +255,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
// Create invoice 1 (subscriptions 1-4)
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final UUID invoiceId1 = invoice1.getId();
@@ -264,24 +263,24 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
DateTime endDate = startDate.plusMonths(1);
final FixedPriceInvoiceItem item1 = new FixedPriceInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId1, "test plan", "test A", startDate, endDate,
- rate1, Currency.USD);
+ rate1, Currency.USD);
invoiceItemSqlDao.create(item1, context);
final FixedPriceInvoiceItem item2 = new FixedPriceInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId2, "test plan", "test B", startDate, endDate,
- rate2, Currency.USD);
+ rate2, Currency.USD);
invoiceItemSqlDao.create(item2, context);
final FixedPriceInvoiceItem item3 = new FixedPriceInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId3, "test plan", "test C", startDate, endDate,
- rate3, Currency.USD);
+ rate3, Currency.USD);
invoiceItemSqlDao.create(item3, context);
final FixedPriceInvoiceItem item4 = new FixedPriceInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId4, "test plan", "test D", startDate, endDate,
- rate4, Currency.USD);
+ rate4, Currency.USD);
invoiceItemSqlDao.create(item4, context);
// create invoice 2 (subscriptions 1-3)
final DefaultInvoice invoice2 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate, Currency.USD);
- invoiceDao.create(invoice2, context);
+ invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
final UUID invoiceId2 = invoice2.getId();
@@ -289,15 +288,15 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
endDate = startDate.plusMonths(1);
final FixedPriceInvoiceItem item5 = new FixedPriceInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId1, "test plan", "test phase A", startDate, endDate,
- rate1, Currency.USD);
+ rate1, Currency.USD);
invoiceItemSqlDao.create(item5, context);
final FixedPriceInvoiceItem item6 = new FixedPriceInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId2, "test plan", "test phase B", startDate, endDate,
- rate2, Currency.USD);
+ rate2, Currency.USD);
invoiceItemSqlDao.create(item6, context);
final FixedPriceInvoiceItem item7 = new FixedPriceInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId3, "test plan", "test phase C", startDate, endDate,
- rate3, Currency.USD);
+ rate3, Currency.USD);
invoiceItemSqlDao.create(item7, context);
// check that each subscription returns the correct number of invoices
@@ -314,7 +313,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(items4.size(), 1);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetInvoicesBySubscriptionForRecurringAndFixedItems() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
@@ -332,7 +331,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
// Create invoice 1 (subscriptions 1-4)
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final UUID invoiceId1 = invoice1.getId();
@@ -340,40 +339,40 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
DateTime endDate = startDate.plusMonths(1);
final RecurringInvoiceItem recurringItem1 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId1, "test plan", "test A", startDate, endDate,
- rate1, rate1, Currency.USD);
+ rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(recurringItem1, context);
final RecurringInvoiceItem recurringItem2 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId2, "test plan", "test B", startDate, endDate,
- rate2, rate2, Currency.USD);
+ rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(recurringItem2, context);
final RecurringInvoiceItem recurringItem3 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId3, "test plan", "test C", startDate, endDate,
- rate3, rate3, Currency.USD);
+ rate3, rate3, Currency.USD);
invoiceItemSqlDao.create(recurringItem3, context);
final RecurringInvoiceItem recurringItem4 = new RecurringInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId4, "test plan", "test D", startDate, endDate,
- rate4, rate4, Currency.USD);
+ rate4, rate4, Currency.USD);
invoiceItemSqlDao.create(recurringItem4, context);
final FixedPriceInvoiceItem fixedItem1 = new FixedPriceInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId1, "test plan", "test A", startDate, endDate,
- rate1, Currency.USD);
+ rate1, Currency.USD);
invoiceItemSqlDao.create(fixedItem1, context);
final FixedPriceInvoiceItem fixedItem2 = new FixedPriceInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId2, "test plan", "test B", startDate, endDate,
- rate2, Currency.USD);
+ rate2, Currency.USD);
invoiceItemSqlDao.create(fixedItem2, context);
final FixedPriceInvoiceItem fixedItem3 = new FixedPriceInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId3, "test plan", "test C", startDate, endDate,
- rate3, Currency.USD);
+ rate3, Currency.USD);
invoiceItemSqlDao.create(fixedItem3, context);
final FixedPriceInvoiceItem fixedItem4 = new FixedPriceInvoiceItem(invoiceId1, accountId, bundleId, subscriptionId4, "test plan", "test D", startDate, endDate,
- rate4, Currency.USD);
+ rate4, Currency.USD);
invoiceItemSqlDao.create(fixedItem4, context);
// create invoice 2 (subscriptions 1-3)
final DefaultInvoice invoice2 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate, Currency.USD);
- invoiceDao.create(invoice2, context);
+ invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
final UUID invoiceId2 = invoice2.getId();
@@ -381,26 +380,26 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
endDate = startDate.plusMonths(1);
final RecurringInvoiceItem recurringItem5 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId1, "test plan", "test phase A", startDate, endDate,
- rate1, rate1, Currency.USD);
+ rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(recurringItem5, context);
final RecurringInvoiceItem recurringItem6 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId2, "test plan", "test phase B", startDate, endDate,
- rate2, rate2, Currency.USD);
+ rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(recurringItem6, context);
final RecurringInvoiceItem recurringItem7 = new RecurringInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId3, "test plan", "test phase C", startDate, endDate,
- rate3, rate3, Currency.USD);
+ rate3, rate3, Currency.USD);
invoiceItemSqlDao.create(recurringItem7, context);
final FixedPriceInvoiceItem fixedItem5 = new FixedPriceInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId1, "test plan", "test phase A", startDate, endDate,
- rate1, Currency.USD);
+ rate1, Currency.USD);
invoiceItemSqlDao.create(fixedItem5, context);
final FixedPriceInvoiceItem fixedItem6 = new FixedPriceInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId2, "test plan", "test phase B", startDate, endDate,
- rate2, Currency.USD);
+ rate2, Currency.USD);
invoiceItemSqlDao.create(fixedItem6, context);
final FixedPriceInvoiceItem fixedItem7 = new FixedPriceInvoiceItem(invoiceId2, accountId, bundleId, subscriptionId3, "test plan", "test phase C", startDate, endDate,
- rate3, Currency.USD);
+ rate3, Currency.USD);
invoiceItemSqlDao.create(fixedItem7, context);
// check that each subscription returns the correct number of invoices
@@ -417,17 +416,16 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(items4.size(), 2);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetInvoicesForAccountAfterDate() {
final UUID accountId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime targetDate2 = new DateTime(2011, 12, 6, 0, 0, 0, 0);
final Invoice invoice2 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate2, Currency.USD);
- invoiceDao.create(invoice2, context);
-
+ invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
List<Invoice> invoices;
invoices = invoiceDao.getInvoicesByAccount(accountId, new DateTime(2011, 1, 1, 0, 0, 0, 0));
@@ -446,13 +444,13 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(invoices.size(), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalance() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime startDate = new DateTime(2011, 3, 1, 0, 0, 0, 0);
final DateTime endDate = startDate.plusMonths(1);
@@ -461,38 +459,36 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final BigDecimal rate2 = new BigDecimal("42.0");
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate,
- endDate, rate1, rate1, Currency.USD);
+ endDate, rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item1, context);
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate,
- endDate, rate2, rate2, Currency.USD);
+ endDate, rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(item2, context);
final BigDecimal payment1 = new BigDecimal("48.0");
- final InvoicePayment payment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT,UUID.randomUUID(), invoice1.getId(), new DateTime(), payment1, Currency.USD);
+ final InvoicePayment payment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), payment1, Currency.USD);
invoicePaymentDao.create(payment, context);
final BigDecimal balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(rate1.add(rate2).subtract(payment1)), 0);
}
-
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithCredit() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime startDate = new DateTime(2011, 3, 1, 0, 0, 0, 0);
final DateTime endDate = startDate.plusMonths(1);
final BigDecimal rate1 = new BigDecimal("17.0");
-
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate,
- endDate, rate1, rate1, Currency.USD);
+ endDate, rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item1, context);
final CreditAdjInvoiceItem creditItem = new CreditAdjInvoiceItem(invoice1.getId(), accountId, new DateTime(), rate1.negate(), Currency.USD);
@@ -502,13 +498,13 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(balance.compareTo(BigDecimal.ZERO), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithNoPayments() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime startDate = new DateTime(2011, 3, 1, 0, 0, 0, 0);
final DateTime endDate = startDate.plusMonths(1);
@@ -517,23 +513,23 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final BigDecimal rate2 = new BigDecimal("42.0");
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate, endDate,
- rate1, rate1, Currency.USD);
+ rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item1, context);
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate, endDate,
- rate2, rate2, Currency.USD);
+ rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(item2, context);
final BigDecimal balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(rate1.add(rate2)), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithNoInvoiceItems() {
final UUID accountId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final BigDecimal payment1 = new BigDecimal("48.0");
final InvoicePayment payment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), payment1, Currency.USD);
@@ -543,15 +539,15 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(balance.compareTo(BigDecimal.ZERO.subtract(payment1)), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithRefundNoAdj() throws InvoiceApiException {
testAccountBalanceWithRefundInternal(false);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithRefundAndAdj() throws InvoiceApiException {
testAccountBalanceWithRefundInternal(true);
- }
+ }
private void testAccountBalanceWithRefundInternal(boolean withAdjustment) throws InvoiceApiException {
@@ -559,7 +555,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final UUID bundleId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime startDate = new DateTime(2011, 3, 1, 0, 0, 0, 0);
final DateTime endDate = startDate.plusMonths(1);
@@ -568,10 +564,9 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final BigDecimal refund1 = new BigDecimal("-7.00");
final BigDecimal rate2 = new BigDecimal("10.0");
-
// Recurring item
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate,
- endDate, rate1, rate1, Currency.USD);
+ endDate, rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item2, context);
BigDecimal balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(new BigDecimal("20.00")), 0);
@@ -593,42 +588,40 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
}
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithSmallRefundAndCBANoAdj() throws InvoiceApiException {
- BigDecimal refundAmount = new BigDecimal("-7.00");
- BigDecimal expectedBalance = new BigDecimal("-3.00");
+ BigDecimal refundAmount = new BigDecimal("-7.00");
+ BigDecimal expectedBalance = new BigDecimal("-3.00");
testAccountBalanceWithRefundAndCBAInternal(false, refundAmount, expectedBalance);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithSmallRefundAndCBAWithAdj() throws InvoiceApiException {
- BigDecimal refundAmount = new BigDecimal("-7.00");
- BigDecimal expectedBalance = new BigDecimal("-3.00");
+ BigDecimal refundAmount = new BigDecimal("-7.00");
+ BigDecimal expectedBalance = new BigDecimal("-3.00");
testAccountBalanceWithRefundAndCBAInternal(true, refundAmount, expectedBalance);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithLargeRefundAndCBANoAdj() throws InvoiceApiException {
- BigDecimal refundAmount = new BigDecimal("-20.00");
- BigDecimal expectedBalance = new BigDecimal("10.00");
+ BigDecimal refundAmount = new BigDecimal("-20.00");
+ BigDecimal expectedBalance = new BigDecimal("10.00");
testAccountBalanceWithRefundAndCBAInternal(false, refundAmount, expectedBalance);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithLargeRefundAndCBAWithAdj() throws InvoiceApiException {
- BigDecimal refundAmount = new BigDecimal("-20.00");
- BigDecimal expectedBalance = BigDecimal.ZERO;
+ BigDecimal refundAmount = new BigDecimal("-20.00");
+ BigDecimal expectedBalance = BigDecimal.ZERO;
testAccountBalanceWithRefundAndCBAInternal(true, refundAmount, expectedBalance);
}
-
private void testAccountBalanceWithRefundAndCBAInternal(boolean withAdjustment, final BigDecimal refundAmount, final BigDecimal expectedFinalBalance) throws InvoiceApiException {
-
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime startDate = new DateTime(2011, 3, 1, 0, 0, 0, 0);
final DateTime endDate = startDate.plusMonths(1);
@@ -639,7 +632,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
// Fixed Item
final FixedPriceInvoiceItem item1 = new FixedPriceInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate,
- endDate, amount1, Currency.USD);
+ endDate, amount1, Currency.USD);
invoiceItemSqlDao.create(item1, context);
BigDecimal balance = invoiceDao.getAccountBalance(accountId);
@@ -647,7 +640,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
// Recurring item
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate,
- endDate, rate1, rate1, Currency.USD);
+ endDate, rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item2, context);
balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(new BigDecimal("25.00")), 0);
@@ -663,7 +656,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
// Repair previous item with rate 2
final RepairAdjInvoiceItem item2Repair = new RepairAdjInvoiceItem(invoice1.getId(), accountId, startDate, endDate, rate1.negate(), Currency.USD, item2.getId());
final RecurringInvoiceItem item2Replace = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate,
- endDate, rate2, rate2, Currency.USD);
+ endDate, rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(item2Repair, context);
invoiceItemSqlDao.create(item2Replace, context);
balance = invoiceDao.getAccountBalance(accountId);
@@ -674,7 +667,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
invoiceItemSqlDao.create(cbaItem, context);
balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(new BigDecimal("-10.00")), 0);
- BigDecimal cba = invoiceDao.getAccountCBA(accountId);
+ BigDecimal cba = invoiceDao.getAccountCBA(accountId);
assertEquals(cba.compareTo(new BigDecimal("10.00")), 0);
// PARTIAL REFUND on the payment
@@ -682,20 +675,20 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(expectedFinalBalance), 0);
- cba = invoiceDao.getAccountCBA(accountId);
+ cba = invoiceDao.getAccountCBA(accountId);
final BigDecimal expectedFinalCBA = (expectedFinalBalance.compareTo(BigDecimal.ZERO) < 0) ? expectedFinalBalance.negate() : BigDecimal.ZERO;
assertEquals(cba.compareTo(expectedFinalCBA), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAccountBalanceWithAllSortsOfThings() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime startDate = new DateTime(2011, 3, 1, 0, 0, 0, 0);
final DateTime endDate = startDate.plusMonths(1);
@@ -704,10 +697,9 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final BigDecimal rate1 = new BigDecimal("20.0");
final BigDecimal rate2 = new BigDecimal("10.0");
-
// Fixed Item
final FixedPriceInvoiceItem item1 = new FixedPriceInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate,
- endDate, amount1, Currency.USD);
+ endDate, amount1, Currency.USD);
invoiceItemSqlDao.create(item1, context);
BigDecimal balance = invoiceDao.getAccountBalance(accountId);
@@ -715,7 +707,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
// Recurring item
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate,
- endDate, rate1, rate1, Currency.USD);
+ endDate, rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item2, context);
balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(new BigDecimal("25.00")), 0);
@@ -730,7 +722,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
// Repair previous item with rate 2
final RepairAdjInvoiceItem item2Repair = new RepairAdjInvoiceItem(invoice1.getId(), accountId, startDate, endDate, rate1.negate(), Currency.USD, item2.getId());
final RecurringInvoiceItem item2Replace = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate,
- endDate, rate2, rate2, Currency.USD);
+ endDate, rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(item2Repair, context);
invoiceItemSqlDao.create(item2Replace, context);
balance = invoiceDao.getAccountBalance(accountId);
@@ -741,54 +733,50 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
invoiceItemSqlDao.create(cbaItem, context);
balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(new BigDecimal("-10.00")), 0);
- BigDecimal cba = invoiceDao.getAccountCBA(accountId);
+ BigDecimal cba = invoiceDao.getAccountCBA(accountId);
assertEquals(cba.compareTo(new BigDecimal("10.00")), 0);
// partial REFUND on the payment (along with CBA generated by the system)
- final InvoicePayment refund = new DefaultInvoicePayment(UUID.randomUUID(), InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), rate2.negate(), Currency.USD, null, payment.getId());
+ final InvoicePayment refund = new DefaultInvoicePayment(UUID.randomUUID(), InvoicePaymentType.ATTEMPT, UUID.randomUUID(), invoice1.getId(), new DateTime(), rate2.negate(), Currency.USD, null, payment.getId());
invoicePaymentDao.create(refund, context);
final CreditBalanceAdjInvoiceItem cbaItem2 = new CreditBalanceAdjInvoiceItem(invoice1.getId(), accountId, new DateTime(), rate2.negate(), Currency.USD);
invoiceItemSqlDao.create(cbaItem2, context);
balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(BigDecimal.ZERO), 0);
- cba = invoiceDao.getAccountCBA(accountId);
+ cba = invoiceDao.getAccountCBA(accountId);
assertEquals(cba.compareTo(BigDecimal.ZERO), 0);
-
-
// NEXT RECURRING on invoice 2
final Invoice invoice2 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1.plusMonths(1), Currency.USD);
- invoiceDao.create(invoice2, context);
-
+ invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
final RecurringInvoiceItem nextItem = new RecurringInvoiceItem(invoice2.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test bla", startDate.plusMonths(1),
- endDate.plusMonths(1), rate2, rate2, Currency.USD);
+ endDate.plusMonths(1), rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(nextItem, context);
balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(new BigDecimal("10.00")), 0);
- cba = invoiceDao.getAccountCBA(accountId);
+ cba = invoiceDao.getAccountCBA(accountId);
assertEquals(cba.compareTo(new BigDecimal("0.00")), 0);
-
// FINALLY ISSUE A CREDIT ADJ
- final CreditAdjInvoiceItem creditItem = new CreditAdjInvoiceItem(invoice2.getId(), accountId, new DateTime(), rate2.negate(), Currency.USD);
+ final CreditAdjInvoiceItem creditItem = new CreditAdjInvoiceItem(invoice2.getId(), accountId, new DateTime(), rate2.negate(), Currency.USD);
invoiceItemSqlDao.create(creditItem, context);
balance = invoiceDao.getAccountBalance(accountId);
assertEquals(balance.compareTo(new BigDecimal("0.00")), 0);
- cba = invoiceDao.getAccountCBA(accountId);
+ cba = invoiceDao.getAccountCBA(accountId);
assertEquals(cba.compareTo(new BigDecimal("0.00")), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetUnpaidInvoicesByAccountId() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final DateTime targetDate1 = new DateTime(2011, 10, 6, 0, 0, 0, 0);
final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate1, Currency.USD);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime startDate = new DateTime(2011, 3, 1, 0, 0, 0, 0);
final DateTime endDate = startDate.plusMonths(1);
@@ -796,13 +784,12 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final BigDecimal rate1 = new BigDecimal("17.0");
final BigDecimal rate2 = new BigDecimal("42.0");
-
final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate, endDate,
- rate1, rate1, Currency.USD);
+ rate1, rate1, Currency.USD);
invoiceItemSqlDao.create(item1, context);
final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate, endDate,
- rate2, rate2, Currency.USD);
+ rate2, rate2, Currency.USD);
invoiceItemSqlDao.create(item2, context);
DateTime upToDate;
@@ -818,7 +805,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime targetDate2 = new DateTime(2011, 7, 1, 0, 0, 0, 0);
final Invoice invoice2 = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate2, Currency.USD);
- invoiceDao.create(invoice2, context);
+ invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
final DateTime startDate2 = new DateTime(2011, 6, 1, 0, 0, 0, 0);
final DateTime endDate2 = startDate2.plusMonths(3);
@@ -826,7 +813,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final BigDecimal rate3 = new BigDecimal("21.0");
final RecurringInvoiceItem item3 = new RecurringInvoiceItem(invoice2.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase C", startDate2, endDate2,
- rate3, rate3, Currency.USD);
+ rate3, rate3, Currency.USD);
invoiceItemSqlDao.create(item3, context);
upToDate = new DateTime(2011, 1, 1, 0, 0, 0, 0);
@@ -843,7 +830,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
* this test verifies that immediate changes give the correct results
*
*/
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testInvoiceGenerationForImmediateChanges() throws InvoiceApiException, CatalogApiException {
final UUID accountId = UUID.randomUUID();
final List<Invoice> invoiceList = new ArrayList<Invoice>();
@@ -860,8 +847,8 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime effectiveDate1 = new DateTime(2011, 2, 1, 0, 0, 0, 0);
final BillingEvent event1 = createMockBillingEvent(null, subscription, effectiveDate1, plan1, phase1, null,
- recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
- "testEvent1", 1L, SubscriptionTransitionType.CREATE);
+ recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
+ "testEvent1", 1L, SubscriptionTransitionType.CREATE);
final BillingEventSet events = new MockBillingEventSet();
events.add(event1);
@@ -878,8 +865,8 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime effectiveDate2 = new DateTime(2011, 2, 15, 0, 0, 0, 0);
final BillingEvent event2 = createMockBillingEvent(null, subscription, effectiveDate2, plan2, phase2, null,
- recurringPrice2.getPrice(currency), currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
- "testEvent2", 2L, SubscriptionTransitionType.CREATE);
+ recurringPrice2.getPrice(currency), currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
+ "testEvent2", 2L, SubscriptionTransitionType.CREATE);
events.add(event2);
// second invoice should be for one half (14/28 days) the difference between the rate plans
@@ -888,8 +875,8 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(invoice2.getBalance(), FIVE);
invoiceList.add(invoice2);
- invoiceDao.create(invoice1, context);
- invoiceDao.create(invoice2, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
+ invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
final Invoice savedInvoice1 = invoiceDao.getById(invoice1.getId());
assertEquals(savedInvoice1.getBalance(), ZERO);
@@ -898,7 +885,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(savedInvoice2.getBalance(), FIFTEEN);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testInvoiceForFreeTrial() throws InvoiceApiException, CatalogApiException {
final Currency currency = Currency.USD;
final DefaultPrice price = new DefaultPrice(BigDecimal.ZERO, Currency.USD);
@@ -910,8 +897,8 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime effectiveDate = buildDateTime(2011, 1, 1);
final BillingEvent event = createMockBillingEvent(null, subscription, effectiveDate, plan, phase, null,
- recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 15, BillingModeType.IN_ADVANCE,
- "testEvent", 1L, SubscriptionTransitionType.CREATE);
+ recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 15, BillingModeType.IN_ADVANCE,
+ "testEvent", 1L, SubscriptionTransitionType.CREATE);
final BillingEventSet events = new MockBillingEventSet();
events.add(event);
@@ -924,13 +911,13 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
}
private Subscription getZombieSubscription() {
- final Subscription subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) subscription).addResult("getId", UUID.randomUUID());
- ((ZombieControl) subscription).addResult("getBundleId", UUID.randomUUID());
+ final Subscription subscription = Mockito.mock(Subscription.class);
+ Mockito.when(subscription.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(subscription.getBundleId()).thenReturn(UUID.randomUUID());
return subscription;
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testInvoiceForFreeTrialWithRecurringDiscount() throws InvoiceApiException, CatalogApiException {
final Currency currency = Currency.USD;
@@ -949,8 +936,8 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime effectiveDate1 = buildDateTime(2011, 1, 1);
final BillingEvent event1 = createMockBillingEvent(null, subscription, effectiveDate1, plan, phase1, fixedPrice.getPrice(currency),
- null, currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
- "testEvent1", 1L, SubscriptionTransitionType.CREATE);
+ null, currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
+ "testEvent1", 1L, SubscriptionTransitionType.CREATE);
final BillingEventSet events = new MockBillingEventSet();
events.add(event1);
@@ -963,12 +950,12 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final List<Invoice> invoiceList = new ArrayList<Invoice>();
invoiceList.add(invoice1);
- //invoiceDao.create(invoice1, context);
+ //invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
final DateTime effectiveDate2 = effectiveDate1.plusDays(30);
final BillingEvent event2 = createMockBillingEvent(null, subscription, effectiveDate2, plan, phase2, null,
- recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
- "testEvent2", 2L, SubscriptionTransitionType.PHASE);
+ recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
+ "testEvent2", 2L, SubscriptionTransitionType.PHASE);
events.add(event2);
final Invoice invoice2 = generator.generateInvoice(accountId, events, invoiceList, effectiveDate2, Currency.USD);
@@ -978,7 +965,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
invoiceList.add(invoice2);
- //invoiceDao.create(invoice2, context);
+ //invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
final DateTime effectiveDate3 = effectiveDate2.plusMonths(1);
final Invoice invoice3 = generator.generateInvoice(accountId, events, invoiceList, effectiveDate3, Currency.USD);
@@ -986,17 +973,17 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(invoice3.getNumberOfItems(), 1);
assertEquals(invoice3.getBalance().compareTo(cheapAmount), 0);
- //invoiceDao.create(invoice3, context);
+ //invoiceDao.create(invoice3, invoice3.getTargetDate().getDayOfMonth(), context);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testInvoiceForEmptyEventSet() throws InvoiceApiException {
final BillingEventSet events = new MockBillingEventSet();
final Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, new DateTime(), Currency.USD);
assertNull(invoice);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testMixedModeInvoicePersistence() throws InvoiceApiException, CatalogApiException {
final Currency currency = Currency.USD;
final DefaultPrice zeroPrice = new DefaultPrice(BigDecimal.ZERO, Currency.USD);
@@ -1014,16 +1001,16 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final DateTime effectiveDate1 = buildDateTime(2011, 1, 1);
final BillingEvent event1 = createMockBillingEvent(null, subscription, effectiveDate1, plan, phase1,
- fixedPrice.getPrice(currency), null, currency,
- BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
- "testEvent1", 1L, SubscriptionTransitionType.CREATE);
+ fixedPrice.getPrice(currency), null, currency,
+ BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
+ "testEvent1", 1L, SubscriptionTransitionType.CREATE);
final BillingEventSet events = new MockBillingEventSet();
events.add(event1);
final DateTime effectiveDate2 = effectiveDate1.plusDays(30);
final BillingEvent event2 = createMockBillingEvent(null, subscription, effectiveDate2, plan, phase2, null,
- recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
- "testEvent2", 2L, SubscriptionTransitionType.CHANGE);
+ recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
+ "testEvent2", 2L, SubscriptionTransitionType.CHANGE);
events.add(event2);
final Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, effectiveDate2, Currency.USD);
@@ -1031,7 +1018,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(invoice.getNumberOfItems(), 2);
assertEquals(invoice.getBalance().compareTo(cheapAmount), 0);
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, invoice.getTargetDate().getDayOfMonth(), context);
final Invoice savedInvoice = invoiceDao.getById(invoice.getId());
assertNotNull(savedInvoice);
@@ -1039,7 +1026,7 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertEquals(savedInvoice.getBalance().compareTo(cheapAmount), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testInvoiceNumber() throws InvoiceApiException {
final Currency currency = Currency.USD;
final DateTime targetDate1 = DateTime.now().plusMonths(1);
@@ -1047,64 +1034,64 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
final Subscription subscription = getZombieSubscription();
- final Plan plan = BrainDeadProxyFactory.createBrainDeadProxyFor(Plan.class);
- ((ZombieControl) plan).addResult("getName", "plan");
+ final Plan plan = Mockito.mock(Plan.class);
+ Mockito.when(plan.getName()).thenReturn("plan");
- final PlanPhase phase1 = BrainDeadProxyFactory.createBrainDeadProxyFor(PlanPhase.class);
- ((ZombieControl) phase1).addResult("getName", "plan-phase1");
+ final PlanPhase phase1 = Mockito.mock(PlanPhase.class);
+ Mockito.when(phase1.getName()).thenReturn("plan-phase1");
- final PlanPhase phase2 = BrainDeadProxyFactory.createBrainDeadProxyFor(PlanPhase.class);
- ((ZombieControl) phase2).addResult("getName", "plan-phase2");
+ final PlanPhase phase2 = Mockito.mock(PlanPhase.class);
+ Mockito.when(phase2.getName()).thenReturn("plan-phase2");
final BillingEventSet events = new MockBillingEventSet();
final List<Invoice> invoices = new ArrayList<Invoice>();
final BillingEvent event1 = createMockBillingEvent(null, subscription, targetDate1, plan, phase1, null,
- TEN, currency,
- BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
- "testEvent1", 1L, SubscriptionTransitionType.CHANGE);
+ TEN, currency,
+ BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
+ "testEvent1", 1L, SubscriptionTransitionType.CHANGE);
events.add(event1);
Invoice invoice1 = generator.generateInvoice(UUID.randomUUID(), events, invoices, targetDate1, Currency.USD);
invoices.add(invoice1);
- invoiceDao.create(invoice1, context);
+ invoiceDao.create(invoice1, invoice1.getTargetDate().getDayOfMonth(), context);
invoice1 = invoiceDao.getById(invoice1.getId());
assertNotNull(invoice1.getInvoiceNumber());
final BillingEvent event2 = createMockBillingEvent(null, subscription, targetDate1, plan, phase2, null,
- TWENTY, currency,
- BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
- "testEvent2", 2L, SubscriptionTransitionType.CHANGE);
+ TWENTY, currency,
+ BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
+ "testEvent2", 2L, SubscriptionTransitionType.CHANGE);
events.add(event2);
Invoice invoice2 = generator.generateInvoice(UUID.randomUUID(), events, invoices, targetDate2, Currency.USD);
- invoiceDao.create(invoice2, context);
+ invoiceDao.create(invoice2, invoice2.getTargetDate().getDayOfMonth(), context);
invoice2 = invoiceDao.getById(invoice2.getId());
assertNotNull(invoice2.getInvoiceNumber());
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testAddingWrittenOffTag() throws InvoiceApiException, TagApiException {
final Subscription subscription = getZombieSubscription();
- final Plan plan = BrainDeadProxyFactory.createBrainDeadProxyFor(Plan.class);
- ((ZombieControl) plan).addResult("getName", "plan");
+ final Plan plan = Mockito.mock(Plan.class);
+ Mockito.when(plan.getName()).thenReturn("plan");
- final PlanPhase phase1 = BrainDeadProxyFactory.createBrainDeadProxyFor(PlanPhase.class);
- ((ZombieControl) phase1).addResult("getName", "plan-phase1");
+ final PlanPhase phase1 = Mockito.mock(PlanPhase.class);
+ Mockito.when(phase1.getName()).thenReturn("plan-phase1");
final DateTime targetDate1 = clock.getUTCNow();
final Currency currency = Currency.USD;
// create pseudo-random invoice
final BillingEvent event1 = createMockBillingEvent(null, subscription, targetDate1, plan, phase1, null,
- TEN, currency,
- BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
- "testEvent1", 1L, SubscriptionTransitionType.CHANGE);
+ TEN, currency,
+ BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
+ "testEvent1", 1L, SubscriptionTransitionType.CHANGE);
final BillingEventSet events = new MockBillingEventSet();
events.add(event1);
final Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, targetDate1, Currency.USD);
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, invoice.getTargetDate().getDayOfMonth(), context);
invoiceDao.setWrittenOff(invoice.getId(), context);
final TagDao tagDao = new AuditedTagDao(dbi, tagEventBuilder, bus);
@@ -1113,29 +1100,29 @@ public class TestInvoiceDao extends InvoiceDaoTestBase {
assertTrue(tags.containsKey(ControlTagType.WRITTEN_OFF.toString()));
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testRemoveWrittenOffTag() throws InvoiceApiException, TagApiException {
final Subscription subscription = getZombieSubscription();
- final Plan plan = BrainDeadProxyFactory.createBrainDeadProxyFor(Plan.class);
- ((ZombieControl) plan).addResult("getName", "plan");
+ final Plan plan = Mockito.mock(Plan.class);
+ Mockito.when(plan.getName()).thenReturn("plan");
- final PlanPhase phase1 = BrainDeadProxyFactory.createBrainDeadProxyFor(PlanPhase.class);
- ((ZombieControl) phase1).addResult("getName", "plan-phase1");
+ final PlanPhase phase1 = Mockito.mock(PlanPhase.class);
+ Mockito.when(phase1.getName()).thenReturn("plan-phase1");
final DateTime targetDate1 = clock.getUTCNow();
final Currency currency = Currency.USD;
// create pseudo-random invoice
final BillingEvent event1 = createMockBillingEvent(null, subscription, targetDate1, plan, phase1, null,
- TEN, currency,
- BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
- "testEvent1", 1L, SubscriptionTransitionType.CHANGE);
+ TEN, currency,
+ BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
+ "testEvent1", 1L, SubscriptionTransitionType.CHANGE);
final BillingEventSet events = new MockBillingEventSet();
events.add(event1);
final Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, targetDate1, Currency.USD);
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, invoice.getTargetDate().getDayOfMonth(), context);
invoiceDao.setWrittenOff(invoice.getId(), context);
final TagDao tagDao = new AuditedTagDao(dbi, tagEventBuilder, bus);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceItemDao.java b/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceItemDao.java
index 931d0ae..11825c2 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceItemDao.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceItemDao.java
@@ -35,8 +35,7 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
public class TestInvoiceItemDao extends InvoiceDaoTestBase {
-
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testInvoiceItemCreation() {
final UUID accountId = UUID.randomUUID();
final UUID invoiceId = UUID.randomUUID();
@@ -64,7 +63,7 @@ public class TestInvoiceItemDao extends InvoiceDaoTestBase {
// assertEquals(thisItem.getCreatedDate().compareTo(item.getCreatedDate()), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetInvoiceItemsBySubscriptionId() {
final UUID accountId = UUID.randomUUID();
final UUID subscriptionId = UUID.randomUUID();
@@ -85,7 +84,7 @@ public class TestInvoiceItemDao extends InvoiceDaoTestBase {
assertEquals(items.size(), 3);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetInvoiceItemsByInvoiceId() {
final UUID accountId = UUID.randomUUID();
final UUID invoiceId = UUID.randomUUID();
@@ -107,14 +106,14 @@ public class TestInvoiceItemDao extends InvoiceDaoTestBase {
assertEquals(items.size(), 5);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetInvoiceItemsByAccountId() {
final UUID accountId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final DateTime targetDate = new DateTime(2011, 5, 23, 0, 0, 0, 0);
final DefaultInvoice invoice = new DefaultInvoice(accountId, clock.getUTCNow(), targetDate, Currency.USD);
- invoiceDao.create(invoice, context);
+ invoiceDao.create(invoice, targetDate.getDayOfMonth(), context);
final UUID invoiceId = invoice.getId();
final DateTime startDate = new DateTime(2011, 3, 1, 0, 0, 0, 0);
@@ -131,7 +130,7 @@ public class TestInvoiceItemDao extends InvoiceDaoTestBase {
assertEquals(items.size(), 1);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testCreditBalanceInvoiceSqlDao() {
final UUID invoiceId = UUID.randomUUID();
final UUID accountId = UUID.randomUUID();
@@ -144,7 +143,7 @@ public class TestInvoiceItemDao extends InvoiceDaoTestBase {
assertEquals(savedItem, creditInvoiceItem);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testFixedPriceInvoiceSqlDao() {
final UUID invoiceId = UUID.randomUUID();
final UUID accountId = UUID.randomUUID();
diff --git a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
index b46edc7..974c48c 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
@@ -26,6 +26,8 @@ import java.util.Map;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
@@ -50,8 +52,6 @@ import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceApiException;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoicePayment.InvoicePaymentType;
-import com.ning.billing.invoice.generator.DefaultInvoiceGenerator;
-import com.ning.billing.invoice.generator.InvoiceGenerator;
import com.ning.billing.invoice.model.CreditBalanceAdjInvoiceItem;
import com.ning.billing.invoice.model.DefaultInvoice;
import com.ning.billing.invoice.model.DefaultInvoicePayment;
@@ -59,8 +59,6 @@ import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.model.RecurringInvoiceItem;
import com.ning.billing.invoice.tests.InvoicingTestBase;
import com.ning.billing.junction.api.BillingEventSet;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
import com.ning.billing.util.clock.DefaultClock;
@@ -71,7 +69,6 @@ import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
-
private static final Logger log = LoggerFactory.getLogger(TestDefaultInvoiceGenerator.class);
private final Clock clock = new ClockMock();
@@ -79,8 +76,6 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
private final InvoiceGenerator generator;
public TestDefaultInvoiceGenerator() {
- super();
-
final Clock clock = new DefaultClock();
final InvoiceConfig invoiceConfig = new InvoiceConfig() {
@Override
@@ -106,7 +101,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
this.generator = new DefaultInvoiceGenerator(clock, invoiceConfig);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testWithNullEventSetAndNullInvoiceSet() throws InvoiceApiException {
final UUID accountId = UUID.randomUUID();
final Invoice invoice = generator.generateInvoice(accountId, null, null, new DateTime(), Currency.USD);
@@ -114,7 +109,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertNull(invoice);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testWithEmptyEventSet() throws InvoiceApiException {
final BillingEventSet events = new MockBillingEventSet();
@@ -124,7 +119,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertNull(invoice);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testWithSingleMonthlyEvent() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
@@ -153,14 +148,14 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
}
private Subscription createZombieSubscription(final UUID subscriptionId) {
- final Subscription sub = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) sub).addResult("getId", subscriptionId);
- ((ZombieControl) sub).addResult("getBundleId", UUID.randomUUID());
+ final Subscription sub = Mockito.mock(Subscription.class);
+ Mockito.when(sub.getId()).thenReturn(subscriptionId);
+ Mockito.when(sub.getBundleId()).thenReturn(UUID.randomUUID());
return sub;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testWithSingleMonthlyEventWithLeadingProRation() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
@@ -186,7 +181,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice.getBalance(), expectedAmount);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTwoMonthlySubscriptionsWithAlignedBillingDates() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
@@ -215,7 +210,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice.getBalance(), rate1.add(rate2).setScale(NUMBER_OF_DECIMALS));
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testOnePlan_TwoMonthlyPhases_ChangeImmediate() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
@@ -252,7 +247,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice.getBalance(), expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testOnePlan_ThreeMonthlyPhases_ChangeEOT() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
@@ -283,7 +278,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice.getBalance(), rate1.add(rate2).add(TWO.multiply(rate3)).setScale(NUMBER_OF_DECIMALS));
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSingleEventWithExistingInvoice() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
@@ -310,7 +305,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
}
// TODO: modify this test to keep a running total of expected invoice amount over time
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testMultiplePlansWithUtterChaos() throws InvoiceApiException, CatalogApiException {
// plan 1: change of phase from trial to discount followed by immediate cancellation; (covers phase change, cancel, pro-ration)
// plan 2: single plan that moves from trial to discount to evergreen; BCD = 10 (covers phase change)
@@ -471,7 +466,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
testInvoiceGeneration(accountId, events, invoices, buildDateTime(2011, 10, 10), 1, expectedAmount);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testZeroDollarEvents() throws InvoiceApiException, CatalogApiException {
final Plan plan = new MockPlan();
final PlanPhase planPhase = createMockMonthlyPlanPhase(ZERO);
@@ -484,7 +479,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice.getNumberOfItems(), 1);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testEndDateIsCorrect() throws InvoiceApiException, CatalogApiException {
final Plan plan = new MockPlan();
final PlanPhase planPhase = createMockMonthlyPlanPhase(ZERO);
@@ -497,11 +492,11 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
final Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, targetDate, Currency.USD);
final RecurringInvoiceItem item = (RecurringInvoiceItem) invoice.getInvoiceItems().get(0);
- // end date of the invoice item should be equal to exactly one month later
- assertEquals(item.getEndDate().compareTo(startDate.plusMonths(1)), 0);
+ // end date of the invoice item should be equal to exactly one month later (rounded)
+ assertDatesEqualRounded(item.getEndDate(), startDate.plusMonths(1));
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testFixedPriceLifeCycle() throws InvoiceApiException {
final UUID accountId = UUID.randomUUID();
final Subscription subscription = createZombieSubscription();
@@ -541,10 +536,10 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertNotNull(invoice2);
assertEquals(invoice2.getNumberOfItems(), 1);
final FixedPriceInvoiceItem item = (FixedPriceInvoiceItem) invoice2.getInvoiceItems().get(0);
- assertEquals(item.getStartDate().compareTo(changeDate), 0);
+ assertDatesEqualRounded(item.getStartDate(), changeDate);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testMixedModeLifeCycle() throws InvoiceApiException, CatalogApiException {
// create a subscription with a fixed price and recurring price
final Plan plan1 = new MockPlan();
@@ -579,7 +574,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice2.getBalance(), FIVE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testFixedModePlanChange() throws InvoiceApiException, CatalogApiException {
// create a subscription with a fixed price and recurring price
final Plan plan1 = new MockPlan();
@@ -617,7 +612,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice2.getBalance(), fixedCost2);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testInvoiceGenerationFailureScenario() throws InvoiceApiException, CatalogApiException {
final BillingEventSet events = new MockBillingEventSet();
final UUID subscriptionId = UUID.randomUUID();
@@ -632,7 +627,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
final PlanPhase phase3 = createMockMonthlyPlanPhase(new BigDecimal("19.95"), null, PhaseType.EVERGREEN);
// set up billing events
- final DateTime creationDate = new DateTime(2012, 3, 6, 21, 36, 18, 896);
+ final DateTime creationDate = new DateTime(2012, 3, 6, 21, 36, 18, 896, DateTimeZone.UTC);
events.add(createBillingEvent(subscriptionId, creationDate, plan1, phase1, BILL_CYCLE_DAY));
// trialPhaseEndDate = 2012/4/5
@@ -654,7 +649,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
final Invoice invoice2 = generator.generateInvoice(accountId, events, invoiceList, trialPhaseEndDate, Currency.USD);
assertNotNull(invoice2);
assertEquals(invoice2.getNumberOfItems(), 1);
- assertEquals(invoice2.getInvoiceItems().get(0).getStartDate().compareTo(trialPhaseEndDate), 0);
+ assertDatesEqualRounded(invoice2.getInvoiceItems().get(0).getStartDate(), trialPhaseEndDate);
assertEquals(invoice2.getBalance().compareTo(new BigDecimal("3.21")), 0);
invoiceList.add(invoice2);
@@ -662,7 +657,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
final Invoice invoice3 = generator.generateInvoice(accountId, events, invoiceList, targetDate, Currency.USD);
assertNotNull(invoice3);
assertEquals(invoice3.getNumberOfItems(), 1);
- assertEquals(invoice3.getInvoiceItems().get(0).getStartDate().compareTo(targetDate), 0);
+ assertDatesEqualRounded(invoice3.getInvoiceItems().get(0).getStartDate(), targetDate);
assertEquals(invoice3.getBalance().compareTo(DISCOUNT_PRICE), 0);
invoiceList.add(invoice3);
@@ -672,7 +667,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice4.getNumberOfItems(), 7);
}
- @Test(groups = {"fast"}, expectedExceptions = {InvoiceApiException.class})
+ @Test(groups = "fast", expectedExceptions = {InvoiceApiException.class})
public void testTargetDateRestrictionFailure() throws InvoiceApiException, CatalogApiException {
final DateTime targetDate = DateTime.now().plusMonths(60);
final BillingEventSet events = new MockBillingEventSet();
@@ -735,7 +730,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(invoice.getBalance(), expectedAmount);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testAddOnInvoiceGeneration() throws CatalogApiException, InvoiceApiException {
final DateTime april25 = new DateTime(2012, 4, 25, 0, 0, 0, 0);
@@ -881,7 +876,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
}
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testAutoInvoiceOffAccount() throws Exception {
final MockBillingEventSet events = new MockBillingEventSet();
events.setAccountInvoiceOff(true);
@@ -949,8 +944,7 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertTrue(invoice3.getBalance().compareTo(FIFTEEN.multiply(TWO).add(TWELVE)) == 0);
}
-
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testAccountCredit() throws CatalogApiException, InvoiceApiException {
final BillingEventSet billingEventSet = new MockBillingEventSet();
@@ -994,17 +988,22 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
assertEquals(finalInvoice.getNumberOfItems(), 2);
}
- private void printDetailInvoice(final Invoice invoice) {
+ private void printDetailInvoice(final Invoice invoice) {
log.info("-------------------- START DETAIL ----------------------");
log.info("Invoice " + invoice.getId() + ": BALANCE = " + invoice.getBalance()
- + ", CBA = " + invoice.getCBAAmount()
- + ", CHARGE_AMOUNT = " + invoice.getChargedAmount()
- + ", ADJ_AMOUNT = " + invoice.getCreditAdjAmount());
+ + ", CBA = " + invoice.getCBAAmount()
+ + ", CHARGE_AMOUNT = " + invoice.getChargedAmount()
+ + ", ADJ_AMOUNT = " + invoice.getCreditAdjAmount());
- for (InvoiceItem cur : invoice.getInvoiceItems()) {
+ for (final InvoiceItem cur : invoice.getInvoiceItems()) {
log.info(cur.toString());
}
log.info("-------------------- END DETAIL ----------------------");
}
+ private void assertDatesEqualRounded(final DateTime date1, final DateTime date2) {
+ assertEquals(date1.toDateTime(DateTimeZone.UTC).getDayOfMonth(), date2.toDateTime(DateTimeZone.UTC).getDayOfMonth());
+ assertEquals(date1.toDateTime(DateTimeZone.UTC).getMonthOfYear(), date2.toDateTime(DateTimeZone.UTC).getMonthOfYear());
+ assertEquals(date1.toDateTime(DateTimeZone.UTC).getYear(), date2.toDateTime(DateTimeZone.UTC).getYear());
+ }
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java
index 53066ea..1afb905 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java
@@ -13,11 +13,8 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-package com.ning.billing.invoice.generator;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
+package com.ning.billing.invoice.generator;
import java.math.BigDecimal;
import java.util.LinkedList;
@@ -37,11 +34,15 @@ import com.ning.billing.invoice.model.CreditBalanceAdjInvoiceItem;
import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.model.RecurringInvoiceItem;
import com.ning.billing.invoice.model.RepairAdjInvoiceItem;
+import com.ning.billing.invoice.tests.InvoicingTestBase;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
-public class TestDefaultInvoiceGeneratorUnit {
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+public class TestDefaultInvoiceGeneratorUnit extends InvoicingTestBase {
private DefaultInvoiceGenerator gen;
private Clock clock;
@@ -59,7 +60,7 @@ public class TestDefaultInvoiceGeneratorUnit {
}
}
- @BeforeClass(groups = {"fast"})
+ @BeforeClass(groups = "fast")
public void setup() {
clock = new ClockMock();
gen = new TestDefaultInvoiceGeneratorMock(clock, new InvoiceConfig() {
@@ -67,14 +68,17 @@ public class TestDefaultInvoiceGeneratorUnit {
public boolean isNotificationProcessingOff() {
return false;
}
+
@Override
public boolean isEmailNotificationsEnabled() {
return false;
}
+
@Override
public long getSleepTimeMs() {
return 100;
}
+
@Override
public int getNumberOfMonthsInFuture() {
return 5;
@@ -82,143 +86,139 @@ public class TestDefaultInvoiceGeneratorUnit {
});
}
- @Test(groups = {"fast"}, enabled= true)
+ @Test(groups = "fast")
public void testRemoveCancellingInvoiceItemsFixedPrice() {
-
- DateTime startDate = clock.getUTCNow();
- DateTime endDate = startDate.plusDays(30);
- DateTime nextEndDate = startDate.plusMonths(1);
-
- BigDecimal amount = new BigDecimal("12.00");
- BigDecimal rate2 = new BigDecimal("14.85");
- BigDecimal amount2 = rate2;
- List<InvoiceItem> items = new LinkedList<InvoiceItem>();
- InvoiceItem item1 = new FixedPriceInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount, currency);
+ final DateTime startDate = clock.getUTCNow();
+ final DateTime endDate = startDate.plusDays(30);
+ final DateTime nextEndDate = startDate.plusMonths(1);
+
+ final BigDecimal amount = new BigDecimal("12.00");
+ final BigDecimal rate2 = new BigDecimal("14.85");
+ final BigDecimal amount2 = rate2;
+ final List<InvoiceItem> items = new LinkedList<InvoiceItem>();
+ final InvoiceItem item1 = new FixedPriceInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount, currency);
items.add(item1);
items.add(new RepairAdjInvoiceItem(invoiceId, accountId, startDate, endDate, amount.negate(), currency, item1.getId()));
items.add(new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endDate, nextEndDate, amount2, rate2, currency));
gen.removeCancellingInvoiceItems(items);
assertEquals(items.size(), 1);
- InvoiceItem leftItem = items.get(0);
+ final InvoiceItem leftItem = items.get(0);
assertEquals(leftItem.getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(leftItem.getAmount(), amount2);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testRemoveCancellingInvoiceItemsRecurringPrice() {
-
- DateTime startDate = clock.getUTCNow();
- DateTime endDate = startDate.plusDays(30);
- DateTime nextEndDate = startDate.plusMonths(1);
-
- BigDecimal rate1 = new BigDecimal("12.00");
- BigDecimal amount1 = rate1;
- BigDecimal rate2 = new BigDecimal("14.85");
- BigDecimal amount2 = rate2;
- List<InvoiceItem> items = new LinkedList<InvoiceItem>();
- InvoiceItem item1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
+ final DateTime startDate = clock.getUTCNow();
+ final DateTime endDate = startDate.plusDays(30);
+ final DateTime nextEndDate = startDate.plusMonths(1);
+
+ final BigDecimal rate1 = new BigDecimal("12.00");
+ final BigDecimal amount1 = rate1;
+ final BigDecimal rate2 = new BigDecimal("14.85");
+ final BigDecimal amount2 = rate2;
+ final List<InvoiceItem> items = new LinkedList<InvoiceItem>();
+ final InvoiceItem item1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
items.add(item1);
items.add(new RepairAdjInvoiceItem(invoiceId, accountId, startDate, endDate, amount1.negate(), currency, item1.getId()));
items.add(new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endDate, nextEndDate, amount2, rate2, currency));
gen.removeCancellingInvoiceItems(items);
assertEquals(items.size(), 1);
- InvoiceItem leftItem = items.get(0);
+ final InvoiceItem leftItem = items.get(0);
assertEquals(leftItem.getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(leftItem.getAmount(), amount2);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testRemoveDuplicatedInvoiceItemsFixedPrice() {
+ final DateTime startDate = clock.getUTCNow();
+ final DateTime endDate = startDate.plusDays(30);
+ final DateTime nextEndDate = startDate.plusMonths(1);
- DateTime startDate = clock.getUTCNow();
- DateTime endDate = startDate.plusDays(30);
- DateTime nextEndDate = startDate.plusMonths(1);
-
- BigDecimal amount1 = new BigDecimal("12.00");
+ final BigDecimal amount1 = new BigDecimal("12.00");
- BigDecimal amount2 = new BigDecimal("14.85");
+ final BigDecimal amount2 = new BigDecimal("14.85");
- BigDecimal rate3 = new BigDecimal("14.85");
- BigDecimal amount3 = rate3;
+ final BigDecimal rate3 = new BigDecimal("14.85");
+ final BigDecimal amount3 = rate3;
- List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
- InvoiceItem item1 = new FixedPriceInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, currency);
+ final List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
+ final InvoiceItem item1 = new FixedPriceInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, currency);
existing.add(item1);
- List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
- InvoiceItem other = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endDate, nextEndDate, amount3, rate3, currency, null);
+ final List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
+ final InvoiceItem other = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endDate, nextEndDate, amount3, rate3, currency, null);
proposed.add(item1);
proposed.add(other);
gen.removeDuplicatedInvoiceItems(proposed, existing);
assertEquals(existing.size(), 0);
assertEquals(proposed.size(), 1);
- InvoiceItem leftItem = proposed.get(0);
+ final InvoiceItem leftItem = proposed.get(0);
assertEquals(leftItem.getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(leftItem.getAmount(), amount2);
}
- @Test(groups = {"fast"})
- public void testRemoveDuplicatedInvoiceItemsRecuringPrice() {
+ @Test(groups = "fast")
+ public void testRemoveDuplicatedInvoiceItemsRecurringPrice() {
+ final DateTime startDate = clock.getUTCNow();
+ final DateTime endDate = startDate.plusDays(30);
+ final DateTime nextEndDate = startDate.plusMonths(1);
- DateTime startDate = clock.getUTCNow();
- DateTime endDate = startDate.plusDays(30);
- DateTime nextEndDate = startDate.plusMonths(1);
+ final BigDecimal rate1 = new BigDecimal("12.00");
+ final BigDecimal amount1 = rate1;
- BigDecimal rate1 = new BigDecimal("12.00");
- BigDecimal amount1 = rate1;
+ final BigDecimal rate2 = new BigDecimal("14.85");
+ final BigDecimal amount2 = rate2;
- BigDecimal rate2 = new BigDecimal("14.85");
- BigDecimal amount2 = rate2;
-
- List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
- InvoiceItem item1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
+ final List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
+ final InvoiceItem item1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
existing.add(item1);
- List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
- InvoiceItem other = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endDate, nextEndDate, amount2, rate2, currency, null);
+ final List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
+ final InvoiceItem other = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endDate, nextEndDate, amount2, rate2, currency, null);
proposed.add(item1);
proposed.add(other);
gen.removeDuplicatedInvoiceItems(proposed, existing);
assertEquals(existing.size(), 0);
assertEquals(proposed.size(), 1);
- InvoiceItem leftItem = proposed.get(0);
+ final InvoiceItem leftItem = proposed.get(0);
assertEquals(leftItem.getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(leftItem.getAmount(), amount2);
}
// STEPH same as testRemoveCancellingInvoiceItemsFixedPrice: should we have one for FixedPrice?
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testAddRepairedItemsItemsRecurringPrice() {
- DateTime startDate = clock.getUTCNow();
- DateTime endDate = startDate.plusDays(30);
- DateTime nextEndDate = startDate.plusMonths(1);
+ final DateTime startDate = clock.getUTCNow();
+ final DateTime endDate = startDate.plusDays(30);
+ final DateTime nextEndDate = startDate.plusMonths(1);
- BigDecimal rate1 = new BigDecimal("12.00");
- BigDecimal amount1 = rate1;
+ final BigDecimal rate1 = new BigDecimal("12.00");
+ final BigDecimal amount1 = rate1;
- BigDecimal rate2 = new BigDecimal("14.85");
- BigDecimal amount2 = rate2;
+ final BigDecimal rate2 = new BigDecimal("14.85");
+ final BigDecimal amount2 = rate2;
- UUID firstInvoiceId = UUID.randomUUID();
- List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
- InvoiceItem item1 = new RecurringInvoiceItem(firstInvoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
+ final UUID firstInvoiceId = UUID.randomUUID();
+ final List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
+ final InvoiceItem item1 = new RecurringInvoiceItem(firstInvoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
existing.add(item1);
- List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
- InvoiceItem other = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endDate, nextEndDate, amount2, rate2, currency, null);
+ final List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
+ final InvoiceItem other = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, endDate, nextEndDate, amount2, rate2, currency, null);
proposed.add(other);
gen.addRepairedItems(existing, proposed);
assertEquals(existing.size(), 1);
assertEquals(proposed.size(), 2);
- InvoiceItem leftItem1 = proposed.get(0);
+ final InvoiceItem leftItem1 = proposed.get(0);
assertEquals(leftItem1.getInvoiceId(), invoiceId);
assertEquals(leftItem1.getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(leftItem1.getAmount(), amount2);
- InvoiceItem newItem2 = proposed.get(1);
+ final InvoiceItem newItem2 = proposed.get(1);
assertEquals(newItem2.getInvoiceId(), firstInvoiceId);
assertEquals(newItem2.getInvoiceItemType(), InvoiceItemType.REPAIR_ADJ);
assertEquals(newItem2.getAmount(), item1.getAmount().negate());
@@ -226,109 +226,105 @@ public class TestDefaultInvoiceGeneratorUnit {
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testGenerateCreditsForPastRepairedInvoices() {
- DateTime startDate = clock.getUTCNow();
- DateTime endDate = startDate.plusDays(30);
- DateTime nextEndDate = startDate.plusMonths(1);
+ final DateTime startDate = clock.getUTCNow();
+ final DateTime endDate = startDate.plusDays(30);
+ final DateTime nextEndDate = startDate.plusMonths(1);
- BigDecimal rate1 = new BigDecimal("10.00");
- BigDecimal amount1 = rate1;
+ final BigDecimal rate1 = new BigDecimal("10.00");
+ final BigDecimal amount1 = rate1;
- List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
- InvoiceItem item1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
+ final List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
+ final InvoiceItem item1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
existing.add(item1);
-
- UUID existingInvoiceId = UUID.randomUUID();
- List<Invoice> existingInvoices = new LinkedList<Invoice>();
- Invoice existingInvoice = mock(Invoice.class);
+ final UUID existingInvoiceId = UUID.randomUUID();
+ final List<Invoice> existingInvoices = new LinkedList<Invoice>();
+ final Invoice existingInvoice = mock(Invoice.class);
when(existingInvoice.getId()).thenReturn(existingInvoiceId);
when(existingInvoice.getBalance()).thenReturn(BigDecimal.ZERO);
when(existingInvoice.getInvoiceItems()).thenReturn(existing);
- BigDecimal rate2 = new BigDecimal("20.0");
- BigDecimal amount2 = rate2;
+ final BigDecimal rate2 = new BigDecimal("20.0");
+ final BigDecimal amount2 = rate2;
- List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
- InvoiceItem reversedItem1 = new RepairAdjInvoiceItem(existingInvoiceId, accountId, startDate, nextEndDate, item1.getAmount().negate(), currency, item1.getId());
- InvoiceItem newItem1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount2, rate2, currency, null);
+ final List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
+ final InvoiceItem reversedItem1 = new RepairAdjInvoiceItem(existingInvoiceId, accountId, startDate, nextEndDate, item1.getAmount().negate(), currency, item1.getId());
+ final InvoiceItem newItem1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount2, rate2, currency, null);
proposed.add(reversedItem1);
proposed.add(newItem1);
gen.generateCBAForExistingInvoices(accountId, existingInvoices, proposed, currency);
assertEquals(proposed.size(), 3);
- InvoiceItem reversedItemCheck1 = proposed.get(0);
+ final InvoiceItem reversedItemCheck1 = proposed.get(0);
assertEquals(reversedItemCheck1.getInvoiceId(), existingInvoiceId);
assertEquals(reversedItemCheck1.getInvoiceItemType(), InvoiceItemType.REPAIR_ADJ);
assertEquals(reversedItemCheck1.getAmount(), item1.getAmount().negate());
assertEquals(reversedItemCheck1.getLinkedItemId(), item1.getId());
- InvoiceItem newItemCheck1 = proposed.get(1);
+ final InvoiceItem newItemCheck1 = proposed.get(1);
assertEquals(newItemCheck1.getInvoiceId(), invoiceId);
assertEquals(newItemCheck1.getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(newItemCheck1.getAmount(), amount2);
- InvoiceItem creditItemCheck = proposed.get(2);
+ final InvoiceItem creditItemCheck = proposed.get(2);
assertEquals(creditItemCheck.getInvoiceId(), existingInvoiceId);
assertEquals(creditItemCheck.getInvoiceItemType(), InvoiceItemType.CBA_ADJ);
assertEquals(creditItemCheck.getAmount(), amount2.add(rate1.negate()));
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testConsumeNotEnoughExistingCredit() {
testConsumeCreditInternal(new BigDecimal("12.00"), new BigDecimal("-10.00"));
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testConsumeTooMuchExistingCredit() {
testConsumeCreditInternal(new BigDecimal("7.00"), new BigDecimal("-7.00"));
}
- private void testConsumeCreditInternal(BigDecimal newRate, BigDecimal expectedNewCba) {
- DateTime startDate = clock.getUTCNow();
- DateTime endDate = startDate.plusDays(30);
- DateTime nextEndDate = startDate.plusMonths(1);
-
+ private void testConsumeCreditInternal(final BigDecimal newRate, final BigDecimal expectedNewCba) {
+ final DateTime startDate = clock.getUTCNow();
+ final DateTime endDate = startDate.plusDays(30);
+ final DateTime nextEndDate = startDate.plusMonths(1);
- BigDecimal rate1 = new BigDecimal("20.00");
- BigDecimal amount1 = rate1;
+ final BigDecimal rate1 = new BigDecimal("20.00");
+ final BigDecimal amount1 = rate1;
- BigDecimal rate2 = new BigDecimal("10.00");
- BigDecimal amount2 = rate2;
+ final BigDecimal rate2 = new BigDecimal("10.00");
+ final BigDecimal amount2 = rate2;
+ final UUID firstInvoiceId = UUID.randomUUID();
+ final List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
+ final BigDecimal pcba1 = new BigDecimal("10.00");
- UUID firstInvoiceId = UUID.randomUUID();
- List<InvoiceItem> existing = new LinkedList<InvoiceItem>();
- BigDecimal pcba1 = new BigDecimal("10.00");
-
- InvoiceItem item1 = new RecurringInvoiceItem(firstInvoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
- InvoiceItem reversedItem1 = new RepairAdjInvoiceItem(firstInvoiceId, accountId, startDate, nextEndDate, amount1.negate(), currency, item1.getId());
- InvoiceItem newItem1 = new RecurringInvoiceItem(firstInvoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount2, rate2, currency, null);
- InvoiceItem cba1 = new CreditBalanceAdjInvoiceItem(firstInvoiceId, accountId, startDate, pcba1, currency);
+ final InvoiceItem item1 = new RecurringInvoiceItem(firstInvoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount1, rate1, currency, null);
+ final InvoiceItem reversedItem1 = new RepairAdjInvoiceItem(firstInvoiceId, accountId, startDate, nextEndDate, amount1.negate(), currency, item1.getId());
+ final InvoiceItem newItem1 = new RecurringInvoiceItem(firstInvoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, amount2, rate2, currency, null);
+ final InvoiceItem cba1 = new CreditBalanceAdjInvoiceItem(firstInvoiceId, accountId, startDate, pcba1, currency);
existing.add(item1);
existing.add(reversedItem1);
existing.add(newItem1);
existing.add(cba1);
+ final BigDecimal newRate2 = newRate;
+ final BigDecimal newAmount2 = newRate2;
- BigDecimal newRate2 = newRate;
- BigDecimal newAmount2 = newRate2;
-
- List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
- InvoiceItem item2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate.plusMonths(1), endDate.plusMonths(1), newAmount2, newRate2, currency, null);
+ final List<InvoiceItem> proposed = new LinkedList<InvoiceItem>();
+ final InvoiceItem item2 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate.plusMonths(1), endDate.plusMonths(1), newAmount2, newRate2, currency, null);
proposed.add(item2);
gen.consumeExistingCredit(invoiceId, firstInvoiceId, existing, proposed, currency);
assertEquals(proposed.size(), 2);
- InvoiceItem item2Check = proposed.get(0);
+ final InvoiceItem item2Check = proposed.get(0);
assertEquals(item2Check.getInvoiceId(), invoiceId);
assertEquals(item2Check.getInvoiceItemType(), InvoiceItemType.RECURRING);
assertEquals(item2Check.getAmount(), newAmount2);
- InvoiceItem cbaCheck = proposed.get(1);
+ final InvoiceItem cbaCheck = proposed.get(1);
assertEquals(cbaCheck.getInvoiceId(), invoiceId);
assertEquals(cbaCheck.getInvoiceItemType(), InvoiceItemType.CBA_ADJ);
assertEquals(cbaCheck.getAmount(), expectedNewCba);
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 a317cad..34b74d5 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
@@ -19,24 +19,20 @@ package com.ning.billing.invoice.glue;
import java.io.IOException;
import java.net.URL;
+import org.mockito.Mockito;
import org.skife.jdbi.v2.IDBI;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.catalog.glue.CatalogModule;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.invoice.api.InvoiceNotifier;
-import com.ning.billing.invoice.api.test.DefaultInvoiceTestApi;
-import com.ning.billing.invoice.api.test.InvoiceTestApi;
-import com.ning.billing.invoice.dao.InvoiceItemSqlDao;
-import com.ning.billing.invoice.dao.InvoicePaymentSqlDao;
import com.ning.billing.invoice.notification.MockNextBillingDateNotifier;
import com.ning.billing.invoice.notification.MockNextBillingDatePoster;
import com.ning.billing.invoice.notification.NextBillingDateNotifier;
import com.ning.billing.invoice.notification.NextBillingDatePoster;
import com.ning.billing.invoice.notification.NullInvoiceNotifier;
import com.ning.billing.junction.api.BillingApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.mock.glue.MockEntitlementModule;
import com.ning.billing.util.callcontext.CallContextFactory;
import com.ning.billing.util.callcontext.DefaultCallContextFactory;
@@ -53,32 +49,7 @@ import com.ning.billing.util.notificationq.NotificationQueueService;
import static org.testng.Assert.assertNotNull;
public class InvoiceModuleWithEmbeddedDb extends DefaultInvoiceModule {
- private final MysqlTestingHelper helper = new MysqlTestingHelper();
- private IDBI dbi;
-
- public void startDb() throws IOException {
- helper.startMysql();
- }
-
- public void initDb(final String ddl) throws IOException {
- helper.initDb(ddl);
- }
-
- public void stopDb() {
- helper.stopMysql();
- }
-
- public IDBI getDbi() {
- return dbi;
- }
-
- public InvoiceItemSqlDao getInvoiceItemSqlDao() {
- return dbi.onDemand(InvoiceItemSqlDao.class);
- }
-
- public InvoicePaymentSqlDao getInvoicePaymentSqlDao() {
- return dbi.onDemand(InvoicePaymentSqlDao.class);
- }
+ private final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
private void installNotificationQueue() {
bind(NotificationQueueService.class).to(MockNotificationQueueService.class).asEagerSingleton();
@@ -95,7 +66,7 @@ public class InvoiceModuleWithEmbeddedDb extends DefaultInvoiceModule {
public void configure() {
loadSystemPropertiesFromClasspath("/resource.properties");
- dbi = helper.getDBI();
+ final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
bind(Clock.class).to(DefaultClock.class).asEagerSingleton();
@@ -104,11 +75,9 @@ public class InvoiceModuleWithEmbeddedDb extends DefaultInvoiceModule {
install(new TagStoreModule());
installNotificationQueue();
-// install(new AccountModule());
- bind(AccountUserApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class));
+ bind(AccountUserApi.class).toInstance(Mockito.mock(AccountUserApi.class));
- final BillingApi billingApi = BrainDeadProxyFactory.createBrainDeadProxyFor(BillingApi.class);
- ((ZombieControl) billingApi).addResult("setChargedThroughDateFromTransaction", BrainDeadProxyFactory.ZOMBIE_VOID);
+ final BillingApi billingApi = Mockito.mock(BillingApi.class);
bind(BillingApi.class).toInstance(billingApi);
install(new CatalogModule());
@@ -117,10 +86,8 @@ public class InvoiceModuleWithEmbeddedDb extends DefaultInvoiceModule {
super.configure();
- bind(InvoiceTestApi.class).to(DefaultInvoiceTestApi.class).asEagerSingleton();
install(new BusModule());
install(new TemplateModule());
-
}
private static void loadSystemPropertiesFromClasspath(final String resource) {
diff --git a/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithMocks.java b/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithMocks.java
index 1019710..3e2a772 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithMocks.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/glue/InvoiceModuleWithMocks.java
@@ -28,7 +28,6 @@ import com.ning.billing.util.globallocker.GlobalLocker;
import com.ning.billing.util.globallocker.MockGlobalLocker;
import com.ning.billing.util.template.translation.TranslatorConfig;
-
public class InvoiceModuleWithMocks extends DefaultInvoiceModule {
@Override
protected void installInvoiceDao() {
@@ -39,7 +38,6 @@ public class InvoiceModuleWithMocks extends DefaultInvoiceModule {
@Override
protected void installInvoiceListener() {
-
}
@Override
@@ -52,11 +50,9 @@ public class InvoiceModuleWithMocks extends DefaultInvoiceModule {
@Override
protected void installInvoiceService() {
-
}
@Override
public void installInvoiceMigrationApi() {
-
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/InvoiceTestSuite.java b/invoice/src/test/java/com/ning/billing/invoice/InvoiceTestSuite.java
new file mode 100644
index 0000000..7291fce
--- /dev/null
+++ b/invoice/src/test/java/com/ning/billing/invoice/InvoiceTestSuite.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.invoice;
+
+import com.ning.billing.KillbillTestSuite;
+
+public abstract class InvoiceTestSuite extends KillbillTestSuite {
+}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/InvoiceTestSuiteWithEmbeddedDB.java b/invoice/src/test/java/com/ning/billing/invoice/InvoiceTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..de4234f
--- /dev/null
+++ b/invoice/src/test/java/com/ning/billing/invoice/InvoiceTestSuiteWithEmbeddedDB.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.invoice;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class InvoiceTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/MockModule.java b/invoice/src/test/java/com/ning/billing/invoice/MockModule.java
index 0e1ff55..4b15dc3 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/MockModule.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/MockModule.java
@@ -16,8 +16,6 @@
package com.ning.billing.invoice;
-import static org.testng.Assert.assertNotNull;
-
import java.io.IOException;
import java.net.URL;
@@ -25,6 +23,7 @@ import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
import com.google.inject.AbstractModule;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.catalog.glue.CatalogModule;
import com.ning.billing.dbi.DBIProvider;
import com.ning.billing.dbi.DbiConfig;
@@ -46,10 +45,11 @@ import com.ning.billing.util.glue.GlobalLockerModule;
import com.ning.billing.util.glue.NotificationQueueModule;
import com.ning.billing.util.glue.TagStoreModule;
+import static org.testng.Assert.assertNotNull;
+
public class MockModule extends AbstractModule {
@Override
protected void configure() {
-
loadSystemPropertiesFromClasspath("/resource.properties");
bind(Clock.class).to(ClockMock.class).asEagerSingleton();
@@ -58,7 +58,7 @@ public class MockModule extends AbstractModule {
install(new TagStoreModule());
install(new CustomFieldModule());
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
if (helper.isUsingLocalInstance()) {
bind(IDBI.class).toProvider(DBIProvider.class).asEagerSingleton();
@@ -79,14 +79,12 @@ public class MockModule extends AbstractModule {
installInvoiceModule();
install(new MockJunctionModule());
install(new TemplateModule());
-
}
protected void installInvoiceModule() {
install(new DefaultInvoiceModule());
}
-
private static void loadSystemPropertiesFromClasspath(final String resource) {
final URL url = TestDefaultInvoiceMigrationApi.class.getResource(resource);
assertNotNull(url);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/notification/MockNextBillingDatePoster.java b/invoice/src/test/java/com/ning/billing/invoice/notification/MockNextBillingDatePoster.java
index 1079a2f..5742247 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/notification/MockNextBillingDatePoster.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/notification/MockNextBillingDatePoster.java
@@ -23,7 +23,7 @@ import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
public class MockNextBillingDatePoster implements NextBillingDatePoster {
@Override
- public void insertNextBillingNotification(final Transmogrifier transactionalDao, final UUID subscriptionId, final DateTime futureNotificationTime) {
+ public void insertNextBillingNotification(final Transmogrifier transactionalDao, final UUID accountId, final UUID subscriptionId, final DateTime futureNotificationTime) {
// do nothing
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
index f1f7614..e126ba2 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
@@ -22,6 +22,7 @@ import java.util.UUID;
import java.util.concurrent.Callable;
import org.joda.time.DateTime;
+import org.mockito.Mockito;
import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.Transaction;
@@ -29,26 +30,26 @@ import org.skife.jdbi.v2.TransactionStatus;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.catalog.MockCatalogModule;
import com.ning.billing.config.InvoiceConfig;
import com.ning.billing.dbi.DBIProvider;
import com.ning.billing.dbi.DbiConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.invoice.InvoiceDispatcher;
import com.ning.billing.invoice.InvoiceListener;
+import com.ning.billing.invoice.InvoiceTestSuiteWithEmbeddedDB;
import com.ning.billing.invoice.glue.InvoiceModuleWithMocks;
import com.ning.billing.lifecycle.KillbillService;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.mock.glue.MockClockModule;
import com.ning.billing.mock.glue.MockJunctionModule;
import com.ning.billing.util.bus.Bus;
@@ -60,20 +61,17 @@ import com.ning.billing.util.email.templates.TemplateModule;
import com.ning.billing.util.glue.BusModule;
import com.ning.billing.util.glue.BusModule.BusType;
import com.ning.billing.util.glue.NotificationQueueModule;
-import com.ning.billing.util.io.IOUtils;
import com.ning.billing.util.notificationq.DummySqlTest;
import com.ning.billing.util.notificationq.NotificationQueueService;
-import com.ning.billing.util.notificationq.dao.NotificationSqlDao;
import static com.jayway.awaitility.Awaitility.await;
import static java.util.concurrent.TimeUnit.MINUTES;
-public class TestNextBillingDateNotifier {
+public class TestNextBillingDateNotifier extends InvoiceTestSuiteWithEmbeddedDB {
private Clock clock;
private DefaultNextBillingDateNotifier notifier;
private DummySqlTest dao;
private Bus eventBus;
- private MysqlTestingHelper helper;
private InvoiceListenerMock listener;
private NotificationQueueService notificationQueueService;
@@ -102,16 +100,11 @@ public class TestNextBillingDateNotifier {
}
- @BeforeMethod(groups = {"slow"})
- public void cleanDb() {
- helper.cleanupAllTables();
- }
-
@BeforeClass(groups = {"slow"})
- public void setup() throws KillbillService.ServiceException, IOException, ClassNotFoundException, SQLException {
+ public void setup() throws KillbillService.ServiceException, IOException, ClassNotFoundException, SQLException, EntitlementUserApiException {
//TestApiBase.loadSystemPropertiesFromClasspath("/entitlement.properties");
final Injector g = Guice.createInjector(Stage.PRODUCTION, new AbstractModule() {
-
+ @Override
protected void configure() {
install(new MockClockModule());
install(new BusModule(BusType.MEMORY));
@@ -121,7 +114,7 @@ public class TestNextBillingDateNotifier {
install(new NotificationQueueModule());
install(new TemplateModule());
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
if (helper.isUsingLocalInstance()) {
bind(IDBI.class).toProvider(DBIProvider.class).asEagerSingleton();
@@ -131,8 +124,6 @@ public class TestNextBillingDateNotifier {
final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
}
-
-
}
});
@@ -140,31 +131,22 @@ public class TestNextBillingDateNotifier {
final IDBI dbi = g.getInstance(IDBI.class);
dao = dbi.onDemand(DummySqlTest.class);
eventBus = g.getInstance(Bus.class);
- helper = g.getInstance(MysqlTestingHelper.class);
notificationQueueService = g.getInstance(NotificationQueueService.class);
final InvoiceDispatcher dispatcher = g.getInstance(InvoiceDispatcher.class);
- final Subscription subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- final EntitlementUserApi entitlementUserApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class);
- ((ZombieControl) entitlementUserApi).addResult("getSubscriptionFromId", subscription);
+ final Subscription subscription = Mockito.mock(Subscription.class);
+ final EntitlementUserApi entitlementUserApi = Mockito.mock(EntitlementUserApi.class);
+ Mockito.when(entitlementUserApi.getSubscriptionFromId(Mockito.<UUID>any())).thenReturn(subscription);
final CallContextFactory factory = new DefaultCallContextFactory(clock);
listener = new InvoiceListenerMock(factory, dispatcher);
notifier = new DefaultNextBillingDateNotifier(notificationQueueService, g.getInstance(InvoiceConfig.class), entitlementUserApi, listener);
- startMysql();
- }
-
- private void startMysql() throws IOException, ClassNotFoundException, SQLException {
- final String ddl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- final String testDdl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl_test.sql"));
- helper.startMysql();
- helper.initDb(ddl);
- helper.initDb(testDdl);
}
-
- @Test(enabled = true, groups = "slow")
+ @Test(groups = "slow")
public void testInvoiceNotifier() throws Exception {
+
+ final UUID accountId = UUID.randomUUID();
final UUID subscriptionId = new UUID(0L, 1L);
final DateTime now = new DateTime();
final DateTime readyTime = now.plusMillis(2000);
@@ -174,22 +156,19 @@ public class TestNextBillingDateNotifier {
notifier.initialize();
notifier.start();
-
dao.inTransaction(new Transaction<Void, DummySqlTest>() {
@Override
public Void inTransaction(final DummySqlTest transactional,
final TransactionStatus status) throws Exception {
- poster.insertNextBillingNotification(transactional, subscriptionId, readyTime);
+ poster.insertNextBillingNotification(transactional, accountId, subscriptionId, readyTime);
return null;
}
});
-
// Move time in the future after the notification effectiveDate
((ClockMock) clock).setDeltaFromReality(3000);
-
await().atMost(1, MINUTES).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
@@ -204,7 +183,5 @@ public class TestNextBillingDateNotifier {
@AfterClass(groups = "slow")
public void tearDown() throws Exception {
notifier.stop();
- helper.stopMysql();
}
-
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/TestHtmlInvoiceGenerator.java b/invoice/src/test/java/com/ning/billing/invoice/TestHtmlInvoiceGenerator.java
index 8c9ace4..56fa7fa 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/TestHtmlInvoiceGenerator.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/TestHtmlInvoiceGenerator.java
@@ -35,13 +35,11 @@ import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.formatters.InvoiceFormatterFactory;
import com.ning.billing.invoice.template.HtmlInvoiceGenerator;
import com.ning.billing.invoice.template.formatters.DefaultInvoiceFormatterFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.email.templates.MustacheTemplateEngine;
import com.ning.billing.util.email.templates.TemplateEngine;
import com.ning.billing.util.template.translation.TranslatorConfig;
-public class TestHtmlInvoiceGenerator {
+public class TestHtmlInvoiceGenerator extends InvoiceTestSuite {
private HtmlInvoiceGenerator g;
@BeforeSuite(groups = "fast")
@@ -72,20 +70,19 @@ public class TestHtmlInvoiceGenerator {
}
private Account createAccount() {
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- final ZombieControl zombieControl = (ZombieControl) account;
- zombieControl.addResult("getExternalKey", "1234abcd");
- zombieControl.addResult("getName", "Jim Smith");
- zombieControl.addResult("getFirstNameLength", 3);
- zombieControl.addResult("getEmail", "jim.smith@mail.com");
- zombieControl.addResult("getLocale", Locale.US.toString());
- zombieControl.addResult("getAddress1", "123 Some Street");
- zombieControl.addResult("getAddress2", "Apt 456");
- zombieControl.addResult("getCity", "Some City");
- zombieControl.addResult("getStateOrProvince", "Some State");
- zombieControl.addResult("getPostalCode", "12345-6789");
- zombieControl.addResult("getCountry", "USA");
- zombieControl.addResult("getPhone", "123-456-7890");
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getExternalKey()).thenReturn("1234abcd");
+ Mockito.when(account.getName()).thenReturn("Jim Smith");
+ Mockito.when(account.getFirstNameLength()).thenReturn(3);
+ Mockito.when(account.getEmail()).thenReturn("jim.smith@mail.com");
+ Mockito.when(account.getLocale()).thenReturn(Locale.US.toString());
+ Mockito.when(account.getAddress1()).thenReturn("123 Some Street");
+ Mockito.when(account.getAddress2()).thenReturn("Apt 456");
+ Mockito.when(account.getCity()).thenReturn("Some City");
+ Mockito.when(account.getStateOrProvince()).thenReturn("Some State");
+ Mockito.when(account.getPostalCode()).thenReturn("12345-6789");
+ Mockito.when(account.getCountry()).thenReturn("USA");
+ Mockito.when(account.getPhone()).thenReturn("123-456-7890");
return account;
}
@@ -96,31 +93,29 @@ public class TestHtmlInvoiceGenerator {
final BigDecimal price1 = new BigDecimal("29.95");
final BigDecimal price2 = new BigDecimal("59.95");
- final Invoice dummyInvoice = BrainDeadProxyFactory.createBrainDeadProxyFor(Invoice.class);
- final ZombieControl zombie = (ZombieControl) dummyInvoice;
- zombie.addResult("getInvoiceDate", startDate);
- zombie.addResult("getInvoiceNumber", 42);
- zombie.addResult("getCurrency", Currency.USD);
- zombie.addResult("getChargedAmount", price1.add(price2));
- zombie.addResult("getPaidAmount", BigDecimal.ZERO);
- zombie.addResult("getBalance", price1.add(price2));
+ final Invoice dummyInvoice = Mockito.mock(Invoice.class);
+ Mockito.when(dummyInvoice.getInvoiceDate()).thenReturn(startDate);
+ Mockito.when(dummyInvoice.getInvoiceNumber()).thenReturn(42);
+ Mockito.when(dummyInvoice.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(dummyInvoice.getChargedAmount()).thenReturn(price1.add(price2));
+ Mockito.when(dummyInvoice.getPaidAmount()).thenReturn(BigDecimal.ZERO);
+ Mockito.when(dummyInvoice.getBalance()).thenReturn(price1.add(price2));
final List<InvoiceItem> items = new ArrayList<InvoiceItem>();
items.add(createInvoiceItem(price1, "Domain 1", startDate, endDate, "ning-plus"));
items.add(createInvoiceItem(price2, "Domain 2", startDate, endDate, "ning-pro"));
- zombie.addResult("getInvoiceItems", items);
+ Mockito.when(dummyInvoice.getInvoiceItems()).thenReturn(items);
return dummyInvoice;
}
private InvoiceItem createInvoiceItem(final BigDecimal amount, final String networkName, final DateTime startDate, final DateTime endDate, final String planName) {
- final InvoiceItem item = BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceItem.class);
- final ZombieControl zombie = (ZombieControl) item;
- zombie.addResult("getAmount", amount);
- zombie.addResult("getStartDate", startDate);
- zombie.addResult("getEndDate", endDate);
- zombie.addResult("getPlanName", planName);
- zombie.addResult("getDescription", networkName);
+ final InvoiceItem item = Mockito.mock(InvoiceItem.class);
+ Mockito.when(item.getAmount()).thenReturn(amount);
+ Mockito.when(item.getStartDate()).thenReturn(startDate);
+ Mockito.when(item.getEndDate()).thenReturn(endDate);
+ Mockito.when(item.getPlanName()).thenReturn(planName);
+ Mockito.when(item.getDescription()).thenReturn(networkName);
return item;
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
index b586cd7..73acc50 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
@@ -31,6 +32,7 @@ import org.testng.annotations.Test;
import com.google.inject.Inject;
import com.ning.billing.account.api.Account;
+import com.ning.billing.account.api.AccountApiException;
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.catalog.MockPlan;
import com.ning.billing.catalog.MockPlanPhase;
@@ -52,8 +54,6 @@ import com.ning.billing.invoice.notification.NullInvoiceNotifier;
import com.ning.billing.invoice.tests.InvoicingTestBase;
import com.ning.billing.junction.api.BillingApi;
import com.ning.billing.junction.api.BillingEventSet;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.bus.BusService;
import com.ning.billing.util.bus.DefaultBusService;
import com.ning.billing.util.callcontext.CallContext;
@@ -62,7 +62,6 @@ import com.ning.billing.util.callcontext.DefaultCallContextFactory;
import com.ning.billing.util.callcontext.UserType;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.globallocker.GlobalLocker;
-import com.ning.billing.util.io.IOUtils;
@Guice(modules = {MockModule.class})
public class TestInvoiceDispatcher extends InvoicingTestBase {
@@ -96,20 +95,12 @@ public class TestInvoiceDispatcher extends InvoicingTestBase {
@BeforeSuite(groups = {"slow"})
public void setup() throws Exception {
- final String invoiceDdl = IOUtils.toString(TestInvoiceDispatcher.class.getResourceAsStream("/com/ning/billing/invoice/ddl.sql"));
- final String utilDdl = IOUtils.toString(TestInvoiceDispatcher.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
- helper.startMysql();
-
- helper.initDb(invoiceDdl);
- helper.initDb(utilDdl);
notifier.initialize();
notifier.start();
context = new DefaultCallContextFactory(clock).createCallContext("Miracle Max", CallOrigin.TEST, UserType.TEST);
busService.getBus().start();
- ((ZombieControl) billingApi).addResult("setChargedThroughDate", BrainDeadProxyFactory.ZOMBIE_VOID);
}
@AfterClass(groups = {"slow"})
@@ -117,28 +108,27 @@ public class TestInvoiceDispatcher extends InvoicingTestBase {
try {
((DefaultBusService) busService).stopBus();
notifier.stop();
- helper.stopMysql();
} catch (Exception e) {
log.warn("Failed to tearDown test properly ", e);
}
}
@Test(groups = {"slow"}, enabled = true)
- public void testDryRunInvoice() throws InvoiceApiException {
+ public void testDryRunInvoice() throws InvoiceApiException, AccountApiException {
final UUID accountId = UUID.randomUUID();
final UUID subscriptionId = UUID.randomUUID();
- final AccountUserApi accountUserApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
+ final AccountUserApi accountUserApi = Mockito.mock(AccountUserApi.class);
+ final Account account = Mockito.mock(Account.class);
- ((ZombieControl) accountUserApi).addResult("getAccountById", account);
- ((ZombieControl) account).addResult("getCurrency", Currency.USD);
- ((ZombieControl) account).addResult("getId", accountId);
- ((ZombieControl) account).addResult(("isNotifiedForInvoices"), true);
+ Mockito.when(accountUserApi.getAccountById(accountId)).thenReturn(account);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getId()).thenReturn(accountId);
+ Mockito.when(account.isNotifiedForInvoices()).thenReturn(true);
- final Subscription subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) subscription).addResult("getId", subscriptionId);
- ((ZombieControl) subscription).addResult("getBundleId", new UUID(0L, 0L));
+ final Subscription subscription = Mockito.mock(Subscription.class);
+ Mockito.when(subscription.getId()).thenReturn(subscriptionId);
+ Mockito.when(subscription.getBundleId()).thenReturn(new UUID(0L, 0L));
final BillingEventSet events = new MockBillingEventSet();
final Plan plan = MockPlan.createBicycleNoTrialEvergreen1USD();
final PlanPhase planPhase = MockPlanPhase.create1USDMonthlyEvergreen();
@@ -149,7 +139,7 @@ public class TestInvoiceDispatcher extends InvoicingTestBase {
fixedPrice, BigDecimal.ONE, currency, BillingPeriod.MONTHLY, 1,
BillingModeType.IN_ADVANCE, "", 1L, SubscriptionTransitionType.CREATE));
- ((ZombieControl) billingApi).addResult("getBillingEventsForAccountAndUpdateAccountBCD", events);
+ Mockito.when(billingApi.getBillingEventsForAccountAndUpdateAccountBCD(accountId)).thenReturn(events);
final DateTime target = new DateTime();
@@ -180,5 +170,4 @@ public class TestInvoiceDispatcher extends InvoicingTestBase {
}
//MDW add a test to cover when the account auto-invoice-off tag is present
-
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java
index a16b26e..082b751 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java
@@ -31,7 +31,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.ANNUAL;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 1);
@@ -41,7 +41,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInFirstProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 7);
@@ -51,7 +51,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnFirstBillingCycleDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 15);
@@ -61,7 +61,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInFullBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 22);
@@ -74,7 +74,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnSecondBillingCycleDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2012, 1, 15);
@@ -89,7 +89,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2012, 1, 17);
@@ -104,7 +104,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2012, 1, 27);
@@ -119,7 +119,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2012, 3, 7);
@@ -134,7 +134,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2012, 2, 26);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java
index 1121a7b..bfe28ac 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java
@@ -31,7 +31,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.ANNUAL;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 1);
@@ -42,7 +42,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 4);
@@ -53,7 +53,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateOnFirstBillingDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 13);
@@ -64,7 +64,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateAfterFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 4, 13);
@@ -75,7 +75,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 1);
@@ -87,7 +87,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 4);
@@ -99,7 +99,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnFirstBillingDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 13);
@@ -111,7 +111,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateInFinalBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 4, 10);
@@ -123,7 +123,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2012, 2, 13);
@@ -135,7 +135,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2012, 4, 10);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestProRation.java
index 9b75501..b9afbeb 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestProRation.java
@@ -31,7 +31,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.ANNUAL;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_PrecedingProRation() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 31);
final DateTime targetDate = buildDateTime(2011, 2, 24);
@@ -40,7 +40,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_PrecedingProRation_CrossingYearBoundary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 12, 15);
final DateTime targetDate = buildDateTime(2011, 1, 13);
@@ -49,8 +49,8 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 4, expectedValue);
}
- // Test fails, needs to be investigated
- @Test(groups = {"fast"}, enabled=false)
+ // TODO Test fails, needs to be investigated
+ @Test(groups = "fast", enabled=false)
public void testSinglePlanDoubleProRation() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 10);
final DateTime endDate = buildDateTime(2012, 3, 4);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java
index 35d35c1..798231a 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java
@@ -25,14 +25,13 @@ import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
-
public class TestTrailingProRation extends ProRationInAdvanceTestBase {
@Override
protected BillingPeriod getBillingPeriod() {
return BillingPeriod.ANNUAL;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2012, 6, 25);
@@ -41,7 +40,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateInFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2011, 6, 25);
@@ -50,7 +49,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateAtEndOfFirstBillingCycle() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2011, 6, 25);
@@ -60,7 +59,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2011, 6, 25);
@@ -70,7 +69,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2011, 6, 25);
@@ -79,7 +78,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, endDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2011, 6, 25);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java
index ebf816e..500ffd0 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java
@@ -31,14 +31,14 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
*/
protected abstract BigDecimal getDaysInTestPeriod();
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_OnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 15);
testCalculateNumberOfBillingCycles(startDate, startDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LessThanOnePeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 15);
final DateTime targetDate = buildDateTime(2011, 3, 1);
@@ -46,7 +46,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_OnePeriodLessADayAfterStart() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 15);
final DateTime targetDate = startDate.plusMonths(getBillingPeriod().getNumberOfMonths()).plusDays(-1);
@@ -54,7 +54,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_ExactlyOnePeriodAfterStart() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 15);
final DateTime targetDate = startDate.plusMonths(getBillingPeriod().getNumberOfMonths());
@@ -62,7 +62,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_SlightlyMoreThanOnePeriodAfterStart() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 15);
final DateTime targetDate = startDate.plusMonths(getBillingPeriod().getNumberOfMonths()).plusDays(1);
@@ -70,7 +70,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_CrossingYearBoundary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 12, 15);
final DateTime oneCycleLater = startDate.plusMonths(getBillingPeriod().getNumberOfMonths());
@@ -85,7 +85,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, oneCycleLater.plusDays(1), 15, TWO);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_StartingMidFebruary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 15);
final DateTime targetDate = startDate.plusMonths(getBillingPeriod().getNumberOfMonths());
@@ -93,7 +93,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_StartingMidFebruaryOfLeapYear() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 2, 15);
final DateTime targetDate = startDate.plusMonths(getBillingPeriod().getNumberOfMonths());
@@ -101,7 +101,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_MovingForwardThroughTime() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 31);
BigDecimal expectedValue = ONE;
@@ -122,7 +122,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
}
// tests for cancellation in less than one period, beginning Jan 1
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelledBeforeOnePeriod_TargetDateInStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 1);
@@ -132,7 +132,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelledBeforeOnePeriod_TargetDateInSubscriptionPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 7);
@@ -142,7 +142,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelledBeforeOnePeriod_TargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 15);
@@ -152,7 +152,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelledBeforeOnePeriod_TargetDateAfterEndDateButInFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 17);
@@ -162,7 +162,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelledBeforeOnePeriod_TargetDateAtEndOfFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 2, 1);
@@ -172,7 +172,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testCancelledBeforeOnePeriod_TargetDateAfterFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 4, 5);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java
index fb8a71c..06573d9 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java
@@ -31,7 +31,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.MONTHLY;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 1);
@@ -41,7 +41,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInFirstProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 7);
@@ -51,7 +51,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnFirstBillingCycleDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 15);
@@ -61,7 +61,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInFullBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 22);
@@ -74,7 +74,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnSecondBillingCycleDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 2, 27);
@@ -88,7 +88,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 2, 26);
@@ -102,7 +102,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 2, 27);
@@ -116,7 +116,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 3, 7);
@@ -130,7 +130,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 2, 26);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java
index c25721a..aa76033 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java
@@ -25,14 +25,13 @@ import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
-
public class TestLeadingProRation extends ProRationInAdvanceTestBase {
@Override
protected BillingPeriod getBillingPeriod() {
return BillingPeriod.MONTHLY;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 1);
@@ -43,7 +42,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 4);
@@ -54,7 +53,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateOnFirstBillingDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 13);
@@ -65,7 +64,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateAfterFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 4, 13);
@@ -76,7 +75,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 1);
@@ -88,7 +87,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 4);
@@ -100,7 +99,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnFirstBillingDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 13);
@@ -112,7 +111,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateInFinalBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 4, 10);
@@ -124,7 +123,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 4, 13);
@@ -136,7 +135,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 4, 10);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java
index 9fbf5b3..d0e4726 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java
@@ -31,7 +31,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.MONTHLY;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_WithPhaseChange() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 10);
final DateTime phaseChangeDate = buildDateTime(2011, 2, 24);
@@ -41,7 +41,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 10, ONE_HALF);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_WithPhaseChange_BeforeBillCycleDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 3);
final DateTime phaseChangeDate = buildDateTime(2011, 2, 17);
@@ -51,7 +51,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, ONE_HALF);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_WithPhaseChange_OnBillCycleDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 3);
final DateTime phaseChangeDate = buildDateTime(2011, 2, 17);
@@ -61,7 +61,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, ONE_AND_A_HALF);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_WithPhaseChange_AfterBillCycleDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 3);
final DateTime phaseChangeDate = buildDateTime(2011, 2, 17);
@@ -71,7 +71,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, ONE_AND_A_HALF);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_WithChangeOfBillCycleDayToLaterDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime planChangeDate = buildDateTime(2011, 2, 15);
@@ -81,7 +81,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_WithChangeOfBillCycleDayToEarlierDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 20);
final DateTime planChangeDate = buildDateTime(2011, 3, 6);
@@ -91,7 +91,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 6, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_CrossingYearBoundary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 12, 15);
final DateTime targetDate = buildDateTime(2011, 1, 16);
@@ -99,7 +99,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LeapYear_StartingMidFebruary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 2, 15);
final DateTime targetDate = buildDateTime(2012, 3, 15);
@@ -107,7 +107,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LeapYear_StartingBeforeFebruary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 1, 15);
final DateTime targetDate = buildDateTime(2012, 2, 3);
@@ -115,7 +115,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LeapYear_IncludingAllOfFebruary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 1, 30);
final DateTime targetDate = buildDateTime(2012, 3, 1);
@@ -123,7 +123,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 30, TWO);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_ChangeBCDTo31() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime planChangeDate = buildDateTime(2011, 2, 14);
@@ -138,7 +138,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 31, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_ChangeBCD() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime planChangeDate = buildDateTime(2011, 2, 14);
@@ -153,7 +153,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 27, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LeapYearFebruaryProRation() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 2, 1);
final DateTime endDate = buildDateTime(2012, 2, 15);
@@ -165,7 +165,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_BeforeBillingDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 7);
final DateTime changeDate = buildDateTime(2011, 2, 15);
@@ -179,7 +179,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, THREE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_OnBillingDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 7);
final DateTime changeDate = buildDateTime(2011, 3, 7);
@@ -192,7 +192,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_AfterBillingDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 7);
final DateTime changeDate = buildDateTime(2011, 3, 10);
@@ -207,7 +207,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_DoubleProRation() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 31);
final DateTime planChangeDate = buildDateTime(2011, 3, 10);
@@ -224,7 +224,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testStartTargetEnd() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 12, 15);
final DateTime targetDate = buildDateTime(2011, 3, 15);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java
index 7f814df..40b62e8 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java
@@ -31,7 +31,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.MONTHLY;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 7, 25);
@@ -40,7 +40,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateInFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 7, 25);
@@ -49,7 +49,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateAtEndOfFirstBillingCycle() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 7, 25);
@@ -59,7 +59,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 7, 25);
@@ -69,7 +69,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 7, 25);
@@ -78,7 +78,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, endDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 7, 25);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java
index 3b2b78c..9fe0746 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java
@@ -25,14 +25,13 @@ import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
-
public class TestDoubleProRation extends ProRationInAdvanceTestBase {
@Override
protected BillingPeriod getBillingPeriod() {
return BillingPeriod.QUARTERLY;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 1);
@@ -43,7 +42,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInFirstProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 7);
@@ -54,7 +53,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnFirstBillingCycleDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 15);
@@ -65,7 +64,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInFullBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 1, 22);
@@ -79,7 +78,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnSecondBillingCycleDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 4, 15);
@@ -94,7 +93,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 4, 26);
@@ -109,7 +108,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 4, 27);
@@ -124,7 +123,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRation_TargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 5, 7);
@@ -139,7 +138,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 1);
final DateTime targetDate = buildDateTime(2011, 6, 26);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java
index c2291ec..fc7e423 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java
@@ -31,7 +31,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.QUARTERLY;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 1);
@@ -42,7 +42,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 4);
@@ -53,7 +53,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateOnFirstBillingDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 13);
@@ -64,7 +64,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_Evergreen_TargetDateAfterFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 6, 13);
@@ -75,7 +75,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 1);
@@ -87,7 +87,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 4);
@@ -99,7 +99,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnFirstBillingDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 2, 13);
@@ -111,7 +111,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateInFinalBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 8, 10);
@@ -123,7 +123,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 8, 13);
@@ -135,7 +135,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testLeadingProRation_WithEndDate_TargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime targetDate = buildDateTime(2011, 9, 10);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java
index e0ebba3..a2884c3 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java
@@ -31,7 +31,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.QUARTERLY;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_WithPhaseChange() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 10);
final DateTime phaseChangeDate = buildDateTime(2011, 2, 24);
@@ -45,7 +45,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 10, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_WithPhaseChange_BeforeBillCycleDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 3);
final DateTime phaseChangeDate = buildDateTime(2011, 2, 17);
@@ -59,7 +59,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_WithPhaseChange_OnBillCycleDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 3);
final DateTime phaseChangeDate = buildDateTime(2011, 2, 17);
@@ -73,7 +73,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_WithPhaseChange_AfterBillCycleDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 3);
final DateTime phaseChangeDate = buildDateTime(2011, 2, 17);
@@ -87,7 +87,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_WithChangeOfBillCycleDayToLaterDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime planChangeDate = buildDateTime(2011, 2, 15);
@@ -98,7 +98,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_WithChangeOfBillCycleDayToEarlierDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 20);
final DateTime planChangeDate = buildDateTime(2011, 3, 6);
@@ -109,7 +109,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 6, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_CrossingYearBoundary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 12, 15);
final DateTime targetDate = buildDateTime(2011, 1, 16);
@@ -117,7 +117,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LeapYear_StartingMidFebruary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 2, 15);
final DateTime targetDate = buildDateTime(2012, 3, 15);
@@ -125,7 +125,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LeapYear_StartingBeforeFebruary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 1, 15);
final DateTime targetDate = buildDateTime(2012, 2, 3);
@@ -133,7 +133,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LeapYear_IncludingAllOfFebruary() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 1, 30);
final DateTime targetDate = buildDateTime(2012, 3, 1);
@@ -141,7 +141,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, targetDate, 30, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_ChangeBCDTo31() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime planChangeDate = buildDateTime(2011, 2, 14);
@@ -156,7 +156,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 31, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_ChangeBCD() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 1);
final DateTime planChangeDate = buildDateTime(2011, 2, 14);
@@ -171,7 +171,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 27, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testSinglePlan_LeapYearFebruaryProRation() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2012, 2, 1);
final DateTime endDate = buildDateTime(2012, 2, 15);
@@ -183,7 +183,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_BeforeBillingDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 7);
final DateTime changeDate = buildDateTime(2011, 2, 15);
@@ -197,7 +197,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, THREE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_OnBillingDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 7);
final DateTime changeDate = buildDateTime(2011, 5, 7);
@@ -210,7 +210,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_AfterBillingDay() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 2, 7);
final DateTime changeDate = buildDateTime(2011, 5, 10);
@@ -225,7 +225,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testPlanChange_DoubleProRation() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 31);
final DateTime planChangeDate = buildDateTime(2011, 5, 10);
@@ -241,7 +241,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testStartTargetEnd() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 12, 15);
final DateTime targetDate = buildDateTime(2011, 6, 15);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java
index 15e63b2..bb40078 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java
@@ -31,7 +31,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
return BillingPeriod.QUARTERLY;
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateOnStartDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 9, 25);
@@ -40,7 +40,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateInFirstBillingPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 9, 25);
@@ -49,7 +49,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, ONE);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateAtEndOfFirstBillingCycle() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 9, 25);
@@ -59,7 +59,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateInProRationPeriod() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 9, 25);
@@ -69,7 +69,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateOnEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 9, 25);
@@ -78,7 +78,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, endDate, endDate, 17, expectedValue);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testTargetDateAfterEndDate() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2010, 6, 17);
final DateTime endDate = buildDateTime(2010, 9, 25);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java
index e00fad9..6dcf75a 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java
@@ -40,7 +40,7 @@ public class TestValidationProRation extends ProRationTestBase {
return new InAdvanceBillingMode();
}
- @Test(groups = {"fast"}, expectedExceptions = InvalidDateSequenceException.class)
+ @Test(groups = "fast", expectedExceptions = InvalidDateSequenceException.class)
public void testTargetStartEnd() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 30);
final DateTime endDate = buildDateTime(2011, 3, 15);
@@ -49,7 +49,7 @@ public class TestValidationProRation extends ProRationTestBase {
calculateNumberOfBillingCycles(startDate, endDate, targetDate, 15);
}
- @Test(groups = {"fast"},expectedExceptions = InvalidDateSequenceException.class)
+ @Test(groups = "fast", expectedExceptions = InvalidDateSequenceException.class)
public void testTargetEndStart() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 4, 30);
final DateTime endDate = buildDateTime(2011, 3, 15);
@@ -58,7 +58,7 @@ public class TestValidationProRation extends ProRationTestBase {
calculateNumberOfBillingCycles(startDate, endDate, targetDate, 15);
}
- @Test(groups = {"fast"},expectedExceptions = InvalidDateSequenceException.class)
+ @Test(groups = "fast", expectedExceptions = InvalidDateSequenceException.class)
public void testEndTargetStart() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 3, 30);
final DateTime endDate = buildDateTime(2011, 1, 15);
@@ -67,7 +67,7 @@ public class TestValidationProRation extends ProRationTestBase {
calculateNumberOfBillingCycles(startDate, endDate, targetDate, 15);
}
- @Test(groups = {"fast"},expectedExceptions = InvalidDateSequenceException.class)
+ @Test(groups = "fast", expectedExceptions = InvalidDateSequenceException.class)
public void testEndStartTarget() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 1, 30);
final DateTime endDate = buildDateTime(2011, 1, 15);
@@ -76,7 +76,7 @@ public class TestValidationProRation extends ProRationTestBase {
calculateNumberOfBillingCycles(startDate, endDate, targetDate, 15);
}
- @Test(groups = {"fast"},expectedExceptions = InvalidDateSequenceException.class)
+ @Test(groups = "fast", expectedExceptions = InvalidDateSequenceException.class)
public void testTargetStart() throws InvalidDateSequenceException {
final DateTime startDate = buildDateTime(2011, 4, 30);
final DateTime targetDate = buildDateTime(2011, 2, 15);
@@ -84,7 +84,7 @@ public class TestValidationProRation extends ProRationTestBase {
calculateNumberOfBillingCycles(startDate, targetDate, 15);
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testBigDecimalTruncation() {
final BigDecimal value = new BigDecimal("1.3349573498567");
final BigDecimal truncated = value.setScale(0, BigDecimal.ROUND_DOWN).setScale(NUMBER_OF_DECIMALS);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/InvoicingTestBase.java b/invoice/src/test/java/com/ning/billing/invoice/tests/InvoicingTestBase.java
index 1b4efdd..edb4450 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/InvoicingTestBase.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/InvoicingTestBase.java
@@ -31,9 +31,10 @@ import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.billing.BillingEvent;
import com.ning.billing.entitlement.api.billing.BillingModeType;
import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.invoice.InvoiceTestSuiteWithEmbeddedDB;
import com.ning.billing.invoice.model.InvoicingConfiguration;
-public abstract class InvoicingTestBase {
+public abstract class InvoicingTestBase extends InvoiceTestSuiteWithEmbeddedDB {
protected static final int NUMBER_OF_DECIMALS = InvoicingConfiguration.getNumberOfDecimals();
protected static final int ROUNDING_METHOD = InvoicingConfiguration.getRoundingMode();
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/TestChargeBacks.java b/invoice/src/test/java/com/ning/billing/invoice/tests/TestChargeBacks.java
index 23c31c2..7989167 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/TestChargeBacks.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/TestChargeBacks.java
@@ -23,13 +23,16 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
+import org.mockito.Mockito;
import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.exceptions.TransactionFailedException;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.invoice.InvoiceTestSuiteWithEmbeddedDB;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceApiException;
import com.ning.billing.invoice.api.InvoiceItem;
@@ -44,14 +47,11 @@ import com.ning.billing.invoice.glue.InvoiceModuleWithEmbeddedDb;
import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.notification.MockNextBillingDatePoster;
import com.ning.billing.invoice.notification.NextBillingDatePoster;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.api.TagUserApi;
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.ClockMock;
-import com.ning.billing.util.io.IOUtils;
import com.ning.billing.util.tag.api.DefaultTagUserApi;
import com.ning.billing.util.tag.dao.MockTagDao;
import com.ning.billing.util.tag.dao.MockTagDefinitionDao;
@@ -63,7 +63,7 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-public class TestChargeBacks {
+public class TestChargeBacks extends InvoiceTestSuiteWithEmbeddedDB {
private static final BigDecimal FIFTEEN = new BigDecimal("15.00");
private static final BigDecimal THIRTY = new BigDecimal("30.00");
private static final BigDecimal ONE_MILLION = new BigDecimal("1000000.00");
@@ -73,22 +73,13 @@ public class TestChargeBacks {
private final Clock clock = new ClockMock();
private static final Currency CURRENCY = Currency.EUR;
-
- @BeforeSuite(groups = {"slow"})
+ @BeforeSuite(groups = "slow")
public void setup() throws IOException {
-
loadSystemPropertiesFromClasspath("/resource.properties");
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
final IDBI dbi = helper.getDBI();
- final String invoiceDdl = IOUtils.toString(DefaultInvoiceDao.class.getResourceAsStream("/com/ning/billing/invoice/ddl.sql"));
- final String utilDdl = IOUtils.toString(DefaultInvoiceDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
- helper.startMysql();
- helper.initDb(invoiceDdl);
- helper.initDb(utilDdl);
-
invoiceSqlDao = dbi.onDemand(InvoiceSqlDao.class);
invoiceSqlDao.test();
@@ -102,7 +93,6 @@ public class TestChargeBacks {
context = new TestCallContext("Charge back tests");
}
-
private static void loadSystemPropertiesFromClasspath(final String resource) {
final URL url = InvoiceModuleWithEmbeddedDb.class.getResource(resource);
assertNotNull(url);
@@ -113,8 +103,7 @@ public class TestChargeBacks {
}
}
-
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testCompleteChargeBack() throws InvoiceApiException {
final Invoice invoice = createAndPersistInvoice(THIRTY);
final InvoicePayment payment = createAndPersistPayment(invoice.getId(), THIRTY);
@@ -127,7 +116,7 @@ public class TestChargeBacks {
assertTrue(amount.compareTo(BigDecimal.ZERO) == 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testPartialChargeBack() throws InvoiceApiException {
final Invoice invoice = createAndPersistInvoice(THIRTY);
final InvoicePayment payment = createAndPersistPayment(invoice.getId(), THIRTY);
@@ -140,7 +129,7 @@ public class TestChargeBacks {
assertTrue(amount.compareTo(FIFTEEN) == 0);
}
- @Test(groups = {"slow"}, expectedExceptions = InvoiceApiException.class)
+ @Test(groups = "slow", expectedExceptions = InvoiceApiException.class)
public void testChargeBackLargerThanPaymentAmount() throws InvoiceApiException {
try {
final Invoice invoice = createAndPersistInvoice(THIRTY);
@@ -154,7 +143,7 @@ public class TestChargeBacks {
}
}
- @Test(groups = {"slow"}, expectedExceptions = InvoiceApiException.class)
+ @Test(groups = "slow", expectedExceptions = InvoiceApiException.class)
public void testNegativeChargeBackAmount() throws InvoiceApiException {
try {
final Invoice invoice = createAndPersistInvoice(THIRTY);
@@ -167,7 +156,7 @@ public class TestChargeBacks {
}
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetAccountIdFromPaymentIdHappyPath() throws InvoiceApiException {
final Invoice invoice = createAndPersistInvoice(THIRTY);
final InvoicePayment payment = createAndPersistPayment(invoice.getId(), THIRTY);
@@ -175,19 +164,19 @@ public class TestChargeBacks {
assertEquals(accountId, invoice.getAccountId());
}
- @Test(groups = {"slow"}, expectedExceptions = InvoiceApiException.class)
+ @Test(groups = "slow", expectedExceptions = InvoiceApiException.class)
public void testGetAccountIdFromPaymentIdBadPaymentId() throws InvoiceApiException {
invoicePaymentApi.getAccountIdFromInvoicePaymentId(UUID.randomUUID());
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetChargeBacksByAccountIdWithEmptyReturnSet() throws InvoiceApiException {
final List<InvoicePayment> chargebacks = invoicePaymentApi.getChargebacksByAccountId(UUID.randomUUID());
assertNotNull(chargebacks);
assertEquals(chargebacks.size(), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetChargeBacksByAccountIdHappyPath() throws InvoiceApiException {
final Invoice invoice = createAndPersistInvoice(THIRTY);
final InvoicePayment payment = createAndPersistPayment(invoice.getId(), THIRTY);
@@ -201,14 +190,14 @@ public class TestChargeBacks {
assertEquals(chargebacks.get(0).getLinkedInvoicePaymentId(), payment.getId());
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetChargeBacksByPaymentIdWithEmptyReturnSet() throws InvoiceApiException {
final List<InvoicePayment> chargebacks = invoicePaymentApi.getChargebacksByPaymentId(UUID.randomUUID());
assertNotNull(chargebacks);
assertEquals(chargebacks.size(), 0);
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testGetChargeBacksByInvoicePaymentIdHappyPath() throws InvoiceApiException {
final Invoice invoice = createAndPersistInvoice(THIRTY);
final InvoicePayment payment = createAndPersistPayment(invoice.getId(), THIRTY);
@@ -223,20 +212,20 @@ public class TestChargeBacks {
}
private Invoice createAndPersistInvoice(final BigDecimal amount) {
- final Invoice invoice = BrainDeadProxyFactory.createBrainDeadProxyFor(Invoice.class);
+ final Invoice invoice = Mockito.mock(Invoice.class);
final UUID invoiceId = UUID.randomUUID();
final UUID accountId = UUID.randomUUID();
- final ZombieControl zombie = (ZombieControl) invoice;
- zombie.addResult("getId", invoiceId);
- zombie.addResult("getAccountId", accountId);
- zombie.addResult("getInvoiceDate", clock.getUTCNow());
- zombie.addResult("getTargetDate", clock.getUTCNow());
- zombie.addResult("getCurrency", CURRENCY);
- zombie.addResult("isMigrationInvoice", false);
+
+ Mockito.when(invoice.getId()).thenReturn(invoiceId);
+ Mockito.when(invoice.getAccountId()).thenReturn(accountId);
+ Mockito.when(invoice.getInvoiceDate()).thenReturn(clock.getUTCNow());
+ Mockito.when(invoice.getTargetDate()).thenReturn(clock.getUTCNow());
+ Mockito.when(invoice.getCurrency()).thenReturn(CURRENCY);
+ Mockito.when(invoice.isMigrationInvoice()).thenReturn(false);
final List<InvoiceItem> items = new ArrayList<InvoiceItem>();
items.add(createInvoiceItem(invoiceId, accountId, amount));
- zombie.addResult("getInvoiceItems", items);
+ Mockito.when(invoice.getInvoiceItems()).thenReturn(items);
invoiceSqlDao.create(invoice, context);
@@ -249,17 +238,15 @@ public class TestChargeBacks {
}
private InvoicePayment createAndPersistPayment(final UUID invoiceId, final BigDecimal amount) {
- final InvoicePayment payment = BrainDeadProxyFactory.createBrainDeadProxyFor(InvoicePayment.class);
- final ZombieControl zombie = (ZombieControl) payment;
- zombie.addResult("getId", UUID.randomUUID());
- zombie.addResult("getType", InvoicePaymentType.ATTEMPT);
- zombie.addResult("getInvoiceId", invoiceId);
- zombie.addResult("getPaymentId", UUID.randomUUID());
- zombie.addResult("getPaymentDate", clock.getUTCNow());
- zombie.addResult("getAmount", amount);
- zombie.addResult("getCurrency", CURRENCY);
- zombie.addResult("getLinkedInvoicePaymentId", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getPaymentCookieId", BrainDeadProxyFactory.ZOMBIE_VOID);
+ final InvoicePayment payment = Mockito.mock(InvoicePayment.class);
+ Mockito.when(payment.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(payment.getType()).thenReturn(InvoicePaymentType.ATTEMPT);
+ Mockito.when(payment.getInvoiceId()).thenReturn(invoiceId);
+ Mockito.when(payment.getPaymentId()).thenReturn(UUID.randomUUID());
+ Mockito.when(payment.getPaymentDate()).thenReturn(clock.getUTCNow());
+ Mockito.when(payment.getAmount()).thenReturn(amount);
+ Mockito.when(payment.getCurrency()).thenReturn(CURRENCY);
+
invoicePaymentApi.notifyOfPayment(payment, context);
return payment;
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/InvoiceResource.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/InvoiceResource.java
index 822e0ab..1144a36 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/InvoiceResource.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/InvoiceResource.java
@@ -208,6 +208,9 @@ public class InvoiceResource extends JaxRsResourceBase {
@HeaderParam(HDR_CREATED_BY) final String createdBy,
@HeaderParam(HDR_REASON) final String reason,
@HeaderParam(HDR_COMMENT) final String comment) {
+ if (externalPayment) {
+ return Response.status(Status.BAD_REQUEST).entity("External payments have not been implemented yet").build();
+ }
try {
final Account account = accountApi.getAccountById(UUID.fromString(payment.getAccountId()));
paymentApi.createPayment(account, UUID.fromString(payment.getInvoiceId()), null, context.createContext(createdBy, reason, comment));
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/SubscriptionResource.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/SubscriptionResource.java
index 969830c..6cb4de1 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/SubscriptionResource.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/SubscriptionResource.java
@@ -49,7 +49,7 @@ import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
import com.ning.billing.entitlement.api.user.EntitlementUserApi;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
-import com.ning.billing.invoice.api.EmptyInvoiceEvent;
+import com.ning.billing.invoice.api.NullInvoiceEvent;
import com.ning.billing.invoice.api.InvoiceCreationEvent;
import com.ning.billing.jaxrs.json.CustomFieldJson;
import com.ning.billing.jaxrs.json.SubscriptionJsonNoEvents;
@@ -295,7 +295,7 @@ public class SubscriptionResource extends JaxRsResourceBase {
}
@Override
- public void onEmptyInvoice(final EmptyInvoiceEvent curEvent) {
+ public void onEmptyInvoice(final NullInvoiceEvent curEvent) {
log.info(String.format("Got event EmptyInvoiceNotification token = %s ", curEvent.getUserToken()));
notifyForCompletion();
}
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/JaxrsTestSuite.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/JaxrsTestSuite.java
new file mode 100644
index 0000000..51e2ac7
--- /dev/null
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/JaxrsTestSuite.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.jaxrs;
+
+import com.ning.billing.KillbillTestSuite;
+
+public abstract class JaxrsTestSuite extends KillbillTestSuite {
+}
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountEmailJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountEmailJson.java
index c9e55f8..08a56fd 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountEmailJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountEmailJson.java
@@ -23,8 +23,9 @@ import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ning.billing.account.api.AccountEmail;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestAccountEmailJson {
+public class TestAccountEmailJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java
index 96b497f..f06c4ea 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJson.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.jaxrs.json;
import java.util.UUID;
@@ -24,9 +25,10 @@ import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ning.billing.account.api.Account;
import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
import com.ning.billing.mock.MockAccountBuilder;
-public class TestAccountJson {
+public class TestAccountJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJsonSimple.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJsonSimple.java
index 386d7cd..b26c086 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJsonSimple.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountJsonSimple.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.jaxrs.json;
import java.util.UUID;
@@ -21,8 +22,9 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestAccountJsonSimple {
+public class TestAccountJsonSimple extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountTimelineJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountTimelineJson.java
index 50b9a4f..612557f 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountTimelineJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestAccountTimelineJson.java
@@ -16,5 +16,7 @@
package com.ning.billing.jaxrs.json;
-public class TestAccountTimelineJson {
+import com.ning.billing.jaxrs.JaxrsTestSuite;
+
+public class TestAccountTimelineJson extends JaxrsTestSuite {
}
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonNoSubscriptions.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonNoSubscriptions.java
index e0e89ea..97caed0 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonNoSubscriptions.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonNoSubscriptions.java
@@ -24,8 +24,9 @@ import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestBundleJsonNoSubscriptions {
+public class TestBundleJsonNoSubscriptions extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonSimple.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonSimple.java
index 7ac93ed..e00ed56 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonSimple.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonSimple.java
@@ -22,8 +22,9 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestBundleJsonSimple {
+public class TestBundleJsonSimple extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonWithSubscriptions.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonWithSubscriptions.java
index 5c65a7d..84cac3c 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonWithSubscriptions.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleJsonWithSubscriptions.java
@@ -36,9 +36,10 @@ import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.timeline.BundleTimeline;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
import com.ning.billing.util.clock.DefaultClock;
-public class TestBundleJsonWithSubscriptions {
+public class TestBundleJsonWithSubscriptions extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleTimelineJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleTimelineJson.java
index 0331473..d6bf35f 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleTimelineJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestBundleTimelineJson.java
@@ -35,9 +35,10 @@ import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
import com.ning.billing.util.clock.DefaultClock;
-public class TestBundleTimelineJson {
+public class TestBundleTimelineJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
@@ -158,7 +159,6 @@ public class TestBundleTimelineJson {
final String currency = "USD";
final String status = UUID.randomUUID().toString();
-
return new PaymentJsonSimple(amount, paidAmount, accountId.toString(), invoiceId.toString(), paymentId.toString(),
paymentRequestedDate, paymentEffectiveDate, retryCount,
currency, status);
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackCollectionJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackCollectionJson.java
index b9a7612..af4c8c6 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackCollectionJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackCollectionJson.java
@@ -28,8 +28,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.google.common.collect.ImmutableList;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestChargebackCollectionJson {
+public class TestChargebackCollectionJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackJson.java
index 3806741..006582d 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackJson.java
@@ -27,8 +27,9 @@ import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestChargebackJson {
+public class TestChargebackJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCreditCollectionJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCreditCollectionJson.java
index 5a93778..31be145 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCreditCollectionJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCreditCollectionJson.java
@@ -28,8 +28,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.google.common.collect.ImmutableList;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestCreditCollectionJson {
+public class TestCreditCollectionJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCreditJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCreditJson.java
index eee0cef..b15b6d1 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCreditJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCreditJson.java
@@ -27,8 +27,9 @@ import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestCreditJson {
+public class TestCreditJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCustomFieldJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCustomFieldJson.java
index ab7af78..6342b57 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCustomFieldJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestCustomFieldJson.java
@@ -22,8 +22,9 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestCustomFieldJson {
+public class TestCustomFieldJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceEmailJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceEmailJson.java
index c859596..f72ba4c 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceEmailJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceEmailJson.java
@@ -22,8 +22,9 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestInvoiceEmailJson {
+public class TestInvoiceEmailJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceItemJsonSimple.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceItemJsonSimple.java
index ec9fc54..3191568 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceItemJsonSimple.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceItemJsonSimple.java
@@ -30,8 +30,9 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.invoice.api.InvoiceItem;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestInvoiceItemJsonSimple {
+public class TestInvoiceItemJsonSimple extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonSimple.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonSimple.java
index bd5ab0d..0080402 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonSimple.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonSimple.java
@@ -29,8 +29,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.ning.billing.invoice.api.Invoice;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestInvoiceJsonSimple {
+public class TestInvoiceJsonSimple extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonWithBundleKeys.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonWithBundleKeys.java
index dd4cbad..e50bd4b 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonWithBundleKeys.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonWithBundleKeys.java
@@ -29,8 +29,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.ning.billing.invoice.api.Invoice;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestInvoiceJsonWithBundleKeys {
+public class TestInvoiceJsonWithBundleKeys extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonWithItems.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonWithItems.java
index 89766c0..8722422 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonWithItems.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestInvoiceJsonWithItems.java
@@ -32,8 +32,9 @@ import com.google.common.collect.ImmutableList;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceItem;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestInvoiceJsonWithItems {
+public class TestInvoiceJsonWithItems extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestPlanDetailJason.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestPlanDetailJason.java
index ee7ba0d..49f7e44 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestPlanDetailJason.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestPlanDetailJason.java
@@ -30,8 +30,9 @@ import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.catalog.api.PriceList;
import com.ning.billing.catalog.api.Product;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestPlanDetailJason {
+public class TestPlanDetailJason extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonNoEvents.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonNoEvents.java
index c663b30..d4e62f0 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonNoEvents.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonNoEvents.java
@@ -35,8 +35,9 @@ import com.ning.billing.catalog.api.PriceList;
import com.ning.billing.catalog.api.Product;
import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestSubscriptionJsonNoEvents {
+public class TestSubscriptionJsonNoEvents extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonSimple.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonSimple.java
index de6523d..e4631f9 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonSimple.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonSimple.java
@@ -22,8 +22,9 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestSubscriptionJsonSimple {
+public class TestSubscriptionJsonSimple extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonWithEvents.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonWithEvents.java
index 874f6bb..a0dac08 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonWithEvents.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestSubscriptionJsonWithEvents.java
@@ -35,9 +35,10 @@ import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.timeline.SubscriptionTimeline;
import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
import com.ning.billing.util.clock.DefaultClock;
-public class TestSubscriptionJsonWithEvents {
+public class TestSubscriptionJsonWithEvents extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
static {
@@ -64,7 +65,6 @@ public class TestSubscriptionJsonWithEvents {
null,
null);
-
final String asJson = mapper.writeValueAsString(subscriptionJsonWithEvents);
final SubscriptionJsonWithEvents.SubscriptionReadEventJson event = subscriptionJsonWithEvents.getEvents().get(0);
Assert.assertEquals(asJson, "{\"events\":[{\"eventId\":\"" + event.getEventId() + "\"," +
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestTagDefinitionJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestTagDefinitionJson.java
index 16a2cb6..d771085 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestTagDefinitionJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestTagDefinitionJson.java
@@ -22,8 +22,9 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
-public class TestTagDefinitionJson {
+public class TestTagDefinitionJson extends JaxrsTestSuite {
private static final ObjectMapper mapper = new ObjectMapper();
@Test(groups = "fast")
diff --git a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultBillingApi.java b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultBillingApi.java
index 7aa55ff..3bc8f28 100644
--- a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultBillingApi.java
+++ b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultBillingApi.java
@@ -111,10 +111,10 @@ public class DefaultBillingApi implements BillingApi {
private void debugLog(final SortedSet<BillingEvent> result, final String title) {
- log.debug(title);
+ log.info(title);
final Iterator<BillingEvent> i = result.iterator();
while (i.hasNext()) {
- log.debug(i.next().toString());
+ log.info(i.next().toString());
}
}
diff --git a/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java b/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
index b8f4343..de56229 100644
--- a/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
+++ b/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
@@ -16,71 +16,41 @@
package com.ning.billing.junction.api.blocking;
-import java.io.IOException;
import java.util.SortedSet;
import java.util.UUID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.mockito.Mockito;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.inject.Inject;
-import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.junction.JunctionTestSuiteWithEmbeddedDB;
import com.ning.billing.junction.MockModule;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApi;
import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.junction.api.DefaultBlockingState;
-import com.ning.billing.junction.dao.TestBlockingDao;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.mock.glue.MockEntitlementModule;
import com.ning.billing.util.clock.ClockMock;
-import com.ning.billing.util.io.IOUtils;
@Guice(modules = {MockModule.class, MockEntitlementModule.class})
-public class TestBlockingApi {
- private final Logger log = LoggerFactory.getLogger(TestBlockingDao.class);
-
- @Inject
- private MysqlTestingHelper helper;
-
+public class TestBlockingApi extends JunctionTestSuiteWithEmbeddedDB {
@Inject
private BlockingApi api;
@Inject
private ClockMock clock;
- @BeforeClass(groups = {"slow"})
- public void setup() throws IOException {
- log.info("Starting set up TestBlockingApi");
-
- final String utilDdl = IOUtils.toString(TestBlockingDao.class.getResourceAsStream("/com/ning/billing/junction/ddl.sql"));
-
- helper.startMysql();
- helper.initDb(utilDdl);
- }
-
- @BeforeMethod(groups = {"slow"})
+ @BeforeMethod(groups = "slow")
public void clean() {
- helper.cleanupTable("blocking_states");
clock.resetDeltaFromReality();
}
- @AfterClass(groups = "slow")
- public void stopMysql() {
- helper.stopMysql();
- }
-
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testApi() {
-
final UUID uuid = UUID.randomUUID();
final String overdueStateName = "WayPassedItMan";
final String service = "TEST";
@@ -97,15 +67,14 @@ public class TestBlockingApi {
final BlockingState state2 = new DefaultBlockingState(uuid, overdueStateName2, Blockable.Type.SUBSCRIPTION_BUNDLE, service, blockChange, blockEntitlement, blockBilling);
api.setBlockingState(state2);
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getId", uuid);
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getId()).thenReturn(uuid);
Assert.assertEquals(api.getBlockingStateFor(bundle).getStateName(), overdueStateName2);
Assert.assertEquals(api.getBlockingStateFor(bundle.getId()).getStateName(), overdueStateName2);
-
}
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testApiHistory() throws Exception {
final UUID uuid = UUID.randomUUID();
final String overdueStateName = "WayPassedItMan";
@@ -124,9 +93,8 @@ public class TestBlockingApi {
final BlockingState state2 = new DefaultBlockingState(uuid, overdueStateName2, Blockable.Type.SUBSCRIPTION_BUNDLE, service, blockChange, blockEntitlement, blockBilling);
api.setBlockingState(state2);
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getId", uuid);
-
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getId()).thenReturn(uuid);
final SortedSet<BlockingState> history1 = api.getBlockingHistory(bundle);
final SortedSet<BlockingState> history2 = api.getBlockingHistory(bundle.getId());
@@ -138,7 +106,5 @@ public class TestBlockingApi {
Assert.assertEquals(history2.size(), 2);
Assert.assertEquals(history2.first().getStateName(), overdueStateName);
Assert.assertEquals(history2.last().getStateName(), overdueStateName2);
-
}
-
}
diff --git a/junction/src/test/java/com/ning/billing/junction/blocking/MockBlockingChecker.java b/junction/src/test/java/com/ning/billing/junction/blocking/MockBlockingChecker.java
index ccf372b..0fa2e8c 100644
--- a/junction/src/test/java/com/ning/billing/junction/blocking/MockBlockingChecker.java
+++ b/junction/src/test/java/com/ning/billing/junction/blocking/MockBlockingChecker.java
@@ -24,11 +24,9 @@ import com.ning.billing.junction.api.BlockingApiException;
import com.ning.billing.junction.block.BlockingChecker;
public class MockBlockingChecker implements BlockingChecker {
-
@Override
public void checkBlockedChange(final Blockable blockable) throws BlockingApiException {
// Intentionally blank
-
}
@Override
@@ -55,5 +53,4 @@ public class MockBlockingChecker implements BlockingChecker {
public void checkBlockedBilling(final UUID bundleId, final Type type) throws BlockingApiException {
// Intentionally blank
}
-
}
diff --git a/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java b/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
index 43a2e79..9959583 100644
--- a/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
+++ b/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
@@ -19,6 +19,7 @@ package com.ning.billing.junction.blocking;
import java.util.SortedSet;
import java.util.UUID;
+import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -28,8 +29,10 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.ning.billing.account.api.Account;
import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.junction.JunctionTestSuite;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApiException;
import com.ning.billing.junction.api.BlockingState;
@@ -37,18 +40,14 @@ import com.ning.billing.junction.api.DefaultBlockingState;
import com.ning.billing.junction.block.BlockingChecker;
import com.ning.billing.junction.block.DefaultBlockingChecker;
import com.ning.billing.junction.dao.BlockingStateDao;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.clock.Clock;
-public class TestBlockingChecker {
-
+public class TestBlockingChecker extends JunctionTestSuite {
private BlockingState bundleState;
private BlockingState subscriptionState;
private BlockingState accountState;
private final BlockingStateDao dao = new BlockingStateDao() {
-
@Override
public BlockingState getBlockingStateFor(final Blockable blockable) {
if (blockable.getId() == account.getId()) {
@@ -92,43 +91,44 @@ public class TestBlockingChecker {
private Account account;
private SubscriptionBundle bundle;
- @BeforeClass(groups = {"fast"})
+ @BeforeClass(groups = "fast")
public void setup() {
- account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getId", UUID.randomUUID());
-
- bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getAccountId", account.getId());
- ((ZombieControl) bundle).addResult("getId", UUID.randomUUID());
- ((ZombieControl) bundle).addResult("getKey", "key");
+ final UUID accountId = UUID.randomUUID();
+ account = Mockito.mock(Account.class);
+ Mockito.when(account.getId()).thenReturn(accountId);
- subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) subscription).addResult("getId", UUID.randomUUID());
- ((ZombieControl) subscription).addResult("getBundleId", bundle.getId());
+ bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getAccountId()).thenReturn(accountId);
+ final UUID bundleId = UUID.randomUUID();
+ Mockito.when(bundle.getId()).thenReturn(bundleId);
+ Mockito.when(bundle.getKey()).thenReturn("key");
+ subscription = Mockito.mock(Subscription.class);
+ Mockito.when(subscription.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(subscription.getBundleId()).thenReturn(bundleId);
final Injector i = Guice.createInjector(new AbstractModule() {
-
@Override
protected void configure() {
bind(BlockingChecker.class).to(DefaultBlockingChecker.class).asEagerSingleton();
bind(BlockingStateDao.class).toInstance(dao);
- final EntitlementUserApi entitlementUserApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class);
+ final EntitlementUserApi entitlementUserApi = Mockito.mock(EntitlementUserApi.class);
bind(EntitlementUserApi.class).toInstance(entitlementUserApi);
- ((ZombieControl) entitlementUserApi).addResult("getBundleFromId", bundle);
-
+ try {
+ Mockito.when(entitlementUserApi.getBundleFromId(Mockito.<UUID>any())).thenReturn(bundle);
+ } catch (EntitlementUserApiException e) {
+ Assert.fail(e.toString());
+ }
}
-
});
checker = i.getInstance(BlockingChecker.class);
}
-
private void setStateBundle(final boolean bC, final boolean bE, final boolean bB) {
bundleState = new DefaultBlockingState(UUID.randomUUID(), "state", Blockable.Type.SUBSCRIPTION_BUNDLE, "test-service", bC, bE, bB);
- ((ZombieControl) bundle).addResult("getBlockingState", bundleState);
+ Mockito.when(bundle.getBlockingState()).thenReturn(bundleState);
}
private void setStateAccount(final boolean bC, final boolean bE, final boolean bB) {
@@ -137,10 +137,10 @@ public class TestBlockingChecker {
private void setStateSubscription(final boolean bC, final boolean bE, final boolean bB) {
subscriptionState = new DefaultBlockingState(UUID.randomUUID(), "state", Blockable.Type.SUBSCRIPTION_BUNDLE, "test-service", bC, bE, bB);
- ((ZombieControl) subscription).addResult("getBlockingState", subscriptionState);
+ Mockito.when(subscription.getBlockingState()).thenReturn(subscriptionState);
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testSubscriptionChecker() throws Exception {
setStateAccount(false, false, false);
setStateBundle(false, false, false);
@@ -212,7 +212,6 @@ public class TestBlockingChecker {
//Expected behavior
}
-
//BLOCKED ACCOUNT
setStateSubscription(false, false, false);
setStateBundle(false, false, false);
@@ -245,11 +244,9 @@ public class TestBlockingChecker {
} catch (BlockingApiException e) {
//Expected behavior
}
-
-
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testBundleChecker() throws Exception {
setStateAccount(false, false, false);
setStateBundle(false, false, false);
@@ -290,7 +287,6 @@ public class TestBlockingChecker {
//Expected behavior
}
-
//BLOCKED ACCOUNT
setStateSubscription(false, false, false);
setStateBundle(false, false, false);
@@ -323,11 +319,9 @@ public class TestBlockingChecker {
} catch (BlockingApiException e) {
//Expected behavior
}
-
-
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testAccountChecker() throws Exception {
setStateAccount(false, false, false);
setStateBundle(false, false, false);
@@ -368,9 +362,5 @@ public class TestBlockingChecker {
} catch (BlockingApiException e) {
//Expected behavior
}
-
-
}
-
-
}
diff --git a/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java b/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
index 4659778..17c7f18 100644
--- a/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
+++ b/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
@@ -16,59 +16,30 @@
package com.ning.billing.junction.dao;
-import java.io.IOException;
import java.util.SortedSet;
import java.util.UUID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.mockito.Mockito;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.inject.Inject;
-import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.junction.JunctionTestSuiteWithEmbeddedDB;
import com.ning.billing.junction.MockModule;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.junction.api.DefaultBlockingState;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.mock.glue.MockEntitlementModule;
import com.ning.billing.util.clock.ClockMock;
-import com.ning.billing.util.io.IOUtils;
@Guice(modules = {MockModule.class, MockEntitlementModule.class})
-public class TestBlockingDao {
- private final Logger log = LoggerFactory.getLogger(TestBlockingDao.class);
-
- @Inject
- private MysqlTestingHelper helper;
-
+public class TestBlockingDao extends JunctionTestSuiteWithEmbeddedDB {
@Inject
private BlockingStateDao dao;
- @BeforeClass(groups = {"slow"})
- public void setup() throws IOException {
- log.info("Starting set up TestBlockingDao");
-
- final String utilDdl = IOUtils.toString(TestBlockingDao.class.getResourceAsStream("/com/ning/billing/junction/ddl.sql"));
-
- helper.startMysql();
- helper.initDb(utilDdl);
- }
-
- @AfterClass(groups = "slow")
- public void stopMysql() {
- if (helper != null) {
- helper.stopMysql();
- }
- }
-
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testDao() {
final ClockMock clock = new ClockMock();
final UUID uuid = UUID.randomUUID();
@@ -87,15 +58,14 @@ public class TestBlockingDao {
final BlockingState state2 = new DefaultBlockingState(uuid, overdueStateName2, Blockable.Type.SUBSCRIPTION_BUNDLE, service, blockChange, blockEntitlement, blockBilling);
dao.setBlockingState(state2, clock);
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getId", uuid);
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getId()).thenReturn(uuid);
Assert.assertEquals(dao.getBlockingStateFor(bundle).getStateName(), state2.getStateName());
Assert.assertEquals(dao.getBlockingStateFor(bundle.getId()).getStateName(), overdueStateName2);
-
}
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testDaoHistory() throws Exception {
final ClockMock clock = new ClockMock();
final UUID uuid = UUID.randomUUID();
@@ -114,9 +84,8 @@ public class TestBlockingDao {
final BlockingState state2 = new DefaultBlockingState(uuid, overdueStateName2, Blockable.Type.SUBSCRIPTION_BUNDLE, service, blockChange, blockEntitlement, blockBilling);
dao.setBlockingState(state2, clock);
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getId", uuid);
-
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getId()).thenReturn(uuid);
final SortedSet<BlockingState> history1 = dao.getBlockingHistoryFor(bundle);
final SortedSet<BlockingState> history2 = dao.getBlockingHistoryFor(bundle.getId());
@@ -128,7 +97,5 @@ public class TestBlockingDao {
Assert.assertEquals(history2.size(), 2);
Assert.assertEquals(history2.first().getStateName(), overdueStateName);
Assert.assertEquals(history2.last().getStateName(), overdueStateName2);
-
}
-
}
diff --git a/junction/src/test/java/com/ning/billing/junction/JunctionTestSuite.java b/junction/src/test/java/com/ning/billing/junction/JunctionTestSuite.java
new file mode 100644
index 0000000..69d5ebf
--- /dev/null
+++ b/junction/src/test/java/com/ning/billing/junction/JunctionTestSuite.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.junction;
+
+import com.ning.billing.KillbillTestSuite;
+
+public abstract class JunctionTestSuite extends KillbillTestSuite {
+}
diff --git a/junction/src/test/java/com/ning/billing/junction/JunctionTestSuiteWithEmbeddedDB.java b/junction/src/test/java/com/ning/billing/junction/JunctionTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..3089ee7
--- /dev/null
+++ b/junction/src/test/java/com/ning/billing/junction/JunctionTestSuiteWithEmbeddedDB.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.junction;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class JunctionTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/junction/src/test/java/com/ning/billing/junction/MockBlockingModule.java b/junction/src/test/java/com/ning/billing/junction/MockBlockingModule.java
index 2b7a0a9..3158d68 100644
--- a/junction/src/test/java/com/ning/billing/junction/MockBlockingModule.java
+++ b/junction/src/test/java/com/ning/billing/junction/MockBlockingModule.java
@@ -16,20 +16,18 @@
package com.ning.billing.junction;
+import org.mockito.Mockito;
+
import com.google.inject.AbstractModule;
import com.ning.billing.junction.api.BlockingApi;
import com.ning.billing.junction.dao.BlockingStateDao;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
public class MockBlockingModule extends AbstractModule {
- public static final String CLEAR_STATE = "Clear";
-
@Override
protected void configure() {
- final BlockingApi BlockingApi = BrainDeadProxyFactory.createBrainDeadProxyFor(BlockingApi.class);
- ((ZombieControl) BlockingApi).addResult("getOverdueStateNameFor", MockBlockingModule.CLEAR_STATE);
- bind(BlockingStateDao.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(BlockingStateDao.class));
- bind(BlockingApi.class).toInstance(BlockingApi);
+ bind(BlockingStateDao.class).toInstance(Mockito.mock(BlockingStateDao.class));
+
+ final BlockingApi blockingApi = Mockito.mock(BlockingApi.class);
+ bind(BlockingApi.class).toInstance(blockingApi);
}
}
diff --git a/junction/src/test/java/com/ning/billing/junction/MockModule.java b/junction/src/test/java/com/ning/billing/junction/MockModule.java
index 1291437..7865bcd 100644
--- a/junction/src/test/java/com/ning/billing/junction/MockModule.java
+++ b/junction/src/test/java/com/ning/billing/junction/MockModule.java
@@ -22,10 +22,7 @@ import com.ning.billing.mock.glue.MockClockModule;
import com.ning.billing.mock.glue.MockDbHelperModule;
import com.ning.billing.util.glue.CallContextModule;
-
public class MockModule extends DefaultJunctionModule {
- public static final String PLUGIN_NAME = "Booboo";
-
@Override
protected void configure() {
super.configure();
@@ -38,13 +35,10 @@ public class MockModule extends DefaultJunctionModule {
@Override
public void installBillingApi() {
- // no billinggApi
+ // no billing Api
}
@Override
public void installAccountUserApi() {
-
}
-
-
}
diff --git a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillingApi.java b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillingApi.java
index 2a31a6e..ad6522c 100644
--- a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillingApi.java
+++ b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillingApi.java
@@ -29,12 +29,14 @@ import java.util.UUID;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.ning.billing.account.api.Account;
+import com.ning.billing.account.api.AccountApiException;
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.catalog.MockCatalog;
import com.ning.billing.catalog.MockCatalogService;
@@ -54,9 +56,11 @@ import com.ning.billing.entitlement.api.billing.BillingEvent;
import com.ning.billing.entitlement.api.billing.BillingModeType;
import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.Subscription.SubscriptionState;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.junction.JunctionTestSuite;
import com.ning.billing.junction.api.BillingApi;
import com.ning.billing.junction.api.BillingEventSet;
import com.ning.billing.junction.api.Blockable;
@@ -64,8 +68,6 @@ import com.ning.billing.junction.api.BlockingApi;
import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.junction.api.DefaultBlockingState;
import com.ning.billing.lifecycle.KillbillService.ServiceException;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.mock.MockEffectiveSubscriptionEvent;
import com.ning.billing.mock.MockSubscription;
import com.ning.billing.util.api.TagUserApi;
@@ -83,8 +85,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
-public class TestBillingApi {
-
+public class TestBillingApi extends JunctionTestSuite {
class MockPrice implements InternationalPrice {
private final BigDecimal price;
@@ -101,7 +102,6 @@ public class TestBillingApi {
public Price[] getPrices() {
return new Price[]{
new Price() {
-
@Override
public Currency getCurrency() {
return Currency.USD;
@@ -111,7 +111,6 @@ public class TestBillingApi {
public BigDecimal getValue() throws CurrencyValueNull {
return price;
}
-
}
};
}
@@ -137,9 +136,7 @@ public class TestBillingApi {
private final BlockingCalculator blockCalculator = new BlockingCalculator(null) {
@Override
public void insertBlockingEvents(final SortedSet<BillingEvent> billingEvents) {
-
}
-
};
private Clock clock;
@@ -148,17 +145,17 @@ public class TestBillingApi {
private Plan subscriptionPlan;
private TagUserApi tagApi;
- @BeforeSuite(groups = {"fast", "slow"})
+ @BeforeSuite(groups = "fast")
public void setup() throws ServiceException {
catalogService = new MockCatalogService(new MockCatalog());
clock = new ClockMock();
}
- @BeforeMethod(groups = {"fast", "slow"})
- public void setupEveryTime() {
+ @BeforeMethod(groups = "fast")
+ public void setupEveryTime() throws EntitlementUserApiException {
final List<SubscriptionBundle> bundles = new ArrayList<SubscriptionBundle>();
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getId", bunId);
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getId()).thenReturn(bunId);
//new SubscriptionBundleData( eventId,"TestKey", subId, clock.getUTCNow().minusDays(4), null);
bundles.add(bundle);
@@ -171,26 +168,27 @@ public class TestBillingApi {
subscriptions.add(subscription);
- entitlementApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class);
- ((ZombieControl) entitlementApi).addResult("getBundlesForAccount", bundles);
- ((ZombieControl) entitlementApi).addResult("getSubscriptionsForBundle", subscriptions);
- ((ZombieControl) entitlementApi).addResult("getSubscriptionFromId", subscription);
- ((ZombieControl) entitlementApi).addResult("getBundleFromId", bundle);
- ((ZombieControl) entitlementApi).addResult("getBaseSubscription", subscription);
+ entitlementApi = Mockito.mock(EntitlementUserApi.class);
+ Mockito.when(entitlementApi.getBundlesForAccount(Mockito.<UUID>any())).thenReturn(bundles);
+ Mockito.when(entitlementApi.getSubscriptionsForBundle(Mockito.<UUID>any())).thenReturn(subscriptions);
+ Mockito.when(entitlementApi.getSubscriptionFromId(Mockito.<UUID>any())).thenReturn(subscription);
+ Mockito.when(entitlementApi.getBundleFromId(Mockito.<UUID>any())).thenReturn(bundle);
+ Mockito.when(entitlementApi.getBaseSubscription(Mockito.<UUID>any())).thenReturn(subscription);
tagApi = mock(TagUserApi.class);
assertTrue(true);
}
- @Test(enabled = true, groups = "fast")
- public void testBillingEventsEmpty() {
+ @Test(groups = "fast")
+ public void testBillingEventsEmpty() throws AccountApiException {
final UUID accountId = UUID.randomUUID();
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getId", accountId).addResult("getCurrency", Currency.USD);
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getId()).thenReturn(accountId);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
- final AccountUserApi accountApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- ((ZombieControl) accountApi).addResult("getAccountById", account);
+ final AccountUserApi accountApi = Mockito.mock(AccountUserApi.class);
+ Mockito.when(accountApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
final BillCycleDayCalculator bcdCalculator = new BillCycleDayCalculator(catalogService, entitlementApi);
final CallContextFactory factory = new DefaultCallContextFactory(clock);
@@ -201,8 +199,8 @@ public class TestBillingApi {
Assert.assertEquals(events.size(), 0);
}
- @Test(enabled = true, groups = "fast")
- public void testBillingEventsNoBillingPeriod() throws CatalogApiException {
+ @Test(groups = "fast")
+ public void testBillingEventsNoBillingPeriod() throws CatalogApiException, AccountApiException {
final DateTime now = clock.getUTCNow();
final DateTime then = now.minusDays(1);
final Plan nextPlan = catalogService.getFullCatalog().findPlan("PickupTrialEvergreen10USD", now);
@@ -217,13 +215,13 @@ public class TestBillingApi {
effectiveSubscriptionTransitions.add(t);
- final AccountUserApi accountApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getBillCycleDay", 32);
- ((ZombieControl) account).addResult("getCurrency", Currency.USD);
- ((ZombieControl) account).addResult("getId", UUID.randomUUID());
- ((ZombieControl) account).addResult("getTimeZone", DateTimeZone.UTC);
- ((ZombieControl) accountApi).addResult("getAccountById", account);
+ final AccountUserApi accountApi = Mockito.mock(AccountUserApi.class);
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getBillCycleDay()).thenReturn(32);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
+ Mockito.when(accountApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
final BillCycleDayCalculator bcdCalculator = new BillCycleDayCalculator(catalogService, entitlementApi);
final CallContextFactory factory = new DefaultCallContextFactory(clock);
@@ -234,7 +232,7 @@ public class TestBillingApi {
}
@Test(enabled = false, groups = "fast")
- public void testBillingEventsAnnual() throws CatalogApiException {
+ public void testBillingEventsAnnual() throws CatalogApiException, AccountApiException {
final DateTime now = clock.getUTCNow();
final DateTime then = now.minusDays(1);
final Plan nextPlan = catalogService.getFullCatalog().findPlan("PickupTrialEvergreen10USD", now);
@@ -248,14 +246,15 @@ public class TestBillingApi {
effectiveSubscriptionTransitions.add(t);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getBillCycleDay", 1).addResult("getTimeZone", DateTimeZone.UTC)
- .addResult("getCurrency", Currency.USD);
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getBillCycleDay()).thenReturn(1);
+ Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
((MockCatalog) catalogService.getFullCatalog()).setBillingAlignment(BillingAlignment.SUBSCRIPTION);
- final AccountUserApi accountApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- ((ZombieControl) accountApi).addResult("getAccountById", account);
+ final AccountUserApi accountApi = Mockito.mock(AccountUserApi.class);
+ Mockito.when(accountApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
final BillCycleDayCalculator bcdCalculator = new BillCycleDayCalculator(catalogService, entitlementApi);
final CallContextFactory factory = new DefaultCallContextFactory(clock);
@@ -266,8 +265,8 @@ public class TestBillingApi {
checkFirstEvent(events, nextPlan, subscription.getStartDate().plusDays(30).getDayOfMonth(), subId, now, nextPhase, SubscriptionTransitionType.CREATE.toString());
}
- @Test(enabled = true, groups = "fast")
- public void testBillingEventsMonthly() throws CatalogApiException {
+ @Test(groups = "fast")
+ public void testBillingEventsMonthly() throws CatalogApiException, AccountApiException {
final DateTime now = clock.getUTCNow();
final DateTime then = now.minusDays(1);
final Plan nextPlan = catalogService.getFullCatalog().findPlan("PickupTrialEvergreen10USD", now);
@@ -282,13 +281,13 @@ public class TestBillingApi {
effectiveSubscriptionTransitions.add(t);
- final AccountUserApi accountApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getBillCycleDay", 32);
- ((ZombieControl) account).addResult("getCurrency", Currency.USD);
- ((ZombieControl) account).addResult("getId", UUID.randomUUID());
- ((ZombieControl) account).addResult("getTimeZone", DateTimeZone.UTC);
- ((ZombieControl) accountApi).addResult("getAccountById", account);
+ final AccountUserApi accountApi = Mockito.mock(AccountUserApi.class);
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getBillCycleDay()).thenReturn(32);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
+ Mockito.when(accountApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
((MockCatalog) catalogService.getFullCatalog()).setBillingAlignment(BillingAlignment.ACCOUNT);
@@ -302,7 +301,7 @@ public class TestBillingApi {
}
@Test(enabled = false, groups = "fast")
- public void testBillingEventsAddOn() throws CatalogApiException {
+ public void testBillingEventsAddOn() throws CatalogApiException, AccountApiException {
final DateTime now = clock.getUTCNow();
final DateTime then = now.minusDays(1);
final Plan nextPlan = catalogService.getFullCatalog().findPlan("Horn1USD", now);
@@ -317,14 +316,15 @@ public class TestBillingApi {
effectiveSubscriptionTransitions.add(t);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getBillCycleDay", 1).addResult("getTimeZone", DateTimeZone.UTC);
- ((ZombieControl) account).addResult("getCurrency", Currency.USD);
- ((ZombieControl) account).addResult("getId", UUID.randomUUID());
- ((ZombieControl) account).addResult("getTimeZone", DateTimeZone.UTC);
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getBillCycleDay()).thenReturn(1);
+ Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
- final AccountUserApi accountApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- ((ZombieControl) accountApi).addResult("getAccountById", account);
+ final AccountUserApi accountApi = Mockito.mock(AccountUserApi.class);
+ Mockito.when(accountApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
((MockCatalog) catalogService.getFullCatalog()).setBillingAlignment(BillingAlignment.BUNDLE);
@@ -339,8 +339,8 @@ public class TestBillingApi {
checkFirstEvent(events, nextPlan, subscription.getStartDate().plusDays(30).getDayOfMonth(), subId, now, nextPhase, SubscriptionTransitionType.CREATE.toString());
}
- @Test(enabled = true, groups = "fast")
- public void testBillingEventsWithBlock() throws CatalogApiException {
+ @Test(groups = "fast")
+ public void testBillingEventsWithBlock() throws CatalogApiException, AccountApiException {
final DateTime now = clock.getUTCNow();
final DateTime then = now.minusDays(1);
final Plan nextPlan = catalogService.getFullCatalog().findPlan("PickupTrialEvergreen10USD", now);
@@ -355,13 +355,13 @@ public class TestBillingApi {
effectiveSubscriptionTransitions.add(t);
- final AccountUserApi accountApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getBillCycleDay", 32);
- ((ZombieControl) account).addResult("getCurrency", Currency.USD);
- ((ZombieControl) account).addResult("getTimeZone", DateTimeZone.UTC);
- ((ZombieControl) accountApi).addResult("getAccountById", account);
- ((ZombieControl) account).addResult("getId", UUID.randomUUID());
+ final AccountUserApi accountApi = Mockito.mock(AccountUserApi.class);
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getBillCycleDay()).thenReturn(32);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
+ Mockito.when(accountApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
+ Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
((MockCatalog) catalogService.getFullCatalog()).setBillingAlignment(BillingAlignment.ACCOUNT);
@@ -370,7 +370,6 @@ public class TestBillingApi {
blockingStates.add(new DefaultBlockingState(bunId, CLEAR_BUNDLE, Blockable.Type.SUBSCRIPTION_BUNDLE, "test", false, false, false, now.plusDays(2)));
final BlockingCalculator blockingCal = new BlockingCalculator(new BlockingApi() {
-
@Override
public <T extends Blockable> void setBlockingState(final BlockingState state) {
}
@@ -410,11 +409,10 @@ public class TestBillingApi {
checkEvent(it.next(), nextPlan, 32, subId, now, nextPhase, SubscriptionTransitionType.CREATE.toString(), nextPhase.getFixedPrice(), nextPhase.getRecurringPrice());
checkEvent(it.next(), nextPlan, 32, subId, now.plusDays(1), nextPhase, SubscriptionTransitionType.CANCEL.toString(), new MockPrice("0"), new MockPrice("0"));
checkEvent(it.next(), nextPlan, 32, subId, now.plusDays(2), nextPhase, SubscriptionTransitionType.RE_CREATE.toString(), nextPhase.getFixedPrice(), nextPhase.getRecurringPrice());
-
}
- @Test(enabled = true, groups = "fast")
- public void testBillingEventsAutoInvoicingOffAccount() throws CatalogApiException {
+ @Test(groups = "fast")
+ public void testBillingEventsAutoInvoicingOffAccount() throws CatalogApiException, AccountApiException {
final DateTime now = clock.getUTCNow();
final DateTime then = now.minusDays(1);
final Plan nextPlan = catalogService.getFullCatalog().findPlan("PickupTrialEvergreen10USD", now);
@@ -429,12 +427,12 @@ public class TestBillingApi {
effectiveSubscriptionTransitions.add(t);
- final AccountUserApi accountApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getBillCycleDay", 32);
- ((ZombieControl) account).addResult("getCurrency", Currency.USD);
- ((ZombieControl) account).addResult("getId", UUID.randomUUID());
- ((ZombieControl) accountApi).addResult("getAccountById", account);
+ final AccountUserApi accountApi = Mockito.mock(AccountUserApi.class);
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getBillCycleDay()).thenReturn(32);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(accountApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
final Map<String, Tag> tags = new HashMap<String, Tag>();
final Tag aioTag = mock(Tag.class);
@@ -455,8 +453,8 @@ public class TestBillingApi {
assertEquals(events.size(), 0);
}
- @Test(enabled = true, groups = "fast")
- public void testBillingEventsAutoInvoicingOffBundle() throws CatalogApiException {
+ @Test(groups = "fast")
+ public void testBillingEventsAutoInvoicingOffBundle() throws CatalogApiException, AccountApiException {
final DateTime now = clock.getUTCNow();
final DateTime then = now.minusDays(1);
final Plan nextPlan = catalogService.getFullCatalog().findPlan("PickupTrialEvergreen10USD", now);
@@ -471,12 +469,12 @@ public class TestBillingApi {
effectiveSubscriptionTransitions.add(t);
- final AccountUserApi accountApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getBillCycleDay", 32);
- ((ZombieControl) account).addResult("getCurrency", Currency.USD);
- ((ZombieControl) account).addResult("getId", UUID.randomUUID());
- ((ZombieControl) accountApi).addResult("getAccountById", account);
+ final AccountUserApi accountApi = Mockito.mock(AccountUserApi.class);
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getBillCycleDay()).thenReturn(32);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(accountApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
final Map<String, Tag> tags = new HashMap<String, Tag>();
final Tag aioTag = mock(Tag.class);
diff --git a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBlockingCalculator.java b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBlockingCalculator.java
index ce0b6dc..f17f681 100644
--- a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBlockingCalculator.java
+++ b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBlockingCalculator.java
@@ -27,6 +27,7 @@ import java.util.UUID;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -44,6 +45,7 @@ import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.billing.BillingEvent;
import com.ning.billing.entitlement.api.billing.BillingModeType;
import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.junction.JunctionTestSuite;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.Blockable.Type;
import com.ning.billing.junction.api.BlockingApi;
@@ -51,8 +53,6 @@ import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.junction.api.DefaultBlockingState;
import com.ning.billing.junction.dao.BlockingStateDao;
import com.ning.billing.junction.plumbing.billing.BlockingCalculator.DisabledDuration;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
@@ -60,9 +60,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
-
-public class TestBlockingCalculator {
-
+public class TestBlockingCalculator extends JunctionTestSuite {
private static final String DISABLED_BUNDLE = "disabled-bundle";
private static final String CLEAR_BUNDLE = "clear-bundle";
@@ -79,37 +77,29 @@ public class TestBlockingCalculator {
@BeforeClass
public void setUpBeforeClass() throws Exception {
-
clock = new ClockMock();
final Injector i = Guice.createInjector(new AbstractModule() {
-
@Override
protected void configure() {
- blockingApi = BrainDeadProxyFactory.createBrainDeadProxyFor(BlockingApi.class);
- account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- subscription1 = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class, Comparable.class);
- subscription2 = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class, Comparable.class);
- subscription3 = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class, Comparable.class);
- subscription4 = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class, Comparable.class);
- ((ZombieControl) account).addResult("getId", UUID.randomUUID());
- ((ZombieControl) subscription1).addResult("getBundleId", bundleId1);
- ((ZombieControl) subscription2).addResult("getBundleId", bundleId1);
- ((ZombieControl) subscription3).addResult("getBundleId", bundleId1);
- ((ZombieControl) subscription4).addResult("getBundleId", bundleId2);
- ((ZombieControl) subscription1).addResult("compareTo", 1);
- ((ZombieControl) subscription2).addResult("compareTo", 1);
- ((ZombieControl) subscription3).addResult("compareTo", 1);
- ((ZombieControl) subscription4).addResult("compareTo", 1);
- ((ZombieControl) subscription1).addResult("getId", UUID.randomUUID());
- ((ZombieControl) subscription2).addResult("getId", UUID.randomUUID());
- ((ZombieControl) subscription3).addResult("getId", UUID.randomUUID());
- ((ZombieControl) subscription4).addResult("getId", UUID.randomUUID());
-
-
- bind(BlockingStateDao.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(BlockingStateDao.class));
+ blockingApi = Mockito.mock(BlockingApi.class);
+ account = Mockito.mock(Account.class);
+ subscription1 = Mockito.mock(Subscription.class);
+ subscription2 = Mockito.mock(Subscription.class);
+ subscription3 = Mockito.mock(Subscription.class);
+ subscription4 = Mockito.mock(Subscription.class);
+ Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(subscription1.getBundleId()).thenReturn(bundleId1);
+ Mockito.when(subscription2.getBundleId()).thenReturn(bundleId1);
+ Mockito.when(subscription3.getBundleId()).thenReturn(bundleId1);
+ Mockito.when(subscription4.getBundleId()).thenReturn(bundleId2);
+ Mockito.when(subscription1.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(subscription2.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(subscription3.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(subscription4.getId()).thenReturn(UUID.randomUUID());
+
+ bind(BlockingStateDao.class).toInstance(Mockito.mock(BlockingStateDao.class));
bind(BlockingApi.class).toInstance(blockingApi);
-
}
});
@@ -117,19 +107,17 @@ public class TestBlockingCalculator {
}
- @Test
// S1-S2-S3 subscriptions in B1
// B1 -----[--------]
// S1 --A-------------------------------------
// S2 --B------C------------------------------
// S3 ------------------D---------------------
-
//Result
// S1 --A--[-------]--------------------------
// S2 --B--[-------]--------------------------
// S3 ------------------D---------------------
-
+ @Test
public void testInsertBlockingEvents() {
final DateTime now = clock.getUTCNow();
final List<DisabledDuration> disabledDuration = new ArrayList<BlockingCalculator.DisabledDuration>();
@@ -149,8 +137,7 @@ public class TestBlockingCalculator {
blockingStates.add(new DefaultBlockingState(bundleId1, DISABLED_BUNDLE, Blockable.Type.SUBSCRIPTION_BUNDLE, "test", true, true, true, now));
blockingStates.add(new DefaultBlockingState(bundleId1, CLEAR_BUNDLE, Blockable.Type.SUBSCRIPTION_BUNDLE, "test", false, false, false, now.plusDays(2)));
- ((ZombieControl) blockingApi).addResult("getBlockingHistory", blockingStates);
-
+ Mockito.when(blockingApi.getBlockingHistory(Mockito.<Blockable>anyObject())).thenReturn(blockingStates);
odc.insertBlockingEvents(billingEvents);
@@ -258,7 +245,6 @@ public class TestBlockingCalculator {
billingEvents.add(e1);
billingEvents.add(e2);
-
final SortedSet<BillingEvent> results = odc.eventsToRemove(disabledDuration, billingEvents, subscription1);
assertEquals(results.size(), 1);
@@ -299,7 +285,6 @@ public class TestBlockingCalculator {
final BillingEvent e2 = createRealEvent(now.plusDays(1), subscription1);
billingEvents.add(e2);
-
final SortedSet<BillingEvent> results = odc.eventsToRemove(disabledDuration, billingEvents, subscription1);
assertEquals(results.size(), 1);
@@ -566,7 +551,6 @@ public class TestBlockingCalculator {
description, totalOrdering, type, tz);
}
-
@Test
public void testFilter() {
final SortedSet<BillingEvent> events = new TreeSet<BillingEvent>();
@@ -653,9 +637,9 @@ public class TestBlockingCalculator {
}
private BillingEvent createBillingEvent(final Subscription subscription) {
- final BillingEvent result = BrainDeadProxyFactory.createBrainDeadProxyFor(BillingEvent.class, Comparable.class);
- ((ZombieControl) result).addResult("getSubscription", subscription);
- ((ZombieControl) result).addResult("compareTo", 1);
+ final BillingEvent result = Mockito.mock(BillingEvent.class);
+ Mockito.when(result.getSubscription()).thenReturn(subscription);
+ Mockito.when(result.compareTo(Mockito.<BillingEvent>any())).thenReturn(1);
return result;
}
@@ -702,7 +686,6 @@ public class TestBlockingCalculator {
assertNotNull(pairs.get(0).getEnd());
assertEquals(pairs.get(0).getEnd(), now.plusDays(2));
-
//two or more disableds in a row
blockingEvents = new TreeSet<BlockingState>();
blockingEvents.add(new DefaultBlockingState(ovdId, CLEAR_BUNDLE, Type.SUBSCRIPTION_BUNDLE, "test", false, false, false, now));
@@ -717,7 +700,6 @@ public class TestBlockingCalculator {
assertNotNull(pairs.get(0).getEnd());
assertEquals(pairs.get(0).getEnd(), now.plusDays(3));
-
blockingEvents = new TreeSet<BlockingState>();
blockingEvents.add(new DefaultBlockingState(ovdId, CLEAR_BUNDLE, Type.SUBSCRIPTION_BUNDLE, "test", false, false, false, now));
blockingEvents.add(new DefaultBlockingState(ovdId, DISABLED_BUNDLE, Type.SUBSCRIPTION_BUNDLE, "test", true, true, true, now.plusDays(1)));
@@ -731,6 +713,5 @@ public class TestBlockingCalculator {
assertEquals(pairs.get(0).getStart(), now.plusDays(1));
assertNotNull(pairs.get(0).getEnd());
assertEquals(pairs.get(0).getEnd(), now.plusDays(4));
-
}
}
diff --git a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultBillingEvent.java b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultBillingEvent.java
index 6a6abfb..6f8ea89 100644
--- a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultBillingEvent.java
+++ b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultBillingEvent.java
@@ -25,6 +25,7 @@ import java.util.UUID;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -41,15 +42,14 @@ import com.ning.billing.entitlement.api.SubscriptionTransitionType;
import com.ning.billing.entitlement.api.billing.BillingEvent;
import com.ning.billing.entitlement.api.billing.BillingModeType;
import com.ning.billing.entitlement.api.user.Subscription;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
+import com.ning.billing.junction.JunctionTestSuite;
-public class TestDefaultBillingEvent {
+public class TestDefaultBillingEvent extends JunctionTestSuite {
public static final UUID ID_ZERO = new UUID(0L, 0L);
public static final UUID ID_ONE = new UUID(0L, 1L);
public static final UUID ID_TWO = new UUID(0L, 2L);
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testEventOrderingSubscription() {
final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-31T00:02:04.000Z"), SubscriptionTransitionType.CREATE);
@@ -68,9 +68,8 @@ public class TestDefaultBillingEvent {
Assert.assertEquals(event2, it.next());
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testEventOrderingDate() {
-
final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionTransitionType.CREATE);
final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-02-01T00:02:04.000Z"), SubscriptionTransitionType.CREATE);
final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-03-01T00:02:04.000Z"), SubscriptionTransitionType.CREATE);
@@ -87,9 +86,8 @@ public class TestDefaultBillingEvent {
Assert.assertEquals(event2, it.next());
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testEventTotalOrdering() {
-
final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionTransitionType.CREATE, 1L);
final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionTransitionType.CANCEL, 2L);
final BillingEvent event2 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionTransitionType.RE_CREATE, 3L);
@@ -106,9 +104,8 @@ public class TestDefaultBillingEvent {
Assert.assertEquals(event2, it.next());
}
- @Test(groups = {"fast"})
+ @Test(groups = "fast")
public void testEventOrderingMix() {
-
final BillingEvent event0 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionTransitionType.CREATE);
final BillingEvent event1 = createEvent(subscription(ID_ZERO), new DateTime("2012-01-02T00:02:04.000Z"), SubscriptionTransitionType.CHANGE);
final BillingEvent event2 = createEvent(subscription(ID_ONE), new DateTime("2012-01-01T00:02:04.000Z"), SubscriptionTransitionType.CANCEL);
@@ -149,9 +146,8 @@ public class TestDefaultBillingEvent {
}
private Subscription subscription(final UUID id) {
- final Subscription subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) subscription).addResult("getId", id);
+ final Subscription subscription = Mockito.mock(Subscription.class);
+ Mockito.when(subscription.getId()).thenReturn(id);
return subscription;
}
-
}
overdue/pom.xml 5(+5 -0)
diff --git a/overdue/pom.xml b/overdue/pom.xml
index 9e1e589..97eda9c 100644
--- a/overdue/pom.xml
+++ b/overdue/pom.xml
@@ -99,6 +99,11 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
index 0d58473..cf51e2b 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
@@ -35,20 +35,19 @@ import com.ning.billing.util.notificationq.NotificationQueueService.Notification
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
public class DefaultOverdueCheckNotifier implements OverdueCheckNotifier {
-
private static final Logger log = LoggerFactory.getLogger(DefaultOverdueCheckNotifier.class);
public static final String OVERDUE_CHECK_NOTIFIER_QUEUE = "overdue-check-queue";
private final NotificationQueueService notificationQueueService;
private final OverdueProperties config;
+ private final OverdueListener listener;
private NotificationQueue overdueQueue;
- private final OverdueListener listener;
@Inject
- public DefaultOverdueCheckNotifier(final NotificationQueueService notificationQueueService,
- final OverdueProperties config, final OverdueListener listener) {
+ public DefaultOverdueCheckNotifier(final NotificationQueueService notificationQueueService, final OverdueProperties config,
+ final OverdueListener listener) {
this.notificationQueueService = notificationQueueService;
this.config = config;
this.listener = listener;
@@ -56,38 +55,41 @@ public class DefaultOverdueCheckNotifier implements OverdueCheckNotifier {
@Override
public void initialize() {
- try {
- overdueQueue = notificationQueueService.createNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME,
- OVERDUE_CHECK_NOTIFIER_QUEUE,
- new NotificationQueueHandler() {
- @Override
- public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDate) {
- try {
- if (! (notificationKey instanceof OverdueCheckNotificationKey)) {
- log.error("Overdue service received Unexpected notificationKey {}", notificationKey.getClass().getName());
- return;
- }
- final OverdueCheckNotificationKey key = (OverdueCheckNotificationKey) notificationKey;
- processEvent(key.getUuidKey(), eventDate);
- } catch (IllegalArgumentException e) {
- log.error("The key returned from the NextBillingNotificationQueue is not a valid UUID", e);
+ final NotificationConfig notificationConfig = new NotificationConfig() {
+ @Override
+ public boolean isNotificationProcessingOff() {
+ return config.isNotificationProcessingOff();
+ }
+
+ @Override
+ public long getSleepTimeMs() {
+ return config.getSleepTimeMs();
+ }
+ };
+
+ final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() {
+ @Override
+ public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDate) {
+ try {
+ if (!(notificationKey instanceof OverdueCheckNotificationKey)) {
+ log.error("Overdue service received Unexpected notificationKey {}", notificationKey.getClass().getName());
return;
}
- }
- },
- new NotificationConfig() {
- @Override
- public boolean isNotificationProcessingOff() {
- return config.isNotificationProcessingOff();
+ final OverdueCheckNotificationKey key = (OverdueCheckNotificationKey) notificationKey;
+ processEvent(key.getUuidKey(), eventDate);
+ } catch (IllegalArgumentException e) {
+ log.error("The key returned from the NextBillingNotificationQueue is not a valid UUID", e);
}
- @Override
- public long getSleepTimeMs() {
- return config.getSleepTimeMs();
- }
}
- );
+ };
+
+ try {
+ overdueQueue = notificationQueueService.createNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME,
+ OVERDUE_CHECK_NOTIFIER_QUEUE,
+ notificationQueueHandler,
+ notificationConfig);
} catch (NotificationQueueAlreadyExists e) {
throw new RuntimeException(e);
}
@@ -113,6 +115,4 @@ public class DefaultOverdueCheckNotifier implements OverdueCheckNotifier {
private void processEvent(final UUID overdueableId, final DateTime eventDateTime) {
listener.handleNextOverdueCheck(overdueableId);
}
-
-
}
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
index 79cfdf9..ad11522 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
@@ -50,11 +50,11 @@ public class DefaultOverdueCheckPoster implements OverdueCheckPoster {
DefaultOverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE);
log.info("Queuing overdue check notification. id: {}, timestamp: {}", overdueable.getId().toString(), futureNotificationTime.toString());
- checkOverdueQueue.recordFutureNotification(futureNotificationTime, new OverdueCheckNotificationKey(overdueable.getId()));
+ checkOverdueQueue.recordFutureNotification(futureNotificationTime, null, new OverdueCheckNotificationKey(overdueable.getId()));
} catch (NoSuchNotificationQueue e) {
log.error("Attempting to put items on a non-existent queue (DefaultOverdueCheck).", e);
} catch (IOException e) {
- log.error("Failed to serialize notifcationKey for {}", overdueable.toString());
+ log.error("Failed to serialize notifcationKey for {}", overdueable.toString());
}
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/applicator/TestOverdueStateApplicator.java b/overdue/src/test/java/com/ning/billing/overdue/applicator/TestOverdueStateApplicator.java
index a58ac39..87347a3 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/applicator/TestOverdueStateApplicator.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/applicator/TestOverdueStateApplicator.java
@@ -16,25 +16,19 @@
package com.ning.billing.overdue.applicator;
-
-import static com.jayway.awaitility.Awaitility.await;
-import static java.util.concurrent.TimeUnit.SECONDS;
-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
-import junit.framework.Assert;
-
+import org.mockito.Mockito;
+import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.inject.Inject;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.junction.api.BlockingApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.overdue.OverdueChangeEvent;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.OverdueTestBase;
@@ -42,18 +36,20 @@ import com.ning.billing.overdue.config.OverdueConfig;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.config.XMLLoader;
+import static com.jayway.awaitility.Awaitility.await;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
public class TestOverdueStateApplicator extends OverdueTestBase {
@Inject
OverdueStateApplicator<SubscriptionBundle> applicator;
@Inject
OverdueBusListenerTester listener;
-
- @Inject
+
+ @Inject
Bus bus;
-
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testApplicator() throws Exception {
bus.register(listener);
bus.start();
@@ -61,8 +57,8 @@ public class TestOverdueStateApplicator extends OverdueTestBase {
config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
overdueWrapperFactory.setOverdueConfig(config);
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getId", UUID.randomUUID());
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getId()).thenReturn(UUID.randomUUID());
OverdueState<SubscriptionBundle> state;
@@ -70,38 +66,30 @@ public class TestOverdueStateApplicator extends OverdueTestBase {
applicator.apply(bundle, BlockingApi.CLEAR_STATE_NAME, state);
checkStateApplied(state);
checkBussEvent("OD1");
-
-
state = config.getBundleStateSet().findState("OD2");
applicator.apply(bundle, BlockingApi.CLEAR_STATE_NAME, state);
checkStateApplied(state);
checkBussEvent("OD2");
-
state = config.getBundleStateSet().findState("OD3");
applicator.apply(bundle, BlockingApi.CLEAR_STATE_NAME, state);
checkStateApplied(state);
checkBussEvent("OD3");
bus.stop();
-
}
-
private void checkBussEvent(final String state) throws Exception {
await().atMost(10, SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
- List<OverdueChangeEvent> events = listener.getEventsReceived();
+ final List<OverdueChangeEvent> events = listener.getEventsReceived();
return events.size() == 1;
}
});
- List<OverdueChangeEvent> events = listener.getEventsReceived();
+ final List<OverdueChangeEvent> events = listener.getEventsReceived();
Assert.assertEquals(1, events.size());
Assert.assertEquals(state, events.get(0).getNextOverdueStateName());
listener.clearEventsReceived();
-
}
-
-
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculator.java b/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculator.java
index 8f38f08..57426a3 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculator.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculator.java
@@ -24,6 +24,7 @@ import java.util.SortedSet;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -31,16 +32,14 @@ import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceUserApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
+import com.ning.billing.overdue.OverdueTestSuite;
import com.ning.billing.overdue.config.api.BillingState;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
-public class TestBillingStateCalculator {
+public class TestBillingStateCalculator extends OverdueTestSuite {
Clock clock = new ClockMock();
- InvoiceUserApi invoiceApi = BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceUserApi.class);
- private int hash = 0;
+ InvoiceUserApi invoiceApi = Mockito.mock(InvoiceUserApi.class);
DateTime now;
public BillingStateCalculator<SubscriptionBundle> createBSCalc() {
@@ -50,7 +49,7 @@ public class TestBillingStateCalculator {
invoices.add(createInvoice(now.plusDays(1), BigDecimal.TEN, null));
invoices.add(createInvoice(now.plusDays(2), new BigDecimal("100.0"), null));
- ((ZombieControl) invoiceApi).addResult("getUnpaidInvoicesByAccountId", invoices);
+ Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<DateTime>any())).thenReturn(invoices);
return new BillingStateCalculator<SubscriptionBundle>(invoiceApi, clock) {
@Override
@@ -62,17 +61,16 @@ public class TestBillingStateCalculator {
}
public Invoice createInvoice(final DateTime date, final BigDecimal balance, final List<InvoiceItem> invoiceItems) {
- final Invoice invoice = BrainDeadProxyFactory.createBrainDeadProxyFor(Invoice.class);
- ((ZombieControl) invoice).addResult("getBalance", balance);
- ((ZombieControl) invoice).addResult("getInvoiceDate", date);
- ((ZombieControl) invoice).addResult("hashCode", hash++);
- ((ZombieControl) invoice).addResult("getInvoiceItems", invoiceItems);
- ((ZombieControl) invoice).addResult("getId", UUID.randomUUID());
+ final Invoice invoice = Mockito.mock(Invoice.class);
+ Mockito.when(invoice.getBalance()).thenReturn(balance);
+ Mockito.when(invoice.getInvoiceDate()).thenReturn(date);
+ Mockito.when(invoice.getInvoiceItems()).thenReturn(invoiceItems);
+ Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID());
return invoice;
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testUnpaidInvoices() {
final BillingStateCalculator<SubscriptionBundle> calc = createBSCalc();
final SortedSet<Invoice> invoices = calc.unpaidInvoicesForAccount(new UUID(0L, 0L));
@@ -82,21 +80,17 @@ public class TestBillingStateCalculator {
Assert.assertEquals(new BigDecimal("100.0").compareTo(invoices.last().getBalance()), 0);
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testSum() {
-
final BillingStateCalculator<SubscriptionBundle> calc = createBSCalc();
final SortedSet<Invoice> invoices = calc.unpaidInvoicesForAccount(new UUID(0L, 0L));
Assert.assertEquals(new BigDecimal("110.0").compareTo(calc.sumBalance(invoices)), 0);
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testEarliest() {
-
final BillingStateCalculator<SubscriptionBundle> calc = createBSCalc();
final SortedSet<Invoice> invoices = calc.unpaidInvoicesForAccount(new UUID(0L, 0L));
Assert.assertEquals(calc.earliest(invoices).getInvoiceDate(), now);
}
-
-
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java b/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java
index dc5b6a4..67b63ab 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/calculator/TestBillingStateCalculatorBundle.java
@@ -16,6 +16,7 @@
package com.ning.billing.overdue.calculator;
+import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@@ -23,9 +24,12 @@ import java.util.SortedSet;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
import com.ning.billing.catalog.MockPlan;
import com.ning.billing.catalog.MockPriceList;
import com.ning.billing.catalog.api.Plan;
@@ -36,27 +40,23 @@ import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceUserApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.overdue.config.api.BillingStateBundle;
import com.ning.billing.overdue.config.api.PaymentResponse;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
public class TestBillingStateCalculatorBundle extends TestBillingStateCalculator {
-
-
private List<InvoiceItem> createInvoiceItems(final UUID[] bundleIds) {
final List<InvoiceItem> result = new ArrayList<InvoiceItem>();
for (final UUID id : bundleIds) {
- final InvoiceItem ii = BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceItem.class);
- ((ZombieControl) ii).addResult("getBundleId", id);
+ final InvoiceItem ii = Mockito.mock(InvoiceItem.class);
+ Mockito.when(ii.getBundleId()).thenReturn(id);
result.add(ii);
}
return result;
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testUnpaidInvoiceForBundle() {
final UUID thisBundleId = new UUID(0L, 0L);
final UUID thatBundleId = new UUID(0L, 1L);
@@ -64,30 +64,32 @@ public class TestBillingStateCalculatorBundle extends TestBillingStateCalculator
now = new DateTime();
final List<Invoice> invoices = new ArrayList<Invoice>(5);
invoices.add(createInvoice(now, BigDecimal.ZERO, createInvoiceItems(new UUID[]{thisBundleId, thatBundleId})));
- invoices.add(createInvoice(now, BigDecimal.TEN, createInvoiceItems(new UUID[]{thatBundleId})));
- invoices.add(createInvoice(now, new BigDecimal("100.00"), createInvoiceItems(new UUID[]{thatBundleId, thisBundleId, thatBundleId})));
- invoices.add(createInvoice(now, new BigDecimal("1000.00"), createInvoiceItems(new UUID[]{thisBundleId})));
- invoices.add(createInvoice(now, new BigDecimal("10000.00"), createInvoiceItems(new UUID[]{thatBundleId, thisBundleId})));
-
+ // Will not be seen below
+ invoices.add(createInvoice(now.plusDays(1), BigDecimal.TEN, createInvoiceItems(new UUID[]{thatBundleId})));
+ invoices.add(createInvoice(now.plusDays(2), new BigDecimal("100.00"), createInvoiceItems(new UUID[]{thatBundleId, thisBundleId, thatBundleId})));
+ invoices.add(createInvoice(now.plusDays(3), new BigDecimal("1000.00"), createInvoiceItems(new UUID[]{thisBundleId})));
+ invoices.add(createInvoice(now.plusDays(4), new BigDecimal("10000.00"), createInvoiceItems(new UUID[]{thatBundleId, thisBundleId})));
final Clock clock = new ClockMock();
- final InvoiceUserApi invoiceApi = BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceUserApi.class);
- final EntitlementUserApi entitlementApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class);
- ((ZombieControl) invoiceApi).addResult("getUnpaidInvoicesByAccountId", invoices);
-
+ final InvoiceUserApi invoiceApi = Mockito.mock(InvoiceUserApi.class);
+ final EntitlementUserApi entitlementApi = Mockito.mock(EntitlementUserApi.class);
+ Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<DateTime>any())).thenReturn(Collections2.filter(invoices, new Predicate<Invoice>() {
+ @Override
+ public boolean apply(@Nullable final Invoice invoice) {
+ return invoice != null && BigDecimal.ZERO.compareTo(invoice.getBalance()) < 0;
+ }
+ }));
final BillingStateCalculatorBundle calc = new BillingStateCalculatorBundle(entitlementApi, invoiceApi, clock);
final SortedSet<Invoice> resultinvoices = calc.unpaidInvoicesForBundle(thisBundleId, new UUID(0L, 0L));
- Assert.assertEquals(resultinvoices.size(), 4);
- Assert.assertEquals(BigDecimal.ZERO.compareTo(resultinvoices.first().getBalance()), 0);
+ Assert.assertEquals(resultinvoices.size(), 3);
+ Assert.assertEquals(new BigDecimal("100.0").compareTo(resultinvoices.first().getBalance()), 0);
Assert.assertEquals(new BigDecimal("10000.0").compareTo(resultinvoices.last().getBalance()), 0);
-
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testcalculateBillingStateForBundle() throws Exception {
-
final UUID thisBundleId = new UUID(0L, 0L);
final UUID thatBundleId = new UUID(0L, 1L);
@@ -99,24 +101,23 @@ public class TestBillingStateCalculatorBundle extends TestBillingStateCalculator
invoices.add(createInvoice(now.minusDays(2), new BigDecimal("1000.00"), createInvoiceItems(new UUID[]{thisBundleId})));
invoices.add(createInvoice(now.minusDays(1), new BigDecimal("10000.00"), createInvoiceItems(new UUID[]{thatBundleId, thisBundleId})));
-
final Clock clock = new ClockMock();
- final InvoiceUserApi invoiceApi = BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceUserApi.class);
- ((ZombieControl) invoiceApi).addResult("getUnpaidInvoicesByAccountId", invoices);
+ final InvoiceUserApi invoiceApi = Mockito.mock(InvoiceUserApi.class);
+ Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<DateTime>any())).thenReturn(invoices);
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getId", thisBundleId);
- ((ZombieControl) bundle).addResult("getAccountId", UUID.randomUUID());
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getId()).thenReturn(thisBundleId);
+ Mockito.when(bundle.getAccountId()).thenReturn(UUID.randomUUID());
- final EntitlementUserApi entitlementApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class);
- final Subscription subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) entitlementApi).addResult("getBaseSubscription", subscription);
+ final EntitlementUserApi entitlementApi = Mockito.mock(EntitlementUserApi.class);
+ final Subscription subscription = Mockito.mock(Subscription.class);
+ Mockito.when(entitlementApi.getBaseSubscription(Mockito.<UUID>any())).thenReturn(subscription);
final Plan plan = MockPlan.createBicycleNoTrialEvergreen1USD();
final PriceList pricelist = new MockPriceList();
- ((ZombieControl) subscription).addResult("getCurrentPlan", plan);
- ((ZombieControl) subscription).addResult("getCurrentPriceList", pricelist);
- ((ZombieControl) subscription).addResult("getCurrentPhase", plan.getFinalPhase());
+ Mockito.when(subscription.getCurrentPlan()).thenReturn(plan);
+ Mockito.when(subscription.getCurrentPriceList()).thenReturn(pricelist);
+ Mockito.when(subscription.getCurrentPhase()).thenReturn(plan.getFinalPhase());
final BillingStateCalculatorBundle calc = new BillingStateCalculatorBundle(entitlementApi, invoiceApi, clock);
@@ -134,33 +135,30 @@ public class TestBillingStateCalculatorBundle extends TestBillingStateCalculator
}
-
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testcalculateBillingStateForBundleNoOverdueInvoices() throws Exception {
-
final UUID thisBundleId = new UUID(0L, 0L);
- final UUID thatBundleId = new UUID(0L, 1L);
now = new DateTime();
final List<Invoice> invoices = new ArrayList<Invoice>(5);
final Clock clock = new ClockMock();
- final InvoiceUserApi invoiceApi = BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceUserApi.class);
- ((ZombieControl) invoiceApi).addResult("getUnpaidInvoicesByAccountId", invoices);
+ final InvoiceUserApi invoiceApi = Mockito.mock(InvoiceUserApi.class);
+ Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<DateTime>any())).thenReturn(invoices);
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getId", thisBundleId);
- ((ZombieControl) bundle).addResult("getAccountId", UUID.randomUUID());
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
+ Mockito.when(bundle.getId()).thenReturn(thisBundleId);
+ Mockito.when(bundle.getAccountId()).thenReturn(UUID.randomUUID());
- final EntitlementUserApi entitlementApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class);
- final Subscription subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) entitlementApi).addResult("getBaseSubscription", subscription);
+ final EntitlementUserApi entitlementApi = Mockito.mock(EntitlementUserApi.class);
+ final Subscription subscription = Mockito.mock(Subscription.class);
+ Mockito.when(entitlementApi.getBaseSubscription(Mockito.<UUID>any())).thenReturn(subscription);
final Plan plan = MockPlan.createBicycleNoTrialEvergreen1USD();
final PriceList pricelist = new MockPriceList();
- ((ZombieControl) subscription).addResult("getCurrentPlan", plan);
- ((ZombieControl) subscription).addResult("getCurrentPriceList", pricelist);
- ((ZombieControl) subscription).addResult("getCurrentPhase", plan.getFinalPhase());
+ Mockito.when(subscription.getCurrentPlan()).thenReturn(plan);
+ Mockito.when(subscription.getCurrentPriceList()).thenReturn(pricelist);
+ Mockito.when(subscription.getCurrentPhase()).thenReturn(plan.getFinalPhase());
final BillingStateCalculatorBundle calc = new BillingStateCalculatorBundle(entitlementApi, invoiceApi, clock);
@@ -181,6 +179,4 @@ public class TestBillingStateCalculatorBundle extends TestBillingStateCalculator
public void testCorrectBehaviorForNoOverdueConfig() {
//TODO with no overdue config the system should be fine - take no action but see no NPEs
}
-
-
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/config/CreateOverdueConfigSchema.java b/overdue/src/test/java/com/ning/billing/overdue/config/CreateOverdueConfigSchema.java
index b801a2d..61e2fbe 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/config/CreateOverdueConfigSchema.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/config/CreateOverdueConfigSchema.java
@@ -23,10 +23,6 @@ import java.io.Writer;
import com.ning.billing.util.config.XMLSchemaGenerator;
public class CreateOverdueConfigSchema {
-
- /**
- * @param args
- */
public static void main(final String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Usage: <filepath>");
@@ -37,7 +33,5 @@ public class CreateOverdueConfigSchema {
final Writer w = new FileWriter(f);
w.write(XMLSchemaGenerator.xmlSchemaAsString(OverdueConfig.class));
w.close();
-
}
-
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/config/io/TestReadConfig.java b/overdue/src/test/java/com/ning/billing/overdue/config/io/TestReadConfig.java
index 75b3239..bc65015 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/config/io/TestReadConfig.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/config/io/TestReadConfig.java
@@ -19,13 +19,13 @@ package com.ning.billing.overdue.config.io;
import org.testng.annotations.Test;
import com.google.common.io.Resources;
+import com.ning.billing.overdue.OverdueTestSuite;
import com.ning.billing.overdue.config.OverdueConfig;
import com.ning.billing.util.config.XMLLoader;
-public class TestReadConfig {
- @Test(enabled = true)
+public class TestReadConfig extends OverdueTestSuite {
+ @Test(groups = "fast")
public void testConfigLoad() throws Exception {
XMLLoader.getObjectFromString(Resources.getResource("OverdueConfig.xml").toExternalForm(), OverdueConfig.class);
}
-
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/config/TestCondition.java b/overdue/src/test/java/com/ning/billing/overdue/config/TestCondition.java
index 508dcb4..dad1a9e 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/config/TestCondition.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/config/TestCondition.java
@@ -27,6 +27,7 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueTestSuite;
import com.ning.billing.overdue.config.api.BillingState;
import com.ning.billing.overdue.config.api.PaymentResponse;
import com.ning.billing.util.config.XMLLoader;
@@ -35,12 +36,11 @@ import com.ning.billing.util.tag.DefaultControlTag;
import com.ning.billing.util.tag.DescriptiveTag;
import com.ning.billing.util.tag.Tag;
-public class TestCondition {
-
+public class TestCondition extends OverdueTestSuite {
@XmlRootElement(name = "condition")
private static class MockCondition extends DefaultCondition<Blockable> {}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testNumberOfUnpaidInvoicesEqualsOrExceeds() throws Exception {
final String xml =
"<condition>" +
@@ -59,7 +59,7 @@ public class TestCondition {
Assert.assertTrue(c.evaluate(state2, new DateTime()));
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testTotalUnpaidInvoiceBalanceEqualsOrExceeds() throws Exception {
final String xml =
"<condition>" +
@@ -78,8 +78,7 @@ public class TestCondition {
Assert.assertTrue(c.evaluate(state2, new DateTime()));
}
-
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds() throws Exception {
final String xml =
"<condition>" +
@@ -100,7 +99,7 @@ public class TestCondition {
Assert.assertTrue(c.evaluate(state2, now));
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testResponseForLastFailedPaymentIn() throws Exception {
final String xml =
"<condition>" +
@@ -121,7 +120,7 @@ public class TestCondition {
Assert.assertTrue(c.evaluate(state2, now));
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "fast")
public void testHasControlTag() throws Exception {
final String xml =
"<condition>" +
@@ -136,15 +135,13 @@ public class TestCondition {
final BillingState<Blockable> state0 = new BillingState<Blockable>(new UUID(0L, 1L), 0, BigDecimal.ZERO, null, unpaidInvoiceId, PaymentResponse.LOST_OR_STOLEN_CARD, new Tag[]{new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF), new DescriptiveTag("Tag")});
final BillingState<Blockable> state1 = new BillingState<Blockable>(new UUID(0L, 1L), 1, new BigDecimal("100.00"), now.minusDays(10), unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF)});
final BillingState<Blockable> state2 = new BillingState<Blockable>(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20), unpaidInvoiceId,
- PaymentResponse.DO_NOT_HONOR,
- new Tag[]{new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF),
- new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF),
- new DescriptiveTag("Tag")});
+ PaymentResponse.DO_NOT_HONOR,
+ new Tag[]{new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF),
+ new DefaultControlTag(ControlTagType.AUTO_INVOICING_OFF),
+ new DescriptiveTag("Tag")});
Assert.assertTrue(!c.evaluate(state0, now));
Assert.assertTrue(c.evaluate(state1, now));
Assert.assertTrue(c.evaluate(state2, now));
}
-
-
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/config/TestOverdueConfig.java b/overdue/src/test/java/com/ning/billing/overdue/config/TestOverdueConfig.java
index 58aabcf..2b2c264 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/config/TestOverdueConfig.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/config/TestOverdueConfig.java
@@ -21,11 +21,11 @@ import java.io.InputStream;
import org.testng.annotations.Test;
+import com.ning.billing.overdue.OverdueTestSuite;
import com.ning.billing.util.config.XMLLoader;
-public class TestOverdueConfig {
-
- @Test
+public class TestOverdueConfig extends OverdueTestSuite {
+ @Test(groups = "fast")
public void testParseConfig() throws Exception {
final String xml = "<overdueConfig>" +
" <bundleOverdueStates>" +
@@ -59,7 +59,5 @@ public class TestOverdueConfig {
"</overdueConfig>";
final InputStream is = new ByteArrayInputStream(xml.getBytes());
final OverdueConfig c = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
-
}
-
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
index a098a25..5965e02 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
@@ -22,6 +22,7 @@ import java.util.UUID;
import java.util.concurrent.Callable;
import org.joda.time.DateTime;
+import org.mockito.Mockito;
import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
import org.testng.Assert;
@@ -32,6 +33,7 @@ import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.catalog.DefaultCatalogService;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.config.CatalogConfig;
@@ -39,11 +41,10 @@ import com.ning.billing.config.InvoiceConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.entitlement.api.billing.ChargeThruApi;
import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.lifecycle.KillbillService.ServiceException;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.mock.glue.MockInvoiceModule;
import com.ning.billing.mock.glue.MockJunctionModule;
import com.ning.billing.mock.glue.MockPaymentModule;
@@ -51,6 +52,7 @@ import com.ning.billing.ovedue.notification.DefaultOverdueCheckNotifier;
import com.ning.billing.ovedue.notification.DefaultOverdueCheckPoster;
import com.ning.billing.ovedue.notification.OverdueCheckPoster;
import com.ning.billing.overdue.OverdueProperties;
+import com.ning.billing.overdue.OverdueTestSuiteWithEmbeddedDB;
import com.ning.billing.overdue.glue.DefaultOverdueModule;
import com.ning.billing.overdue.listener.OverdueListener;
import com.ning.billing.util.bus.Bus;
@@ -73,12 +75,11 @@ import com.ning.billing.util.tag.dao.TagDao;
import static com.jayway.awaitility.Awaitility.await;
import static java.util.concurrent.TimeUnit.MINUTES;
-public class TestOverdueCheckNotifier {
+public class TestOverdueCheckNotifier extends OverdueTestSuiteWithEmbeddedDB {
private Clock clock;
private DefaultOverdueCheckNotifier notifier;
private Bus eventBus;
- private MysqlTestingHelper helper;
private OverdueListenerMock listener;
private NotificationQueueService notificationQueueService;
@@ -103,15 +104,11 @@ public class TestOverdueCheckNotifier {
public UUID getLatestSubscriptionId() {
return latestSubscriptionId;
}
-
}
-
- @BeforeClass(groups = {"slow"})
- public void setup() throws ServiceException, IOException, ClassNotFoundException, SQLException {
- //TestApiBase.loadSystemPropertiesFromClasspath("/entitlement.properties");
+ @BeforeClass(groups = "slow")
+ public void setup() throws ServiceException, IOException, ClassNotFoundException, SQLException, EntitlementUserApiException {
final Injector g = Guice.createInjector(Stage.PRODUCTION, new MockInvoiceModule(), new MockPaymentModule(), new BusModule(), new DefaultOverdueModule() {
-
protected void configure() {
super.configure();
bind(Clock.class).to(ClockMock.class).asEagerSingleton();
@@ -122,68 +119,52 @@ public class TestOverdueCheckNotifier {
final CatalogConfig catalogConfig = new ConfigurationObjectFactory(System.getProperties()).build(CatalogConfig.class);
bind(CatalogConfig.class).toInstance(catalogConfig);
bind(CatalogService.class).to(DefaultCatalogService.class).asEagerSingleton();
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
bind(TagDao.class).to(AuditedTagDao.class).asEagerSingleton();
bind(CustomFieldDao.class).to(AuditedCustomFieldDao.class).asEagerSingleton();
bind(GlobalLocker.class).to(MySqlGlobalLocker.class).asEagerSingleton();
- bind(ChargeThruApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(ChargeThruApi.class));
+ bind(ChargeThruApi.class).toInstance(Mockito.mock(ChargeThruApi.class));
install(new MockJunctionModule());
}
});
clock = g.getInstance(Clock.class);
- final IDBI dbi = g.getInstance(IDBI.class);
eventBus = g.getInstance(Bus.class);
- helper = g.getInstance(MysqlTestingHelper.class);
notificationQueueService = g.getInstance(NotificationQueueService.class);
final OverdueProperties properties = g.getInstance(OverdueProperties.class);
- final Subscription subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- final EntitlementUserApi entitlementUserApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class);
- ((ZombieControl) entitlementUserApi).addResult("getSubscriptionFromId", subscription);
+ final Subscription subscription = Mockito.mock(Subscription.class);
+ final EntitlementUserApi entitlementUserApi = Mockito.mock(EntitlementUserApi.class);
+ Mockito.when(entitlementUserApi.getSubscriptionFromId(Mockito.<UUID>any())).thenReturn(subscription);
-// CallContextFactory factory = new DefaultCallContextFactory(clock);
listener = new OverdueListenerMock();
notifier = new DefaultOverdueCheckNotifier(notificationQueueService,
properties, listener);
- startMysql();
eventBus.start();
notifier.initialize();
notifier.start();
}
- private void startMysql() throws IOException, ClassNotFoundException, SQLException {
- final String ddl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- final String testDdl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl_test.sql"));
-
- helper.startMysql();
- helper.initDb(ddl);
- helper.initDb(testDdl);
- }
-
- @Test(enabled = true, groups = "slow")
+ @Test(groups = "slow")
public void test() throws Exception {
final UUID subscriptionId = new UUID(0L, 1L);
- final Blockable blockable = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) blockable).addResult("getId", subscriptionId);
+ final Blockable blockable = Mockito.mock(Subscription.class);
+ Mockito.when(blockable.getId()).thenReturn(subscriptionId);
final DateTime now = new DateTime();
final DateTime readyTime = now.plusMillis(2000);
final OverdueCheckPoster poster = new DefaultOverdueCheckPoster(notificationQueueService);
-
poster.insertOverdueCheckNotification(blockable, readyTime);
-
// Move time in the future after the notification effectiveDate
((ClockMock) clock).setDeltaFromReality(3000);
-
await().atMost(1, MINUTES).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
@@ -193,14 +174,11 @@ public class TestOverdueCheckNotifier {
Assert.assertEquals(listener.getEventCount(), 1);
Assert.assertEquals(listener.getLatestSubscriptionId(), subscriptionId);
-
}
@AfterClass(groups = "slow")
public void tearDown() {
eventBus.stop();
notifier.stop();
- helper.stopMysql();
}
-
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestBase.java b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestBase.java
index afc93e5..9a01428 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestBase.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestBase.java
@@ -16,13 +16,13 @@
package com.ning.billing.overdue;
-import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -33,10 +33,9 @@ import com.google.inject.Inject;
import com.ning.billing.account.api.Account;
import com.ning.billing.catalog.MockPlan;
import com.ning.billing.catalog.MockPriceList;
-import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.glue.CatalogModule;
-import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.invoice.api.Invoice;
@@ -44,8 +43,6 @@ import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceUserApi;
import com.ning.billing.junction.api.BlockingApi;
import com.ning.billing.junction.api.BlockingState;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.mock.glue.MockClockModule;
import com.ning.billing.mock.glue.MockInvoiceModule;
import com.ning.billing.mock.glue.MockPaymentModule;
@@ -53,20 +50,17 @@ import com.ning.billing.mock.glue.TestDbiModule;
import com.ning.billing.overdue.applicator.ApplicatorMockJunctionModule;
import com.ning.billing.overdue.applicator.ApplicatorMockJunctionModule.ApplicatorBlockingApi;
import com.ning.billing.overdue.applicator.OverdueListenerTesterModule;
-import com.ning.billing.overdue.applicator.TestOverdueStateApplicator;
import com.ning.billing.overdue.config.OverdueConfig;
import com.ning.billing.overdue.glue.DefaultOverdueModule;
import com.ning.billing.overdue.service.DefaultOverdueService;
import com.ning.billing.overdue.wrapper.OverdueWrapperFactory;
import com.ning.billing.util.bus.BusService;
import com.ning.billing.util.clock.ClockMock;
-import com.ning.billing.util.glue.BusModule;
import com.ning.billing.util.glue.NotificationQueueModule;
-import com.ning.billing.util.io.IOUtils;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
-@Guice(modules = {DefaultOverdueModule.class,OverdueListenerTesterModule.class, MockClockModule.class, ApplicatorMockJunctionModule.class, CatalogModule.class, MockInvoiceModule.class, MockPaymentModule.class, NotificationQueueModule.class, TestDbiModule.class})
-public class OverdueTestBase {
+@Guice(modules = {DefaultOverdueModule.class, OverdueListenerTesterModule.class, MockClockModule.class, ApplicatorMockJunctionModule.class, CatalogModule.class, MockInvoiceModule.class, MockPaymentModule.class, NotificationQueueModule.class, TestDbiModule.class})
+public abstract class OverdueTestBase extends OverdueTestSuiteWithEmbeddedDB {
protected final String configXml =
"<overdueConfig>" +
" <bundleOverdueStates>" +
@@ -125,36 +119,23 @@ public class OverdueTestBase {
@Inject
protected OverdueUserApi overdueApi;
-
@Inject
protected InvoiceUserApi invoiceApi;
protected Account account;
protected SubscriptionBundle bundle;
- protected String productName;
- protected BillingPeriod term;
- protected String planSetName;
@Inject
EntitlementUserApi entitlementApi;
@Inject
protected DefaultOverdueService service;
+
@Inject
protected BusService busService;
- @Inject
- protected MysqlTestingHelper helper;
-
- protected void setupMySQL() throws IOException {
- final String utilDdl = IOUtils.toString(TestOverdueStateApplicator.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- helper.startMysql();
- helper.initDb(utilDdl);
- }
@BeforeClass(groups = "slow")
public void setup() throws Exception {
-
- setupMySQL();
service.registerForBus();
try {
service.initialize();
@@ -168,21 +149,14 @@ public class OverdueTestBase {
@AfterClass(groups = "slow")
public void tearDown() throws Exception {
- helper.stopMysql();
service.stop();
}
-
@BeforeMethod(groups = "slow")
public void setupTest() throws Exception {
-
- // Pre test cleanup
- helper.cleanupAllTables();
clock.resetDeltaFromReality();
-
}
-
protected void checkStateApplied(final OverdueState<SubscriptionBundle> state) {
final BlockingState result = ((ApplicatorBlockingApi) blockingApi).getBlockingState();
checkStateApplied(result, state);
@@ -195,36 +169,33 @@ public class OverdueTestBase {
Assert.assertEquals(result.isBlockBilling(), state.disableEntitlementAndChangesBlocked());
}
-
- protected SubscriptionBundle createBundle(final DateTime dateOfLastUnPaidInvoice) {
- final SubscriptionBundle bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
+ protected SubscriptionBundle createBundle(final DateTime dateOfLastUnPaidInvoice) throws EntitlementUserApiException {
+ final SubscriptionBundle bundle = Mockito.mock(SubscriptionBundle.class);
final UUID bundleId = UUID.randomUUID();
- ((ZombieControl) bundle).addResult("getId", bundleId);
- ((ZombieControl) bundle).addResult("getAccountId", UUID.randomUUID());
+ Mockito.when(bundle.getId()).thenReturn(bundleId);
+ Mockito.when(bundle.getAccountId()).thenReturn(UUID.randomUUID());
- final Invoice invoice = BrainDeadProxyFactory.createBrainDeadProxyFor(Invoice.class);
- ((ZombieControl) invoice).addResult("getInvoiceDate", dateOfLastUnPaidInvoice);
- ((ZombieControl) invoice).addResult("getBalance", BigDecimal.TEN);
- ((ZombieControl) invoice).addResult("getId", UUID.randomUUID());
- ((ZombieControl) invoice).addResult("hashCode", UUID.randomUUID().hashCode());
+ final Invoice invoice = Mockito.mock(Invoice.class);
+ Mockito.when(invoice.getInvoiceDate()).thenReturn(dateOfLastUnPaidInvoice);
+ Mockito.when(invoice.getBalance()).thenReturn(BigDecimal.TEN);
+ Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID());
- final InvoiceItem item = BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceItem.class);
- ((ZombieControl) item).addResult("getBundleId", bundleId);
+ final InvoiceItem item = Mockito.mock(InvoiceItem.class);
+ Mockito.when(item.getBundleId()).thenReturn(bundleId);
final List<InvoiceItem> items = new ArrayList<InvoiceItem>();
items.add(item);
- ((ZombieControl) invoice).addResult("getInvoiceItems", items);
+ Mockito.when(invoice.getInvoiceItems()).thenReturn(items);
final List<Invoice> invoices = new ArrayList<Invoice>();
invoices.add(invoice);
- ((ZombieControl) invoiceApi).addResult("getUnpaidInvoicesByAccountId", invoices);
-
+ Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<DateTime>any())).thenReturn(invoices);
- final Subscription base = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) base).addResult("getCurrentPlan", MockPlan.createBicycleNoTrialEvergreen1USD());
- ((ZombieControl) base).addResult("getCurrentPriceList", new MockPriceList());
- ((ZombieControl) base).addResult("getCurrentPhase", MockPlan.createBicycleNoTrialEvergreen1USD().getFinalPhase());
- ((ZombieControl) entitlementApi).addResult("getBaseSubscription", base);
+ final Subscription base = Mockito.mock(Subscription.class);
+ Mockito.when(base.getCurrentPlan()).thenReturn(MockPlan.createBicycleNoTrialEvergreen1USD());
+ Mockito.when(base.getCurrentPriceList()).thenReturn(new MockPriceList());
+ Mockito.when(base.getCurrentPhase()).thenReturn(MockPlan.createBicycleNoTrialEvergreen1USD().getFinalPhase());
+ Mockito.when(entitlementApi.getBaseSubscription(Mockito.<UUID>any())).thenReturn(base);
return bundle;
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuite.java b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuite.java
new file mode 100644
index 0000000..e0fb28c
--- /dev/null
+++ b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuite.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.overdue;
+
+import com.ning.billing.KillbillTestSuite;
+
+public abstract class OverdueTestSuite extends KillbillTestSuite {
+}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteWithEmbeddedDB.java b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..17380be
--- /dev/null
+++ b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteWithEmbeddedDB.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.overdue;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class OverdueTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/wrapper/TestOverdueWrapper.java b/overdue/src/test/java/com/ning/billing/overdue/wrapper/TestOverdueWrapper.java
index 84e7467..108a420 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/wrapper/TestOverdueWrapper.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/wrapper/TestOverdueWrapper.java
@@ -30,7 +30,7 @@ import com.ning.billing.overdue.config.OverdueConfig;
import com.ning.billing.util.config.XMLLoader;
public class TestOverdueWrapper extends OverdueTestBase {
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "slow")
public void testWrapperBasic() throws Exception {
final InputStream is = new ByteArrayInputStream(configXml.getBytes());
config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
@@ -46,7 +46,6 @@ public class TestOverdueWrapper extends OverdueTestBase {
wrapper.refresh();
checkStateApplied(state);
-
state = config.getBundleStateSet().findState("OD2");
bundle = createBundle(clock.getUTCNow().minusDays(41));
wrapper = overdueWrapperFactory.createOverdueWrapperFor(bundle);
@@ -58,15 +57,12 @@ public class TestOverdueWrapper extends OverdueTestBase {
wrapper = overdueWrapperFactory.createOverdueWrapperFor(bundle);
wrapper.refresh();
checkStateApplied(state);
-
}
- @Test(groups = {"fast"}, enabled = true)
+ @Test(groups = "slow")
public void testWrapperNoConfig() throws Exception {
-
overdueWrapperFactory.setOverdueConfig(null);
-
final SubscriptionBundle bundle;
final OverdueWrapper<SubscriptionBundle> wrapper;
final OverdueState<SubscriptionBundle> state;
@@ -78,10 +74,8 @@ public class TestOverdueWrapper extends OverdueTestBase {
wrapper = overdueWrapperFactory.createOverdueWrapperFor(bundle);
final OverdueState<SubscriptionBundle> result = wrapper.refresh();
-
Assert.assertEquals(result.getName(), state.getName());
Assert.assertEquals(result.blockChanges(), state.blockChanges());
Assert.assertEquals(result.disableEntitlementAndChangesBlocked(), state.disableEntitlementAndChangesBlocked());
-
}
}
payment/pom.xml 5(+5 -0)
diff --git a/payment/pom.xml b/payment/pom.xml
index 7ba68ca..aad97d8 100644
--- a/payment/pom.xml
+++ b/payment/pom.xml
@@ -77,6 +77,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
diff --git a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
index e284d6a..c40707c 100644
--- a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
+++ b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
@@ -141,6 +141,22 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEv
return extPaymentRefId;
}
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("DefaultPaymentInfoEvent");
+ sb.append("{accountId=").append(accountId);
+ sb.append(", invoiceId=").append(invoiceId);
+ sb.append(", paymentId=").append(paymentId);
+ sb.append(", amount=").append(amount);
+ sb.append(", paymentNumber=").append(paymentNumber);
+ sb.append(", status=").append(status);
+ sb.append(", userToken=").append(userToken);
+ sb.append(", effectiveDate=").append(effectiveDate);
+ sb.append(", extPaymentRefId='").append(extPaymentRefId).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
@Override
public int hashCode() {
diff --git a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
index 6c154fd..0167a71 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
@@ -445,7 +445,7 @@ public class PaymentProcessor extends ProcessorBase {
paymentDao.updateStatusForPaymentWithAttempt(paymentInput.getId(), paymentStatus, e.getMessage(), null, attemptInput.getId(), context);
- throw new PaymentApiException(ErrorCode.PAYMENT_CREATE_PAYMENT, account.getId(), e.getMessage());
+ throw new PaymentApiException(ErrorCode.PAYMENT_CREATE_PAYMENT, account.getId(), e.toString());
} finally {
if (event != null) {
diff --git a/payment/src/main/java/com/ning/billing/payment/core/RefundProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/RefundProcessor.java
index 92c4544..a7768c2 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/RefundProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/RefundProcessor.java
@@ -42,8 +42,6 @@ import com.ning.billing.payment.api.DefaultRefund;
import com.ning.billing.payment.api.PaymentApiException;
import com.ning.billing.payment.api.PaymentStatus;
import com.ning.billing.payment.api.Refund;
-import com.ning.billing.payment.core.ProcessorBase.WithAccountLock;
-import com.ning.billing.payment.core.ProcessorBase.WithAccountLockCallback;
import com.ning.billing.payment.dao.PaymentAttemptModelDao;
import com.ning.billing.payment.dao.PaymentDao;
import com.ning.billing.payment.dao.RefundModelDao;
@@ -91,7 +89,6 @@ public class RefundProcessor extends ProcessorBase {
public Refund doOperation() throws PaymentApiException {
try {
-
final PaymentAttemptModelDao successfulAttempt = getPaymentAttempt(paymentId);
if (successfulAttempt == null) {
throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_SUCCESS_PAYMENT, paymentId);
@@ -130,7 +127,7 @@ public class RefundProcessor extends ProcessorBase {
}
paymentDao.updateRefundStatus(refundInfo.getId(), RefundStatus.PLUGIN_COMPLETED, context);
- invoicePaymentApi.createRefund(successfulAttempt.getId(), refundAmount, isAdjusted, refundInfo.getId(), context);
+ invoicePaymentApi.createRefund(paymentId, refundAmount, isAdjusted, refundInfo.getId(), context);
paymentDao.updateRefundStatus(refundInfo.getId(), RefundStatus.COMPLETED, context);
@@ -223,11 +220,8 @@ public class RefundProcessor extends ProcessorBase {
try {
final CallContext context = factory.createCallContext("RefundProcessor", CallOrigin.INTERNAL, UserType.SYSTEM);
for (RefundModelDao cur : refundsToBeFixed) {
- final PaymentAttemptModelDao successfulAttempt = getPaymentAttempt(cur.getPaymentId());
- if (successfulAttempt != null) {
- invoicePaymentApi.createRefund(successfulAttempt.getId(), cur.getAmount(), cur.isAdjsuted(), cur.getId(), context);
- paymentDao.updateRefundStatus(cur.getId(), RefundStatus.COMPLETED, context);
- }
+ invoicePaymentApi.createRefund(cur.getPaymentId(), cur.getAmount(), cur.isAdjsuted(), cur.getId(), context);
+ paymentDao.updateRefundStatus(cur.getId(), RefundStatus.COMPLETED, context);
}
} catch (InvoiceApiException e) {
throw new PaymentApiException(e);
diff --git a/payment/src/main/java/com/ning/billing/payment/retry/BaseRetryService.java b/payment/src/main/java/com/ning/billing/payment/retry/BaseRetryService.java
index 292583e..cd48c67 100644
--- a/payment/src/main/java/com/ning/billing/payment/retry/BaseRetryService.java
+++ b/payment/src/main/java/com/ning/billing/payment/retry/BaseRetryService.java
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2010-2011 Ning, Inc.
*
* Ning licenses this file to you under the Apache License, version 2.0
@@ -66,7 +66,7 @@ public abstract class BaseRetryService implements RetryService {
},
config);
}
-
+
@Override
public void start() {
retryQueue.startQueue();
@@ -80,6 +80,7 @@ public abstract class BaseRetryService implements RetryService {
}
}
+ @Override
public abstract String getQueueName();
@@ -125,9 +126,9 @@ public abstract class BaseRetryService implements RetryService {
final NotificationKey key = new PaymentRetryNotificationKey(paymentId);
if (retryQueue != null) {
if (transactionalDao == null) {
- retryQueue.recordFutureNotification(timeOfRetry, key);
+ retryQueue.recordFutureNotification(timeOfRetry, null, key);
} else {
- retryQueue.recordFutureNotificationFromTransaction(transactionalDao, timeOfRetry, key);
+ retryQueue.recordFutureNotificationFromTransaction(transactionalDao, timeOfRetry, null, key);
}
}
} catch (NoSuchNotificationQueue e) {
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 6e33f2d..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
@@ -23,6 +23,7 @@ import java.util.UUID;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
@@ -38,11 +39,10 @@ import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoicePaymentApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
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;
@@ -62,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
@@ -86,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;
@@ -110,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;
@@ -119,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");
@@ -128,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");
@@ -138,8 +137,6 @@ public class TestPaymentApi {
}
private void testSimplePayment(final BigDecimal invoiceAmount, final BigDecimal requestedAmount, final BigDecimal expectedAmount) throws Exception {
- ((ZombieControl) invoicePaymentApi).addResult("notifyOfPayment", BrainDeadProxyFactory.ZOMBIE_VOID);
-
final DateTime now = new DateTime(DateTimeZone.UTC);
final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD);
@@ -182,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);
@@ -192,7 +189,7 @@ public class TestPaymentApi {
final PaymentMethodPlugin newPaymenrMethod = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null);
final UUID newPaymentMethodId = paymentApi.addPaymentMethod(PaymentTestModuleWithMocks.PLUGIN_TEST_NAME, account, true, newPaymenrMethod, context);
- ((ZombieControl) account).addResult("getPaymentMethodId", newPaymentMethodId);
+ Mockito.when(account.getPaymentMethodId()).thenReturn(newPaymentMethodId);
methods = paymentApi.getPaymentMethods(account, false);
assertEquals(methods.size(), 2);
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/glue/PaymentTestModuleWithEmbeddedDb.java b/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithEmbeddedDb.java
index 4937184..1d2ed05 100644
--- a/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithEmbeddedDb.java
+++ b/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithEmbeddedDb.java
@@ -17,15 +17,17 @@
package com.ning.billing.payment.glue;
import java.util.HashMap;
+import java.util.UUID;
+
+import org.mockito.Mockito;
import com.google.inject.Provider;
import com.ning.billing.config.PaymentConfig;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.payment.provider.MockPaymentProviderPluginModule;
import com.ning.billing.util.api.TagUserApi;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.InMemoryBus;
+import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.glue.GlobalLockerModule;
import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
import com.ning.billing.util.notificationq.NotificationQueueService;
@@ -35,11 +37,10 @@ public class PaymentTestModuleWithEmbeddedDb extends PaymentModule {
public static class MockTagApiProvider implements Provider<TagUserApi> {
@Override
public TagUserApi get() {
- final TagUserApi api = BrainDeadProxyFactory.createBrainDeadProxyFor(TagUserApi.class);
- ((ZombieControl) api).addResult("getTags", new HashMap<String, Tag>());
+ final TagUserApi api = Mockito.mock(TagUserApi.class);
+ Mockito.when(api.getTags(Mockito.<UUID>any(), Mockito.<ObjectType>any())).thenReturn(new HashMap<String, Tag>());
return api;
}
-
}
@Override
diff --git a/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithMocks.java b/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithMocks.java
index ca497f6..c253ff3 100644
--- a/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithMocks.java
+++ b/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithMocks.java
@@ -20,22 +20,26 @@ import java.io.IOException;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
+import java.util.UUID;
+import org.mockito.Mockito;
import org.skife.config.ConfigSource;
import org.skife.config.SimplePropertyConfigSource;
+import com.google.common.collect.ImmutableMap;
import com.ning.billing.config.PaymentConfig;
import com.ning.billing.mock.glue.MockInvoiceModule;
import com.ning.billing.mock.glue.MockNotificationQueueModule;
-import com.ning.billing.mock.glue.TestDbiModule;
import com.ning.billing.payment.dao.MockPaymentDao;
import com.ning.billing.payment.dao.PaymentDao;
import com.ning.billing.payment.provider.MockPaymentProviderPluginModule;
+import com.ning.billing.util.api.TagUserApi;
+import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.globallocker.GlobalLocker;
import com.ning.billing.util.globallocker.MockGlobalLocker;
import com.ning.billing.util.glue.BusModule;
import com.ning.billing.util.glue.BusModule.BusType;
-import com.ning.billing.util.glue.TagStoreModule;
+import com.ning.billing.util.tag.Tag;
import static org.testng.Assert.assertNotNull;
@@ -89,8 +93,11 @@ public class PaymentTestModuleWithMocks extends PaymentModule {
install(new BusModule(BusType.MEMORY));
install(new MockNotificationQueueModule());
install(new MockInvoiceModule());
- install(new TestDbiModule());
- install(new TagStoreModule());
+
+ final TagUserApi tagUserApi = Mockito.mock(TagUserApi.class);
+ bind(TagUserApi.class).toInstance(tagUserApi);
+ Mockito.when(tagUserApi.getTags(Mockito.<UUID>any(), Mockito.<ObjectType>any())).thenReturn(ImmutableMap.<String, Tag>of());
+
bind(GlobalLocker.class).to(MockGlobalLocker.class).asEagerSingleton();
}
}
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/TestHelper.java b/payment/src/test/java/com/ning/billing/payment/TestHelper.java
index 6a9e422..abeaa54 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestHelper.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestHelper.java
@@ -19,6 +19,7 @@ package com.ning.billing.payment;
import java.util.UUID;
import org.joda.time.DateTime;
+import org.mockito.Mockito;
import com.google.inject.Inject;
import com.ning.billing.account.api.Account;
@@ -28,8 +29,6 @@ import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceCreationEvent;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoicePaymentApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.payment.api.PaymentApi;
import com.ning.billing.payment.api.PaymentMethodPlugin;
import com.ning.billing.payment.glue.PaymentTestModuleWithMocks;
@@ -57,7 +56,6 @@ public class TestHelper {
context = factory.createCallContext("Princess Buttercup", CallOrigin.TEST, UserType.TEST);
}
-
public Invoice createTestInvoice(final Account account,
final DateTime targetDate,
final Currency currency,
@@ -81,7 +79,7 @@ public class TestHelper {
}
}
- ((ZombieControl) invoicePaymentApi).addResult("getInvoice", invoice);
+ Mockito.when(invoicePaymentApi.getInvoice(invoice.getId())).thenReturn(invoice);
final InvoiceCreationEvent event = new MockInvoiceCreationEvent(invoice.getId(), invoice.getAccountId(),
invoice.getBalance(), invoice.getCurrency(),
invoice.getInvoiceDate(),
@@ -95,34 +93,20 @@ public class TestHelper {
final String name = "First" + UUID.randomUUID().toString() + " " + "Last" + UUID.randomUUID().toString();
final String externalKey = UUID.randomUUID().toString();
- final Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- final ZombieControl zombie = (ZombieControl) account;
- zombie.addResult("getId", UUID.randomUUID());
- zombie.addResult("getExternalKey", externalKey);
- zombie.addResult("getName", name);
- zombie.addResult("getFirstNameLength", 10);
- zombie.addResult("getPhone", "123-456-7890");
- zombie.addResult("getEmail", email);
- zombie.addResult("getCurrency", Currency.USD);
- zombie.addResult("getBillCycleDay", 1);
- zombie.addResult("isMigrated", false);
- zombie.addResult("isNotifiedForInvoices", false);
- zombie.addResult("getTimeZone", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getLocale", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getAddress1", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getAddress2", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getCompanyName", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getCity", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getStateOrProvince", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getCountry", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getPostalCode", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getPhone", BrainDeadProxyFactory.ZOMBIE_VOID);
- zombie.addResult("getPaymentMethodId", BrainDeadProxyFactory.ZOMBIE_VOID);
-
- ((ZombieControl) accountUserApi).addResult("getAccountById", account);
- ((ZombieControl) accountUserApi).addResult("getAccountByKey", account);
- ((ZombieControl) accountUserApi).addResult("updateAccount", BrainDeadProxyFactory.ZOMBIE_VOID);
- //updateAccount
+ final Account account = Mockito.mock(Account.class);
+ Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
+ Mockito.when(account.getExternalKey()).thenReturn(externalKey);
+ Mockito.when(account.getName()).thenReturn(name);
+ Mockito.when(account.getFirstNameLength()).thenReturn(10);
+ Mockito.when(account.getPhone()).thenReturn("123-456-7890");
+ Mockito.when(account.getEmail()).thenReturn(email);
+ Mockito.when(account.getCurrency()).thenReturn(Currency.USD);
+ Mockito.when(account.getBillCycleDay()).thenReturn(1);
+ Mockito.when(account.isMigrated()).thenReturn(false);
+ Mockito.when(account.isNotifiedForInvoices()).thenReturn(false);
+
+ Mockito.when(accountUserApi.getAccountById(Mockito.<UUID>any())).thenReturn(account);
+ Mockito.when(accountUserApi.getAccountByKey(Mockito.anyString())).thenReturn(account);
final PaymentMethodPlugin pm = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null);
addTestPaymentMethod(account, pm);
@@ -131,8 +115,6 @@ public class TestHelper {
private void addTestPaymentMethod(final Account account, final PaymentMethodPlugin paymentMethodInfo) throws Exception {
final UUID paymentMethodId = paymentApi.addPaymentMethod(PaymentTestModuleWithMocks.PLUGIN_TEST_NAME, account, true, paymentMethodInfo, context);
- final ZombieControl zombie = (ZombieControl) account;
- zombie.addResult("getPaymentMethodId", paymentMethodId);
+ Mockito.when(account.getPaymentMethodId()).thenReturn(paymentMethodId);
}
-
}
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 957ce75..e8e1580 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
@@ -26,7 +26,6 @@ import java.util.concurrent.TimeoutException;
import org.joda.time.DateTime;
import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -37,8 +36,6 @@ import com.ning.billing.catalog.api.Currency;
import com.ning.billing.config.PaymentConfig;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoicePaymentApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
-import com.ning.billing.mock.BrainDeadProxyFactory.ZombieControl;
import com.ning.billing.mock.glue.MockClockModule;
import com.ning.billing.mock.glue.MockJunctionModule;
import com.ning.billing.payment.api.Payment;
@@ -67,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
@@ -104,7 +101,6 @@ public class TestRetryService {
mockPaymentProviderPlugin.clear();
context = new DefaultCallContext("RetryServiceTests", CallOrigin.INTERNAL, UserType.TEST, clock);
- ((ZombieControl) invoicePaymentApi).addResult("notifyOfPayment", BrainDeadProxyFactory.ZOMBIE_VOID);
}
@AfterMethod(groups = "fast")
@@ -137,7 +133,6 @@ public class TestRetryService {
testSchedulesRetryInternal(paymentConfig.getPluginFailureRetryMaxAttempts() + 1, FailureType.PLUGIN_EXCEPTION);
}
-
@Test(groups = "fast")
public void testFailedPaymentWithOneSuccessfulRetry() throws Exception {
testSchedulesRetryInternal(1, FailureType.PAYMENT_FAILURE);
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
index 54ecd11..6ccdce6 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
@@ -298,13 +298,17 @@ public class TestAccount extends TestJaxrsBase {
@Test(groups = "slow", enabled = true)
public void testCustomFields() throws Exception {
+
+ final AccountJson accountJson = createAccount("yoyoq", "gfgrqe", "yoyoq@yahoo.com");
+ assertNotNull(accountJson);
+
final List<CustomFieldJson> customFields = new LinkedList<CustomFieldJson>();
customFields.add(new CustomFieldJson("1", "value1"));
customFields.add(new CustomFieldJson("2", "value2"));
customFields.add(new CustomFieldJson("3", "value3"));
final String baseJson = mapper.writeValueAsString(customFields);
- final String uri = JaxrsResource.ACCOUNTS_PATH + "/" + UUID.randomUUID().toString() + "/" + JaxrsResource.CUSTOM_FIELDS;
+ final String uri = JaxrsResource.ACCOUNTS_PATH + "/" + accountJson.getAccountId() + "/" + JaxrsResource.CUSTOM_FIELDS;
Response response = doPost(uri, baseJson, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
assertEquals(response.getStatusCode(), Status.CREATED.getStatusCode());
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestChargeback.java b/server/src/test/java/com/ning/billing/jaxrs/TestChargeback.java
index 9dc8d51..34cf968 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestChargeback.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestChargeback.java
@@ -47,7 +47,7 @@ import static org.testng.Assert.assertTrue;
public class TestChargeback extends TestJaxrsBase {
@Test(groups = "slow")
public void testAddChargeback() throws Exception {
- final PaymentJsonSimple payment = createInvoicePayment();
+ final PaymentJsonSimple payment = createAccountWithInvoiceAndPayment();
final ChargebackJson input = new ChargebackJson(null, null, BigDecimal.TEN, payment.getPaymentId(), null);
final String jsonInput = mapper.writeValueAsString(input);
@@ -124,12 +124,12 @@ public class TestChargeback extends TestJaxrsBase {
//assertEquals(response.getStatusCode(), javax.ws.rs.core.Response.Status.NO_CONTENT.getStatusCode(), response.getResponseBody());
}
- private PaymentJsonSimple createInvoicePayment() throws Exception {
- final InvoiceJsonSimple invoice = createInvoice();
+ private PaymentJsonSimple createAccountWithInvoiceAndPayment() throws Exception {
+ final InvoiceJsonSimple invoice = createAccountWithInvoice();
return getPayment(invoice);
}
- private InvoiceJsonSimple createInvoice() throws Exception {
+ private InvoiceJsonSimple createAccountWithInvoice() throws Exception {
// Create account
final AccountJson accountJson = createAccountWithDefaultPaymentMethod(UUID.randomUUID().toString(), UUID.randomUUID().toString(), "nohup@yahoo.com");
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java b/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
index 36f7b53..3d93c6d 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2010-2011 Ning, Inc.
*
* Ning licenses this file to you under the Apache License, version 2.0
@@ -51,7 +51,7 @@ public class TestInvoice extends TestJaxrsBase {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
- final AccountJson accountJson = createAccount("poupou", "qhddffrwe", "poupou@yahoo.com");
+ final AccountJson accountJson = createAccountWithDefaultPaymentMethod("poupou", "qhddffrwe", "poupou@yahoo.com");
assertNotNull(accountJson);
final BundleJsonNoSubscriptions bundleJson = createBundle(accountJson.getAccountId(), "9967599");
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestInvoiceNotification.java b/server/src/test/java/com/ning/billing/jaxrs/TestInvoiceNotification.java
index 370ce77..d1aa37f 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestInvoiceNotification.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestInvoiceNotification.java
@@ -56,7 +56,7 @@ public class TestInvoiceNotification extends TestJaxrsBase {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
- final AccountJson accountJson = createAccount(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
+ final AccountJson accountJson = createAccountWithDefaultPaymentMethod(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
Assert.assertNotNull(accountJson);
final BundleJsonNoSubscriptions bundleJson = createBundle(accountJson.getAccountId(), UUID.randomUUID().toString());
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
index 160fa9b..5ef2bb7 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
@@ -46,6 +46,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.google.inject.Module;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.account.glue.AccountModule;
import com.ning.billing.analytics.setup.AnalyticsModule;
import com.ning.billing.api.TestApiListener;
@@ -71,6 +72,7 @@ import com.ning.billing.jaxrs.resources.JaxrsResource;
import com.ning.billing.junction.glue.DefaultJunctionModule;
import com.ning.billing.payment.glue.PaymentModule;
import com.ning.billing.payment.provider.MockPaymentProviderPluginModule;
+import com.ning.billing.server.ServerTestSuiteWithEmbeddedDB;
import com.ning.billing.server.listeners.KillbillGuiceListener;
import com.ning.billing.server.modules.KillbillServerModule;
import com.ning.billing.util.clock.Clock;
@@ -95,7 +97,7 @@ import com.ning.jetty.core.server.HttpServer;
import static org.testng.Assert.assertNotNull;
-public class TestJaxrsBase {
+public class TestJaxrsBase extends ServerTestSuiteWithEmbeddedDB {
protected static final String PLUGIN_NAME = "noop";
// STEPH
@@ -110,7 +112,7 @@ public class TestJaxrsBase {
private static TestKillbillGuiceListener listener;
- private MysqlTestingHelper helper;
+ private final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
private HttpServer server;
protected CoreConfig config;
@@ -236,19 +238,7 @@ public class TestJaxrsBase {
@BeforeMethod(groups = "slow")
public void cleanupBeforeMethod(final Method method) {
- log.info("***************************************************************************************************");
- log.info("*** Starting test {}:{}", method.getDeclaringClass().getName(), method.getName());
- log.info("***************************************************************************************************");
-
busHandler.reset();
- helper.cleanupAllTables();
- }
-
- @AfterMethod(groups = "slow")
- public void endTest(final Method method) throws Exception {
- log.info("***************************************************************************************************");
- log.info("*** Ending test {}:{}", method.getDeclaringClass().getName(), method.getName());
- log.info("***************************************************************************************************");
}
@BeforeClass(groups = "slow")
@@ -262,30 +252,9 @@ public class TestJaxrsBase {
//mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy());
busHandler = new TestApiListener(null);
- this.helper = listener.getMysqlTestingHelper();
this.clock = (ClockMock) listener.getClock();
}
- private void setupMySQL() throws IOException {
- final String accountDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/account/ddl.sql"));
- final String entitlementDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/entitlement/ddl.sql"));
- final String invoiceDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/invoice/ddl.sql"));
- final String paymentDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/payment/ddl.sql"));
- final String utilDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- final String analyticsDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/analytics/ddl.sql"));
- final String junctionDdl = IOUtils.toString(TestIntegration.class.getResourceAsStream("/com/ning/billing/junction/ddl.sql"));
-
- helper.startMysql();
-
- helper.initDb(accountDdl);
- helper.initDb(entitlementDdl);
- helper.initDb(invoiceDdl);
- helper.initDb(paymentDdl);
- helper.initDb(utilDdl);
- helper.initDb(analyticsDdl);
- helper.initDb(junctionDdl);
- }
-
private void loadConfig() {
if (config == null) {
config = new ConfigurationObjectFactory(System.getProperties()).build(CoreConfig.class);
@@ -294,11 +263,9 @@ public class TestJaxrsBase {
@BeforeSuite(groups = "slow")
public void setup() throws Exception {
-
loadSystemPropertiesFromClasspath("/killbill.properties");
loadConfig();
- this.helper = new MysqlTestingHelper();
this.clock = new ClockMock();
listener = new TestKillbillGuiceListener(helper, clock);
server = new HttpServer();
@@ -313,9 +280,6 @@ public class TestJaxrsBase {
};
server.configure(config, eventListeners, new HashMap<FilterHolder, String>());
- setupMySQL();
- helper.cleanupAllTables();
-
server.start();
}
@@ -325,10 +289,6 @@ public class TestJaxrsBase {
server.stop();
} catch (Exception ignored) {
}
-
- if (helper != null) {
- helper.stopMysql();
- }
}
protected List<PaymentMethodProperties> getPaymentMethodCCProperties() {
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java b/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
index 4997c96..9e2d92f 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
@@ -52,7 +52,7 @@ public class TestSubscription extends TestJaxrsBase {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
- final AccountJson accountJson = createAccount("xil", "shdxilhkkl", "xil@yahoo.com");
+ final AccountJson accountJson = createAccountWithDefaultPaymentMethod("xil", "shdxilhkkl", "xil@yahoo.com");
final BundleJsonNoSubscriptions bundleJson = createBundle(accountJson.getAccountId(), "99999");
final String productName = "Shotgun";
@@ -60,7 +60,7 @@ public class TestSubscription extends TestJaxrsBase {
final SubscriptionJsonNoEvents subscriptionJson = createSubscription(bundleJson.getBundleId(), productName, ProductCategory.BASE.toString(), term.toString(), true);
Assert.assertNotNull(subscriptionJson.getChargedThroughDate());
- Assert.assertEquals(subscriptionJson.getChargedThroughDate(), subscriptionJson.getStartDate().plusDays(30));
+ Assert.assertEquals(subscriptionJson.getChargedThroughDate().toString(), "2012-05-25T00:00:00.000Z");
String uri = JaxrsResource.SUBSCRIPTIONS_PATH + "/" + subscriptionJson.getSubscriptionId().toString();
diff --git a/server/src/test/java/com/ning/billing/server/ServerTestSuiteWithEmbeddedDB.java b/server/src/test/java/com/ning/billing/server/ServerTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..57d4044
--- /dev/null
+++ b/server/src/test/java/com/ning/billing/server/ServerTestSuiteWithEmbeddedDB.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.server;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class ServerTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/dao/NotificationSqlDao.java b/util/src/main/java/com/ning/billing/util/notificationq/dao/NotificationSqlDao.java
index dc3ee4d..0e56efd 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/dao/NotificationSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/dao/NotificationSqlDao.java
@@ -51,6 +51,13 @@ public interface NotificationSqlDao extends Transactional<NotificationSqlDao>, C
@Mapper(NotificationSqlMapper.class)
public List<Notification> getReadyNotifications(@Bind("now") Date now, @Bind("owner") String owner, @Bind("max") int max, @Bind("queueName") String queueName);
+ @SqlQuery
+ @Mapper(NotificationSqlMapper.class)
+ public List<Notification> getNotificationForAccountAndDate(@Bind("accountId") final String accountId, @Bind("effectiveDate") final Date effectiveDate);
+
+ @SqlUpdate
+ public void removeNotification(@Bind("id") String id);
+
@SqlUpdate
public int claimNotification(@Bind("owner") String owner, @Bind("nextAvailable") Date nextAvailable,
@Bind("id") String id, @Bind("now") Date now);
@@ -73,7 +80,8 @@ public interface NotificationSqlDao extends Transactional<NotificationSqlDao>, C
stmt.bind("id", evt.getId().toString());
stmt.bind("createdDate", getDate(new DateTime()));
stmt.bind("creatingOwner", evt.getCreatedOwner());
- stmt.bind("className", evt.getNotificationKeyClass());
+ stmt.bind("className", evt.getNotificationKeyClass());
+ stmt.bind("accountId", evt.getAccountId() != null ? evt.getAccountId().toString() : null);
stmt.bind("notificationKey", evt.getNotificationKey());
stmt.bind("effectiveDate", getDate(evt.getEffectiveDate()));
stmt.bind("queueName", evt.getQueueName());
@@ -92,8 +100,9 @@ public interface NotificationSqlDao extends Transactional<NotificationSqlDao>, C
final Long ordering = r.getLong("record_id");
final UUID id = getUUID(r, "id");
final String createdOwner = r.getString("creating_owner");
- final String className = r.getString("class_name");
+ final String className = r.getString("class_name");
final String notificationKey = r.getString("notification_key");
+ final UUID accountId = getUUID(r, "account_id");
final String queueName = r.getString("queue_name");
final DateTime effectiveDate = getDate(r, "effective_date");
final DateTime nextAvailableDate = getDate(r, "processing_available_date");
@@ -101,7 +110,7 @@ public interface NotificationSqlDao extends Transactional<NotificationSqlDao>, C
final PersistentQueueEntryLifecycleState processingState = PersistentQueueEntryLifecycleState.valueOf(r.getString("processing_state"));
return new DefaultNotification(ordering, id, createdOwner, processingOwner, queueName, nextAvailableDate,
- processingState, className, notificationKey, effectiveDate);
+ processingState, className, notificationKey, accountId, effectiveDate);
}
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotification.java b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotification.java
index 1d74210..70c49c4 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotification.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotification.java
@@ -32,11 +32,12 @@ public class DefaultNotification extends EntityBase implements Notification {
private final String notificationKeyClass;
private final String notificationKey;
private final DateTime effectiveDate;
+ private final UUID accountId;
public DefaultNotification(final long ordering, final UUID id, final String createdOwner, final String owner, final String queueName, final DateTime nextAvailableDate,
final PersistentQueueEntryLifecycleState lifecycleState,
- final String notificationKeyClass, final String notificationKey, final DateTime effectiveDate) {
+ final String notificationKeyClass, final String notificationKey, final UUID accountId, final DateTime effectiveDate) {
super(id);
this.ordering = ordering;
this.owner = owner;
@@ -46,11 +47,12 @@ public class DefaultNotification extends EntityBase implements Notification {
this.lifecycleState = lifecycleState;
this.notificationKeyClass = notificationKeyClass;
this.notificationKey = notificationKey;
+ this.accountId = accountId;
this.effectiveDate = effectiveDate;
}
- public DefaultNotification(final String queueName, final String createdOwner, final String notificationKeyClass, final String notificationKey, final DateTime effectiveDate) {
- this(-1L, UUID.randomUUID(), createdOwner, null, queueName, null, PersistentQueueEntryLifecycleState.AVAILABLE, notificationKeyClass, notificationKey, effectiveDate);
+ public DefaultNotification(final String queueName, final String createdOwner, final String notificationKeyClass, final String notificationKey, final UUID accountId, final DateTime effectiveDate) {
+ this(-1L, UUID.randomUUID(), createdOwner, null, queueName, null, PersistentQueueEntryLifecycleState.AVAILABLE, notificationKeyClass, notificationKey, accountId, effectiveDate);
}
@Override
@@ -97,7 +99,7 @@ public class DefaultNotification extends EntityBase implements Notification {
return notificationKeyClass;
}
-
+
@Override
public String getNotificationKey() {
return notificationKey;
@@ -117,4 +119,9 @@ public class DefaultNotification extends EntityBase implements Notification {
public String getCreatedOwner() {
return createdOwner;
}
+
+ @Override
+ public UUID getAccountId() {
+ return accountId;
+ }
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
index c89f908..246b187 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.UUID;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.IDBI;
@@ -69,23 +70,26 @@ public class DefaultNotificationQueue extends NotificationQueueBase {
}
@Override
- public void recordFutureNotification(final DateTime futureNotificationTime, final NotificationKey notificationKey) throws IOException {
- recordFutureNotificationInternal(futureNotificationTime, notificationKey, dao);
+ public void recordFutureNotification(final DateTime futureNotificationTime, final UUID accountId, final NotificationKey notificationKey) throws IOException {
+ recordFutureNotificationInternal(futureNotificationTime, accountId, notificationKey, dao);
}
@Override
public void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao,
final DateTime futureNotificationTime,
+ final UUID accountId,
final NotificationKey notificationKey) throws IOException {
final NotificationSqlDao transactionalNotificationDao = transactionalDao.become(NotificationSqlDao.class);
- recordFutureNotificationInternal(futureNotificationTime, notificationKey, transactionalNotificationDao);
+ recordFutureNotificationInternal(futureNotificationTime, accountId, notificationKey, transactionalNotificationDao);
}
private void recordFutureNotificationInternal(final DateTime futureNotificationTime,
- final NotificationKey notificationKey,
+ final UUID accountId,
+ final NotificationKey notificationKey,
+
final NotificationSqlDao thisDao) throws IOException {
final String json = objectMapper.writeValueAsString(notificationKey);
- final Notification notification = new DefaultNotification(getFullQName(), getHostname(), notificationKey.getClass().getName(), json, futureNotificationTime);
+ final Notification notification = new DefaultNotification(getFullQName(), getHostname(), notificationKey.getClass().getName(), json, accountId, futureNotificationTime);
thisDao.insertNotification(notification);
}
@@ -133,4 +137,14 @@ public class DefaultNotificationQueue extends NotificationQueueBase {
public void removeNotificationsByKey(final NotificationKey notificationKey) {
dao.removeNotificationsByKey(notificationKey.toString());
}
+
+ @Override
+ public List<Notification> getNotificationForAccountAndDate(final UUID accountId, final DateTime effectiveDate) {
+ return dao.getNotificationForAccountAndDate(accountId.toString(), effectiveDate.toDate());
+ }
+
+ @Override
+ public void removeNotification(UUID notificationId) {
+ dao.removeNotification(notificationId.toString());
+ }
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java
index bfa2379..9949110 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java
@@ -23,7 +23,6 @@ import com.ning.billing.config.NotificationConfig;
import com.ning.billing.util.clock.Clock;
public class DefaultNotificationQueueService extends NotificationQueueServiceBase {
-
private final IDBI dbi;
@Inject
@@ -34,7 +33,8 @@ public class DefaultNotificationQueueService extends NotificationQueueServiceBas
@Override
protected NotificationQueue createNotificationQueueInternal(final String svcName,
- final String queueName, final NotificationQueueHandler handler,
+ final String queueName,
+ final NotificationQueueHandler handler,
final NotificationConfig config) {
return new DefaultNotificationQueue(dbi, clock, svcName, queueName, handler, config);
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/Notification.java b/util/src/main/java/com/ning/billing/util/notificationq/Notification.java
index 2ecea54..8e578c9 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/Notification.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/Notification.java
@@ -16,6 +16,8 @@
package com.ning.billing.util.notificationq;
+import java.util.UUID;
+
import org.joda.time.DateTime;
import com.ning.billing.util.entity.Entity;
@@ -25,10 +27,12 @@ public interface Notification extends PersistentQueueEntryLifecycle, Entity {
public Long getOrdering();
public String getNotificationKeyClass();
-
+
public String getNotificationKey();
public DateTime getEffectiveDate();
public String getQueueName();
+
+ public UUID getAccountId();
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
index 678da46..42cacea 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
@@ -17,6 +17,8 @@
package com.ning.billing.util.notificationq;
import java.io.IOException;
+import java.util.List;
+import java.util.UUID;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
@@ -31,7 +33,7 @@ public interface NotificationQueue extends QueueLifecycle {
* @param futureNotificationTime the time at which the notification is ready
* @param notificationKey the key for that notification
*/
- public void recordFutureNotification(final DateTime futureNotificationTime, final NotificationKey notificationKey)
+ public void recordFutureNotification(final DateTime futureNotificationTime, final UUID accountId, final NotificationKey notificationKey)
throws IOException;
/**
@@ -42,7 +44,9 @@ public interface NotificationQueue extends QueueLifecycle {
* @param notificationKey the key for that notification
*/
public void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao,
- final DateTime futureNotificationTime, final NotificationKey notificationKey)
+ final DateTime futureNotificationTime,
+ final UUID accountId,
+ final NotificationKey notificationKey)
throws IOException;
@@ -53,6 +57,13 @@ public interface NotificationQueue extends QueueLifecycle {
*/
public void removeNotificationsByKey(final NotificationKey notificationKey);
+
+
+ public List<Notification> getNotificationForAccountAndDate(final UUID accountId, final DateTime effectiveDate);
+
+ public void removeNotification(final UUID notificationId);
+
+
/**
* This is only valid when the queue has been configured with isNotificationProcessingOff is true
* In which case, it will callback users for all the ready notifications.
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
index fcc8c08..e26dd6a 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
@@ -44,8 +44,7 @@ public abstract class NotificationQueueBase extends PersistentQueueBase implemen
private final NotificationConfig config;
private final Clock clock;
private final String hostname;
-
- private AtomicLong nbProcessedEvents;
+ private final AtomicLong nbProcessedEvents;
// Package visibility on purpose
NotificationQueueBase(final Clock clock, final String svcName, final String queueName, final NotificationQueueHandler handler, final NotificationConfig config) {
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueServiceBase.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueServiceBase.java
index 03aed2c..f39fc46 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueServiceBase.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueServiceBase.java
@@ -31,7 +31,6 @@ import com.ning.billing.config.NotificationConfig;
import com.ning.billing.util.clock.Clock;
public abstract class NotificationQueueServiceBase implements NotificationQueueService {
-
protected final Logger log = LoggerFactory.getLogger(DefaultNotificationQueueService.class);
protected final Clock clock;
@@ -44,10 +43,10 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
this.queues = new TreeMap<String, NotificationQueue>();
}
-
@Override
public NotificationQueue createNotificationQueue(final String svcName,
- final String queueName, final NotificationQueueHandler handler,
+ final String queueName,
+ final NotificationQueueHandler handler,
final NotificationConfig config) throws NotificationQueueAlreadyExists {
if (svcName == null || queueName == null || handler == null || config == null) {
throw new RuntimeException("Need to specify all parameters");
@@ -71,7 +70,7 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
public NotificationQueue getNotificationQueue(final String svcName,
final String queueName) throws NoSuchNotificationQueue {
- NotificationQueue result = null;
+ NotificationQueue result;
final String compositeName = getCompositeName(svcName, queueName);
synchronized (queues) {
result = queues.get(compositeName);
@@ -83,7 +82,6 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
return result;
}
-
public void deleteNotificationQueue(final String svcName, final String queueName)
throws NoSuchNotificationQueue {
final String compositeName = getCompositeName(svcName, queueName);
@@ -97,7 +95,6 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
}
}
-
//
// Test ONLY
//
@@ -144,8 +141,16 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
String queueName, NotificationQueueHandler handler,
NotificationConfig config);
-
public static String getCompositeName(final String svcName, final String queueName) {
return svcName + ":" + queueName;
}
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("NotificationQueueServiceBase");
+ sb.append("{queues=").append(queues);
+ sb.append('}');
+ return sb.toString();
+ }
}
diff --git a/util/src/main/java/com/ning/billing/util/userrequest/CompletionUserRequestBase.java b/util/src/main/java/com/ning/billing/util/userrequest/CompletionUserRequestBase.java
index 7468c27..20ecbc4 100644
--- a/util/src/main/java/com/ning/billing/util/userrequest/CompletionUserRequestBase.java
+++ b/util/src/main/java/com/ning/billing/util/userrequest/CompletionUserRequestBase.java
@@ -23,7 +23,7 @@ import java.util.concurrent.TimeoutException;
import com.ning.billing.account.api.AccountChangeEvent;
import com.ning.billing.account.api.AccountCreationEvent;
import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
-import com.ning.billing.invoice.api.EmptyInvoiceEvent;
+import com.ning.billing.invoice.api.NullInvoiceEvent;
import com.ning.billing.invoice.api.InvoiceCreationEvent;
import com.ning.billing.payment.api.PaymentErrorEvent;
import com.ning.billing.payment.api.PaymentInfoEvent;
@@ -106,7 +106,7 @@ public abstract class CompletionUserRequestBase implements CompletionUserRequest
onSubscriptionTransition((EffectiveSubscriptionEvent) curEvent);
break;
case INVOICE_EMPTY:
- onEmptyInvoice((EmptyInvoiceEvent) curEvent);
+ onEmptyInvoice((NullInvoiceEvent) curEvent);
break;
case INVOICE_CREATION:
onInvoiceCreation((InvoiceCreationEvent) curEvent);
@@ -139,7 +139,7 @@ public abstract class CompletionUserRequestBase implements CompletionUserRequest
}
@Override
- public void onEmptyInvoice(final EmptyInvoiceEvent curEvent) {
+ public void onEmptyInvoice(final NullInvoiceEvent curEvent) {
}
@Override
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 a0e7dad..acb8d69 100644
--- a/util/src/main/resources/com/ning/billing/util/ddl.sql
+++ b/util/src/main/resources/com/ning/billing/util/ddl.sql
@@ -103,6 +103,7 @@ CREATE TABLE notifications (
id char(36) NOT NULL,
created_date datetime NOT NULL,
class_name varchar(256) NOT NULL,
+ account_id char(36),
notification_key varchar(2048) NOT NULL,
creating_owner char(50) NOT NULL,
effective_date datetime NOT NULL,
diff --git a/util/src/main/resources/com/ning/billing/util/notificationq/dao/NotificationSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/notificationq/dao/NotificationSqlDao.sql.stg
index 3c81e21..8cb0a27 100644
--- a/util/src/main/resources/com/ning/billing/util/notificationq/dao/NotificationSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/notificationq/dao/NotificationSqlDao.sql.stg
@@ -5,6 +5,7 @@ getReadyNotifications() ::= <<
record_id
, id
, class_name
+ , account_id
, notification_key
, created_date
, creating_owner
@@ -30,6 +31,35 @@ getReadyNotifications() ::= <<
;
>>
+getNotificationForAccountAndDate() ::= <<
+ select
+ record_id
+ , id
+ , class_name
+ , account_id
+ , notification_key
+ , created_date
+ , creating_owner
+ , effective_date
+ , queue_name
+ , processing_owner
+ , processing_available_date
+ , processing_state
+ from notifications
+ where
+ account_id = :accountId AND effective_date = :effectiveDate
+ ;
+>>
+
+removeNotification() ::= <<
+ update notifications
+ set
+ processing_state = 'REMOVED'
+ where
+ id = :id
+;
+>>
+
claimNotification() ::= <<
update notifications
set
@@ -66,6 +96,7 @@ insertNotification() ::= <<
insert into notifications (
id
, class_name
+ , account_id
, notification_key
, created_date
, creating_owner
@@ -77,6 +108,7 @@ insertNotification() ::= <<
) values (
:id
, :className
+ , :accountId
, :notificationKey
, :createdDate
, :creatingOwner
diff --git a/util/src/test/java/com/ning/billing/api/TestApiListener.java b/util/src/test/java/com/ning/billing/api/TestApiListener.java
index 45543f3..133e883 100644
--- a/util/src/test/java/com/ning/billing/api/TestApiListener.java
+++ b/util/src/test/java/com/ning/billing/api/TestApiListener.java
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2010-2011 Ning, Inc.
*
* Ning licenses this file to you under the Apache License, version 2.0
@@ -28,6 +28,7 @@ import com.google.common.eventbus.Subscribe;
import com.ning.billing.entitlement.api.timeline.RepairEntitlementEvent;
import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
import com.ning.billing.invoice.api.InvoiceCreationEvent;
+import com.ning.billing.invoice.api.InvoiceEvent;
import com.ning.billing.payment.api.PaymentErrorEvent;
import com.ning.billing.payment.api.PaymentInfoEvent;
@@ -126,7 +127,6 @@ public class TestApiListener {
log.info(String.format("TestApiListener Got Invoice event %s", event.toString()));
assertEqualsNicely(NextEvent.INVOICE);
notifyIfStackEmpty();
-
}
@Subscribe
diff --git a/util/src/test/java/com/ning/billing/dbi/LoggingOutputStream.java b/util/src/test/java/com/ning/billing/dbi/LoggingOutputStream.java
new file mode 100644
index 0000000..603b155
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/dbi/LoggingOutputStream.java
@@ -0,0 +1,197 @@
+/*
+ * 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.dbi;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.slf4j.Logger;
+
+/**
+ * Adapted from http://www.mail-archive.com/user@slf4j.org/msg00674.html for slf4j.
+ * <p/>
+ * An OutputStream that flushes out to a Category.<p>
+ * <p/>
+ * Note that no data is written out to the Category until the stream is
+ * flushed or closed.<p>
+ * <p/>
+ * Example:<pre>
+ * // make sure everything sent to System.err is logged
+ * System.setErr(new PrintStream(new
+ * LoggingOutputStream(Logger.getRootCategory(),
+ * Level.WARN), true));
+ * <p/>
+ * // make sure everything sent to System.out is also logged
+ * System.setOut(new PrintStream(new
+ * LoggingOutputStream(Logger.getRootCategory(),
+ * Level.INFO), true));
+ * </pre>
+ *
+ * @author <a href="[EMAIL PROTECTED]">Jim Moore</a>
+ * @see {{http://www.mail-archive.com/user@slf4j.org/msg00674.html}}
+ */
+
+public class LoggingOutputStream extends OutputStream {
+ /**
+ * Used to maintain the contract of [EMAIL PROTECTED] #close()}.
+ */
+ private boolean hasBeenClosed = false;
+
+ /**
+ * The internal buffer where data is stored.
+ */
+ private byte[] buf;
+
+ /**
+ * The number of valid bytes in the buffer. This value is always
+ * in the range <tt>0</tt> through <tt>buf.length</tt>; elements
+ * <tt>buf[0]</tt> through <tt>buf[count-1]</tt> contain valid
+ * byte data.
+ */
+ private int count;
+
+ /**
+ * Remembers the size of the buffer for speed.
+ */
+ private int bufLength;
+
+ /**
+ * The default number of bytes in the buffer. =2048
+ */
+ public static final int DEFAULT_BUFFER_LENGTH = 2048;
+
+ /**
+ * The category to write to.
+ */
+ private final Logger logger;
+
+ /**
+ * Creates the LoggingOutputStream to flush to the given Category.
+ *
+ * @param log the Logger to write to
+ * @throws IllegalArgumentException if log == null
+ */
+ public LoggingOutputStream(final Logger log) throws IllegalArgumentException {
+ if (log == null) {
+ throw new IllegalArgumentException("log == null");
+ }
+
+ logger = log;
+ bufLength = DEFAULT_BUFFER_LENGTH;
+ buf = new byte[DEFAULT_BUFFER_LENGTH];
+ count = 0;
+ }
+
+ /**
+ * Closes this output stream and releases any system resources
+ * associated with this stream. The general contract of
+ * <code>close</code>
+ * is that it closes the output stream. A closed stream cannot
+ * perform
+ * output operations and cannot be reopened.
+ */
+ public void close() {
+ flush();
+ hasBeenClosed = true;
+ }
+
+ /**
+ * Writes the specified byte to this output stream. The general
+ * contract for <code>write</code> is that one byte is written
+ * to the output stream. The byte to be written is the eight
+ * low-order bits of the argument <code>b</code>. The 24
+ * high-order bits of <code>b</code> are ignored.
+ *
+ * @param b the <code>byte</code> to write
+ * @throws java.io.IOException if an I/O error occurs. In particular, an
+ * <code>IOException</code> may be
+ * thrown if the output stream has been closed.
+ */
+ public void write(final int b) throws IOException {
+ if (hasBeenClosed) {
+ throw new IOException("The stream has been closed.");
+ }
+
+ if (((char) b) == '\r' || ((char) b) == '\n') {
+ return;
+ }
+
+ // would this be writing past the buffer?
+
+ if (count == bufLength) {
+ // grow the buffer
+ final int newBufLength = bufLength + DEFAULT_BUFFER_LENGTH;
+ final byte[] newBuf = new byte[newBufLength];
+
+ System.arraycopy(buf, 0, newBuf, 0, bufLength);
+ buf = newBuf;
+
+ bufLength = newBufLength;
+ }
+
+ buf[count] = (byte) b;
+
+ count++;
+ }
+
+ /**
+ * Flushes this output stream and forces any buffered output bytes
+ * to be written out. The general contract of <code>flush</code> is
+ * that calling it is an indication that, if any bytes previously
+ * written have been buffered by the implementation of the output
+ * stream, such bytes should immediately be written to their
+ * intended destination.
+ */
+ public void flush() {
+ if (count == 0) {
+ return;
+ }
+
+ // don't print out blank lines; flushing from PrintStream puts
+
+ // For linux system
+
+ if (count == 1 && ((char) buf[0]) == '\n') {
+ reset();
+ return;
+ }
+
+ // For mac system
+
+ if (count == 1 && ((char) buf[0]) == '\r') {
+ reset();
+ return;
+ }
+
+ // On windows system
+
+ if (count == 2 && (char) buf[0] == '\r' && (char) buf[1] == '\n') {
+ reset();
+ return;
+ }
+
+ final byte[] theBytes = new byte[count];
+ System.arraycopy(buf, 0, theBytes, 0, count);
+ logger.debug(new String(theBytes));
+ reset();
+ }
+
+ private void reset() {
+ // not resetting the buffer -- assuming that if it grew then it will likely grow similarly again
+ count = 0;
+ }
+}
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 f1bfc60..a1b64f4 100644
--- a/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java
+++ b/util/src/test/java/com/ning/billing/dbi/MysqlTestingHelper.java
@@ -19,6 +19,7 @@ package com.ning.billing.dbi;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.PrintStream;
import java.net.ServerSocket;
import java.util.HashMap;
import java.util.List;
@@ -33,8 +34,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
+import com.google.common.io.Resources;
import com.mysql.management.MysqldResource;
import com.mysql.management.MysqldResourceI;
+import com.ning.billing.util.io.IOUtils;
/**
* Utility class to embed MySQL for testing purposes
@@ -90,7 +93,8 @@ public class MysqlTestingHelper {
Assert.assertTrue(dataDir.delete());
Assert.assertTrue(dataDir.mkdir());
- mysqldResource = new MysqldResource(dbDir, dataDir);
+ final PrintStream out = new PrintStream(new LoggingOutputStream(log), true);
+ mysqldResource = new MysqldResource(dbDir, dataDir, null, out, out);
final Map<String, String> dbOpts = new HashMap<String, String>();
dbOpts.put(MysqldResourceI.PORT, Integer.toString(port));
@@ -115,7 +119,7 @@ public class MysqlTestingHelper {
return;
}
- log.info("Deleting table: " + table);
+ log.debug("Deleting table: " + table);
final IDBI dbi = getDBI();
dbi.withHandle(new HandleCallback<Void>() {
@Override
@@ -173,6 +177,19 @@ public class MysqlTestingHelper {
return new DBI(dbiString, USERNAME, PASSWORD);
}
+ public void initDb() throws IOException {
+ for (final String pack : new String[]{"account", "analytics", "entitlement", "util", "payment", "invoice", "junction"}) {
+ final String ddl;
+ try {
+ ddl = IOUtils.toString(Resources.getResource("com/ning/billing/" + pack + "/ddl.sql").openStream());
+ } catch (IllegalArgumentException ignored) {
+ // The test doesn't have this module ddl in the classpath - that's fine
+ continue;
+ }
+ initDb(ddl);
+ }
+ }
+
public void initDb(final String ddl) throws IOException {
if (isUsingLocalInstance()) {
return;
@@ -181,7 +198,7 @@ public class MysqlTestingHelper {
dbi.withHandle(new HandleCallback<Void>() {
@Override
public Void withHandle(final Handle handle) throws Exception {
- log.info("Executing DDL script: " + ddl);
+ log.debug("Executing DDL script: " + ddl);
handle.createScript(ddl).execute();
return null;
}
diff --git a/util/src/test/java/com/ning/billing/KillbillTestSuite.java b/util/src/test/java/com/ning/billing/KillbillTestSuite.java
new file mode 100644
index 0000000..0d8edb2
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/KillbillTestSuite.java
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import java.lang.reflect.Method;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.ITestResult;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+
+public class KillbillTestSuite {
+ // Use the simple name here to save screen real estate
+ private static final Logger log = LoggerFactory.getLogger(KillbillTestSuite.class.getSimpleName());
+
+ @BeforeMethod(alwaysRun = true)
+ public void startTestSuite(final Method method) throws Exception {
+ log.info("***************************************************************************************************");
+ log.info("*** Starting test {}:{}", method.getDeclaringClass().getName(), method.getName());
+ log.info("***************************************************************************************************");
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void endTestSuite(final Method method, final ITestResult result) throws Exception {
+ log.info("***************************************************************************************************");
+ log.info("*** Ending test {}:{} {} ({} s.)", new Object[]{method.getDeclaringClass().getName(), method.getName(),
+ result.isSuccess() ? "SUCCESS" : "!!! FAILURE !!!", (result.getEndMillis() - result.getStartMillis()) / 1000});
+ log.info("***************************************************************************************************");
+ }
+}
diff --git a/util/src/test/java/com/ning/billing/mock/glue/MockDbHelperModule.java b/util/src/test/java/com/ning/billing/mock/glue/MockDbHelperModule.java
index be1ade6..d1b8027 100644
--- a/util/src/test/java/com/ning/billing/mock/glue/MockDbHelperModule.java
+++ b/util/src/test/java/com/ning/billing/mock/glue/MockDbHelperModule.java
@@ -20,21 +20,19 @@ import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
import com.google.inject.AbstractModule;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.DBIProvider;
import com.ning.billing.dbi.DbiConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
public class MockDbHelperModule extends AbstractModule {
-
-
@Override
protected void configure() {
installMysqlTestingHelper();
}
public void installMysqlTestingHelper() {
-
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
if (helper.isUsingLocalInstance()) {
bind(IDBI.class).toProvider(DBIProvider.class).asEagerSingleton();
@@ -44,7 +42,5 @@ public class MockDbHelperModule extends AbstractModule {
final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
}
-
}
-
}
diff --git a/util/src/test/java/com/ning/billing/mock/glue/MockEntitlementModule.java b/util/src/test/java/com/ning/billing/mock/glue/MockEntitlementModule.java
index 5037f48..d712082 100644
--- a/util/src/test/java/com/ning/billing/mock/glue/MockEntitlementModule.java
+++ b/util/src/test/java/com/ning/billing/mock/glue/MockEntitlementModule.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2011 Ning, Inc.
+ * 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
@@ -16,6 +16,8 @@
package com.ning.billing.mock.glue;
+import org.mockito.Mockito;
+
import com.google.inject.AbstractModule;
import com.ning.billing.entitlement.api.EntitlementService;
import com.ning.billing.entitlement.api.billing.ChargeThruApi;
@@ -23,41 +25,27 @@ import com.ning.billing.entitlement.api.migration.EntitlementMigrationApi;
import com.ning.billing.entitlement.api.timeline.EntitlementTimelineApi;
import com.ning.billing.entitlement.api.user.EntitlementUserApi;
import com.ning.billing.glue.EntitlementModule;
-import com.ning.billing.mock.BrainDeadProxyFactory;
import com.ning.billing.util.glue.RealImplementation;
public class MockEntitlementModule extends AbstractModule implements EntitlementModule {
-
- /* (non-Javadoc)
- * @see com.ning.billing.mock.glue.EntitlementModule#installEntitlementService()
- */
@Override
public void installEntitlementService() {
- bind(EntitlementService.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementService.class));
+ bind(EntitlementService.class).toInstance(Mockito.mock(EntitlementService.class));
}
- /* (non-Javadoc)
- * @see com.ning.billing.mock.glue.EntitlementModule#installEntitlementUserApi()
- */
@Override
public void installEntitlementUserApi() {
- bind(EntitlementUserApi.class).annotatedWith(RealImplementation.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class));
+ bind(EntitlementUserApi.class).annotatedWith(RealImplementation.class).toInstance(Mockito.mock(EntitlementUserApi.class));
}
- /* (non-Javadoc)
- * @see com.ning.billing.mock.glue.EntitlementModule#installEntitlementMigrationApi()
- */
@Override
public void installEntitlementMigrationApi() {
- bind(EntitlementMigrationApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementMigrationApi.class));
+ bind(EntitlementMigrationApi.class).toInstance(Mockito.mock(EntitlementMigrationApi.class));
}
- /* (non-Javadoc)
- * @see com.ning.billing.mock.glue.EntitlementModule#installChargeThruApi()
- */
@Override
public void installChargeThruApi() {
- bind(ChargeThruApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(ChargeThruApi.class));
+ bind(ChargeThruApi.class).toInstance(Mockito.mock(ChargeThruApi.class));
}
@Override
@@ -71,6 +59,6 @@ public class MockEntitlementModule extends AbstractModule implements Entitlement
@Override
public void installEntitlementTimelineApi() {
- bind(EntitlementTimelineApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementTimelineApi.class));
+ bind(EntitlementTimelineApi.class).toInstance(Mockito.mock(EntitlementTimelineApi.class));
}
}
diff --git a/util/src/test/java/com/ning/billing/mock/glue/MockInvoiceModule.java b/util/src/test/java/com/ning/billing/mock/glue/MockInvoiceModule.java
index 90e41c4..ecca1cd 100644
--- a/util/src/test/java/com/ning/billing/mock/glue/MockInvoiceModule.java
+++ b/util/src/test/java/com/ning/billing/mock/glue/MockInvoiceModule.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2011 Ning, Inc.
+ * 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
@@ -16,34 +16,28 @@
package com.ning.billing.mock.glue;
+import org.mockito.Mockito;
+
import com.google.inject.AbstractModule;
import com.ning.billing.glue.InvoiceModule;
import com.ning.billing.invoice.api.InvoiceMigrationApi;
import com.ning.billing.invoice.api.InvoicePaymentApi;
import com.ning.billing.invoice.api.InvoiceUserApi;
-import com.ning.billing.invoice.api.test.InvoiceTestApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
public class MockInvoiceModule extends AbstractModule implements InvoiceModule {
-
@Override
public void installInvoiceUserApi() {
- bind(InvoiceUserApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceUserApi.class));
+ bind(InvoiceUserApi.class).toInstance(Mockito.mock(InvoiceUserApi.class));
}
@Override
public void installInvoicePaymentApi() {
- bind(InvoicePaymentApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(InvoicePaymentApi.class));
+ bind(InvoicePaymentApi.class).toInstance(Mockito.mock(InvoicePaymentApi.class));
}
@Override
public void installInvoiceMigrationApi() {
- bind(InvoiceMigrationApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceMigrationApi.class));
- }
-
- @Override
- public void installInvoiceTestApi() {
- bind(InvoiceTestApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(InvoiceTestApi.class));
+ bind(InvoiceMigrationApi.class).toInstance(Mockito.mock(InvoiceMigrationApi.class));
}
@Override
@@ -51,6 +45,5 @@ public class MockInvoiceModule extends AbstractModule implements InvoiceModule {
installInvoiceUserApi();
installInvoicePaymentApi();
installInvoiceMigrationApi();
- installInvoiceTestApi();
}
}
diff --git a/util/src/test/java/com/ning/billing/mock/glue/MockJunctionModule.java b/util/src/test/java/com/ning/billing/mock/glue/MockJunctionModule.java
index 67769dd..fedd51e 100644
--- a/util/src/test/java/com/ning/billing/mock/glue/MockJunctionModule.java
+++ b/util/src/test/java/com/ning/billing/mock/glue/MockJunctionModule.java
@@ -16,19 +16,20 @@
package com.ning.billing.mock.glue;
+import org.mockito.Mockito;
+
import com.google.inject.AbstractModule;
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.entitlement.api.user.EntitlementUserApi;
import com.ning.billing.glue.JunctionModule;
import com.ning.billing.junction.api.BillingApi;
import com.ning.billing.junction.api.BlockingApi;
-import com.ning.billing.mock.BrainDeadProxyFactory;
public class MockJunctionModule extends AbstractModule implements JunctionModule {
- private final BillingApi billingApi = BrainDeadProxyFactory.createBrainDeadProxyFor(BillingApi.class);
- private final BlockingApi blockingApi = BrainDeadProxyFactory.createBrainDeadProxyFor(BlockingApi.class);
- private final AccountUserApi userApi = BrainDeadProxyFactory.createBrainDeadProxyFor(AccountUserApi.class);
- private final EntitlementUserApi entUserApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementUserApi.class);
+ private final BillingApi billingApi = Mockito.mock(BillingApi.class);
+ private final BlockingApi blockingApi = Mockito.mock(BlockingApi.class);
+ private final AccountUserApi userApi = Mockito.mock(AccountUserApi.class);
+ private final EntitlementUserApi entUserApi = Mockito.mock(EntitlementUserApi.class);
@Override
protected void configure() {
@@ -43,7 +44,6 @@ public class MockJunctionModule extends AbstractModule implements JunctionModule
bind(BillingApi.class).toInstance(billingApi);
}
-
@Override
public void installAccountUserApi() {
bind(AccountUserApi.class).toInstance(userApi);
diff --git a/util/src/test/java/com/ning/billing/mock/glue/MockOverdueModule.java b/util/src/test/java/com/ning/billing/mock/glue/MockOverdueModule.java
index 7ab87d8..013005b 100644
--- a/util/src/test/java/com/ning/billing/mock/glue/MockOverdueModule.java
+++ b/util/src/test/java/com/ning/billing/mock/glue/MockOverdueModule.java
@@ -16,21 +16,20 @@
package com.ning.billing.mock.glue;
+import org.mockito.Mockito;
+
import com.google.inject.AbstractModule;
import com.ning.billing.glue.OverdueModule;
-import com.ning.billing.mock.BrainDeadProxyFactory;
import com.ning.billing.overdue.OverdueUserApi;
public class MockOverdueModule extends AbstractModule implements OverdueModule {
-
@Override
public void installOverdueUserApi() {
- bind(OverdueUserApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(OverdueUserApi.class));
+ bind(OverdueUserApi.class).toInstance(Mockito.mock(OverdueUserApi.class));
}
@Override
protected void configure() {
installOverdueUserApi();
}
-
}
diff --git a/util/src/test/java/com/ning/billing/mock/glue/MockPaymentModule.java b/util/src/test/java/com/ning/billing/mock/glue/MockPaymentModule.java
index e974333..d2c7ddd 100644
--- a/util/src/test/java/com/ning/billing/mock/glue/MockPaymentModule.java
+++ b/util/src/test/java/com/ning/billing/mock/glue/MockPaymentModule.java
@@ -16,16 +16,14 @@
package com.ning.billing.mock.glue;
+import org.mockito.Mockito;
+
import com.google.inject.AbstractModule;
-import com.ning.billing.mock.BrainDeadProxyFactory;
import com.ning.billing.payment.api.PaymentApi;
public class MockPaymentModule extends AbstractModule {
-
@Override
protected void configure() {
-
- bind(PaymentApi.class).toInstance(BrainDeadProxyFactory.createBrainDeadProxyFor(PaymentApi.class));
-
+ bind(PaymentApi.class).toInstance(Mockito.mock(PaymentApi.class));
}
}
diff --git a/util/src/test/java/com/ning/billing/mock/glue/TestDbiModule.java b/util/src/test/java/com/ning/billing/mock/glue/TestDbiModule.java
index 76dea1d..634631a 100644
--- a/util/src/test/java/com/ning/billing/mock/glue/TestDbiModule.java
+++ b/util/src/test/java/com/ning/billing/mock/glue/TestDbiModule.java
@@ -20,15 +20,14 @@ import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
import com.google.inject.AbstractModule;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.DBIProvider;
import com.ning.billing.dbi.DbiConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
public class TestDbiModule extends AbstractModule {
-
protected void configure() {
-
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
if (helper.isUsingLocalInstance()) {
bind(IDBI.class).toProvider(DBIProvider.class).asEagerSingleton();
@@ -38,6 +37,5 @@ public class TestDbiModule extends AbstractModule {
final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
}
-
}
}
diff --git a/util/src/test/java/com/ning/billing/mock/MockSubscription.java b/util/src/test/java/com/ning/billing/mock/MockSubscription.java
index af6628d..2a3c024 100644
--- a/util/src/test/java/com/ning/billing/mock/MockSubscription.java
+++ b/util/src/test/java/com/ning/billing/mock/MockSubscription.java
@@ -21,6 +21,7 @@ import java.util.UUID;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
import com.google.common.collect.ImmutableList;
import com.ning.billing.catalog.api.BillingPeriod;
@@ -64,7 +65,7 @@ public class MockSubscription implements Subscription {
this.transitions = ImmutableList.<EffectiveSubscriptionEvent>of();
}
- Subscription sub = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
+ Subscription sub = Mockito.mock(Subscription.class);
@Override
public boolean cancel(final DateTime requestedDate, final boolean eot, final CallContext context) throws EntitlementUserApiException {
diff --git a/util/src/test/java/com/ning/billing/util/bus/TestEventBus.java b/util/src/test/java/com/ning/billing/util/bus/TestEventBus.java
index a91842d..0c92e6d 100644
--- a/util/src/test/java/com/ning/billing/util/bus/TestEventBus.java
+++ b/util/src/test/java/com/ning/billing/util/bus/TestEventBus.java
@@ -19,10 +19,7 @@ package com.ning.billing.util.bus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-@Test(groups = {"slow"})
public class TestEventBus extends TestEventBusBase {
-
-
@BeforeClass(groups = "slow")
public void setup() throws Exception {
eventBus = new InMemoryBus();
diff --git a/util/src/test/java/com/ning/billing/util/bus/TestEventBusBase.java b/util/src/test/java/com/ning/billing/util/bus/TestEventBusBase.java
index 52f06c6..2364c2c 100644
--- a/util/src/test/java/com/ning/billing/util/bus/TestEventBusBase.java
+++ b/util/src/test/java/com/ning/billing/util/bus/TestEventBusBase.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.util.bus;
import java.util.UUID;
@@ -28,10 +29,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.bus.BusEvent.BusEventType;
-public class TestEventBusBase {
-
+public abstract class TestEventBusBase extends UtilTestSuiteWithEmbeddedDB {
protected static final Logger log = LoggerFactory.getLogger(TestEventBusBase.class);
@Inject
@@ -47,9 +48,7 @@ public class TestEventBusBase {
eventBus.stop();
}
-
public static class MyEvent implements BusEvent {
-
private final String name;
private final Long value;
private final UUID userToken;
@@ -102,7 +101,6 @@ public class TestEventBusBase {
}
}
-
public static final class MyOtherEvent implements BusEvent {
private final String name;
@@ -110,7 +108,6 @@ public class TestEventBusBase {
private final UUID userToken;
private final String type;
-
@JsonCreator
public MyOtherEvent(@JsonProperty("name") final String name,
@JsonProperty("value") final Double value,
@@ -159,7 +156,6 @@ public class TestEventBusBase {
private volatile int gotEvents;
-
public MyEventHandler(final int exp) {
this.expectedEvents = exp;
this.gotEvents = 0;
@@ -206,15 +202,12 @@ public class TestEventBusBase {
eventBus.post(new MyEventWithException("my-event", 1L, UUID.randomUUID(), BusEventType.ACCOUNT_CHANGE.toString()));
Thread.sleep(50000);
- } catch (Exception e) {
-
+ } catch (Exception ignored) {
}
-
}
public void testSimple() {
try {
-
final int nbEvents = 5;
final MyEventHandler handler = new MyEventHandler(nbEvents);
eventBus.register(handler);
@@ -232,7 +225,6 @@ public class TestEventBusBase {
public void testDifferentType() {
try {
-
final MyEventHandler handler = new MyEventHandler(1);
eventBus.register(handler);
@@ -246,6 +238,5 @@ public class TestEventBusBase {
} catch (Exception e) {
Assert.fail("", e);
}
-
}
}
diff --git a/util/src/test/java/com/ning/billing/util/bus/TestPersistentEventBus.java b/util/src/test/java/com/ning/billing/util/bus/TestPersistentEventBus.java
index 1b58ce1..2fb937b 100644
--- a/util/src/test/java/com/ning/billing/util/bus/TestPersistentEventBus.java
+++ b/util/src/test/java/com/ning/billing/util/bus/TestPersistentEventBus.java
@@ -13,17 +13,17 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
+
package com.ning.billing.util.bus;
import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.DBIProvider;
import com.ning.billing.dbi.DbiConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
@@ -31,28 +31,12 @@ import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
import com.ning.billing.util.glue.BusModule;
import com.ning.billing.util.glue.BusModule.BusType;
-import com.ning.billing.util.io.IOUtils;
@Guice(modules = TestPersistentEventBus.PersistentBusModuleTest.class)
public class TestPersistentEventBus extends TestEventBusBase {
@Inject
private MysqlTestingHelper helper;
- @BeforeClass(groups = {"slow"})
- public void setup() throws Exception {
- helper.startMysql();
- final String ddl = IOUtils.toString(TestPersistentEventBus.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- helper.initDb(ddl);
- cleanup();
- super.setup();
- }
-
- @BeforeMethod(groups = {"slow"})
- public void cleanup() {
- helper.cleanupTable("bus_events");
- helper.cleanupTable("claimed_bus_events");
- }
-
public static class PersistentBusModuleTest extends AbstractModule {
@Override
protected void configure() {
@@ -61,7 +45,7 @@ public class TestPersistentEventBus extends TestEventBusBase {
bind(Clock.class).to(ClockMock.class).asEagerSingleton();
bind(ClockMock.class).asEagerSingleton();
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
if (helper.isUsingLocalInstance()) {
bind(IDBI.class).toProvider(DBIProvider.class).asEagerSingleton();
@@ -75,16 +59,14 @@ public class TestPersistentEventBus extends TestEventBusBase {
}
}
- @Test(groups = {"slow"})
+ @Test(groups = "slow")
public void testSimple() {
super.testSimple();
}
// Until Guava fixes exception handling, r13?
- @Test(groups = {"slow"}, enabled = false)
+ @Test(groups = "slow", enabled = false)
public void testSimpleWithException() {
super.testSimpleWithException();
-
}
-
}
diff --git a/util/src/test/java/com/ning/billing/util/callcontext/TestCallContext.java b/util/src/test/java/com/ning/billing/util/callcontext/TestCallContext.java
index 3ed0f8d..2ecc629 100644
--- a/util/src/test/java/com/ning/billing/util/callcontext/TestCallContext.java
+++ b/util/src/test/java/com/ning/billing/util/callcontext/TestCallContext.java
@@ -23,7 +23,6 @@ import org.joda.time.DateTime;
import com.ning.billing.util.clock.DefaultClock;
public class TestCallContext implements CallContext {
-
private final String userName;
private final DateTime updatedDate;
private final DateTime createdDate;
diff --git a/util/src/test/java/com/ning/billing/util/clock/ClockMock.java b/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
index d8542e0..681b0b2 100644
--- a/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
+++ b/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
@@ -32,11 +32,9 @@ import com.ning.billing.catalog.api.Duration;
import com.ning.billing.catalog.api.TimeUnit;
public class ClockMock implements Clock {
-
private MutablePeriod delta = new MutablePeriod();
private static final Logger log = LoggerFactory.getLogger(ClockMock.class);
-
@Override
public synchronized DateTime getNow(final DateTimeZone tz) {
return getUTCNow().toDateTime(tz);
@@ -146,6 +144,4 @@ public class ClockMock implements Clock {
return new Period();
}
}
-
-
}
diff --git a/util/src/test/java/com/ning/billing/util/clock/OldClockMock.java b/util/src/test/java/com/ning/billing/util/clock/OldClockMock.java
index b032bed..4197b24 100644
--- a/util/src/test/java/com/ning/billing/util/clock/OldClockMock.java
+++ b/util/src/test/java/com/ning/billing/util/clock/OldClockMock.java
@@ -158,6 +158,4 @@ public class OldClockMock extends DefaultClock {
public String toString() {
return getUTCNow().toString();
}
-
-
}
diff --git a/util/src/test/java/com/ning/billing/util/config/TestXMLLoader.java b/util/src/test/java/com/ning/billing/util/config/TestXMLLoader.java
index 96f7a06..0c3a5dd 100644
--- a/util/src/test/java/com/ning/billing/util/config/TestXMLLoader.java
+++ b/util/src/test/java/com/ning/billing/util/config/TestXMLLoader.java
@@ -28,11 +28,12 @@ import org.testng.annotations.Test;
import org.xml.sax.SAXException;
import com.ning.billing.catalog.api.InvalidConfigException;
+import com.ning.billing.util.UtilTestSuite;
import static org.testng.Assert.assertEquals;
-public class TestXMLLoader {
+public class TestXMLLoader extends UtilTestSuite {
public static final String TEST_XML =
"<xmlTestClass>" +
" <foo>foo</foo>" +
@@ -40,7 +41,7 @@ public class TestXMLLoader {
" <lala>42</lala>" +
"</xmlTestClass>";
- @Test
+ @Test(groups = "fast")
public void test() throws SAXException, InvalidConfigException, JAXBException, IOException, TransformerException, URISyntaxException, ValidationException {
final InputStream is = new ByteArrayInputStream(TEST_XML.getBytes());
final XmlTestClass test = XMLLoader.getObjectFromStream(new URI("internal:/"), is, XmlTestClass.class);
@@ -48,6 +49,4 @@ public class TestXMLLoader {
assertEquals(test.getBar(), 1.0);
assertEquals(test.getLala(), 42);
}
-
-
}
diff --git a/util/src/test/java/com/ning/billing/util/config/TestXMLSchemaGenerator.java b/util/src/test/java/com/ning/billing/util/config/TestXMLSchemaGenerator.java
index 8eae647..fde04b0 100644
--- a/util/src/test/java/com/ning/billing/util/config/TestXMLSchemaGenerator.java
+++ b/util/src/test/java/com/ning/billing/util/config/TestXMLSchemaGenerator.java
@@ -23,9 +23,10 @@ import java.io.InputStream;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.io.IOUtils;
-public class TestXMLSchemaGenerator {
+public class TestXMLSchemaGenerator extends UtilTestSuite {
@Test(groups = "fast", enabled = false)
public void test() throws IOException, TransformerException, JAXBException {
final InputStream stream = XMLSchemaGenerator.xmlSchema(XmlTestClass.class);
diff --git a/util/src/test/java/com/ning/billing/util/config/TestXMLWriter.java b/util/src/test/java/com/ning/billing/util/config/TestXMLWriter.java
index 11878b9..53c854a 100644
--- a/util/src/test/java/com/ning/billing/util/config/TestXMLWriter.java
+++ b/util/src/test/java/com/ning/billing/util/config/TestXMLWriter.java
@@ -22,9 +22,11 @@ import java.net.URI;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
+
import static org.testng.Assert.assertEquals;
-public class TestXMLWriter {
+public class TestXMLWriter extends UtilTestSuite {
public static final String TEST_XML =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"<xmlTestClass>" +
@@ -33,7 +35,7 @@ public class TestXMLWriter {
"<lala>42</lala>" +
"</xmlTestClass>";
- @Test
+ @Test(groups = "fast")
public void test() throws Exception {
final InputStream is = new ByteArrayInputStream(TEST_XML.getBytes());
final XmlTestClass test = XMLLoader.getObjectFromStream(new URI("internal:/"), is, XmlTestClass.class);
@@ -42,11 +44,7 @@ public class TestXMLWriter {
assertEquals(test.getLala(), 42);
final String output = XMLWriter.writeXML(test, XmlTestClass.class);
-
- System.out.println(output);
+ //System.out.println(output);
assertEquals(output.replaceAll("\\s", ""), TEST_XML.replaceAll("\\s", ""));
-
}
-
-
}
diff --git a/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java b/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
index e5caad4..6182629 100644
--- a/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
+++ b/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
@@ -22,11 +22,12 @@ import java.util.UUID;
import org.skife.jdbi.v2.IDBI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.callcontext.CallContext;
import com.ning.billing.util.callcontext.CallOrigin;
import com.ning.billing.util.callcontext.DefaultCallContextFactory;
@@ -36,28 +37,20 @@ import com.ning.billing.util.customfield.dao.AuditedCustomFieldDao;
import com.ning.billing.util.customfield.dao.CustomFieldDao;
import com.ning.billing.util.customfield.dao.CustomFieldSqlDao;
import com.ning.billing.util.dao.ObjectType;
-import com.ning.billing.util.io.IOUtils;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
-@Test(groups = {"util", "slow"})
-public class TestFieldStore {
- Logger log = LoggerFactory.getLogger(TestFieldStore.class);
- private final MysqlTestingHelper helper = new MysqlTestingHelper();
+public class TestFieldStore extends UtilTestSuiteWithEmbeddedDB {
+ private final Logger log = LoggerFactory.getLogger(TestFieldStore.class);
+ private final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
private CallContext context;
private IDBI dbi;
private CustomFieldDao customFieldDao;
- @BeforeClass(groups = {"util", "slow"})
+ @BeforeClass(groups = "slow")
protected void setup() throws IOException {
- // Health check test to make sure MySQL is setup properly
try {
- final String utilDdl = IOUtils.toString(TestFieldStore.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
- helper.startMysql();
- helper.initDb(utilDdl);
-
dbi = helper.getDBI();
customFieldDao = new AuditedCustomFieldDao(dbi);
context = new DefaultCallContextFactory(new ClockMock()).createCallContext("Fezzik", CallOrigin.TEST, UserType.TEST);
@@ -67,14 +60,7 @@ public class TestFieldStore {
}
}
- @AfterClass(groups = {"util", "slow"})
- public void stopMysql() {
- if (helper != null) {
- helper.stopMysql();
- }
- }
-
- @Test
+ @Test(groups = "slow")
public void testFieldStore() {
final UUID id = UUID.randomUUID();
final ObjectType objectType = ObjectType.ACCOUNT;
diff --git a/util/src/test/java/com/ning/billing/util/email/DefaultCatalogTranslationTest.java b/util/src/test/java/com/ning/billing/util/email/DefaultCatalogTranslationTest.java
index 529616e..4fe5198 100644
--- a/util/src/test/java/com/ning/billing/util/email/DefaultCatalogTranslationTest.java
+++ b/util/src/test/java/com/ning/billing/util/email/DefaultCatalogTranslationTest.java
@@ -23,16 +23,17 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.template.translation.DefaultCatalogTranslator;
import com.ning.billing.util.template.translation.Translator;
import com.ning.billing.util.template.translation.TranslatorConfig;
import static org.testng.Assert.assertEquals;
-public class DefaultCatalogTranslationTest {
+public class DefaultCatalogTranslationTest extends UtilTestSuite {
private Translator translation;
- @BeforeClass(groups = {"fast", "email"})
+ @BeforeClass(groups = "fast")
public void setup() {
final ConfigSource configSource = new ConfigSource() {
private final Map<String, String> properties = ImmutableMap.<String, String>of("killbill.template.invoiceFormatterFactoryClass",
diff --git a/util/src/test/java/com/ning/billing/util/email/EmailSenderTest.java b/util/src/test/java/com/ning/billing/util/email/EmailSenderTest.java
index b3e4d64..81b40d9 100644
--- a/util/src/test/java/com/ning/billing/util/email/EmailSenderTest.java
+++ b/util/src/test/java/com/ning/billing/util/email/EmailSenderTest.java
@@ -21,8 +21,10 @@ import org.skife.config.ConfigurationObjectFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-@Test(groups = {"slow", "email"})
-public class EmailSenderTest {
+import com.ning.billing.util.UtilTestSuite;
+
+@Test(groups = "slow")
+public class EmailSenderTest extends UtilTestSuite {
private EmailConfig config;
@BeforeClass
diff --git a/util/src/test/java/com/ning/billing/util/globallocker/MockGlobalLocker.java b/util/src/test/java/com/ning/billing/util/globallocker/MockGlobalLocker.java
index 1e46918..4466b1a 100644
--- a/util/src/test/java/com/ning/billing/util/globallocker/MockGlobalLocker.java
+++ b/util/src/test/java/com/ning/billing/util/globallocker/MockGlobalLocker.java
@@ -17,7 +17,6 @@
package com.ning.billing.util.globallocker;
public class MockGlobalLocker implements GlobalLocker {
-
@Override
public GlobalLock lockWithNumberOfTries(final LockerType service,
final String lockKey, final int retry) {
diff --git a/util/src/test/java/com/ning/billing/util/globallocker/TestMysqlGlobalLocker.java b/util/src/test/java/com/ning/billing/util/globallocker/TestMysqlGlobalLocker.java
index f2fd01a..ed05f5f 100644
--- a/util/src/test/java/com/ning/billing/util/globallocker/TestMysqlGlobalLocker.java
+++ b/util/src/test/java/com/ning/billing/util/globallocker/TestMysqlGlobalLocker.java
@@ -24,45 +24,35 @@ import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.TransactionCallback;
import org.skife.jdbi.v2.TransactionStatus;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.globallocker.GlobalLocker.LockerType;
import com.ning.billing.util.io.IOUtils;
-@Test(groups = "slow")
@Guice(modules = TestMysqlGlobalLocker.TestMysqlGlobalLockerModule.class)
-public class TestMysqlGlobalLocker {
-
+public class TestMysqlGlobalLocker extends UtilTestSuiteWithEmbeddedDB {
@Inject
private IDBI dbi;
@Inject
private MysqlTestingHelper helper;
- @BeforeClass(groups = "slow")
+ @BeforeMethod(groups = "slow")
public void setup() throws IOException {
final String testDdl = IOUtils.toString(TestMysqlGlobalLocker.class.getResourceAsStream("/com/ning/billing/util/ddl_test.sql"));
- helper.startMysql();
helper.initDb(testDdl);
}
- @AfterClass(groups = "slow")
- public void tearDown() {
- if (helper != null) {
- helper.stopMysql();
- }
- }
-
// Used as a manual test to validate the simple DAO by stepping through that locking is done and release correctly
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "slow")
public void testSimpleLocking() {
-
final String lockName = UUID.randomUUID().toString();
final GlobalLocker locker = new MySqlGlobalLocker(dbi);
@@ -92,10 +82,9 @@ public class TestMysqlGlobalLocker {
}
public static final class TestMysqlGlobalLockerModule extends AbstractModule {
-
@Override
protected void configure() {
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java b/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
index d7141d3..ba2232a 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
@@ -16,8 +16,6 @@
package com.ning.billing.util.notificationq.dao;
-import java.io.IOException;
-import java.sql.SQLException;
import java.util.List;
import java.util.UUID;
@@ -27,7 +25,6 @@ import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.tweak.HandleCallback;
import org.testng.Assert;
-import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice;
@@ -35,8 +32,9 @@ import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.MysqlTestingHelper;
-import com.ning.billing.util.io.IOUtils;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.notificationq.DefaultNotification;
import com.ning.billing.util.notificationq.Notification;
import com.ning.billing.util.notificationq.dao.NotificationSqlDao.NotificationSqlMapper;
@@ -45,9 +43,9 @@ import com.ning.billing.util.queue.PersistentQueueEntryLifecycle.PersistentQueue
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
-@Test(groups = "slow")
@Guice(modules = TestNotificationSqlDao.TestNotificationSqlDaoModule.class)
-public class TestNotificationSqlDao {
+public class TestNotificationSqlDao extends UtilTestSuiteWithEmbeddedDB {
+ private static final UUID accountId = UUID.randomUUID();
private static final String hostname = "Yop";
@Inject
@@ -58,34 +56,14 @@ public class TestNotificationSqlDao {
private NotificationSqlDao dao;
- private void startMysql() throws IOException, ClassNotFoundException, SQLException {
- final String ddl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- helper.startMysql();
- helper.initDb(ddl);
- }
-
@BeforeSuite(groups = "slow")
public void setup() {
- try {
- startMysql();
- dao = dbi.onDemand(NotificationSqlDao.class);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterSuite(groups = "slow")
- public void stopMysql() {
- if (helper != null) {
- helper.stopMysql();
- }
+ dao = dbi.onDemand(NotificationSqlDao.class);
}
-
@BeforeTest(groups = "slow")
public void cleanupDb() {
dbi.withHandle(new HandleCallback<Void>() {
-
@Override
public Void withHandle(final Handle handle) throws Exception {
handle.execute("delete from notifications");
@@ -95,14 +73,13 @@ public class TestNotificationSqlDao {
});
}
- @Test
+ @Test(groups = "slow")
public void testBasic() throws InterruptedException {
-
final String ownerId = UUID.randomUUID().toString();
final String notificationKey = UUID.randomUUID().toString();
final DateTime effDt = new DateTime();
- final Notification notif = new DefaultNotification("testBasic", hostname, notificationKey.getClass().getName(), notificationKey, effDt);
+ final Notification notif = new DefaultNotification("testBasic", hostname, notificationKey.getClass().getName(), notificationKey, accountId, effDt);
dao.insertNotification(notif);
Thread.sleep(1000);
@@ -126,7 +103,7 @@ public class TestNotificationSqlDao {
notification = fetchNotification(notification.getId().toString());
assertEquals(notification.getNotificationKey(), notificationKey);
validateDate(notification.getEffectiveDate(), effDt);
- assertEquals(notification.getOwner().toString(), ownerId);
+ assertEquals(notification.getOwner(), ownerId);
assertEquals(notification.getProcessingState(), PersistentQueueEntryLifecycleState.IN_PROCESSING);
validateDate(notification.getNextAvailableDate(), nextAvailable);
@@ -138,35 +115,56 @@ public class TestNotificationSqlDao {
//assertEquals(notification.getOwner(), null);
assertEquals(notification.getProcessingState(), PersistentQueueEntryLifecycleState.PROCESSED);
validateDate(notification.getNextAvailableDate(), nextAvailable);
+ }
+ @Test(groups = "slow")
+ public void testGetByAccountAndDate() throws InterruptedException {
+ final String notificationKey = UUID.randomUUID().toString();
+ final DateTime effDt = new DateTime();
+ final Notification notif1 = new DefaultNotification("testBasic1", hostname, notificationKey.getClass().getName(), notificationKey, accountId, effDt);
+ dao.insertNotification(notif1);
+
+ final Notification notif2 = new DefaultNotification("testBasic2", hostname, notificationKey.getClass().getName(), notificationKey, accountId, effDt);
+ dao.insertNotification(notif2);
+
+ List<Notification> notifications = dao.getNotificationForAccountAndDate(accountId.toString(), effDt.toDate());
+ assertEquals(notifications.size(), 2);
+ for (final Notification cur : notifications) {
+ Assert.assertEquals(cur.getProcessingState(), PersistentQueueEntryLifecycleState.AVAILABLE);
+ dao.removeNotification(cur.getId().toString());
+ }
+
+ notifications = dao.getNotificationForAccountAndDate(accountId.toString(), effDt.toDate());
+ assertEquals(notifications.size(), 2);
+ for (final Notification cur : notifications) {
+ Assert.assertEquals(cur.getProcessingState(), PersistentQueueEntryLifecycleState.REMOVED);
+ }
}
private Notification fetchNotification(final String notificationId) {
- final Notification res = dbi.withHandle(new HandleCallback<Notification>() {
-
+ return dbi.withHandle(new HandleCallback<Notification>() {
@Override
public Notification withHandle(final Handle handle) throws Exception {
- final Notification res = handle.createQuery(" select" +
- " record_id " +
- ", id" +
- ", class_name" +
- ", notification_key" +
- ", created_date" +
- ", creating_owner" +
- ", effective_date" +
- ", queue_name" +
- ", processing_owner" +
- ", processing_available_date" +
- ", processing_state" +
- " from notifications " +
- " where " +
- " id = '" + notificationId + "';")
- .map(new NotificationSqlMapper())
- .first();
- return res;
+ return handle.createQuery(" select" +
+ " record_id " +
+ ", id" +
+ ", class_name" +
+ ", account_id" +
+ ", notification_key" +
+ ", created_date" +
+ ", creating_owner" +
+ ", effective_date" +
+ ", queue_name" +
+ ", processing_owner" +
+ ", processing_available_date" +
+ ", processing_state" +
+ " from notifications " +
+ " where " +
+ " id = '" + notificationId + "';")
+ .map(new NotificationSqlMapper())
+ .first();
}
});
- return res;
}
private void validateDate(DateTime input, DateTime expected) {
@@ -192,8 +190,7 @@ public class TestNotificationSqlDao {
public static class TestNotificationSqlDaoModule extends AbstractModule {
@Override
protected void configure() {
-
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java b/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
index edb4f2e..259952c 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
+import java.util.UUID;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
@@ -51,17 +52,17 @@ public class MockNotificationQueue extends NotificationQueueBase implements Noti
}
@Override
- public void recordFutureNotification(final DateTime futureNotificationTime, final NotificationKey notificationKey) throws IOException {
+ public void recordFutureNotification(final DateTime futureNotificationTime, final UUID accountId, final NotificationKey notificationKey) throws IOException {
final String json = objectMapper.writeValueAsString(notificationKey);
- final Notification notification = new DefaultNotification("MockQueue", getHostname(), notificationKey.getClass().getName(), json, futureNotificationTime);
+ final Notification notification = new DefaultNotification("MockQueue", getHostname(), notificationKey.getClass().getName(), json, accountId, futureNotificationTime);
synchronized (notifications) {
notifications.add(notification);
}
}
@Override
- public void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao, final DateTime futureNotificationTime, final NotificationKey notificationKey) throws IOException {
- recordFutureNotification(futureNotificationTime, notificationKey);
+ public void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao, final DateTime futureNotificationTime, final UUID accountId, final NotificationKey notificationKey) throws IOException {
+ recordFutureNotification(futureNotificationTime, accountId, notificationKey);
}
public List<Notification> getPendingEvents() {
@@ -98,7 +99,7 @@ public class MockNotificationQueue extends NotificationQueueBase implements Noti
final DefaultNotification processedNotification = new DefaultNotification(-1L, cur.getId(), getHostname(), getHostname(),
"MockQueue", getClock().getUTCNow().plus(CLAIM_TIME_MS),
PersistentQueueEntryLifecycleState.PROCESSED, cur.getNotificationKeyClass(),
- cur.getNotificationKey(), cur.getEffectiveDate());
+ cur.getNotificationKey(), cur.getAccountId(), cur.getEffectiveDate());
oldNotifications.add(cur);
processedNotifications.add(processedNotification);
}
@@ -131,4 +132,17 @@ public class MockNotificationQueue extends NotificationQueueBase implements Noti
}
}
}
+
+ @Override
+ public List<Notification> getNotificationForAccountAndDate(UUID accountId,
+ DateTime effectiveDate) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void removeNotification(UUID notificationId) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java b/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
index 11db32e..32fdc70 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
@@ -16,8 +16,6 @@
package com.ning.billing.util.notificationq;
-import java.io.IOException;
-import java.sql.SQLException;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
@@ -34,7 +32,6 @@ import org.skife.jdbi.v2.tweak.HandleCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice;
@@ -47,8 +44,10 @@ import com.google.common.collect.Collections2;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.name.Names;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.config.NotificationConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
import com.ning.billing.util.io.IOUtils;
@@ -59,10 +58,12 @@ import static com.jayway.awaitility.Awaitility.await;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.testng.Assert.assertEquals;
-@Test(groups = "slow")
@Guice(modules = TestNotificationQueue.TestNotificationQueueModule.class)
-public class TestNotificationQueue {
- Logger log = LoggerFactory.getLogger(TestNotificationQueue.class);
+public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
+ private final Logger log = LoggerFactory.getLogger(TestNotificationQueue.class);
+
+ private static final UUID accountId = UUID.randomUUID();
+
@Inject
private IDBI dbi;
@@ -76,23 +77,11 @@ public class TestNotificationQueue {
private int eventsReceived;
- // private NotificationQueue queue;
-
- private void startMysql() throws IOException, ClassNotFoundException, SQLException {
- final String ddl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
- final String testDdl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl_test.sql"));
- helper.startMysql();
- helper.initDb(ddl);
- helper.initDb(testDdl);
- }
-
-
- private final static class TestNotificationKey implements NotificationKey, Comparable<TestNotificationKey> {
-
+ private static final class TestNotificationKey implements NotificationKey, Comparable<TestNotificationKey> {
private final String value;
@JsonCreator
- public TestNotificationKey(@JsonProperty("value") String value) {
+ public TestNotificationKey(@JsonProperty("value") final String value) {
super();
this.value = value;
}
@@ -106,21 +95,14 @@ public class TestNotificationQueue {
return value.compareTo(arg0.value);
}
}
-
-
+
@BeforeSuite(groups = "slow")
public void setup() throws Exception {
- startMysql();
+ final String testDdl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl_test.sql"));
+ helper.initDb(testDdl);
dao = dbi.onDemand(DummySqlTest.class);
}
- @AfterClass(groups = "slow")
- public void tearDown() {
- if (helper != null) {
- helper.stopMysql();
- }
- }
-
@BeforeTest(groups = "slow")
public void beforeTest() {
dbi.withHandle(new HandleCallback<Void>() {
@@ -138,32 +120,30 @@ public class TestNotificationQueue {
eventsReceived = 0;
}
-
/**
* Test that we can post a notification in the future from a transaction and get the notification
* callback with the correct key when the time is ready
*
* @throws Exception
*/
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testSimpleNotification() throws Exception {
final Map<NotificationKey, Boolean> expectedNotifications = new TreeMap<NotificationKey, Boolean>();
final DefaultNotificationQueue queue = new DefaultNotificationQueue(dbi, clock, "test-svc", "foo",
- new NotificationQueueHandler() {
- @Override
- public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDateTime) {
- synchronized (expectedNotifications) {
- log.info("Handler received key: " + notificationKey);
-
- expectedNotifications.put(notificationKey, Boolean.TRUE);
- expectedNotifications.notify();
- }
- }
- },
- getNotificationConfig(false, 100, 1, 10000));
-
+ new NotificationQueueHandler() {
+ @Override
+ public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDateTime) {
+ synchronized (expectedNotifications) {
+ log.info("Handler received key: " + notificationKey);
+
+ expectedNotifications.put(notificationKey, Boolean.TRUE);
+ expectedNotifications.notify();
+ }
+ }
+ },
+ getNotificationConfig(false, 100, 1, 10000));
queue.startQueue();
@@ -175,16 +155,15 @@ public class TestNotificationQueue {
expectedNotifications.put(notificationKey, Boolean.FALSE);
-
// Insert dummy to be processed in 2 sec'
dao.inTransaction(new Transaction<Void, DummySqlTest>() {
@Override
public Void inTransaction(final DummySqlTest transactional,
- final TransactionStatus status) throws Exception {
+ final TransactionStatus status) throws Exception {
transactional.insertDummy(obj);
queue.recordFutureNotificationFromTransaction(transactional,
- readyTime, notificationKey);
+ readyTime, accountId, notificationKey);
log.info("Posted key: " + notificationKey);
return null;
@@ -211,17 +190,16 @@ public class TestNotificationQueue {
final Map<NotificationKey, Boolean> expectedNotifications = new TreeMap<NotificationKey, Boolean>();
final DefaultNotificationQueue queue = new DefaultNotificationQueue(dbi, clock, "test-svc", "many",
- new NotificationQueueHandler() {
- @Override
- public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDateTime) {
- synchronized (expectedNotifications) {
- expectedNotifications.put(notificationKey, Boolean.TRUE);
- expectedNotifications.notify();
- }
- }
- },
- getNotificationConfig(false, 100, 10, 10000));
-
+ new NotificationQueueHandler() {
+ @Override
+ public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDateTime) {
+ synchronized (expectedNotifications) {
+ expectedNotifications.put(notificationKey, Boolean.TRUE);
+ expectedNotifications.notify();
+ }
+ }
+ },
+ getNotificationConfig(false, 100, 10, 10000));
queue.startQueue();
@@ -241,11 +219,11 @@ public class TestNotificationQueue {
dao.inTransaction(new Transaction<Void, DummySqlTest>() {
@Override
public Void inTransaction(final DummySqlTest transactional,
- final TransactionStatus status) throws Exception {
+ final TransactionStatus status) throws Exception {
transactional.insertDummy(obj);
queue.recordFutureNotificationFromTransaction(transactional,
- now.plus((currentIteration + 1) * nextReadyTimeIncrementMs), notificationKey);
+ now.plus((currentIteration + 1) * nextReadyTimeIncrementMs), accountId, notificationKey);
return null;
}
});
@@ -263,7 +241,6 @@ public class TestNotificationQueue {
boolean success = false;
do {
synchronized (expectedNotifications) {
-
final Collection<Boolean> completed = Collections2.filter(expectedNotifications.values(), new Predicate<Boolean>() {
@Override
public boolean apply(final Boolean input) {
@@ -281,7 +258,7 @@ public class TestNotificationQueue {
} while (nbTry-- > 0);
queue.stopQueue();
- log.info("STEPH GOT SIZE " + Collections2.filter(expectedNotifications.values(), new Predicate<Boolean>() {
+ log.info("STEPH GOT SIZE " + Collections2.filter(expectedNotifications.values(), new Predicate<Boolean>() {
@Override
public boolean apply(final Boolean input) {
return input;
@@ -296,9 +273,8 @@ public class TestNotificationQueue {
*
* @throws Exception
*/
- @Test(groups = {"slow"}, enabled = true)
+ @Test(groups = "slow")
public void testMultipleHandlerNotification() throws Exception {
-
final Map<NotificationKey, Boolean> expectedNotificationsFred = new TreeMap<NotificationKey, Boolean>();
final Map<NotificationKey, Boolean> expectedNotificationsBarney = new TreeMap<NotificationKey, Boolean>();
@@ -316,7 +292,6 @@ public class TestNotificationQueue {
}
};
-
final NotificationQueue queueFred = notificationQueueService.createNotificationQueue("UtilTest", "Fred", new NotificationQueueHandler() {
@Override
public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDateTime) {
@@ -325,7 +300,7 @@ public class TestNotificationQueue {
eventsReceived++;
}
},
- config);
+ config);
final NotificationQueue queueBarney = notificationQueueService.createNotificationQueue("UtilTest", "Barney", new NotificationQueueHandler() {
@Override
@@ -335,37 +310,34 @@ public class TestNotificationQueue {
eventsReceived++;
}
},
- config);
+ config);
queueFred.startQueue();
// We don't start Barney so it can never pick up notifications
-
final UUID key = UUID.randomUUID();
final DummyObject obj = new DummyObject("foo", key);
final DateTime now = new DateTime();
final DateTime readyTime = now.plusMillis(2000);
final NotificationKey notificationKeyFred = new TestNotificationKey("Fred");
-
- final NotificationKey notificationKeyBarney = new TestNotificationKey("Barney");
+ final NotificationKey notificationKeyBarney = new TestNotificationKey("Barney");
expectedNotificationsFred.put(notificationKeyFred, Boolean.FALSE);
expectedNotificationsFred.put(notificationKeyBarney, Boolean.FALSE);
-
// Insert dummy to be processed in 2 sec'
dao.inTransaction(new Transaction<Void, DummySqlTest>() {
@Override
public Void inTransaction(final DummySqlTest transactional,
- final TransactionStatus status) throws Exception {
+ final TransactionStatus status) throws Exception {
transactional.insertDummy(obj);
queueFred.recordFutureNotificationFromTransaction(transactional,
- readyTime, notificationKeyFred);
+ readyTime, accountId, notificationKeyFred);
log.info("posted key: " + notificationKeyFred.toString());
queueBarney.recordFutureNotificationFromTransaction(transactional,
- readyTime, notificationKeyBarney);
+ readyTime, accountId, notificationKeyBarney);
log.info("posted key: " + notificationKeyBarney.toString());
return null;
@@ -394,8 +366,7 @@ public class TestNotificationQueue {
Assert.assertFalse(expectedNotificationsFred.get(notificationKeyBarney));
}
- NotificationConfig getNotificationConfig(final boolean off,
- final long sleepTime, final int maxReadyEvents, final long claimTimeMs) {
+ NotificationConfig getNotificationConfig(final boolean off, final long sleepTime, final int maxReadyEvents, final long claimTimeMs) {
return new NotificationConfig() {
@Override
public boolean isNotificationProcessingOff() {
@@ -409,27 +380,24 @@ public class TestNotificationQueue {
};
}
-
@Test(groups = "slow")
public void testRemoveNotifications() throws InterruptedException {
-
final UUID key = UUID.randomUUID();
final NotificationKey notificationKey = new TestNotificationKey(key.toString());
final UUID key2 = UUID.randomUUID();
final NotificationKey notificationKey2 = new TestNotificationKey(key2.toString());
final DefaultNotificationQueue queue = new DefaultNotificationQueue(dbi, clock, "test-svc", "many",
- new NotificationQueueHandler() {
- @Override
- public void handleReadyNotification(final NotificationKey inputKey, final DateTime eventDateTime) {
- if (inputKey.equals(notificationKey) || inputKey.equals(notificationKey2)) { //ignore stray events from other tests
- log.info("Received notification with key: " + notificationKey);
- eventsReceived++;
- }
- }
- },
- getNotificationConfig(false, 100, 10, 10000));
-
+ new NotificationQueueHandler() {
+ @Override
+ public void handleReadyNotification(final NotificationKey inputKey, final DateTime eventDateTime) {
+ if (inputKey.equals(notificationKey) || inputKey.equals(notificationKey2)) { //ignore stray events from other tests
+ log.info("Received notification with key: " + notificationKey);
+ eventsReceived++;
+ }
+ }
+ },
+ getNotificationConfig(false, 100, 10, 10000));
queue.startQueue();
@@ -441,19 +409,18 @@ public class TestNotificationQueue {
dao.inTransaction(new Transaction<Void, DummySqlTest>() {
@Override
public Void inTransaction(final DummySqlTest transactional,
- final TransactionStatus status) throws Exception {
+ final TransactionStatus status) throws Exception {
queue.recordFutureNotificationFromTransaction(transactional,
- start.plus(nextReadyTimeIncrementMs), notificationKey);
+ start.plus(nextReadyTimeIncrementMs), accountId, notificationKey);
queue.recordFutureNotificationFromTransaction(transactional,
- start.plus(2 * nextReadyTimeIncrementMs), notificationKey);
+ start.plus(2 * nextReadyTimeIncrementMs), accountId, notificationKey);
queue.recordFutureNotificationFromTransaction(transactional,
- start.plus(3 * nextReadyTimeIncrementMs), notificationKey2);
+ start.plus(3 * nextReadyTimeIncrementMs), accountId, notificationKey2);
return null;
}
});
-
queue.removeNotificationsByKey(notificationKey); // should remove 2 of the 3
// Move time in the future after the notification effectiveDate
@@ -474,26 +441,17 @@ public class TestNotificationQueue {
queue.stopQueue();
}
-
public static class TestNotificationQueueModule extends AbstractModule {
@Override
protected void configure() {
-
bind(Clock.class).to(ClockMock.class);
- final MysqlTestingHelper helper = new MysqlTestingHelper();
+ final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(MysqlTestingHelper.class).toInstance(helper);
final IDBI dbi = helper.getDBI();
bind(IDBI.class).toInstance(dbi);
final IDBI otherDbi = helper.getDBI();
bind(IDBI.class).annotatedWith(Names.named("global-lock")).toInstance(otherDbi);
- /*
- bind(DBI.class).toProvider(DBIProvider.class).asEagerSingleton();
- final DbiConfig config = new ConfigurationObjectFactory(System.getProperties()).build(DbiConfig.class);
- bind(DbiConfig.class).toInstance(config);
- */
}
}
-
-
}
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagCreationEvent.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagCreationEvent.java
index 5ebd270..9651c31 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagCreationEvent.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagCreationEvent.java
@@ -21,13 +21,14 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.jackson.ObjectMapper;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
-public class TestDefaultControlTagCreationEvent {
+public class TestDefaultControlTagCreationEvent extends UtilTestSuite {
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionCreationEvent.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionCreationEvent.java
index 05d4c05..7ad5252 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionCreationEvent.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionCreationEvent.java
@@ -21,12 +21,13 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.jackson.ObjectMapper;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
-public class TestDefaultControlTagDefinitionCreationEvent {
+public class TestDefaultControlTagDefinitionCreationEvent extends UtilTestSuite {
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagDefinitionId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionDeletionEvent.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionDeletionEvent.java
index 08059d1..2ea3181 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionDeletionEvent.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDefinitionDeletionEvent.java
@@ -21,12 +21,13 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.jackson.ObjectMapper;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
-public class TestDefaultControlTagDefinitionDeletionEvent {
+public class TestDefaultControlTagDefinitionDeletionEvent extends UtilTestSuite {
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagDefinitionId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDeletionEvent.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDeletionEvent.java
index 692149a..5f68460 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDeletionEvent.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultControlTagDeletionEvent.java
@@ -21,13 +21,14 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.jackson.ObjectMapper;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
-public class TestDefaultControlTagDeletionEvent {
+public class TestDefaultControlTagDeletionEvent extends UtilTestSuite {
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagCreationEvent.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagCreationEvent.java
index 4d8162a..e330375 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagCreationEvent.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagCreationEvent.java
@@ -21,13 +21,14 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.jackson.ObjectMapper;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
-public class TestDefaultUserTagCreationEvent {
+public class TestDefaultUserTagCreationEvent extends UtilTestSuite {
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionCreationEvent.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionCreationEvent.java
index 89507d3..ae7ddfa 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionCreationEvent.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionCreationEvent.java
@@ -21,12 +21,13 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.jackson.ObjectMapper;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
-public class TestDefaultUserTagDefinitionCreationEvent {
+public class TestDefaultUserTagDefinitionCreationEvent extends UtilTestSuite {
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagDefinitionId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionDeletionEvent.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionDeletionEvent.java
index bdcfaff..9bc13a2 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionDeletionEvent.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDefinitionDeletionEvent.java
@@ -21,12 +21,13 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.jackson.ObjectMapper;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
-public class TestDefaultUserTagDefinitionDeletionEvent {
+public class TestDefaultUserTagDefinitionDeletionEvent extends UtilTestSuite {
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagDefinitionId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDeletionEvent.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDeletionEvent.java
index ff022ef..2b8bd68 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDeletionEvent.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestDefaultUserTagDeletionEvent.java
@@ -21,13 +21,14 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.jackson.ObjectMapper;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
-public class TestDefaultUserTagDeletionEvent {
+public class TestDefaultUserTagDeletionEvent extends UtilTestSuite {
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/api/user/TestTagEventBuilder.java b/util/src/test/java/com/ning/billing/util/tag/api/user/TestTagEventBuilder.java
index 724ad14..f9f7411 100644
--- a/util/src/test/java/com/ning/billing/util/tag/api/user/TestTagEventBuilder.java
+++ b/util/src/test/java/com/ning/billing/util/tag/api/user/TestTagEventBuilder.java
@@ -21,6 +21,7 @@ import java.util.UUID;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.util.UtilTestSuite;
import com.ning.billing.util.dao.ObjectType;
import com.ning.billing.util.tag.DefaultTagDefinition;
import com.ning.billing.util.tag.TagDefinition;
@@ -35,7 +36,7 @@ import com.ning.billing.util.tag.api.UserTagDefinitionCreationEvent;
import com.ning.billing.util.tag.api.UserTagDefinitionDeletionEvent;
import com.ning.billing.util.tag.api.UserTagDeletionEvent;
-public class TestTagEventBuilder {
+public class TestTagEventBuilder extends UtilTestSuite {
@Test(groups = "fast")
public void testNewUserTagDefinitionCreationEvent() throws Exception {
final UUID tagDefinitionId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/tag/dao/TestAuditedTagDao.java b/util/src/test/java/com/ning/billing/util/tag/dao/TestAuditedTagDao.java
index c21cf14..35c3117 100644
--- a/util/src/test/java/com/ning/billing/util/tag/dao/TestAuditedTagDao.java
+++ b/util/src/test/java/com/ning/billing/util/tag/dao/TestAuditedTagDao.java
@@ -32,6 +32,7 @@ import org.testng.annotations.Test;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.callcontext.CallContext;
@@ -48,7 +49,7 @@ import com.ning.billing.util.tag.TestTagStore;
import com.ning.billing.util.tag.api.TagEvent;
@Guice(modules = MockTagStoreModuleSql.class)
-public class TestAuditedTagDao {
+public class TestAuditedTagDao extends UtilTestSuiteWithEmbeddedDB {
@Inject
private MysqlTestingHelper helper;
@@ -69,25 +70,19 @@ public class TestAuditedTagDao {
@BeforeClass(groups = "slow")
public void setup() throws IOException {
- final String utilDdl = IOUtils.toString(TestTagStore.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
- helper.startMysql();
- helper.initDb(utilDdl);
-
context = new DefaultCallContextFactory(clock).createCallContext("Tag DAO test", CallOrigin.TEST, UserType.TEST, UUID.randomUUID());
bus.start();
}
@BeforeMethod(groups = "slow")
- public void cleanup() throws Bus.EventBusException {
+ public void cleanupBeforeMethod() throws Bus.EventBusException {
eventsListener = new EventsListener();
bus.register(eventsListener);
}
@AfterClass(groups = "slow")
- public void stopMysql() {
+ public void tearDown() {
bus.stop();
- helper.stopMysql();
}
@Test(groups = "slow")
diff --git a/util/src/test/java/com/ning/billing/util/tag/dao/TestDefaultTagDefinitionDao.java b/util/src/test/java/com/ning/billing/util/tag/dao/TestDefaultTagDefinitionDao.java
index c895b67..15d00e1 100644
--- a/util/src/test/java/com/ning/billing/util/tag/dao/TestDefaultTagDefinitionDao.java
+++ b/util/src/test/java/com/ning/billing/util/tag/dao/TestDefaultTagDefinitionDao.java
@@ -31,6 +31,7 @@ import org.testng.annotations.Test;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.BusEvent;
import com.ning.billing.util.callcontext.CallContext;
@@ -45,7 +46,7 @@ import com.ning.billing.util.tag.TestTagStore;
import com.ning.billing.util.tag.api.TagDefinitionEvent;
@Guice(modules = MockTagStoreModuleSql.class)
-public class TestDefaultTagDefinitionDao {
+public class TestDefaultTagDefinitionDao extends UtilTestSuiteWithEmbeddedDB {
@Inject
private MysqlTestingHelper helper;
@@ -63,25 +64,19 @@ public class TestDefaultTagDefinitionDao {
@BeforeClass(groups = "slow")
public void setup() throws IOException {
- final String utilDdl = IOUtils.toString(TestTagStore.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
- helper.startMysql();
- helper.initDb(utilDdl);
-
context = new DefaultCallContextFactory(clock).createCallContext("TagDefinition DAO test", CallOrigin.TEST, UserType.TEST, UUID.randomUUID());
bus.start();
}
@BeforeMethod(groups = "slow")
- public void cleanup() throws Bus.EventBusException {
+ public void cleanupBeforeMethod() throws Bus.EventBusException {
eventsListener = new EventsListener();
bus.register(eventsListener);
}
@AfterClass(groups = "slow")
- public void stopMysql() {
+ public void tearDown() {
bus.stop();
- helper.stopMysql();
}
@Test(groups = "slow")
diff --git a/util/src/test/java/com/ning/billing/util/tag/MockTagStoreModuleSql.java b/util/src/test/java/com/ning/billing/util/tag/MockTagStoreModuleSql.java
index d7a704b..56bb2f7 100644
--- a/util/src/test/java/com/ning/billing/util/tag/MockTagStoreModuleSql.java
+++ b/util/src/test/java/com/ning/billing/util/tag/MockTagStoreModuleSql.java
@@ -21,6 +21,7 @@ import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.tweak.HandleCallback;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.mock.glue.MockClockModule;
import com.ning.billing.util.bus.Bus;
@@ -32,7 +33,7 @@ public class MockTagStoreModuleSql extends TagStoreModule {
@Override
protected void configure() {
- helper = new MysqlTestingHelper();
+ helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
bind(IDBI.class).toInstance(helper.getDBI());
bind(MysqlTestingHelper.class).toInstance(helper);
install(new MockClockModule());
diff --git a/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java b/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
index a5016a7..0fb9e97 100644
--- a/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
+++ b/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
@@ -36,6 +36,7 @@ import org.testng.annotations.Test;
import com.google.inject.Inject;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.api.TagApiException;
import com.ning.billing.util.api.TagDefinitionApiException;
import com.ning.billing.util.bus.Bus;
@@ -57,7 +58,7 @@ import static org.testng.Assert.fail;
@Test(groups = {"slow"})
@Guice(modules = MockTagStoreModuleSql.class)
-public class TestTagStore {
+public class TestTagStore extends UtilTestSuiteWithEmbeddedDB {
@Inject
private MysqlTestingHelper helper;
@@ -83,17 +84,10 @@ public class TestTagStore {
@BeforeClass(groups = "slow")
protected void setup() throws IOException {
- // Health check test to make sure MySQL is setup properly
try {
- final String utilDdl = IOUtils.toString(TestTagStore.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
-
- helper.startMysql();
- helper.initDb(utilDdl);
-
context = new DefaultCallContextFactory(clock).createCallContext("Tag store test", CallOrigin.TEST, UserType.TEST);
bus.start();
- cleanupTags();
tagDefinitionDao.create("tag1", "First tag", context);
testTag = tagDefinitionDao.create("testTag", "Second tag", context);
} catch (Throwable t) {
@@ -103,27 +97,8 @@ public class TestTagStore {
}
@AfterClass(groups = "slow")
- public void stopMysql() {
+ public void tearDown() {
bus.stop();
- if (helper != null) {
- helper.stopMysql();
- }
- }
-
- private void cleanupTags() {
- try {
- helper.getDBI().withHandle(new HandleCallback<Void>() {
- @Override
- public Void withHandle(final Handle handle) throws Exception {
- handle.createScript("delete from tag_definitions").execute();
- handle.createScript("delete from tag_definition_history").execute();
- handle.createScript("delete from tags").execute();
- handle.createScript("delete from tag_history").execute();
- return null;
- }
- });
- } catch (Throwable ignore) {
- }
}
@Test(groups = "slow")
diff --git a/util/src/test/java/com/ning/billing/util/template/translation/TestDefaultTranslatorBase.java b/util/src/test/java/com/ning/billing/util/template/translation/TestDefaultTranslatorBase.java
index d379804..00fc0c2 100644
--- a/util/src/test/java/com/ning/billing/util/template/translation/TestDefaultTranslatorBase.java
+++ b/util/src/test/java/com/ning/billing/util/template/translation/TestDefaultTranslatorBase.java
@@ -23,7 +23,9 @@ import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestDefaultTranslatorBase {
+import com.ning.billing.util.UtilTestSuite;
+
+public class TestDefaultTranslatorBase extends UtilTestSuite {
private final class TestTranslatorBase extends DefaultTranslatorBase {
public TestTranslatorBase(final TranslatorConfig config) {
super(config);
diff --git a/util/src/test/java/com/ning/billing/util/UtilTestSuite.java b/util/src/test/java/com/ning/billing/util/UtilTestSuite.java
new file mode 100644
index 0000000..3b0658b
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/util/UtilTestSuite.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.util;
+
+import com.ning.billing.KillbillTestSuite;
+
+public abstract class UtilTestSuite extends KillbillTestSuite {
+}
diff --git a/util/src/test/java/com/ning/billing/util/UtilTestSuiteWithEmbeddedDB.java b/util/src/test/java/com/ning/billing/util/UtilTestSuiteWithEmbeddedDB.java
new file mode 100644
index 0000000..e0b2c3d
--- /dev/null
+++ b/util/src/test/java/com/ning/billing/util/UtilTestSuiteWithEmbeddedDB.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.util;
+
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
+
+public abstract class UtilTestSuiteWithEmbeddedDB extends KillbillTestSuiteWithEmbeddedDB {
+}
diff --git a/util/src/test/java/com/ning/billing/util/validation/TestValidationManager.java b/util/src/test/java/com/ning/billing/util/validation/TestValidationManager.java
index 204abdb..9406f4d 100644
--- a/util/src/test/java/com/ning/billing/util/validation/TestValidationManager.java
+++ b/util/src/test/java/com/ning/billing/util/validation/TestValidationManager.java
@@ -25,7 +25,10 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import com.ning.billing.KillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.util.UtilTestSuite;
+import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
import com.ning.billing.util.globallocker.TestMysqlGlobalLocker;
import com.ning.billing.util.io.IOUtils;
import com.ning.billing.util.validation.dao.DatabaseSchemaDao;
@@ -36,8 +39,8 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
-public class TestValidationManager {
- private final MysqlTestingHelper helper = new MysqlTestingHelper();
+public class TestValidationManager extends UtilTestSuiteWithEmbeddedDB {
+ private final MysqlTestingHelper helper = KillbillTestSuiteWithEmbeddedDB.getMysqlTestingHelper();
private static final String TABLE_NAME = "validation_test";
private ValidationManager vm;
@@ -57,21 +60,9 @@ public class TestValidationManager {
private void setupDatabase() throws IOException {
final String testDdl = IOUtils.toString(TestMysqlGlobalLocker.class.getResourceAsStream("/com/ning/billing/util/ddl_test.sql"));
- helper.startMysql();
helper.initDb(testDdl);
}
- @AfterClass(groups = "slow")
- public void tearDown() {
- stopDatabase();
- }
-
- private void stopDatabase() {
- if (helper != null) {
- helper.stopMysql();
- }
- }
-
@Test(groups = "slow")
public void testRetrievingColumnInfo() {
final Collection<ColumnInfo> columnInfoList = vm.getTableInfo(TABLE_NAME);