From bb06d537ed1c12edffbb4537b47d40bd71881c71 Mon Sep 17 00:00:00 2001 From: Maciej Nedza Date: Mon, 27 Jan 2025 14:51:38 +0100 Subject: [PATCH 1/3] Document tests, minor tests fixes --- tests/README.md | 29 +++++++++++++++++++ .../AdvanceInvoiceControllerIssueTest.java | 2 +- ...tomersControllerListSubscriptionsTest.java | 3 +- .../PaymentProfilesControllerReadTest.java | 2 ++ .../ProformaInvoicesTestBase.java | 2 +- .../SubscriptionsControllerCreateTest.java | 15 +++++----- .../SubscriptionStatusControllerTestBase.java | 3 +- .../advancedbilling/utils/TestSetup.java | 2 +- 8 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 tests/README.md diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..a1edf4fd --- /dev/null +++ b/tests/README.md @@ -0,0 +1,29 @@ +This test suite is quite large and can occasionally be flaky for certain endpoints, such as when AB returns a server error response. +To mitigate these issues, the suite has been parallelized, allowing for faster reruns when necessary. + +To execute the tests, provide the following environment variables: +- `SUBDOMAINS` - A list of subdomains your tests will use. Locally, a single site should suffice. +- `API_KEYS` - A list of API keys corresponding to the subdomains. The order of keys must match the order of the subdomains. +- `SITE_ID` - (optional): Used only for site-specific assertions. Not required unless you are testing the site endpoint. +- `PRECONFIGURED_SUBDOMAIN` - A subdomain with a preconfigured state. +- `PRECONFIGURED_API_KEY` - The API key for the subdomain in a preconfigured state. + + +### Preconfigured site + +Most tests require setting up resources beforehand. After the test suite finishes, a cleanup process is triggered. +However, not all resources can be set up using the API. + +For tests that require such resources, a Preconfigured Site is used—a special site where resources are manually configured and are not cleared after each test run. + +To use the Preconfigured Site, retrieve a client for it with the following method: +``` +TestClientProvider.getPreconfiguredSiteClient() +``` + +### Notes on parallelism + +- Each subdomain specified in the `SUBDOMAINS` environment variable is assigned a single thread. +- All test cases within a specific test class are executed on the same thread (and therefore the same subdomain) to prevent concurrent execution for the same site, which could result in test failures. This is also because most test classes have a single setup method that runs before all the tests in the class. +- Avoid using static fields in test classes - Some tests override static fields in base classes, which can interfere with other test runs. + diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerIssueTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerIssueTest.java index 4018e1fa..9f22e461 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerIssueTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerIssueTest.java @@ -70,7 +70,7 @@ void teardown() throws IOException, ApiException { @Test void shouldReturn201onIssueAdvanceInvoice() throws IOException, ApiException { // given - ZonedDateTime beforeDateTime = ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS); + ZonedDateTime beforeDateTime = ZonedDateTime.now().plusSeconds(5).truncatedTo(ChronoUnit.SECONDS); LocalDate beforeDate = LocalDate.now(); // when diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/customers/CustomersControllerListSubscriptionsTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/customers/CustomersControllerListSubscriptionsTest.java index a76e77b0..3c03436a 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/customers/CustomersControllerListSubscriptionsTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/customers/CustomersControllerListSubscriptionsTest.java @@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test; import java.io.IOException; +import java.time.LocalDate; import java.util.List; import java.util.stream.Collectors; @@ -95,7 +96,7 @@ void shouldReturnListOfSubscriptionsForCustomer() throws IOException, ApiExcepti .customerId(customerId) .paymentType(PaymentType.CREDIT_CARD) .expirationMonth(CreatePaymentProfileExpirationMonth.fromNumber(10)) - .expirationYear(CreatePaymentProfileExpirationYear.fromNumber(2025)) + .expirationYear(CreatePaymentProfileExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .fullNumber("5424000000000015") .build()) ) diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/paymentprofiles/PaymentProfilesControllerReadTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/paymentprofiles/PaymentProfilesControllerReadTest.java index f3f192b9..b04496a3 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/paymentprofiles/PaymentProfilesControllerReadTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/paymentprofiles/PaymentProfilesControllerReadTest.java @@ -82,6 +82,7 @@ void shouldReadCreditCardPaymentProfile() throws IOException, ApiException { .match(new PaymentProfileResponsePaymentProfileGetter()) ) .usingRecursiveComparison() + .ignoringFields("additionalProperties") .isEqualTo(new CreditCardPaymentProfile.Builder() .maskedCardNumber("XXXX-XXXX-XXXX-1111") .id(creditCardPaymentProfile.getId()) @@ -117,6 +118,7 @@ void shouldReadBankAccountPaymentProfile() throws IOException, ApiException { .match(new PaymentProfileResponsePaymentProfileGetter()) ) .usingRecursiveComparison() + .ignoringFields("additionalProperties") .isEqualTo(new BankAccountPaymentProfile.Builder() .id(bankAccountPaymentProfile.getId()) .firstName(customer.getFirstName()) diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesTestBase.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesTestBase.java index 231ef3a9..642544ba 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesTestBase.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesTestBase.java @@ -109,7 +109,7 @@ protected CreateSubscription getCreateSubscription(Customer customer, Component .cardType(CardType.VISA) .cvv("123") .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)) + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .build() ) .build(); diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/subscriptions/SubscriptionsControllerCreateTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/subscriptions/SubscriptionsControllerCreateTest.java index 09be2a32..a1c05776 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/subscriptions/SubscriptionsControllerCreateTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/subscriptions/SubscriptionsControllerCreateTest.java @@ -55,6 +55,7 @@ import org.junit.jupiter.api.Test; import java.io.IOException; +import java.time.LocalDate; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.List; @@ -140,7 +141,7 @@ void shouldCreateSubscriptionWithCreditCard() throws IOException, ApiException { .cardType(CardType.VISA) .cvv("123") .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)) + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .build()) .build() )).getSubscription(); @@ -159,7 +160,7 @@ void shouldCreateSubscriptionWithCreditCard() throws IOException, ApiException { assertThat(creditCard.getMaskedCardNumber()).isEqualTo("XXXX-XXXX-XXXX-1111"); assertThat(creditCard.getCardType()).isEqualTo(CardType.VISA); assertThat(creditCard.getExpirationMonth()).isEqualTo(5); - assertThat(creditCard.getExpirationYear()).isEqualTo(2050); + assertThat(creditCard.getExpirationYear()).isEqualTo(LocalDate.now().getYear() + 10); assertThat(creditCard.getCurrentVault()).isEqualTo(CreditCardVault.BOGUS); assertThat(creditCard.getVaultToken()).isNotEmpty(); assertThat(creditCard.getBillingAddress()).isEqualTo("My Billing Address"); @@ -255,7 +256,7 @@ void shouldCreateSubscriptionWithCoupon() throws IOException, ApiException { .cardType(CardType.VISA) .cvv("123") .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)) + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .build() ) .customPrice(new SubscriptionCustomPrice.Builder() @@ -319,7 +320,7 @@ void shouldCreateSubscriptionWithComponents() throws IOException, ApiException { .cardType(CardType.VISA) .cvv("123") .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)) + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .build() ) .customPrice(new SubscriptionCustomPrice.Builder() @@ -382,7 +383,7 @@ void shouldCreateSubscriptionWithCustomPrice() throws IOException, ApiException .cardType(CardType.VISA) .cvv("123") .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)) + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .build() ) .customPrice(new SubscriptionCustomPrice.Builder() @@ -479,7 +480,7 @@ void shouldCreateSubscriptionWithGroup() throws IOException, ApiException { .cardType(CardType.VISA) .cvv("123") .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)) + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .build() ) .build() @@ -550,7 +551,7 @@ void shouldCreateSubscriptionWithPrepaidConfiguration() throws IOException, ApiE .cardType(CardType.VISA) .cvv("123") .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)) + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .build() ) .components(List.of( diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/subscriptionstatus/SubscriptionStatusControllerTestBase.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/subscriptionstatus/SubscriptionStatusControllerTestBase.java index 1d1afdf1..e8a9187b 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/subscriptionstatus/SubscriptionStatusControllerTestBase.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/subscriptionstatus/SubscriptionStatusControllerTestBase.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.BeforeAll; import java.io.IOException; +import java.time.LocalDate; abstract class SubscriptionStatusControllerTestBase { @@ -47,7 +48,7 @@ Subscription createSubscription() throws IOException, ApiException { .creditCardAttributes( new PaymentProfileAttributes.Builder() .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(12)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)) + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)) .fullNumber("1") .build() ) diff --git a/tests/src/test/java/com/maxio/advancedbilling/utils/TestSetup.java b/tests/src/test/java/com/maxio/advancedbilling/utils/TestSetup.java index 2f93f392..b9fea769 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/utils/TestSetup.java +++ b/tests/src/test/java/com/maxio/advancedbilling/utils/TestSetup.java @@ -411,7 +411,7 @@ public Subscription createSubscription(Customer customer, Product product, .cardType(CardType.VISA) .cvv("123") .expirationMonth(PaymentProfileAttributesExpirationMonth.fromNumber(5)) - .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(2050)); + .expirationYear(PaymentProfileAttributesExpirationYear.fromNumber(LocalDate.now().getYear() + 10)); paymentProfileCustomizer.accept(paymentProfileBuilder); CreateSubscription.Builder subscriptionBuilder = new CreateSubscription.Builder() From 0d51bc9a7394d565c427c68085b5c7fc563345b5 Mon Sep 17 00:00:00 2001 From: Maciej Nedza Date: Wed, 29 Jan 2025 13:20:51 +0100 Subject: [PATCH 2/3] Fix invoice tests --- .../advanceinvoice/AdvanceInvoiceControllerIssueTest.java | 2 +- .../advanceinvoice/AdvanceInvoiceControllerReadTest.java | 2 +- .../advanceinvoice/AdvanceInvoiceControllerVoidTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerIssueTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerIssueTest.java index 9f22e461..7aeebd5b 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerIssueTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerIssueTest.java @@ -167,7 +167,7 @@ void shouldReturn201onIssueAdvanceInvoice() throws IOException, ApiException { () -> assertThat(invoiceLineItem.getTotalAmount()).isEqualTo("12.5"), () -> assertThat(invoiceLineItem.getTieredUnitPrice()).isFalse(), () -> assertThat(invoiceLineItem.getPeriodRangeStart()).isEqualTo(beforeDate.plusMonths(1)), - () -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(2)), + () -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(1).plusMonths(1)), () -> assertThat(invoiceLineItem.getProductId()).isEqualTo(product.getId()), () -> assertThat(invoiceLineItem.getProductVersion()).isEqualTo(product.getVersionNumber()), () -> assertThat(invoiceLineItem.getProductPricePointId()).isEqualTo(product.getProductPricePointId()), diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerReadTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerReadTest.java index 00133fbb..8d79aa89 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerReadTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerReadTest.java @@ -166,7 +166,7 @@ void shouldReturn200onReadAdvanceInvoice() throws IOException, ApiException { () -> assertThat(invoiceLineItem.getTotalAmount()).isEqualTo("12.5"), () -> assertThat(invoiceLineItem.getTieredUnitPrice()).isFalse(), () -> assertThat(invoiceLineItem.getPeriodRangeStart()).isEqualTo(beforeDate.plusMonths(1)), - () -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(2)), + () -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(1).plusMonths(1)), () -> assertThat(invoiceLineItem.getProductId()).isEqualTo(product.getId()), () -> assertThat(invoiceLineItem.getProductVersion()).isEqualTo(product.getVersionNumber()), () -> assertThat(invoiceLineItem.getProductPricePointId()).isEqualTo(product.getProductPricePointId()), diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerVoidTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerVoidTest.java index da3f7fda..6bc9bbac 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerVoidTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/advanceinvoice/AdvanceInvoiceControllerVoidTest.java @@ -174,7 +174,7 @@ void shouldReturn201onVoidAdvanceInvoice() throws IOException, ApiException { () -> assertThat(invoiceLineItem.getTotalAmount()).isEqualTo("12.5"), () -> assertThat(invoiceLineItem.getTieredUnitPrice()).isFalse(), () -> assertThat(invoiceLineItem.getPeriodRangeStart()).isEqualTo(beforeDate.plusMonths(1)), - () -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(2)), + () -> assertThat(invoiceLineItem.getPeriodRangeEnd()).isEqualTo(beforeDate.plusMonths(1).plusMonths(1)), () -> assertThat(invoiceLineItem.getProductId()).isEqualTo(product.getId()), () -> assertThat(invoiceLineItem.getProductVersion()).isEqualTo(product.getVersionNumber()), () -> assertThat(invoiceLineItem.getProductPricePointId()).isEqualTo(product.getProductPricePointId()), From 1a19c6c956f79114f6be992550f628f19e6f1a0b Mon Sep 17 00:00:00 2001 From: Maciej Nedza Date: Wed, 29 Jan 2025 14:46:47 +0100 Subject: [PATCH 3/3] [DE-1103] Fix read site test --- .../controllers/sites/SitesControllerTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/sites/SitesControllerTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/sites/SitesControllerTest.java index 6726110a..f99cffe2 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/sites/SitesControllerTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/sites/SitesControllerTest.java @@ -23,6 +23,10 @@ class SitesControllerTest { @Test void shouldReadSite() throws Exception { // when + // bug: idle connection can be closed. + try { + Site site = sitesController.readSite().getSite(); + } catch (Exception ignored) {} Site site = sitesController.readSite().getSite(); // then