From 977638bff257f04fba98e2248cc858cae655eac7 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Sat, 31 Aug 2024 20:20:24 +0100 Subject: [PATCH 1/3] test: disable legacy API tests by default Signed-off-by: Pierre-Alexandre Meyer --- .../billing/plugin/stripe/TestStripePaymentPluginApi.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java b/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java index 3303b30..89f79b8 100644 --- a/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java +++ b/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java @@ -133,8 +133,8 @@ public void testPaymentMethodAndChargesAPI() throws PaymentPluginApiException, S verifyPaymentTransactionInfoPlugin(payment2, purchaseTransaction2, purchaseInfoPlugin2, PaymentPluginStatus.PROCESSED); } - @Test(groups = "integration") - public void testSEPADebitSourceAndChargesAPI() throws PaymentPluginApiException, StripeException, PaymentApiException { + @Test(groups = "integration", enabled = false, description = "Legacy API") + public void testLegacySEPADebitSourceAndChargesAPI() throws PaymentPluginApiException, StripeException, PaymentApiException { final UUID kbAccountId = account.getId(); assertEquals(stripePaymentPluginApi.getPaymentMethods(kbAccountId, false, ImmutableList.of(), context).size(), 0); @@ -185,7 +185,7 @@ public void testSEPADebitSourceAndChargesAPI() throws PaymentPluginApiException, verifyPaymentTransactionInfoPlugin(payment2, purchaseTransaction2, purchaseInfoPlugin2, PaymentPluginStatus.PENDING); } - @Test(groups = "integration") + @Test(groups = "integration", enabled = false, description = "Legacy API") public void testLegacyTokensAndChargesAPI() throws PaymentPluginApiException, StripeException, PaymentApiException { final UUID kbAccountId = account.getId(); @@ -237,7 +237,7 @@ public void testLegacyTokensAndChargesAPI() throws PaymentPluginApiException, St verifyPaymentTransactionInfoPlugin(payment2, purchaseTransaction2, purchaseInfoPlugin2, PaymentPluginStatus.PROCESSED); } - @Test(groups = "integration") + @Test(groups = "integration", enabled = false, description = "Legacy API") public void testLegacyTokensAndChargesAPICustomerCreatedOutsideOfKillBill() throws PaymentPluginApiException, StripeException, PaymentApiException { final UUID kbAccountId = account.getId(); From f77e7b63908ce3e4897a7d0c1fd3accc1afcbd59 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Sat, 31 Aug 2024 20:32:02 +0100 Subject: [PATCH 2/3] test: update basic test to not require special account flags Even in test, we cannot send the PAN anymore. Signed-off-by: Pierre-Alexandre Meyer --- .../stripe/TestStripePaymentPluginApi.java | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java b/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java index 89f79b8..af8beb6 100644 --- a/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java +++ b/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java @@ -1,6 +1,6 @@ /* - * Copyright 2020-2020 Equinix, Inc - * Copyright 2014-2020 The Billing Project, LLC + * Copyright 2020-2024 Equinix, Inc + * Copyright 2014-2024 The Billing Project, LLC * * The Billing Project 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 @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.stream.Collector; import java.util.stream.Collectors; import org.joda.time.Period; @@ -79,31 +78,8 @@ public class TestStripePaymentPluginApi extends TestBase { @Test(groups = "integration") public void testPaymentMethodAndChargesAPI() throws PaymentPluginApiException, StripeException, PaymentApiException { - final UUID kbAccountId = account.getId(); - - assertEquals(stripePaymentPluginApi.getPaymentMethods(kbAccountId, false, ImmutableList.of(), context).size(), 0); - - Map paymentMethodParams = new HashMap<>(); - paymentMethodParams.put("type", "card"); - paymentMethodParams.put("card", ImmutableMap.of("number", "4242424242424242", - "exp_month", "6", - "exp_year", "2030", - "cvc", "324")); - Map ownerParams = new HashMap<>(); - ownerParams.put("name", "Autobahn"); - ownerParams.put("email", "email@email.com"); - paymentMethodParams.put("billing_details", ownerParams); - - final RequestOptions options = stripePaymentPluginApi.buildRequestOptions(context); - final PaymentMethod paymentMethod = PaymentMethod.create(paymentMethodParams, options); - - final UUID kbPaymentMethodId = UUID.randomUUID(); - stripePaymentPluginApi.addPaymentMethod(kbAccountId, - kbPaymentMethodId, - new PluginPaymentMethodPlugin(kbPaymentMethodId, paymentMethod.getId(), false, ImmutableList.of()), - true, - null, - context); + createStripeCustomerWithCreditCardAndSyncPaymentMethod(); + final UUID kbPaymentMethodId = paymentMethodPlugin.getKbPaymentMethodId(); final Payment payment1 = TestUtils.buildPayment(account.getId(), kbPaymentMethodId, Currency.EUR, killbillApi); final PaymentTransaction purchaseTransaction1 = TestUtils.buildPaymentTransaction(payment1, TransactionType.PURCHASE, BigDecimal.TEN, payment1.getCurrency()); From a7e5ef14a46179a7dcb1f61392af216b49a76d60 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Sat, 31 Aug 2024 21:22:36 +0100 Subject: [PATCH 3/3] test: fix flakiness Signed-off-by: Pierre-Alexandre Meyer --- pom.xml | 5 +++++ .../stripe/TestStripePaymentPluginApi.java | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 972d442..e7471e4 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,11 @@ org.apache.felix.framework provided + + org.awaitility + awaitility + test + org.jooby jooby diff --git a/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java b/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java index af8beb6..72eb7ce 100644 --- a/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java +++ b/src/test/java/org/killbill/billing/plugin/stripe/TestStripePaymentPluginApi.java @@ -26,8 +26,11 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.awaitility.Awaitility; import org.joda.time.Period; import org.killbill.billing.ObjectType; import org.killbill.billing.catalog.api.Currency; @@ -537,11 +540,16 @@ public void testExpired3DSPurchase() throws PaymentPluginApiException, StripeExc // See getPending3DsPaymentExpirationPeriod clock.addDeltaFromReality(new Period("PT3H").toStandardDuration().getMillis()); - final List paymentTransactionInfoPluginExpired = stripePaymentPluginApi.getPaymentInfo(account.getId(), - payment.getId(), - ImmutableList.of(), - context); - assertEquals(paymentTransactionInfoPluginExpired.get(0).getStatus(), PaymentPluginStatus.CANCELED); + Awaitility.await().atMost(5, TimeUnit.SECONDS).until(new Callable<>() { + @Override + public Boolean call() throws Exception { + final List paymentTransactionInfoPluginExpired = stripePaymentPluginApi.getPaymentInfo(account.getId(), + payment.getId(), + ImmutableList.of(), + context); + return PaymentPluginStatus.CANCELED.equals(paymentTransactionInfoPluginExpired.get(0).getStatus()); + } + }); } @Test(groups = "integration")