From 42b0a8ddac69d15cc4e3ab00265fbcac55798198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Grudzie=C5=84?= <59444374+patryk-grudzien-keen@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:52:17 +0100 Subject: [PATCH] [DE-526] Java test CRUD for customer endpoints (read) (#11) --- .../CustomersControllerReadTest.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerReadTest.java diff --git a/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerReadTest.java b/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerReadTest.java new file mode 100644 index 00000000..ced96619 --- /dev/null +++ b/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerReadTest.java @@ -0,0 +1,123 @@ +package com.maxio.advancedbilling.controllers; + +import com.maxio.advancedbilling.TestClient; +import com.maxio.advancedbilling.exceptions.ApiException; +import com.maxio.advancedbilling.models.CreateCustomer; +import com.maxio.advancedbilling.models.CreateCustomerRequest; +import com.maxio.advancedbilling.models.Customer; +import com.maxio.advancedbilling.models.CustomerResponse; +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +class CustomersControllerReadTest { + + private static final CustomersController CUSTOMERS_CONTROLLER = TestClient.createClient().getCustomersController(); + + private static Customer TEST_CUSTOMER; + + @BeforeAll + static void beforeAll() throws IOException, ApiException { + TEST_CUSTOMER = CUSTOMERS_CONTROLLER + .createCustomer(new CreateCustomerRequest() + .toBuilder() + .customer(new CreateCustomer() + .toBuilder() + .firstName("Cathryn") + .lastName("Washington") + .email("martha@example.com") + .reference(RandomStringUtils.randomAlphanumeric(10)) + .build() + ) + .build() + ) + .getCustomer(); + } + + @Test + void shouldReturnCustomerWhenReadByExistingChargifyID() throws IOException, ApiException { + // given + Integer chargifyId = TEST_CUSTOMER.getId(); + + // when + Customer customerReadByChargifyID = CUSTOMERS_CONTROLLER.readCustomer(chargifyId).getCustomer(); + + // then + assertCustomerAllProperties(customerReadByChargifyID); + } + + @Test + void shouldReturnNullWhenReadByNotExistingChargifyID() throws IOException, ApiException { + // given + int notExistingChargifyId = 12345; + + // when + CustomerResponse customerResponse = CUSTOMERS_CONTROLLER.readCustomer(notExistingChargifyId); + + // then + assertThat(customerResponse).isNull(); + } + + @Test + void shouldReturnCustomerWhenReadByExistingReference() throws IOException, ApiException { + // given + String reference = TEST_CUSTOMER.getReference(); + + // when + Customer customerReadByReference = CUSTOMERS_CONTROLLER.readCustomerByReference(reference).getCustomer(); + + // then + assertCustomerAllProperties(customerReadByReference); + } + + @Test + void shouldReturnNullWhenReadByNotExistingReference() throws IOException, ApiException { + // given + String notExistingReference = "not-existing-reference"; + + // when + CustomerResponse customerResponse = CUSTOMERS_CONTROLLER.readCustomerByReference(notExistingReference); + + // then + assertThat(customerResponse).isNull(); + } + + private void assertCustomerAllProperties(Customer customer) { + assertAll( + () -> assertThat(customer.getFirstName()).isEqualTo("Cathryn"), + () -> assertThat(customer.getLastName()).isEqualTo("Washington"), + () -> assertThat(customer.getEmail()).isEqualTo("martha@example.com"), + + () -> assertThat(customer.getId()).isNotNull(), + () -> assertThat(customer.getCreatedAt()).isNotNull(), + () -> assertThat(customer.getUpdatedAt()).isNotNull(), + + () -> assertThat(customer.getCcEmails()).isNull(), + () -> assertThat(customer.getOrganization()).isNull(), + () -> assertThat(customer.getReference()).isNotNull(), + () -> assertThat(customer.getAddress()).isNull(), + () -> assertThat(customer.getAddress2()).isNull(), + () -> assertThat(customer.getCity()).isNull(), + () -> assertThat(customer.getState()).isNull(), + () -> assertThat(customer.getStateName()).isNull(), + () -> assertThat(customer.getZip()).isNull(), + () -> assertThat(customer.getCountry()).isNull(), + () -> assertThat(customer.getCountryName()).isNull(), + () -> assertThat(customer.getPhone()).isNull(), + () -> assertThat(customer.getVerified()).isFalse(), + () -> assertThat(customer.getPortalCustomerCreatedAt()).isNull(), + () -> assertThat(customer.getPortalInviteLastSentAt()).isNull(), + () -> assertThat(customer.getPortalInviteLastAcceptedAt()).isNull(), + () -> assertThat(customer.getTaxExempt()).isFalse(), + () -> assertThat(customer.getVatNumber()).isNull(), + () -> assertThat(customer.getParentId()).isNull(), + () -> assertThat(customer.getLocale()).isNull(), + () -> assertThat(customer.getDefaultSubscriptionGroupUid()).isNull() + ); + } +}