-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DE-526] Java test CRUD for customer endpoints (read) (#11)
- Loading branch information
1 parent
e8d33da
commit 42b0a8d
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerReadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("[email protected]") | ||
.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("[email protected]"), | ||
|
||
() -> 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() | ||
); | ||
} | ||
} |