From eb2ee6758b87303a4f9f9c6528d5e4732386fee2 Mon Sep 17 00:00:00 2001 From: Maciej Nedza Date: Mon, 27 Nov 2023 10:13:33 +0100 Subject: [PATCH] [DE-619] Use product date fields in tests --- .../ProductsControllerArchiveProductTest.java | 8 +++++--- .../products/ProductsControllerCreateProductTest.java | 5 +++-- .../products/ProductsControllerListProductsTest.java | 11 ++++++----- .../products/ProductsControllerTestBase.java | 3 +-- .../products/ProductsControllerUpdateProductTest.java | 3 ++- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerArchiveProductTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerArchiveProductTest.java index 0b2fc9e8..eaa6690f 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerArchiveProductTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerArchiveProductTest.java @@ -6,12 +6,14 @@ import org.junit.jupiter.api.Test; import java.io.IOException; -import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; import static com.maxio.advancedbilling.utils.CommonAssertions.assertNotFound; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ProductsControllerArchiveProductTest extends ProductsControllerTestBase { @@ -21,7 +23,7 @@ void shouldArchiveProduct() throws IOException, ApiException { Product product = createProduct(); // when - String timestamp = Instant.now().toString(); + ZonedDateTime timestamp = ZonedDateTime.now().minus(5, ChronoUnit.SECONDS); productsController.archiveProduct(product.getId()); // then @@ -29,7 +31,7 @@ void shouldArchiveProduct() throws IOException, ApiException { assertAll( () -> assertThat(archivedProduct.getId()).isEqualTo(product.getId()), () -> assertThat(archivedProduct.getArchivedAt()).isNotNull(), - () -> assertThat(archivedProduct.getArchivedAt()).isAfterOrEqualTo(timestamp) + () -> assertTrue(archivedProduct.getArchivedAt().isAfter(timestamp)) ); } diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerCreateProductTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerCreateProductTest.java index b6b4d83b..1c4f6055 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerCreateProductTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerCreateProductTest.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.time.Instant; +import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; @@ -28,7 +29,7 @@ public class ProductsControllerCreateProductTest extends ProductsControllerTestB @Test void shouldCreateProductWhenOnlyRequiredParametersAreProvided() throws IOException, ApiException { // when - String timestamp = Instant.now().minus(5, ChronoUnit.SECONDS).toString(); + ZonedDateTime timestamp = ZonedDateTime.now().minus(5, ChronoUnit.SECONDS); String handle = "washington-" + RandomStringUtils.randomAlphanumeric(5).toLowerCase(); Product product = productsController .createProduct(productFamily.getId(), new CreateOrUpdateProductRequest( @@ -100,7 +101,7 @@ void shouldCreateProductWhenOnlyRequiredParametersAreProvided() throws IOExcepti @Test void shouldCreateProductWhenAllParametersAreProvided() throws IOException, ApiException { // when - String timestamp = Instant.now().minus(5, ChronoUnit.SECONDS).toString(); + ZonedDateTime timestamp = ZonedDateTime.now().minus(5, ChronoUnit.SECONDS); String handle = "washington-" + RandomStringUtils.randomAlphanumeric(5).toLowerCase(); Product product = productsController .createProduct(productFamily.getId(), new CreateOrUpdateProductRequest( diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerListProductsTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerListProductsTest.java index 527e1bf9..d431b224 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerListProductsTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerListProductsTest.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; @@ -103,8 +104,8 @@ void shouldListProductsFilteringByEndDate() throws IOException, ApiException { @Test void shouldListProductsFilteringByStartDateTime() throws IOException, ApiException { // given - LocalDateTime savedProductCreatedAt = savedProducts.get(0).getCreatedAt(); - LocalDateTime startDateTimeFilterExcludeElements = savedProductCreatedAt.plusMinutes(5); + ZonedDateTime savedProductCreatedAt = savedProducts.get(0).getCreatedAt(); + ZonedDateTime startDateTimeFilterExcludeElements = savedProductCreatedAt.plusMinutes(5); // when List productList1 = productsController.listProducts( @@ -123,9 +124,9 @@ void shouldListProductsFilteringByStartDateTime() throws IOException, ApiExcepti @Test void shouldListProductsFilteringByEndDateTime() throws IOException, ApiException { // given - LocalDateTime savedProductCreatedAt = savedProducts.get(0).getCreatedAt(); - LocalDateTime endDateTimeFilterIncludeElements = savedProductCreatedAt.plusMinutes(5); - LocalDateTime endDateTimeFilterExcludeElements = savedProductCreatedAt.plusMinutes(-5); + ZonedDateTime savedProductCreatedAt = savedProducts.get(0).getCreatedAt(); + ZonedDateTime endDateTimeFilterIncludeElements = savedProductCreatedAt.plusMinutes(5); + ZonedDateTime endDateTimeFilterExcludeElements = savedProductCreatedAt.plusMinutes(-5); // when List productList1 = productsController.listProducts( diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerTestBase.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerTestBase.java index f8dfbac3..f10cb179 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerTestBase.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerTestBase.java @@ -36,7 +36,7 @@ protected Product createProduct() throws IOException, ApiException { } protected static Product createProductWithHandle(String handle) throws IOException, ApiException { - Product product = productsController + return productsController .createProduct(productFamily.getId(), new CreateOrUpdateProductRequest( new CreateOrUpdateProduct.Builder() .name("Initial Sample product-" + RandomStringUtils.randomAlphanumeric(5)) @@ -48,7 +48,6 @@ protected static Product createProductWithHandle(String handle) throws IOExcepti .build() )) .getProduct(); - return product; } } diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerUpdateProductTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerUpdateProductTest.java index 0c4478fb..d30f4ceb 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerUpdateProductTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerUpdateProductTest.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.time.Instant; +import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.List; @@ -28,7 +29,7 @@ public class ProductsControllerUpdateProductTest extends ProductsControllerTestB @Test void shouldUpdateProductWithAllParameters() throws IOException, ApiException { // when - String timestamp = Instant.now().minus(5, ChronoUnit.SECONDS).toString(); + ZonedDateTime timestamp = ZonedDateTime.now().minus(5, ChronoUnit.SECONDS); Product product = createProduct(); Product updatedProduct = productsController.updateProduct(product.getId(), new CreateOrUpdateProductRequest(