diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerCreateSignupProformaTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerCreateSignupProformaTest.java index a425bc3b..0c6002ca 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerCreateSignupProformaTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerCreateSignupProformaTest.java @@ -1,13 +1,12 @@ package com.maxio.advancedbilling.controllers.proformainvoices; -import com.maxio.advancedbilling.AdvancedBillingClient; import com.maxio.advancedbilling.TestClient; -import com.maxio.advancedbilling.controllers.ProformaInvoicesController; import com.maxio.advancedbilling.exceptions.ApiException; +import com.maxio.advancedbilling.models.Component; import com.maxio.advancedbilling.models.CreateSubscription; import com.maxio.advancedbilling.models.CreateSubscriptionRequest; import com.maxio.advancedbilling.models.Customer; -import com.maxio.advancedbilling.utils.TestSetup; +import com.maxio.advancedbilling.models.ProformaInvoice; import com.maxio.advancedbilling.utils.TestTeardown; import com.maxio.advancedbilling.utils.assertions.CommonAssertions; import org.junit.jupiter.api.AfterAll; @@ -18,15 +17,13 @@ import java.util.List; import java.util.Map; -public class ProformaInvoicesControllerCreateSignupProformaTest { - - private static final TestSetup TEST_SETUP = new TestSetup(); - private static final AdvancedBillingClient CLIENT = TestClient.createClient(); - private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT - .getProformaInvoicesController(); +public class ProformaInvoicesControllerCreateSignupProformaTest extends ProformaInvoicesTestBase { private static Customer customer; + ProformaInvoicesControllerCreateSignupProformaTest() throws IOException, ApiException { + } + @BeforeAll static void setUp() throws IOException, ApiException { customer = TEST_SETUP.createCustomer(); @@ -40,12 +37,10 @@ static void teardown() throws IOException, ApiException { @Test void shouldCreateSignupProforma() throws IOException, ApiException { // given-when - ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator(); - ProformaInvoicesCreator.ProformaInvoiceWithComponents invoiceWithData = - proformaInvoicesCreator.createSignupProformaInvoice(customer); + ProformaInvoiceWithComponents invoiceWithData = createSignupProformaInvoice(customer); // then - proformaInvoicesCreator.assertProformaInvoice(customer, invoiceWithData, true, true); + assertProformaInvoice(customer, invoiceWithData, true, true); } @Test @@ -71,4 +66,17 @@ void shouldReturn401WhenProvidingInvalidCredentials() { ); } + private ProformaInvoiceWithComponents createSignupProformaInvoice(Customer customer) throws IOException, ApiException { + Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5); + Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId()); + + ProformaInvoice proformaInvoice = CLIENT.getProformaInvoicesController().createSignupProformaInvoice( + new CreateSubscriptionRequest( + getCreateSubscription(customer, meteredComponent, quantityBasedComponent) + ) + ); + + return new ProformaInvoiceWithComponents(proformaInvoice, quantityBasedComponent, meteredComponent); + } + } diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerCreateTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerCreateTest.java index 61dc8edf..a6b34b31 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerCreateTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerCreateTest.java @@ -1,11 +1,8 @@ package com.maxio.advancedbilling.controllers.proformainvoices; -import com.maxio.advancedbilling.AdvancedBillingClient; import com.maxio.advancedbilling.TestClient; -import com.maxio.advancedbilling.controllers.ProformaInvoicesController; import com.maxio.advancedbilling.exceptions.ApiException; import com.maxio.advancedbilling.models.Customer; -import com.maxio.advancedbilling.utils.TestSetup; import com.maxio.advancedbilling.utils.TestTeardown; import com.maxio.advancedbilling.utils.assertions.CommonAssertions; import org.junit.jupiter.api.AfterAll; @@ -14,15 +11,13 @@ import java.io.IOException; -public class ProformaInvoicesControllerCreateTest { - - private static final TestSetup TEST_SETUP = new TestSetup(); - private static final AdvancedBillingClient CLIENT = TestClient.createClient(); - private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT - .getProformaInvoicesController(); +public class ProformaInvoicesControllerCreateTest extends ProformaInvoicesTestBase { private static Customer customer; + ProformaInvoicesControllerCreateTest() throws IOException, ApiException { + } + @BeforeAll static void setUp() throws IOException, ApiException { customer = TEST_SETUP.createCustomer(); @@ -36,13 +31,10 @@ static void teardown() throws IOException, ApiException { @Test void shouldCreateProformaInvoice() throws IOException, ApiException { // given-when - ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator(); - ProformaInvoicesCreator.ProformaInvoiceWithComponents invoiceWithData = - proformaInvoicesCreator.createProformaInvoiceWithComponents(customer); + ProformaInvoiceWithComponents invoiceWithData = createProformaInvoiceWithComponents(customer); // then - proformaInvoicesCreator.assertProformaInvoice(customer, invoiceWithData, - true, false); + assertProformaInvoice(customer, invoiceWithData, true, false); } @Test diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerPreviewSignupProformaTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerPreviewSignupProformaTest.java index 57ee297a..d11bbeec 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerPreviewSignupProformaTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerPreviewSignupProformaTest.java @@ -1,13 +1,13 @@ package com.maxio.advancedbilling.controllers.proformainvoices; -import com.maxio.advancedbilling.AdvancedBillingClient; import com.maxio.advancedbilling.TestClient; -import com.maxio.advancedbilling.controllers.ProformaInvoicesController; import com.maxio.advancedbilling.exceptions.ApiException; +import com.maxio.advancedbilling.models.Component; +import com.maxio.advancedbilling.models.CreateSignupProformaPreviewInclude; import com.maxio.advancedbilling.models.CreateSubscription; import com.maxio.advancedbilling.models.CreateSubscriptionRequest; import com.maxio.advancedbilling.models.Customer; -import com.maxio.advancedbilling.utils.TestSetup; +import com.maxio.advancedbilling.models.SignupProformaPreview; import com.maxio.advancedbilling.utils.TestTeardown; import com.maxio.advancedbilling.utils.assertions.CommonAssertions; import org.junit.jupiter.api.AfterAll; @@ -20,15 +20,13 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ProformaInvoicesControllerPreviewSignupProformaTest { - - private static final TestSetup TEST_SETUP = new TestSetup(); - private static final AdvancedBillingClient CLIENT = TestClient.createClient(); - private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT - .getProformaInvoicesController(); +public class ProformaInvoicesControllerPreviewSignupProformaTest extends ProformaInvoicesTestBase { private static Customer customer; + ProformaInvoicesControllerPreviewSignupProformaTest() throws IOException, ApiException { + } + @BeforeAll static void setUp() throws IOException, ApiException { customer = TEST_SETUP.createCustomer(); @@ -42,13 +40,10 @@ static void teardown() throws IOException, ApiException { @Test void shouldPreviewSignupProformaWithNextProforma() throws IOException, ApiException { // given-when - ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator(); - ProformaInvoicesCreator.SignupProformaPreviewWithComponents previewWithData = - proformaInvoicesCreator.previewSignupProformaInvoice(customer); + SignupProformaPreviewWithComponents previewWithData = previewSignupProformaInvoice(customer); // then - proformaInvoicesCreator.assertProformaInvoice(customer, - new ProformaInvoicesCreator.ProformaInvoiceWithComponents(previewWithData.preview().getCurrentProformaInvoice(), + assertProformaInvoice(customer, new ProformaInvoiceWithComponents(previewWithData.preview().getCurrentProformaInvoice(), previewWithData.quantityBasedComponent(), previewWithData.meteredComponent()), false, true); @@ -82,4 +77,18 @@ void shouldReturn401WhenProvidingInvalidCredentials() { ); } + private SignupProformaPreviewWithComponents previewSignupProformaInvoice(Customer customer) throws IOException, ApiException { + Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5); + Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId()); + + SignupProformaPreview signupProformaPreview = CLIENT.getProformaInvoicesController().previewSignupProformaInvoice( + CreateSignupProformaPreviewInclude.NEXT_PROFORMA_INVOICE, + new CreateSubscriptionRequest( + getCreateSubscription(customer, meteredComponent, quantityBasedComponent) + ) + ).getProformaInvoicePreview(); + + return new SignupProformaPreviewWithComponents(signupProformaPreview, quantityBasedComponent, meteredComponent); + } + } diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerPreviewTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerPreviewTest.java index 7b327a67..998caed3 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerPreviewTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerPreviewTest.java @@ -1,11 +1,10 @@ package com.maxio.advancedbilling.controllers.proformainvoices; -import com.maxio.advancedbilling.AdvancedBillingClient; import com.maxio.advancedbilling.TestClient; -import com.maxio.advancedbilling.controllers.ProformaInvoicesController; import com.maxio.advancedbilling.exceptions.ApiException; +import com.maxio.advancedbilling.models.Component; import com.maxio.advancedbilling.models.Customer; -import com.maxio.advancedbilling.utils.TestSetup; +import com.maxio.advancedbilling.models.Subscription; import com.maxio.advancedbilling.utils.TestTeardown; import com.maxio.advancedbilling.utils.assertions.CommonAssertions; import org.junit.jupiter.api.AfterAll; @@ -14,15 +13,13 @@ import java.io.IOException; -public class ProformaInvoicesControllerPreviewTest { - - private static final TestSetup TEST_SETUP = new TestSetup(); - private static final AdvancedBillingClient CLIENT = TestClient.createClient(); - private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT - .getProformaInvoicesController(); +public class ProformaInvoicesControllerPreviewTest extends ProformaInvoicesTestBase { private static Customer customer; + ProformaInvoicesControllerPreviewTest() throws IOException, ApiException { + } + @BeforeAll static void setUp() throws IOException, ApiException { customer = TEST_SETUP.createCustomer(); @@ -36,13 +33,10 @@ static void teardown() throws IOException, ApiException { @Test void shouldPreviewProformaInvoice() throws IOException, ApiException { // given-when - ProformaInvoicesCreator proformaInvoicesCreator = new ProformaInvoicesCreator(); - ProformaInvoicesCreator.ProformaInvoiceWithComponents invoiceWithData = - proformaInvoicesCreator.previewProformaInvoiceWithComponents(customer); + ProformaInvoiceWithComponents invoiceWithData = previewProformaInvoiceWithComponents(customer); // then - proformaInvoicesCreator.assertProformaInvoice(customer, invoiceWithData, - false, false); + assertProformaInvoice(customer, invoiceWithData, false, false); } @Test @@ -61,4 +55,15 @@ void shouldReturn401WhenProvidingInvalidCredentials() { ); } + private ProformaInvoiceWithComponents previewProformaInvoiceWithComponents(Customer customer) throws IOException, ApiException { + Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5); + Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId()); + Subscription subscription = setupSubscription(customer, quantityBasedComponent, meteredComponent); + + return new ProformaInvoiceWithComponents( + CLIENT.getProformaInvoicesController().previewProformaInvoice(subscription.getId()), + quantityBasedComponent, meteredComponent + ); + } + } diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerReadTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerReadTest.java index 9ec87827..903bf75b 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerReadTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerReadTest.java @@ -1,12 +1,10 @@ package com.maxio.advancedbilling.controllers.proformainvoices; -import com.maxio.advancedbilling.AdvancedBillingClient; import com.maxio.advancedbilling.TestClient; import com.maxio.advancedbilling.controllers.ProformaInvoicesController; import com.maxio.advancedbilling.exceptions.ApiException; import com.maxio.advancedbilling.models.Customer; import com.maxio.advancedbilling.models.ProformaInvoice; -import com.maxio.advancedbilling.utils.TestSetup; import com.maxio.advancedbilling.utils.TestTeardown; import com.maxio.advancedbilling.utils.assertions.CommonAssertions; import org.junit.jupiter.api.AfterAll; @@ -17,15 +15,13 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ProformaInvoicesControllerReadTest { - - private static final TestSetup TEST_SETUP = new TestSetup(); - private static final AdvancedBillingClient CLIENT = TestClient.createClient(); - private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT - .getProformaInvoicesController(); +public class ProformaInvoicesControllerReadTest extends ProformaInvoicesTestBase { private static Customer customer; + ProformaInvoicesControllerReadTest() throws IOException, ApiException { + } + @BeforeAll static void setUp() throws IOException, ApiException { customer = TEST_SETUP.createCustomer(); @@ -39,8 +35,7 @@ static void teardown() throws IOException, ApiException { @Test void shouldReadProformaInvoice() throws IOException, ApiException { // given - ProformaInvoice createdProformaInvoice = new ProformaInvoicesCreator() - .createProformaInvoiceWithComponents(customer).invoice(); + ProformaInvoice createdProformaInvoice = createProformaInvoiceWithComponents(customer).invoice(); // when ProformaInvoice proformaInvoice = PROFORMA_INVOICES_CONTROLLER.readProformaInvoice(createdProformaInvoice.getUid()); diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerSubscriptionGroupsTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerSubscriptionGroupsTest.java index 9c45a4c5..393c72d5 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerSubscriptionGroupsTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerSubscriptionGroupsTest.java @@ -27,8 +27,8 @@ import java.io.IOException; import java.time.LocalDate; -import java.time.format.DateTimeFormatter; +import static com.maxio.advancedbilling.controllers.proformainvoices.ProformaInvoicesTestBase.formatDescriptionDate; import static com.maxio.advancedbilling.models.ProformaInvoiceStatus.DRAFT; import static com.maxio.advancedbilling.utils.TestFixtures.INVOICE_SELLER; import static org.assertj.core.api.Assertions.assertThat; @@ -201,14 +201,10 @@ void shouldReturn404WhenCreatingConsolidatedProformaInvoiceForNonExistentGroup() @Test void shouldReturn401WhenProvidingInvalidCredentials() { // when - then - CommonAssertions.assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getProformaInvoicesController() + CommonAssertions.assertUnauthorized(() -> TestClient.createInvalidCredentialsClient() + .getProformaInvoicesController() .createConsolidatedProformaInvoice("123") ); } - private String formatDescriptionDate(LocalDate localDate) { - return localDate - .format(DateTimeFormatter.ofPattern("MM/dd/yyyy")); - } - } diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerVoidTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerVoidTest.java index 45a0552b..757f065b 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerVoidTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesControllerVoidTest.java @@ -1,15 +1,13 @@ package com.maxio.advancedbilling.controllers.proformainvoices; -import com.maxio.advancedbilling.AdvancedBillingClient; import com.maxio.advancedbilling.TestClient; -import com.maxio.advancedbilling.controllers.ProformaInvoicesController; import com.maxio.advancedbilling.exceptions.ApiException; import com.maxio.advancedbilling.models.Customer; import com.maxio.advancedbilling.models.ProformaInvoice; import com.maxio.advancedbilling.models.ProformaInvoiceStatus; +import com.maxio.advancedbilling.models.Subscription; import com.maxio.advancedbilling.models.VoidInvoice; import com.maxio.advancedbilling.models.VoidInvoiceRequest; -import com.maxio.advancedbilling.utils.TestSetup; import com.maxio.advancedbilling.utils.TestTeardown; import com.maxio.advancedbilling.utils.assertions.CommonAssertions; import org.junit.jupiter.api.AfterAll; @@ -20,20 +18,16 @@ import static org.assertj.core.api.Assertions.assertThat; -public class ProformaInvoicesControllerVoidTest { - - private static final TestSetup TEST_SETUP = new TestSetup(); - private static final AdvancedBillingClient CLIENT = TestClient.createClient(); - private static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT - .getProformaInvoicesController(); - private static ProformaInvoicesCreator proformaInvoicesCreator; +public class ProformaInvoicesControllerVoidTest extends ProformaInvoicesTestBase { private static Customer customer; + ProformaInvoicesControllerVoidTest() throws IOException, ApiException { + } + @BeforeAll static void setUp() throws IOException, ApiException { customer = TEST_SETUP.createCustomer(); - proformaInvoicesCreator = new ProformaInvoicesCreator(); } @AfterAll @@ -44,7 +38,7 @@ static void teardown() throws IOException, ApiException { @Test public void shouldVoidProformaInvoice() throws IOException, ApiException { // given - ProformaInvoice proformaInvoice = proformaInvoicesCreator.createBasicProformaInvoice(customer); + ProformaInvoice proformaInvoice = createBasicProformaInvoice(customer); // when ProformaInvoice voidedInvoice = PROFORMA_INVOICES_CONTROLLER @@ -61,7 +55,7 @@ public void shouldVoidProformaInvoice() throws IOException, ApiException { @Test void shouldReturn422WhenVoidingVoidedInvoice() throws IOException, ApiException { // given - ProformaInvoice proformaInvoice = proformaInvoicesCreator.createBasicProformaInvoice(customer); + ProformaInvoice proformaInvoice = createBasicProformaInvoice(customer); PROFORMA_INVOICES_CONTROLLER .voidProformaInvoice(proformaInvoice.getUid(), new VoidInvoiceRequest( new VoidInvoice("Duplicate invoice") @@ -78,7 +72,7 @@ void shouldReturn422WhenVoidingVoidedInvoice() throws IOException, ApiException @Test void shouldReturn422WhenVoidingInvoiceWithoutReason() throws IOException, ApiException { // given - ProformaInvoice proformaInvoice = proformaInvoicesCreator.createBasicProformaInvoice(customer); + ProformaInvoice proformaInvoice = createBasicProformaInvoice(customer); // when - then CommonAssertions @@ -105,4 +99,9 @@ void shouldReturn401WhenProvidingInvalidCredentials() { ); } + private ProformaInvoice createBasicProformaInvoice(Customer customer) throws IOException, ApiException { + Subscription subscription = TEST_SETUP.createSubscription(customer, product); + return CLIENT.getProformaInvoicesController().createProformaInvoice(subscription.getId()); + } + } diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesCreator.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesTestBase.java similarity index 84% rename from tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesCreator.java rename to tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesTestBase.java index acb77d98..2485e023 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesCreator.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/proformainvoices/ProformaInvoicesTestBase.java @@ -2,16 +2,15 @@ import com.maxio.advancedbilling.AdvancedBillingClient; import com.maxio.advancedbilling.TestClient; +import com.maxio.advancedbilling.controllers.ProformaInvoicesController; import com.maxio.advancedbilling.exceptions.ApiException; import com.maxio.advancedbilling.models.AllocateComponents; import com.maxio.advancedbilling.models.CardType; import com.maxio.advancedbilling.models.CollectionMethod; import com.maxio.advancedbilling.models.Component; import com.maxio.advancedbilling.models.CreateAllocation; -import com.maxio.advancedbilling.models.CreateSignupProformaPreviewInclude; import com.maxio.advancedbilling.models.CreateSubscription; import com.maxio.advancedbilling.models.CreateSubscriptionComponent; -import com.maxio.advancedbilling.models.CreateSubscriptionRequest; import com.maxio.advancedbilling.models.CreateUsage; import com.maxio.advancedbilling.models.CreateUsageRequest; import com.maxio.advancedbilling.models.Customer; @@ -29,7 +28,6 @@ import com.maxio.advancedbilling.models.ProformaInvoiceCredit; import com.maxio.advancedbilling.models.ProformaInvoiceRole; import com.maxio.advancedbilling.models.SignupProformaPreview; -import com.maxio.advancedbilling.models.SignupProformaPreviewResponse; import com.maxio.advancedbilling.models.Subscription; import com.maxio.advancedbilling.models.containers.CreateSubscriptionComponentAllocatedQuantity; import com.maxio.advancedbilling.models.containers.CreateSubscriptionComponentComponentId; @@ -38,13 +36,11 @@ import com.maxio.advancedbilling.models.containers.PaymentProfileAttributesExpirationMonth; import com.maxio.advancedbilling.models.containers.PaymentProfileAttributesExpirationYear; import com.maxio.advancedbilling.utils.TestSetup; -import io.apimatic.core.types.BaseModel; import java.io.IOException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import static com.maxio.advancedbilling.models.ProformaInvoiceStatus.DRAFT; @@ -52,25 +48,22 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -class ProformaInvoicesCreator { +public abstract class ProformaInvoicesTestBase { - private static final TestSetup TEST_SETUP = new TestSetup(); - private static final AdvancedBillingClient CLIENT = TestClient.createClient(); + protected static final TestSetup TEST_SETUP = new TestSetup(); + protected static final AdvancedBillingClient CLIENT = TestClient.createClient(); + protected static final ProformaInvoicesController PROFORMA_INVOICES_CONTROLLER = CLIENT + .getProformaInvoicesController(); - private final Product product; - private final ProductFamily productFamily; + protected final Product product; + protected final ProductFamily productFamily; - ProformaInvoicesCreator() throws IOException, ApiException { + ProformaInvoicesTestBase() throws IOException, ApiException { productFamily = TEST_SETUP.createProductFamily(); product = TEST_SETUP.createProduct(productFamily, b -> b.priceInCents(1250)); } - ProformaInvoice createBasicProformaInvoice(Customer customer) throws IOException, ApiException { - Subscription subscription = TEST_SETUP.createSubscription(customer, product); - return CLIENT.getProformaInvoicesController().createProformaInvoice(subscription.getId()); - } - - ProformaInvoiceWithComponents createProformaInvoiceWithComponents(Customer customer) throws IOException, ApiException { + protected ProformaInvoiceWithComponents createProformaInvoiceWithComponents(Customer customer) throws IOException, ApiException { Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5); Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId()); Subscription subscription = setupSubscription(customer, quantityBasedComponent, meteredComponent); @@ -81,45 +74,7 @@ ProformaInvoiceWithComponents createProformaInvoiceWithComponents(Customer custo ); } - ProformaInvoiceWithComponents previewProformaInvoiceWithComponents(Customer customer) throws IOException, ApiException { - Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5); - Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId()); - Subscription subscription = setupSubscription(customer, quantityBasedComponent, meteredComponent); - - return new ProformaInvoiceWithComponents( - CLIENT.getProformaInvoicesController().previewProformaInvoice(subscription.getId()), - quantityBasedComponent, meteredComponent - ); - } - - ProformaInvoiceWithComponents createSignupProformaInvoice(Customer customer) throws IOException, ApiException { - Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5); - Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId()); - - ProformaInvoice proformaInvoice = CLIENT.getProformaInvoicesController().createSignupProformaInvoice( - new CreateSubscriptionRequest( - getCreateSubscription(customer, meteredComponent, quantityBasedComponent) - ) - ); - - return new ProformaInvoiceWithComponents(proformaInvoice, quantityBasedComponent, meteredComponent); - } - - SignupProformaPreviewWithComponents previewSignupProformaInvoice(Customer customer) throws IOException, ApiException { - Component meteredComponent = TEST_SETUP.createMeteredComponent(productFamily, 11.5); - Component quantityBasedComponent = TEST_SETUP.createQuantityBasedComponent(productFamily.getId()); - - SignupProformaPreview signupProformaPreview = CLIENT.getProformaInvoicesController().previewSignupProformaInvoice( - CreateSignupProformaPreviewInclude.NEXT_PROFORMA_INVOICE, - new CreateSubscriptionRequest( - getCreateSubscription(customer, meteredComponent, quantityBasedComponent) - ) - ).getProformaInvoicePreview(); - - return new SignupProformaPreviewWithComponents(signupProformaPreview, quantityBasedComponent, meteredComponent); - } - - private CreateSubscription getCreateSubscription(Customer customer, Component meteredComponent, + protected CreateSubscription getCreateSubscription(Customer customer, Component meteredComponent, Component quantityBasedComponent) { return new CreateSubscription.Builder() .productId(product.getId()) @@ -157,7 +112,7 @@ private CreateSubscription getCreateSubscription(Customer customer, Component me } - private Subscription setupSubscription(Customer customer, Component quantityBasedComponent, + protected Subscription setupSubscription(Customer customer, Component quantityBasedComponent, Component meteredComponent) throws IOException, ApiException { Subscription subscription = TEST_SETUP.createSubscription(customer, product); CLIENT.getSubscriptionInvoiceAccountController().issueServiceCredit(subscription.getId(), @@ -405,16 +360,17 @@ void assertProformaInvoice(Customer customer, ); } - private String formatDescriptionDate(LocalDate localDate) { + static String formatDescriptionDate(LocalDate localDate) { return localDate .format(DateTimeFormatter.ofPattern("MM/dd/yyyy")); } - record ProformaInvoiceWithComponents(ProformaInvoice invoice, Component quantityBasedComponent, + protected record ProformaInvoiceWithComponents(ProformaInvoice invoice, Component quantityBasedComponent, Component meteredComponent) { } record SignupProformaPreviewWithComponents(SignupProformaPreview preview, Component quantityBasedComponent, - Component meteredComponent) { + Component meteredComponent) { } + }