From edc3565c06ff61a60078135a0c61226669a5d62b Mon Sep 17 00:00:00 2001
From: maciej-nedza <76946708+maciej-nedza@users.noreply.github.com>
Date: Tue, 21 Nov 2023 09:57:33 +0100
Subject: [PATCH] [DE-611] Use .codegenignore file and add tests to main branch
(#23)
* [DE-611] Use .codegenignore file and add tests to main branch
* [DE-611] Github actions on main branch
---
.codegenignore | 2 +
.github/workflows/build.yaml | 34 ++
.gitignore | 261 +++++++++++
tests/pom.xml | 60 +++
.../PlanExecutionFinishedListener.java | 33 ++
.../com/maxio/advancedbilling/TestClient.java | 28 ++
.../CustomersControllerCreateTest.java | 218 ++++++++++
.../CustomersControllerDeleteTest.java | 58 +++
.../CustomersControllerListOrFindTest.java | 406 ++++++++++++++++++
...tomersControllerListSubscriptionsTest.java | 172 ++++++++
.../CustomersControllerReadTest.java | 123 ++++++
.../CustomersControllerUpdateTest.java | 226 ++++++++++
.../controllers/SitesControllerTest.java | 64 +++
...it.platform.launcher.TestExecutionListener | 1 +
14 files changed, 1686 insertions(+)
create mode 100644 .codegenignore
create mode 100644 .github/workflows/build.yaml
create mode 100644 .gitignore
create mode 100644 tests/pom.xml
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/PlanExecutionFinishedListener.java
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/TestClient.java
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerCreateTest.java
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerDeleteTest.java
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerListOrFindTest.java
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerListSubscriptionsTest.java
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerReadTest.java
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerUpdateTest.java
create mode 100644 tests/src/test/java/com/maxio/advancedbilling/controllers/SitesControllerTest.java
create mode 100644 tests/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener
diff --git a/.codegenignore b/.codegenignore
new file mode 100644
index 00000000..f3317fd1
--- /dev/null
+++ b/.codegenignore
@@ -0,0 +1,2 @@
+tests/**
+.gitignore
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
new file mode 100644
index 00000000..1213bef5
--- /dev/null
+++ b/.github/workflows/build.yaml
@@ -0,0 +1,34 @@
+name: Build & run E2E tests
+on:
+ push:
+ branches:
+ - "main"
+ pull_request:
+ branches:
+ - "main"
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+ - name: Set up JDK 17
+ uses: actions/setup-java@v3
+ with:
+ java-version: "17"
+ distribution: "temurin"
+ architecture: x64
+ - name: Run tests
+ id: build
+ shell: bash
+ env:
+ API_KEY: ${{ secrets.API_KEY }}
+ DOMAIN: ${{ secrets.DOMAIN }}
+ SUBDOMAIN: ${{ secrets.SUBDOMAIN }}
+ run: |
+ mvn install
+ cd tests
+ mvn --batch-mode --update-snapshots verify --fail-at-end
+ - name: Publish Test Report
+ if: success() || failure()
+ uses: scacap/action-surefire-report@v1
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..c90e7acf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,261 @@
+# Created by https://www.toptal.com/developers/gitignore/api/java,macos,intellij,maven,eclipse
+# Edit at https://www.toptal.com/developers/gitignore?templates=java,macos,intellij,maven,eclipse
+
+### Eclipse ###
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+.recommenders
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# PyDev specific (Python IDE for Eclipse)
+*.pydevproject
+
+# CDT-specific (C/C++ Development Tooling)
+.cproject
+
+# CDT- autotools
+.autotools
+
+# Java annotation processor (APT)
+.factorypath
+
+# PDT-specific (PHP Development Tools)
+.buildpath
+
+# sbteclipse plugin
+.target
+
+# Tern plugin
+.tern-project
+
+# TeXlipse plugin
+.texlipse
+
+# STS (Spring Tool Suite)
+.springBeans
+
+# Code Recommenders
+.recommenders/
+
+# Annotation Processing
+.apt_generated/
+.apt_generated_test/
+
+# Scala IDE specific (Scala & Java development for Eclipse)
+.cache-main
+.scala_dependencies
+.worksheet
+
+# Uncomment this line if you wish to ignore the project description file.
+# Typically, this file would be tracked if it contains build/dependency configurations:
+#.project
+
+### Eclipse Patch ###
+# Spring Boot Tooling
+.sts4-cache/
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# AWS User-specific
+.idea/**/aws.xml
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn. Uncomment if using
+# auto-import.
+# .idea/artifacts
+# .idea/compiler.xml
+# .idea/jarRepositories.xml
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+# *.iml
+# *.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+# https://plugins.jetbrains.com/plugin/7973-sonarlint
+.idea/**/sonarlint/
+
+# SonarQube Plugin
+# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
+.idea/**/sonarIssues.xml
+
+# Markdown Navigator plugin
+# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
+.idea/**/markdown-navigator.xml
+.idea/**/markdown-navigator-enh.xml
+.idea/**/markdown-navigator/
+
+# Cache file creation bug
+# See https://youtrack.jetbrains.com/issue/JBR-2257
+.idea/$CACHE_FILE$
+
+# CodeStream plugin
+# https://plugins.jetbrains.com/plugin/12206-codestream
+.idea/codestream.xml
+
+# Azure Toolkit for IntelliJ plugin
+# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
+.idea/**/azureSettings.xml
+
+### Java ###
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+replay_pid*
+
+### macOS ###
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+### macOS Patch ###
+# iCloud generated files
+*.icloud
+
+### Maven ###
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+# https://github.com/takari/maven-wrapper#usage-without-binary-jar
+.mvn/wrapper/maven-wrapper.jar
+
+# Eclipse m2e generated files
+# Eclipse Core
+.project
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
+
+# End of https://www.toptal.com/developers/gitignore/api/java,macos,intellij,maven,eclipse
diff --git a/tests/pom.xml b/tests/pom.xml
new file mode 100644
index 00000000..18dbd13a
--- /dev/null
+++ b/tests/pom.xml
@@ -0,0 +1,60 @@
+
+ 4.0.0
+ com.maxio
+ advanced-billing-sdk-tests
+ 0.0.1
+ jar
+ AdvancedBillingTests
+
+ 1.8
+ 1.8
+ UTF-8
+
+
+
+ com.maxio
+ advanced-billing-sdk
+ [0.0.3,)
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.10.0
+ test
+
+
+ org.assertj
+ assertj-core
+ 3.24.2
+ test
+
+
+ org.junit.platform
+ junit-platform-launcher
+ 1.10.0
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ 5.10.0
+ test
+
+
+ org.apache.commons
+ commons-lang3
+ 3.13.0
+ test
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.2.1
+
+
+
+
diff --git a/tests/src/test/java/com/maxio/advancedbilling/PlanExecutionFinishedListener.java b/tests/src/test/java/com/maxio/advancedbilling/PlanExecutionFinishedListener.java
new file mode 100644
index 00000000..c89856fb
--- /dev/null
+++ b/tests/src/test/java/com/maxio/advancedbilling/PlanExecutionFinishedListener.java
@@ -0,0 +1,33 @@
+package com.maxio.advancedbilling;
+
+import com.maxio.advancedbilling.controllers.SitesController;
+import com.maxio.advancedbilling.exceptions.ApiException;
+import com.maxio.advancedbilling.models.CleanupScope;
+import org.junit.platform.commons.logging.Logger;
+import org.junit.platform.commons.logging.LoggerFactory;
+import org.junit.platform.launcher.TestExecutionListener;
+import org.junit.platform.launcher.TestPlan;
+
+import java.io.IOException;
+
+/**
+ * To make this class registered within JUnit platform, it must have been added:
+ * {@link /test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener}
+ */
+public class PlanExecutionFinishedListener implements TestExecutionListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PlanExecutionFinishedListener.class);
+
+ private final SitesController sitesController = TestClient.createClient().getSitesController();
+
+ @Override
+ public void testPlanExecutionFinished(TestPlan testPlan) {
+ try {
+ sitesController.clearSite(CleanupScope.ALL);
+ } catch (ApiException | IOException e) {
+ LOGGER.error(e, () -> "testPlanExecutionFinished | Failed to clear site data");
+ return;
+ }
+ LOGGER.info(() -> "testPlanExecutionFinished | Successfully cleared site data");
+ }
+}
diff --git a/tests/src/test/java/com/maxio/advancedbilling/TestClient.java b/tests/src/test/java/com/maxio/advancedbilling/TestClient.java
new file mode 100644
index 00000000..bd96d1db
--- /dev/null
+++ b/tests/src/test/java/com/maxio/advancedbilling/TestClient.java
@@ -0,0 +1,28 @@
+package com.maxio.advancedbilling;
+
+public class TestClient {
+ private static final String SUBDOMAIN_ENV = "SUBDOMAIN";
+ private static final String DOMAIN_ENV = "DOMAIN";
+ private static final String API_KEY_ENV = "API_KEY";
+
+ private static final String USER_NAME = "X";
+
+ public static AdvancedBillingClient createClient() {
+ return new AdvancedBillingClient.Builder()
+ .httpClientConfig(configBuilder -> configBuilder
+ .timeout(10))
+ .basicAuthCredentials(getEnvValue(API_KEY_ENV), USER_NAME)
+ .environment(Environment.PRODUCTION)
+ .subdomain(getEnvValue(SUBDOMAIN_ENV))
+ .domain(getEnvValue(DOMAIN_ENV))
+ .build();
+ }
+
+ private static String getEnvValue(String key) {
+ String envValue = System.getenv(key);
+ if (envValue == null) {
+ throw new RuntimeException(key + " environment variable is not defined!");
+ }
+ return envValue;
+ }
+}
diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerCreateTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerCreateTest.java
new file mode 100644
index 00000000..854667d3
--- /dev/null
+++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerCreateTest.java
@@ -0,0 +1,218 @@
+package com.maxio.advancedbilling.controllers;
+
+import com.maxio.advancedbilling.TestClient;
+import com.maxio.advancedbilling.exceptions.ApiException;
+import com.maxio.advancedbilling.exceptions.CustomerErrorResponseException;
+import com.maxio.advancedbilling.models.CreateCustomer;
+import com.maxio.advancedbilling.models.CreateCustomerRequest;
+import com.maxio.advancedbilling.models.Customer;
+import com.maxio.advancedbilling.models.CustomerError;
+import com.maxio.advancedbilling.models.containers.CustomerErrorResponseErrors;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+class CustomersControllerCreateTest {
+
+ private final CustomersController customersController = TestClient.createClient().getCustomersController();
+
+ @Test
+ void shouldCreateCustomerWhenOnlyRequiredParametersAreProvided() throws IOException, ApiException {
+ // when
+ Customer customer = customersController
+ .createCustomer(new CreateCustomerRequest()
+ .toBuilder()
+ .customer(new CreateCustomer()
+ .toBuilder()
+ .firstName("Cathryn")
+ .lastName("Washington")
+ .email("martha@example.com")
+ .build()
+ )
+ .build()
+ )
+ .getCustomer();
+
+ // then
+ 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()).isNull(),
+ () -> 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()
+ );
+ }
+
+ @Test
+ void shouldCreateCustomerWhenAllParametersAreProvided() throws IOException, ApiException {
+ // when
+ Customer customer = customersController
+ .createCustomer(new CreateCustomerRequest()
+ .toBuilder()
+ .customer(new CreateCustomer()
+ .toBuilder()
+ .firstName("Cathryn")
+ .lastName("Washington")
+ .email("martha@example.com")
+ .ccEmails("washington@example.com")
+ .organization("Maxio")
+ .reference("123")
+ .address("739 Stephon Bypass")
+ .address2("Apt. 123")
+ .city("San Antonio")
+ .state("TX")
+ .zip("78015")
+ .country("US")
+ .phone("555-111-222")
+ .locale("es-MX")
+ .vatNumber("123")
+ .taxExempt(true)
+ .taxExemptReason("N") // Local government (US only)
+ .parentId(null)
+ .build()
+ )
+ .build()
+ )
+ .getCustomer();
+
+ // then
+ 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()).isEqualTo("washington@example.com"),
+ () -> assertThat(customer.getOrganization()).isEqualTo("Maxio"),
+ () -> assertThat(customer.getReference()).isEqualTo("123"),
+ () -> assertThat(customer.getAddress()).isEqualTo("739 Stephon Bypass"),
+ () -> assertThat(customer.getAddress2()).isEqualTo("Apt. 123"),
+ () -> assertThat(customer.getCity()).isEqualTo("San Antonio"),
+ () -> assertThat(customer.getState()).isEqualTo("TX"),
+ () -> assertThat(customer.getStateName()).isEqualTo("Texas"),
+ () -> assertThat(customer.getZip()).isEqualTo("78015"),
+ () -> assertThat(customer.getCountry()).isEqualTo("US"),
+ () -> assertThat(customer.getCountryName()).isEqualTo("United States"),
+ () -> assertThat(customer.getPhone()).isEqualTo("555-111-222"),
+ () -> assertThat(customer.getVerified()).isFalse(),
+ () -> assertThat(customer.getPortalCustomerCreatedAt()).isNull(),
+ () -> assertThat(customer.getPortalInviteLastSentAt()).isNull(),
+ () -> assertThat(customer.getPortalInviteLastAcceptedAt()).isNull(),
+ () -> assertThat(customer.getTaxExempt()).isTrue(),
+ () -> assertThat(customer.getVatNumber()).isEqualTo("123"),
+ () -> assertThat(customer.getParentId()).isNull(),
+ () -> assertThat(customer.getLocale()).isEqualTo("es-MX"),
+ () -> assertThat(customer.getDefaultSubscriptionGroupUid()).isNull()
+ );
+ }
+
+ @Test
+ void shouldNotCreateCustomerWhenRequestIsNull() {
+ // when - then
+ assertThatExceptionOfType(CustomerErrorResponseException.class)
+ .isThrownBy(() -> customersController.createCustomer(null))
+ .withMessage("Unprocessable Entity (WebDAV)")
+ .satisfies(e -> {
+ assertThat(e.getResponseCode()).isEqualTo(422);
+ assertThat(e.getErrors().toString()).isEqualTo(
+ CustomerErrorResponseErrors
+ .fromCustomerError(new CustomerError("can't be blank"))
+ .toString()
+ );
+ });
+ }
+
+ @ParameterizedTest
+ @MethodSource("argsForShouldNotCreateCustomerWhenAnyOfTheRequiredParameterIsMissing")
+ void shouldNotCreateCustomerWhenAnyOfTheRequiredParameterIsMissing(CreateCustomer createCustomer, List errorMessages) {
+ // when - then
+ assertThatExceptionOfType(CustomerErrorResponseException.class)
+ .isThrownBy(() -> customersController
+ .createCustomer(new CreateCustomerRequest()
+ .toBuilder()
+ .customer(createCustomer)
+ .build())
+ )
+ .withMessage("Unprocessable Entity (WebDAV)")
+ .satisfies(e -> {
+ assertThat(e.getResponseCode()).isEqualTo(422);
+ assertThat(e.getErrors().toString())
+ .isEqualTo(CustomerErrorResponseErrors.fromListOfString(errorMessages).toString());
+ });
+ }
+
+ private static Stream argsForShouldNotCreateCustomerWhenAnyOfTheRequiredParameterIsMissing() {
+ String firstName = "Cathryn";
+ String lastName = "Washington";
+ String email = "martha@example.com";
+
+ return Stream.of(
+ Arguments.of(
+ new CreateCustomer().toBuilder().build(),
+ Arrays.asList("First name: cannot be blank.", "Last name: cannot be blank.", "Email address: cannot be blank.")
+ ),
+ Arguments.of(
+ new CreateCustomer().toBuilder().firstName(firstName).build(),
+ Arrays.asList("Last name: cannot be blank.", "Email address: cannot be blank.")
+ ),
+ Arguments.of(
+ new CreateCustomer().toBuilder().lastName(lastName).build(),
+ Arrays.asList("First name: cannot be blank.", "Email address: cannot be blank.")
+ ),
+ Arguments.of(
+ new CreateCustomer().toBuilder().email(email).build(),
+ Arrays.asList("First name: cannot be blank.", "Last name: cannot be blank.")
+ ),
+ Arguments.of(
+ new CreateCustomer().toBuilder().firstName(firstName).lastName(lastName).build(),
+ Collections.singletonList("Email address: cannot be blank.")
+ ),
+ Arguments.of(
+ new CreateCustomer().toBuilder().firstName(firstName).email(email).build(),
+ Collections.singletonList("Last name: cannot be blank.")
+ ),
+ Arguments.of(
+ new CreateCustomer().toBuilder().lastName(lastName).email(email).build(),
+ Collections.singletonList("First name: cannot be blank.")
+ )
+ );
+ }
+}
diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerDeleteTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerDeleteTest.java
new file mode 100644
index 00000000..ca0243cb
--- /dev/null
+++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerDeleteTest.java
@@ -0,0 +1,58 @@
+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 io.apimatic.core.types.CoreApiException;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+class CustomersControllerDeleteTest {
+
+ private final CustomersController customersController = TestClient.createClient().getCustomersController();
+
+ @Test
+ void shouldDeleteCustomerByChargifyID() throws IOException, ApiException {
+ // given
+ int chargifyId = customersController
+ .createCustomer(new CreateCustomerRequest()
+ .toBuilder()
+ .customer(new CreateCustomer()
+ .toBuilder()
+ .firstName("Cathryn")
+ .lastName("Washington")
+ .email("martha@example.com")
+ .reference(RandomStringUtils.randomAlphanumeric(10))
+ .build()
+ )
+ .build()
+ )
+ .getCustomer()
+ .getId();
+
+ // when
+ customersController.deleteCustomer(chargifyId);
+
+ // then
+ assertThat(customersController.readCustomer(chargifyId)).isNull();
+ }
+
+ @Test
+ void shouldNotDeleteCustomerAndReturn404WhenProvidingNotExistingChargifyID() {
+ // given
+ int notExistingChargifyID = 12345;
+
+ // when - then
+ assertThatExceptionOfType(ApiException.class)
+ .isThrownBy(() -> customersController.deleteCustomer(notExistingChargifyID))
+ .withMessage("HTTP Response Not OK")
+ .extracting(CoreApiException::getResponseCode)
+ .isEqualTo(404);
+ }
+}
diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerListOrFindTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerListOrFindTest.java
new file mode 100644
index 00000000..cc8c7b87
--- /dev/null
+++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerListOrFindTest.java
@@ -0,0 +1,406 @@
+package com.maxio.advancedbilling.controllers;
+
+import com.maxio.advancedbilling.TestClient;
+import com.maxio.advancedbilling.exceptions.ApiException;
+import com.maxio.advancedbilling.models.BasicDateField;
+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 com.maxio.advancedbilling.models.ListCustomersInput;
+import com.maxio.advancedbilling.models.SortingDirection;
+import com.maxio.advancedbilling.models.containers.ListCustomersInputDirection;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+class CustomersControllerListOrFindTest {
+
+ private static final CustomersController CUSTOMERS_CONTROLLER = TestClient.createClient().getCustomersController();
+ private static final Customer[] TEST_CUSTOMERS = new Customer[10];
+
+ @BeforeAll
+ static void beforeAll() throws IOException, ApiException {
+ for (int i = 0; i < TEST_CUSTOMERS.length; i++) {
+ TEST_CUSTOMERS[i] = CUSTOMERS_CONTROLLER
+ .createCustomer(new CreateCustomerRequest()
+ .toBuilder()
+ .customer(new CreateCustomer()
+ .toBuilder()
+ .firstName(String.format("Cathryn-%s", i))
+ .lastName(String.format("Washington-%s", i))
+ .email(String.format("martha-%s@example.com", i))
+ .organization("Maxio.com")
+ .reference(RandomStringUtils.randomAlphanumeric(10))
+ .build()
+ )
+ .build()
+ )
+ .getCustomer();
+ }
+ }
+
+ @BeforeEach
+ void beforeEach() {
+ assertThat(TEST_CUSTOMERS).hasSize(10);
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingEmail() throws IOException, ApiException {
+ // given
+ String email = "martha-2@example.com";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(email).build()
+ );
+
+ // then
+ assertThat(listCustomers).hasSize(1);
+ Customer customer = listCustomers.get(0).getCustomer();
+ assertAll(
+ () -> assertThat(customer.getFirstName()).isEqualTo("Cathryn-2"),
+ () -> assertThat(customer.getLastName()).isEqualTo("Washington-2"),
+ () -> assertThat(customer.getEmail()).isEqualTo("martha-2@example.com"),
+
+ () -> assertThat(customer.getId()).isNotNull(),
+ () -> assertThat(customer.getCreatedAt()).isNotNull(),
+ () -> assertThat(customer.getUpdatedAt()).isNotNull(),
+
+ () -> assertThat(customer.getCcEmails()).isNull(),
+ () -> assertThat(customer.getOrganization()).isEqualTo("Maxio.com"),
+ () -> 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()
+ );
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenSearchingByNotExistingEmail() throws IOException, ApiException {
+ // given
+ String notExistingEmail = "not-existing@email.com";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(notExistingEmail).build()
+ );
+
+ // then
+ assertThat(listCustomers).isEmpty();
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingChargifyID() throws IOException, ApiException {
+ // given
+ Integer chargifyId = TEST_CUSTOMERS[0].getId();
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(chargifyId.toString()).build()
+ );
+
+ // then
+ assertThat(listCustomers).hasSize(1);
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenSearchingByNotExistingChargifyID() throws IOException, ApiException {
+ // given
+ String notExistingChargifyId = "123456";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(notExistingChargifyId).build()
+ );
+
+ // then
+ assertThat(listCustomers).isEmpty();
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingOrganization() throws IOException, ApiException {
+ // given
+ String organization = "Maxio.com";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(organization).build()
+ );
+
+ // then
+ assertThat(listCustomers).hasSize(10);
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenSearchingByNotExistingOrganization() throws IOException, ApiException {
+ // given
+ String notExistingOrganization = "Google.com";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(notExistingOrganization).build()
+ );
+
+ // then
+ assertThat(listCustomers).isEmpty();
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingReference() throws IOException, ApiException {
+ // given
+ String reference = TEST_CUSTOMERS[0].getReference();
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(reference).build()
+ );
+
+ // then
+ assertThat(listCustomers).hasSize(1);
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenSearchingByNotExistingReference() throws IOException, ApiException {
+ // given
+ String notExistingReference = RandomStringUtils.randomAlphanumeric(10);
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(notExistingReference).build()
+ );
+
+ // then
+ assertThat(listCustomers).isEmpty();
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingFirstName() throws IOException, ApiException {
+ // given
+ String firstName = "Cathryn-2";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(firstName).build()
+ );
+
+ // then
+ assertThat(listCustomers).hasSize(1);
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenSearchingByNotExistingFirstName() throws IOException, ApiException {
+ // given
+ String notExistingFirstName = "NotExistingFirstName";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(notExistingFirstName).build()
+ );
+
+ // then
+ assertThat(listCustomers).isEmpty();
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingLastName() throws IOException, ApiException {
+ // given
+ String lastName = "Washington-2";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(lastName).build()
+ );
+
+ // then
+ assertThat(listCustomers).hasSize(1);
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenSearchingByNotExistingLastName() throws IOException, ApiException {
+ // given
+ String notExistingLastName = "NotExistingLastName";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .q(notExistingLastName).build()
+ );
+
+ // then
+ assertThat(listCustomers).isEmpty();
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingOrganizationAndSortDescDirection() throws IOException, ApiException {
+ // given
+ String organization = "Maxio.com";
+ ListCustomersInputDirection sortDescDirection = ListCustomersInputDirection.fromSortingDirection(SortingDirection.DESC);
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .direction(sortDescDirection)
+ .q(organization).build()
+ );
+
+ // then
+ assertThat(listCustomers).hasSize(10);
+ assertThat(listCustomers.get(0).getCustomer().getFirstName()).isEqualTo("Cathryn-9");
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingOrganizationAndSortAscDirection() throws IOException, ApiException {
+ // given
+ String organization = "Maxio.com";
+ ListCustomersInputDirection sortAscDirection = ListCustomersInputDirection.fromSortingDirection(SortingDirection.ASC);
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .direction(sortAscDirection)
+ .q(organization).build()
+ );
+
+ // then
+ assertThat(listCustomers).hasSize(10);
+ assertThat(listCustomers.get(0).getCustomer().getFirstName()).isEqualTo("Cathryn-0");
+ }
+
+ @Test
+ void shouldReturnNotEmptyListWhenSearchingByExistingOrganizationUsingPagination() throws IOException, ApiException {
+ // given
+ String organization = "Maxio.com";
+ int perPage = 3;
+
+ // when
+ // 1st page (default if not provided)
+ List listCustomersOnPage1 = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .page(1)
+ .perPage(perPage)
+ .q(organization)
+ .build()
+ );
+
+ // 2nd page
+ List listCustomersOnPage2 = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .page(2)
+ .perPage(perPage)
+ .q(organization)
+ .build()
+ );
+
+ // 3rd page
+ List listCustomersOnPage3 = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .page(3)
+ .perPage(perPage)
+ .q(organization)
+ .build()
+ );
+
+ // 4th page
+ List listCustomersOnPage4 = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .page(4)
+ .perPage(perPage)
+ .q(organization)
+ .build()
+ );
+
+ // n-th page
+ List listCustomersOnPageN = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .page(5)
+ .perPage(perPage)
+ .q(organization)
+ .build()
+ );
+
+ // then
+ assertThat(listCustomersOnPage1).hasSize(3);
+ assertThat(listCustomersOnPage2).hasSize(3);
+ assertThat(listCustomersOnPage3).hasSize(3);
+ assertThat(listCustomersOnPage4).hasSize(1);
+ assertThat(listCustomersOnPageN).isEmpty();
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenSearchingByExistingOrganizationAndCreatedAtNotMatchingDateRange() throws IOException, ApiException {
+ // given
+ String organization = "Maxio.com";
+ BasicDateField createdAt = BasicDateField.CREATED_AT;
+ String createdAtStartDate = "2020-01-01";
+ String createdAtEndDate = "2020-05-25";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .dateField(createdAt)
+ .startDate(createdAtStartDate)
+ .endDate(createdAtEndDate)
+ .q(organization)
+ .build()
+ );
+
+ // then
+ assertThat(listCustomers).isEmpty();
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenSearchingByExistingOrganizationAndUpdatedAtNotMatchingDateTimeRange() throws IOException, ApiException {
+ // given
+ String organization = "Maxio.com";
+ BasicDateField updatedAt = BasicDateField.UPDATED_AT;
+ String updatedAtStartDateTime = "2020-01-01 10:12:55";
+ String updatedAtEndDateTime = "2020-05-25 23:55:59";
+
+ // when
+ List listCustomers = CUSTOMERS_CONTROLLER
+ .listCustomers(new ListCustomersInput().toBuilder()
+ .dateField(updatedAt)
+ .startDate(updatedAtStartDateTime)
+ .endDate(updatedAtEndDateTime)
+ .q(organization)
+ .build()
+ );
+
+ // then
+ assertThat(listCustomers).isEmpty();
+ }
+}
diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerListSubscriptionsTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerListSubscriptionsTest.java
new file mode 100644
index 00000000..33cba82c
--- /dev/null
+++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerListSubscriptionsTest.java
@@ -0,0 +1,172 @@
+package com.maxio.advancedbilling.controllers;
+
+import com.maxio.advancedbilling.AdvancedBillingClient;
+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.CreateOrUpdateProduct;
+import com.maxio.advancedbilling.models.CreateOrUpdateProductRequest;
+import com.maxio.advancedbilling.models.CreatePaymentProfile;
+import com.maxio.advancedbilling.models.CreatePaymentProfileRequest;
+import com.maxio.advancedbilling.models.CreateProductFamily;
+import com.maxio.advancedbilling.models.CreateProductFamilyRequest;
+import com.maxio.advancedbilling.models.CreateSubscription;
+import com.maxio.advancedbilling.models.CreateSubscriptionRequest;
+import com.maxio.advancedbilling.models.CreatedPaymentProfile;
+import com.maxio.advancedbilling.models.PaymentType;
+import com.maxio.advancedbilling.models.Product;
+import com.maxio.advancedbilling.models.ProductFamily;
+import com.maxio.advancedbilling.models.Subscription;
+import com.maxio.advancedbilling.models.SubscriptionResponse;
+import com.maxio.advancedbilling.models.containers.CreatePaymentProfileExpirationMonth;
+import com.maxio.advancedbilling.models.containers.CreatePaymentProfileExpirationYear;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class CustomersControllerListSubscriptionsTest {
+
+ public final AdvancedBillingClient advancedBillingClient = TestClient.createClient();
+
+ private final CustomersController customersController = advancedBillingClient.getCustomersController();
+ private final PaymentProfilesController paymentProfilesController = advancedBillingClient.getPaymentProfilesController();
+ private final ProductFamiliesController productFamiliesController = advancedBillingClient.getProductFamiliesController();
+ private final ProductsController productsController = advancedBillingClient.getProductsController();
+ private final SubscriptionsController subscriptionsController = advancedBillingClient.getSubscriptionsController();
+
+ @Test
+ void shouldReturnNullWhenCustomerNotExists() throws IOException, ApiException {
+ // given
+ int notExistingCustomerId = 12345;
+
+ // when - then
+ List subscriptionResponses = customersController.listCustomerSubscriptions(notExistingCustomerId);
+
+ // then
+ assertThat(subscriptionResponses).isNull();
+ }
+
+ @Test
+ void shouldReturnEmptyListWhenCustomerHasNoSubscriptions() throws IOException, ApiException {
+ // given
+ int customerId = customersController
+ .createCustomer(new CreateCustomerRequest()
+ .toBuilder()
+ .customer(new CreateCustomer()
+ .toBuilder()
+ .firstName("Cathryn")
+ .lastName("Washington")
+ .email("martha@example.com")
+ .reference(RandomStringUtils.randomAlphanumeric(10))
+ .build()
+ )
+ .build()
+ )
+ .getCustomer()
+ .getId();
+
+ // when
+ List subscriptionResponses = customersController.listCustomerSubscriptions(customerId);
+
+ // then
+ assertThat(subscriptionResponses).isEmpty();
+ }
+
+ @Test
+ void shouldReturnListOfSubscriptionsForCustomer() throws IOException, ApiException {
+ // given
+ int customerId = customersController
+ .createCustomer(new CreateCustomerRequest()
+ .toBuilder()
+ .customer(new CreateCustomer()
+ .toBuilder()
+ .firstName("Cathryn")
+ .lastName("Washington")
+ .email("martha@example.com")
+ .reference(RandomStringUtils.randomAlphanumeric(10))
+ .build()
+ )
+ .build()
+ )
+ .getCustomer()
+ .getId();
+
+ CreatedPaymentProfile paymentProfile = paymentProfilesController
+ .createPaymentProfile(new CreatePaymentProfileRequest()
+ .toBuilder()
+ .paymentProfile(new CreatePaymentProfile()
+ .toBuilder()
+ .customerId(customerId)
+ .paymentType(PaymentType.CREDIT_CARD)
+ .expirationMonth(CreatePaymentProfileExpirationMonth.fromNumber(10))
+ .expirationYear(CreatePaymentProfileExpirationYear.fromNumber(2025))
+ .fullNumber("5424000000000015")
+ .build()
+ )
+ .build()
+ )
+ .getPaymentProfile();
+
+ ProductFamily productFamily = productFamiliesController
+ .createProductFamily(new CreateProductFamilyRequest()
+ .toBuilder()
+ .productFamily(new CreateProductFamily()
+ .toBuilder()
+ .name("Test Product Family")
+ .build()
+ )
+ .build()
+ )
+ .getProductFamily();
+
+ Product product = productsController
+ .createProduct(
+ productFamily.getId(),
+ new CreateOrUpdateProductRequest()
+ .toBuilder()
+ .product(new CreateOrUpdateProduct()
+ .toBuilder()
+ .name("Test Product")
+ .handle("test-product")
+ .intervalUnit("month")
+ .interval(2)
+ .build()
+ )
+ .build()
+ )
+ .getProduct();
+
+ Subscription subscription = subscriptionsController
+ .createSubscription(new CreateSubscriptionRequest()
+ .toBuilder()
+ .subscription(new CreateSubscription()
+ .toBuilder()
+ .customerId(customerId)
+ .paymentProfileId(paymentProfile.getId())
+ .productId(Integer.toString(product.getId()))
+ .build()
+ )
+ .build()
+ )
+ .getSubscription();
+
+ // when
+ List customerSubscriptions = customersController
+ .listCustomerSubscriptions(customerId)
+ .stream()
+ .map(SubscriptionResponse::getSubscription)
+ .collect(Collectors.toList());
+
+ // then
+ assertThat(customerSubscriptions).hasSize(1);
+ assertThat(customerSubscriptions)
+ .extracting(Subscription::getId)
+ .containsExactly(subscription.getId());
+ }
+}
diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerReadTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerReadTest.java
new file mode 100644
index 00000000..ced96619
--- /dev/null
+++ b/tests/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()
+ );
+ }
+}
diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerUpdateTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerUpdateTest.java
new file mode 100644
index 00000000..7e993bfc
--- /dev/null
+++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/CustomersControllerUpdateTest.java
@@ -0,0 +1,226 @@
+package com.maxio.advancedbilling.controllers;
+
+import com.maxio.advancedbilling.TestClient;
+import com.maxio.advancedbilling.exceptions.ApiException;
+import com.maxio.advancedbilling.exceptions.CustomerErrorResponseException;
+import com.maxio.advancedbilling.models.CreateCustomer;
+import com.maxio.advancedbilling.models.CreateCustomerRequest;
+import com.maxio.advancedbilling.models.Customer;
+import com.maxio.advancedbilling.models.CustomerError;
+import com.maxio.advancedbilling.models.CustomerResponse;
+import com.maxio.advancedbilling.models.UpdateCustomer;
+import com.maxio.advancedbilling.models.UpdateCustomerRequest;
+import com.maxio.advancedbilling.models.containers.CustomerErrorResponseErrors;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+class CustomersControllerUpdateTest {
+
+ private final CustomersController customersController = TestClient.createClient().getCustomersController();
+
+ private Integer customerId;
+
+ @BeforeEach
+ void setUp() throws IOException, ApiException {
+ customerId = customersController
+ .createCustomer(new CreateCustomerRequest()
+ .toBuilder()
+ .customer(new CreateCustomer()
+ .toBuilder()
+ .firstName("Cathryn")
+ .lastName("Washington")
+ .email("martha@example.com")
+ .reference(RandomStringUtils.randomAlphanumeric(10))
+ .build()
+ )
+ .build()
+ )
+ .getCustomer()
+ .getId();
+ }
+
+ @Test
+ void shouldUpdateCustomerWithNewFirstName() throws IOException, ApiException {
+ // when
+ Customer customer = customersController
+ .updateCustomer(
+ customerId,
+ new UpdateCustomerRequest(new UpdateCustomer().toBuilder().firstName("Martha").build())
+ )
+ .getCustomer();
+
+ // then
+ assertThat(customer.getFirstName()).isEqualTo("Martha");
+ assertThat(customer.getLastName()).isEqualTo("Washington");
+ assertThat(customer.getEmail()).isEqualTo("martha@example.com");
+ }
+
+ @Test
+ void shouldUpdateCustomerWithNewLastName() throws IOException, ApiException {
+ // when
+ Customer customer = customersController
+ .updateCustomer(
+ customerId,
+ new UpdateCustomerRequest(new UpdateCustomer().toBuilder().lastName("Newman").build())
+ )
+ .getCustomer();
+
+ // then
+ assertThat(customer.getFirstName()).isEqualTo("Cathryn");
+ assertThat(customer.getLastName()).isEqualTo("Newman");
+ assertThat(customer.getEmail()).isEqualTo("martha@example.com");
+ }
+
+ @Test
+ void shouldUpdateCustomerWithNewEmail() throws IOException, ApiException {
+ // when
+ Customer customer = customersController
+ .updateCustomer(
+ customerId,
+ new UpdateCustomerRequest(new UpdateCustomer().toBuilder().email("company@test.com").build())
+ )
+ .getCustomer();
+
+ // then
+ assertThat(customer.getFirstName()).isEqualTo("Cathryn");
+ assertThat(customer.getLastName()).isEqualTo("Washington");
+ assertThat(customer.getEmail()).isEqualTo("company@test.com");
+ }
+
+ @Test
+ void shouldUpdateCustomerWithNewProperties() throws IOException, ApiException {
+ // when
+ Customer customer = customersController
+ .updateCustomer(
+ customerId,
+ new UpdateCustomerRequest(new UpdateCustomer()
+ .toBuilder()
+ .firstName("Martha")
+ .lastName("Newman")
+ .email("company@test.com")
+ .country("US")
+ .state("NY")
+ .city("New York")
+ .build()
+ )
+ )
+ .getCustomer();
+
+ // then
+ assertThat(customer.getFirstName()).isEqualTo("Martha");
+ assertThat(customer.getLastName()).isEqualTo("Newman");
+ assertThat(customer.getEmail()).isEqualTo("company@test.com");
+ assertThat(customer.getCountry()).isEqualTo("US");
+ assertThat(customer.getState()).isEqualTo("NY");
+ assertThat(customer.getCity()).isEqualTo("New York");
+ }
+
+ @Test
+ void shouldReturnNullWhenNotExists() throws IOException, ApiException {
+ int notExistingCustomerId = 123;
+
+ // when
+ CustomerResponse customerResponse = customersController
+ .updateCustomer(notExistingCustomerId, new UpdateCustomerRequest());
+
+ // then
+ assertThat(customerResponse).isNull();
+ }
+
+ @Test
+ void shouldNotUpdateCustomerWhenRequestIsNull() {
+ // when - then
+ assertThatExceptionOfType(CustomerErrorResponseException.class)
+ .isThrownBy(() -> customersController.updateCustomer(customerId, null))
+ .withMessage("Unprocessable Entity (WebDAV)")
+ .satisfies(e -> {
+ assertThat(e.getResponseCode()).isEqualTo(422);
+ assertThat(e.getErrors().toString()).isEqualTo(
+ CustomerErrorResponseErrors
+ .fromCustomerError(new CustomerError("can't be blank"))
+ .toString()
+ );
+ });
+ }
+
+ @Test
+ void shouldNotUpdateCustomerWhenRequestIsEmpty() {
+ // when - then
+ assertThatExceptionOfType(CustomerErrorResponseException.class)
+ .isThrownBy(() -> customersController.updateCustomer(
+ customerId,
+ new UpdateCustomerRequest(new UpdateCustomer())
+ ))
+ .withMessage("Unprocessable Entity (WebDAV)")
+ .satisfies(e -> {
+ assertThat(e.getResponseCode()).isEqualTo(422);
+ assertThat(e.getErrors().toString()).isEqualTo(
+ CustomerErrorResponseErrors
+ .fromCustomerError(new CustomerError("can't be blank"))
+ .toString()
+ );
+ });
+ }
+
+ @ParameterizedTest
+ @MethodSource("argsForShouldNotUpdateCustomerWhenBasicParametersAreBlank")
+ void shouldNotUpdateCustomerWhenBasicParametersAreBlank(UpdateCustomer updateCustomer, List errorMessages) {
+ // when - then
+ assertThatExceptionOfType(CustomerErrorResponseException.class)
+ .isThrownBy(() -> customersController.updateCustomer(
+ customerId, new UpdateCustomerRequest(updateCustomer))
+ )
+ .withMessage("Unprocessable Entity (WebDAV)")
+ .satisfies(e -> {
+ assertThat(e.getResponseCode()).isEqualTo(422);
+ assertThat(e.getErrors().toString())
+ .isEqualTo(CustomerErrorResponseErrors.fromListOfString(errorMessages).toString());
+ });
+ }
+
+ private static Stream argsForShouldNotUpdateCustomerWhenBasicParametersAreBlank() {
+ return Stream.of(
+ Arguments.of(
+ new UpdateCustomer().toBuilder().firstName("").lastName("").email("").build(),
+ Arrays.asList("First name: cannot be blank.", "Last name: cannot be blank.", "Email address: cannot be blank.")
+ ),
+ Arguments.of(
+ new UpdateCustomer().toBuilder().firstName("").build(),
+ Collections.singletonList("First name: cannot be blank.")
+ ),
+ Arguments.of(
+ new UpdateCustomer().toBuilder().lastName("").build(),
+ Collections.singletonList("Last name: cannot be blank.")
+ ),
+ Arguments.of(
+ new UpdateCustomer().toBuilder().email("").build(),
+ Collections.singletonList("Email address: cannot be blank.")
+ ),
+ Arguments.of(
+ new UpdateCustomer().toBuilder().firstName("").lastName("").build(),
+ Arrays.asList("First name: cannot be blank.", "Last name: cannot be blank.")
+ ),
+ Arguments.of(
+ new UpdateCustomer().toBuilder().firstName("").email("").build(),
+ Arrays.asList("First name: cannot be blank.", "Email address: cannot be blank.")
+ ),
+ Arguments.of(
+ new UpdateCustomer().toBuilder().lastName("").email("").build(),
+ Arrays.asList("Last name: cannot be blank.", "Email address: cannot be blank.")
+ )
+ );
+ }
+}
diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/SitesControllerTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/SitesControllerTest.java
new file mode 100644
index 00000000..608a2453
--- /dev/null
+++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/SitesControllerTest.java
@@ -0,0 +1,64 @@
+package com.maxio.advancedbilling.controllers;
+
+import com.maxio.advancedbilling.TestClient;
+import com.maxio.advancedbilling.models.AllocationSettings;
+import com.maxio.advancedbilling.models.NetTerms;
+import com.maxio.advancedbilling.models.OrganizationAddress;
+import com.maxio.advancedbilling.models.Site;
+import com.maxio.advancedbilling.models.TaxConfiguration;
+import com.maxio.advancedbilling.models.TaxConfigurationKind;
+import com.maxio.advancedbilling.models.TaxDestinationAddress;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class SitesControllerTest {
+ private final SitesController sitesController = TestClient.createClient().getSitesController();
+
+ @Test
+ void shouldReadSite() throws Exception {
+ // when
+ Site site = sitesController.readSite().getSite();
+
+ // then
+ assertThat(site.getId()).isEqualTo(4512);
+ assertThat(site.getName()).isEqualTo("Java SDK Env");
+ assertThat(site.getSubdomain()).isEqualTo("java-sdk");
+ assertThat(site.getCurrency()).isEqualTo("USD");
+ assertThat(site.getSellerId()).isEqualTo(722159);
+ assertThat(site.getNonPrimaryCurrencies()).containsExactlyInAnyOrder("EUR");
+ assertThat(site.getRelationshipInvoicingEnabled()).isTrue();
+ assertThat(site.getCustomerHierarchyEnabled()).isFalse();
+ assertThat(site.getWhopaysEnabled()).isFalse();
+ assertThat(site.getWhopaysDefaultPayer()).isEqualTo("self-ungrouped");
+
+ AllocationSettings allocationSettings = site.getAllocationSettings();
+ assertThat(allocationSettings.getUpgradeCharge()).isEqualTo("prorated");
+ assertThat(allocationSettings.getAccrueCharge()).isTrue();
+ assertThat(allocationSettings.getDowngradeCredit()).isEqualTo("none");
+
+ OrganizationAddress organizationAddress = site.getOrganizationAddress();
+ assertThat(organizationAddress.getStreet()).isEqualTo("Asdf Street");
+ assertThat(organizationAddress.getLine2()).isEqualTo("123/444");
+ assertThat(organizationAddress.getCity()).isEqualTo("San Antonio");
+ assertThat(organizationAddress.getState()).isEqualTo("TX");
+ assertThat(organizationAddress.getZip()).isEqualTo("78015");
+ assertThat(organizationAddress.getCountry()).isEqualTo("US");
+ assertThat(organizationAddress.getName()).isEqualTo("Developer Experience");
+ assertThat(organizationAddress.getPhone()).isEqualTo("555 111 222");
+
+ TaxConfiguration taxConfiguration = site.getTaxConfiguration();
+ assertThat(taxConfiguration.getFullyConfigured()).isFalse();
+ assertThat(taxConfiguration.getKind()).isEqualTo(TaxConfigurationKind.CUSTOM);
+ assertThat(taxConfiguration.getDestinationAddress()).isEqualTo(TaxDestinationAddress.SHIPPING_THEN_BILLING);
+
+ NetTerms netTerms = site.getNetTerms();
+ assertThat(netTerms.getDefaultNetTerms()).isEqualTo(5);
+ assertThat(netTerms.getAutomaticNetTerms()).isEqualTo(5);
+ assertThat(netTerms.getRemittanceNetTerms()).isEqualTo(10);
+ assertThat(netTerms.getNetTermsOnRemittanceSignupsEnabled()).isTrue();
+ assertThat(netTerms.getCustomNetTermsEnabled()).isTrue();
+
+ assertThat(site.getTest()).isTrue();
+ }
+}
diff --git a/tests/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/tests/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener
new file mode 100644
index 00000000..8888808a
--- /dev/null
+++ b/tests/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener
@@ -0,0 +1 @@
+com.maxio.advancedbilling.PlanExecutionFinishedListener