killbill-aplcache
Merge remote-tracking branch 'origin/test-fixes' into test-fixes-doc Signed-off-by: …
5/2/2018 8:05:02 AM
Changes
Details
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestCustomFieldApi.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestCustomFieldApi.java
index 0025633..88da850 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestCustomFieldApi.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestCustomFieldApi.java
@@ -53,6 +53,10 @@ public class TestCustomFieldApi extends TestIntegrationBase {
@Override
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
+ if (hasFailed()) {
+ return;
+ }
+
super.beforeMethod();
account = createAccountWithNonOsgiPaymentMethod(getAccountData(25));
assertNotNull(account);
diff --git a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationBase.java b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationBase.java
index 504dafe..ce7474f 100644
--- a/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationBase.java
+++ b/beatrix/src/test/java/org/killbill/billing/beatrix/integration/TestIntegrationBase.java
@@ -324,6 +324,10 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implemen
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
+ if (hasFailed()) {
+ return;
+ }
+
super.beforeMethod();
log.debug("beforeMethod callcontext classLoader = " + (Thread.currentThread().getContextClassLoader() != null ? Thread.currentThread().getContextClassLoader().toString() : "null"));
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/KillbillClient.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/KillbillClient.java
index 4c378e9..1b11937 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/KillbillClient.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/KillbillClient.java
@@ -211,7 +211,11 @@ public abstract class KillbillClient extends GuicyKillbillTestSuiteWithEmbeddedD
protected Subscription createSubscription(final UUID accountId, final String bundleExternalKey, final String productName,
final ProductCategory productCategory, final BillingPeriod billingPeriod, final boolean waitCompletion) throws Exception {
- callbackServlet.pushExpectedEvents(ExtBusEventType.ACCOUNT_CHANGE, ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.INVOICE_CREATION);
+ final Account account = accountApi.getAccount(accountId, requestOptions);
+ if (account.getBillCycleDayLocal() == null || account.getBillCycleDayLocal() == 0) {
+ callbackServlet.pushExpectedEvent(ExtBusEventType.ACCOUNT_CHANGE);
+ }
+ callbackServlet.pushExpectedEvents(ExtBusEventType.ENTITLEMENT_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.INVOICE_CREATION);
final Subscription input = new Subscription();
input.setAccountId(accountId);
@@ -235,6 +239,10 @@ public abstract class KillbillClient extends GuicyKillbillTestSuiteWithEmbeddedD
}
protected Account createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(final String productName, final boolean paymentSuccess) throws Exception {
+ return createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(productName, paymentSuccess, paymentSuccess);
+ }
+
+ protected Account createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(final String productName, final boolean invoicePaymentSuccess, final boolean paymentSuccess) throws Exception {
final Account accountJson = createAccountWithDefaultPaymentMethod();
assertNotNull(accountJson);
@@ -244,10 +252,15 @@ public abstract class KillbillClient extends GuicyKillbillTestSuiteWithEmbeddedD
assertNotNull(subscriptionJson);
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION);
+ if (invoicePaymentSuccess) {
+ callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_SUCCESS);
+ } else {
+ callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_FAILED);
+ }
if (paymentSuccess) {
- callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
+ callbackServlet.pushExpectedEvents(ExtBusEventType.PAYMENT_SUCCESS);
} else {
- callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_FAILED, ExtBusEventType.PAYMENT_FAILED);
+ callbackServlet.pushExpectedEvents(ExtBusEventType.PAYMENT_FAILED);
}
clock.addDays(32);
callbackServlet.assertListenerStatus();
@@ -301,7 +314,7 @@ public abstract class KillbillClient extends GuicyKillbillTestSuiteWithEmbeddedD
assertNotNull(subscriptionJson);
// No payment will be triggered as the account doesn't have a payment method
- callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_CREATION);
+ callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION);
clock.addMonths(1);
callbackServlet.assertListenerStatus();
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAdmin.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAdmin.java
index 2b4810a..b82d14b 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAdmin.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestAdmin.java
@@ -25,7 +25,6 @@ import java.util.Map;
import java.util.UUID;
import org.joda.time.DateTime;
-import org.killbill.billing.api.FlakyRetryAnalyzer;
import org.killbill.billing.catalog.api.BillingPeriod;
import org.killbill.billing.catalog.api.ProductCategory;
import org.killbill.billing.client.JaxrsResource;
@@ -36,6 +35,7 @@ import org.killbill.billing.client.model.gen.AdminPayment;
import org.killbill.billing.client.model.gen.Invoice;
import org.killbill.billing.client.model.gen.Payment;
import org.killbill.billing.client.model.gen.PaymentTransaction;
+import org.killbill.billing.notification.plugin.api.ExtBusEventType;
import org.killbill.billing.payment.api.TransactionStatus;
import org.killbill.billing.payment.api.TransactionType;
import org.killbill.billing.util.api.AuditLevel;
@@ -53,8 +53,7 @@ import static org.testng.Assert.assertNotNull;
public class TestAdmin extends TestJaxrsBase {
- // Flaky, see https://github.com/killbill/killbill/issues/860
- @Test(groups = "slow", retryAnalyzer = FlakyRetryAnalyzer.class)
+ @Test(groups = "slow")
public void testAdminPaymentEndpoint() throws Exception {
final Account account = createAccountWithDefaultPaymentMethod();
@@ -68,35 +67,21 @@ public class TestAdmin extends TestJaxrsBase {
authTransaction.setPaymentExternalKey(paymentExternalKey);
authTransaction.setTransactionExternalKey(authTransactionExternalKey);
authTransaction.setTransactionType(TransactionType.AUTHORIZE);
+ callbackServlet.pushExpectedEvent(ExtBusEventType.PAYMENT_SUCCESS);
final Payment authPayment = accountApi.processPayment(account.getAccountId(), authTransaction, account.getPaymentMethodId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
-
- // First fix transactionStatus and paymentSstate (but not lastSuccessPaymentState
- // Note that state is not consistent between TransactionStatus and lastSuccessPaymentState but we don't care.
- fixPaymentState(authPayment, "AUTH_SUCCESS", "AUTH_FAILED", TransactionStatus.PAYMENT_FAILURE);
-
- final Payment updatedPayment1 = paymentApi.getPayment(authPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
- Assert.assertEquals(updatedPayment1.getTransactions().size(), 1);
- final PaymentTransaction authTransaction1 = updatedPayment1.getTransactions().get(0);
- Assert.assertEquals(authTransaction1.getStatus(), TransactionStatus.PAYMENT_FAILURE);
-
- // Capture should succeed because lastSuccessPaymentState was left untouched
- doCapture(updatedPayment1, false);
+ callbackServlet.assertListenerStatus();
fixPaymentState(authPayment, "AUTH_FAILED", "AUTH_FAILED", TransactionStatus.PAYMENT_FAILURE);
- final Payment updatedPayment2 = paymentApi.getPayment(authPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
- Assert.assertEquals(updatedPayment2.getTransactions().size(), 2);
- final PaymentTransaction authTransaction2 = updatedPayment2.getTransactions().get(0);
- Assert.assertEquals(authTransaction2.getStatus(), TransactionStatus.PAYMENT_FAILURE);
-
- final PaymentTransaction captureTransaction2 = updatedPayment2.getTransactions().get(1);
- Assert.assertEquals(captureTransaction2.getStatus(), TransactionStatus.SUCCESS);
+ final Payment updatedPayment = paymentApi.getPayment(authPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
+ Assert.assertEquals(updatedPayment.getTransactions().size(), 1);
+ final PaymentTransaction authTransaction2 = updatedPayment.getTransactions().get(0);
+ Assert.assertEquals(authTransaction2.getStatus(), TransactionStatus.PAYMENT_FAILURE.toString());
- // Capture should now failed because lastSuccessPaymentState was moved to AUTH_FAILED
- doCapture(updatedPayment2, true);
+ // Capture should fail because lastSuccessPaymentState was moved to AUTH_FAILED
+ doCapture(updatedPayment, true);
}
-
@Test(groups = "slow")
public void testAdminInvoiceEndpoint() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
@@ -115,7 +100,6 @@ public class TestAdmin extends TestJaxrsBase {
BillingPeriod.MONTHLY,
true);
clock.addDays(2);
- crappyWaitForLackOfProperSynchonization();
Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), i + 1);
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), false, false, false, false, AuditLevel.NONE, requestOptions);
@@ -123,8 +107,11 @@ public class TestAdmin extends TestJaxrsBase {
}
// Trigger first non-trial invoice
+ for (int i = 0; i < 5; i++) {
+ callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
+ }
clock.addDays(32);
- crappyWaitForLackOfProperSynchonization();
+ callbackServlet.assertListenerStatus();
Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
for (final UUID accountId : accounts) {
@@ -137,12 +124,16 @@ public class TestAdmin extends TestJaxrsBase {
final Map<String, String> perTenantProperties = new HashMap<String, String>();
perTenantProperties.put("org.killbill.invoice.enabled", "false");
final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
+ callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
tenantApi.uploadPerTenantConfiguration(perTenantConfig, requestOptions);
- crappyWaitForLackOfProperSynchonization();
+ callbackServlet.assertListenerStatus();
// Verify the second invoice isn't generated
+ for (int i = 0; i < 5; i++) {
+ callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION);
+ }
clock.addDays(32);
- crappyWaitForLackOfProperSynchonization();
+ callbackServlet.assertListenerStatus();
Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
for (final UUID accountId : accounts) {
@@ -156,7 +147,7 @@ public class TestAdmin extends TestJaxrsBase {
Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 11);
// Fix all accounts
- final Response response2 = triggerInvoiceGenerationForParkedAccounts(5);
+ final Response response2 = triggerInvoiceGenerationForParkedAccounts(4);
final Map<String, String> fixedAccounts = mapper.readValue(response2.getResponseBody(), new TypeReference<Map<String, String>>() {});
Assert.assertEquals(fixedAccounts.size(), 4);
Assert.assertEquals(fixedAccounts.get(accounts.get(1).toString()), "OK");
@@ -190,8 +181,10 @@ public class TestAdmin extends TestJaxrsBase {
}
private void fixPaymentState(final Payment payment, final String lastSuccessPaymentState, final String currentPaymentStateName, final TransactionStatus transactionStatus) throws KillBillClientException {
+ callbackServlet.pushExpectedEvent(ExtBusEventType.PAYMENT_FAILED);
final AdminPayment body = new AdminPayment(lastSuccessPaymentState, currentPaymentStateName, transactionStatus.toString());
adminApi.updatePaymentTransactionState(payment.getPaymentId(), payment.getTransactions().get(0).getTransactionId(), body, requestOptions);
+ callbackServlet.assertListenerStatus();
}
private Response triggerInvoiceGenerationForParkedAccounts(final int limit) throws KillBillClientException {
@@ -202,6 +195,11 @@ public class TestAdmin extends TestJaxrsBase {
.withCreatedBy(createdBy)
.withReason(reason)
.withComment(comment).build();
- return killBillHttpClient.doPost(uri, null, requestOptions);
+ for (int i = 0; i < limit; i++) {
+ callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_DELETION, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
+ }
+ final Response response = killBillHttpClient.doPost(uri, null, requestOptions);
+ callbackServlet.assertListenerStatus();
+ return response;
}
}
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoicePayment.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoicePayment.java
index 507d1c5..e418ac0 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoicePayment.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestInvoicePayment.java
@@ -39,6 +39,7 @@ import org.killbill.billing.client.model.gen.Payment;
import org.killbill.billing.client.model.gen.PaymentMethod;
import org.killbill.billing.client.model.gen.PaymentTransaction;
import org.killbill.billing.client.model.gen.Subscription;
+import org.killbill.billing.notification.plugin.api.ExtBusEventType;
import org.killbill.billing.osgi.api.OSGIServiceRegistration;
import org.killbill.billing.payment.api.TransactionStatus;
import org.killbill.billing.payment.api.TransactionType;
@@ -77,7 +78,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
@Test(groups = "slow")
public void testRetrievePayment() throws Exception {
- final InvoicePayment paymentJson = setupScenarioWithPayment();
+ final InvoicePayment paymentJson = setupScenarioWithPayment(true);
final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
verifyInvoicePaymentAgainstPayment(paymentJson, retrievedPaymentJson);
}
@@ -86,7 +87,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
public void testInvoicePaymentCompletion() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentPending();
- final InvoicePayment paymentJson = setupScenarioWithPayment();
+ final InvoicePayment paymentJson = setupScenarioWithPayment(false);
final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
verifyInvoicePaymentAgainstPayment(paymentJson, retrievedPaymentJson);
@@ -110,7 +111,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
@Test(groups = "slow", description = "Can create a full refund with no adjustment")
public void testFullRefundWithNoAdjustment() throws Exception {
- final InvoicePayment invoicePaymentJson = setupScenarioWithPayment();
+ final InvoicePayment invoicePaymentJson = setupScenarioWithPayment(true);
// Issue a refund for the full amount
final BigDecimal refundAmount = invoicePaymentJson.getPurchasedAmount();
@@ -130,7 +131,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
@Test(groups = "slow", description = "Can create a partial refund with no adjustment")
public void testPartialRefundWithNoAdjustment() throws Exception {
- final InvoicePayment paymentJson = setupScenarioWithPayment();
+ final InvoicePayment paymentJson = setupScenarioWithPayment(true);
// Issue a refund for a fraction of the amount
final BigDecimal refundAmount = getFractionOfAmount(paymentJson.getPurchasedAmount());
@@ -151,7 +152,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
@Test(groups = "slow", description = "Can create a full refund with invoice item adjustment")
public void testRefundWithFullInvoiceItemAdjustment() throws Exception {
- final InvoicePayment paymentJson = setupScenarioWithPayment();
+ final InvoicePayment paymentJson = setupScenarioWithPayment(true);
// Get the individual items for the invoice
final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), true, false, AuditLevel.NONE, requestOptions);
@@ -181,7 +182,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
@Test(groups = "slow", description = "Can create a partial refund with invoice item adjustment")
public void testPartialRefundWithInvoiceItemAdjustment() throws Exception {
- final InvoicePayment paymentJson = setupScenarioWithPayment();
+ final InvoicePayment paymentJson = setupScenarioWithPayment(true);
// Get the individual items for the invoice
final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), true, false, AuditLevel.NONE, requestOptions);
@@ -210,7 +211,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
@Test(groups = "slow", description = "Cannot create invoice item adjustments for more than the refund amount")
public void testPartialRefundWithFullInvoiceItemAdjustment() throws Exception {
- final InvoicePayment paymentJson = setupScenarioWithPayment();
+ final InvoicePayment paymentJson = setupScenarioWithPayment(true);
// Get the individual items for the invoice
final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), true, false, AuditLevel.NONE, requestOptions);
@@ -243,7 +244,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
@Test(groups = "slow", description = "Can paginate through all payments and refunds")
public void testPaymentsAndRefundsPagination() throws Exception {
- InvoicePayment lastPayment = setupScenarioWithPayment();
+ InvoicePayment lastPayment = setupScenarioWithPayment(true);
for (int i = 0; i < 5; i++) {
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
@@ -284,7 +285,7 @@ public class TestInvoicePayment extends TestJaxrsBase {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
- final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
+ final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
InvoicePayments invoicePayments = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(invoicePayments.size(), 1);
@@ -315,7 +316,9 @@ public class TestInvoicePayment extends TestJaxrsBase {
assertNotNull(accountJson);
// Disable automatic payments
+ callbackServlet.pushExpectedEvent(ExtBusEventType.TAG_CREATION);
accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(ControlTagType.AUTO_PAY_OFF.getId()), requestOptions);
+ callbackServlet.assertListenerStatus();
// Add a bundle, subscription and move the clock to get the first invoice
final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun",
@@ -359,8 +362,8 @@ public class TestInvoicePayment extends TestJaxrsBase {
return amount.divide(BigDecimal.TEN).setScale(2, BigDecimal.ROUND_HALF_UP);
}
- private InvoicePayment setupScenarioWithPayment() throws Exception {
- final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
+ private InvoicePayment setupScenarioWithPayment(final boolean invoicePaymentSuccess) throws Exception {
+ final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice("Shotgun", invoicePaymentSuccess, true);
final List<InvoicePayment> paymentsForAccount = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(paymentsForAccount.size(), 1);
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
index db0541f..a7cabe3 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestJaxrsBase.java
@@ -444,7 +444,9 @@ public class TestJaxrsBase extends KillbillClient {
protected void uploadTenantOverdueConfig(final String overdue) throws IOException, KillBillClientException {
final String body = getResourceBodyString(overdue);
+ callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
overdueApi.uploadOverdueConfigXml(body, requestOptions);
+ callbackServlet.assertListenerStatus();
}
protected String getResourceBodyString(final String resource) throws IOException {
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestOverdue.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestOverdue.java
index 8b2d22c..6eea003 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestOverdue.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestOverdue.java
@@ -28,6 +28,7 @@ import org.killbill.billing.client.model.Tags;
import org.killbill.billing.client.model.gen.Account;
import org.killbill.billing.client.model.gen.Invoice;
import org.killbill.billing.client.model.gen.InvoicePayment;
+import org.killbill.billing.notification.plugin.api.ExtBusEventType;
import org.killbill.billing.util.tag.ControlTagType;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -106,15 +107,18 @@ public class TestOverdue extends TestJaxrsBase {
// Create an account without a payment method and assign a TEST tag
final Account accountJson = createAccountNoPMBundleAndSubscription();
+ callbackServlet.pushExpectedEvent(ExtBusEventType.TAG_CREATION);
final Tags accountTag = accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(ControlTagType.TEST.getId()), requestOptions);
+ callbackServlet.assertListenerStatus();
assertEquals(accountTag.get(0).getTagDefinitionId(), ControlTagType.TEST.getId());
// Create an account without a TEST tag
final Account accountJsonNoTag = createAccountNoPMBundleAndSubscription();
// No payment will be triggered as the account doesn't have a payment method
+ callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_FAILED, ExtBusEventType.INVOICE_PAYMENT_FAILED);
clock.addMonths(1);
- crappyWaitForLackOfProperSynchonization();
+ callbackServlet.assertListenerStatus();
// Get the invoices
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
@@ -129,8 +133,14 @@ public class TestOverdue extends TestJaxrsBase {
Assert.assertTrue(accountApi.getOverdueAccount(accountJson.getAccountId(), requestOptions).isClearState());
Assert.assertTrue(accountApi.getOverdueAccount(accountJsonNoTag.getAccountId(), requestOptions).isClearState());
+ callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_CREATION,
+ ExtBusEventType.INVOICE_PAYMENT_FAILED,
+ ExtBusEventType.INVOICE_CREATION,
+ ExtBusEventType.INVOICE_PAYMENT_FAILED,
+ ExtBusEventType.BLOCKING_STATE,
+ ExtBusEventType.OVERDUE_CHANGE);
clock.addDays(30);
- crappyWaitForLackOfProperSynchonization();
+ callbackServlet.assertListenerStatus();
// This account is expected to move to OD1 state because it matches with controlTag defined
Assert.assertEquals(accountApi.getOverdueAccount(accountJson.getAccountId(), requestOptions).getName(), "OD1");
@@ -140,12 +150,13 @@ public class TestOverdue extends TestJaxrsBase {
@Test(groups = "slow", description = "Allow overdue condition by exclusion control tag defined in overdue config xml file")
public void testExclusionControlTagOverdueConfig() throws Exception {
-
uploadTenantOverdueConfig("overdueWithExclusionControlTag.xml");
// Create an account without a payment method and assign a TEST tag
final Account accountJson = createAccountNoPMBundleAndSubscription();
+ callbackServlet.pushExpectedEvent(ExtBusEventType.TAG_CREATION);
final Tags accountTag = accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(ControlTagType.TEST.getId()), requestOptions);
+ callbackServlet.assertListenerStatus();
assertEquals(accountTag.get(0).getTagDefinitionId(), ControlTagType.TEST.getId());
// Create an account without a TEST tag
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPayment.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPayment.java
index 9538a4e..e791eb2 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPayment.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestPayment.java
@@ -215,7 +215,7 @@ public class TestPayment extends TestJaxrsBase {
@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
- final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
+ final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
// Getting Invoice #2 (first after Trial period)
UUID failedInvoiceId = accountApi.getInvoicesForAccount(account.getAccountId(), RequestOptions.empty()).get(1).getInvoiceId();
@@ -245,7 +245,7 @@ public class TestPayment extends TestJaxrsBase {
@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPaymentsForAccount() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
- final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
+ final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
HashMultimap<String, String> queryParams = HashMultimap.create();
queryParams.put("withAttempts", "true");
@@ -265,7 +265,7 @@ public class TestPayment extends TestJaxrsBase {
@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPayments() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
- createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
+ createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
HashMultimap<String, String> queryParams = HashMultimap.create();
queryParams.put("withAttempts", "true");
@@ -285,7 +285,7 @@ public class TestPayment extends TestJaxrsBase {
@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsSearchPayments() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
- createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
+ createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
HashMultimap<String, String> queryParams = HashMultimap.create();
queryParams.put("withAttempts", "true");
@@ -305,7 +305,7 @@ public class TestPayment extends TestJaxrsBase {
@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPaymentById() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
- createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
+ createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
Payments payments = paymentApi.searchPayments("", 0L, 100L, false, true, null, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
Assert.assertNotNull(payments.get(0));