diff --git a/account-service/src/test/java/pl/piomin/microservices/advanced/account/repository/AccountRepositoryTest.java b/account-service/src/test/java/pl/piomin/microservices/advanced/account/repository/AccountRepositoryTest.java index def9588..cc74625 100644 --- a/account-service/src/test/java/pl/piomin/microservices/advanced/account/repository/AccountRepositoryTest.java +++ b/account-service/src/test/java/pl/piomin/microservices/advanced/account/repository/AccountRepositoryTest.java @@ -15,8 +15,7 @@ import java.util.Optional; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @DataMongoTest @Testcontainers @@ -45,8 +44,8 @@ public void testAddAccount() { a.setBalance(1232); a.setCustomerId("234353464576586464"); a = repository.save(a); - assertNotNull(a); - assertNotNull(a.getId()); + assertNotNull(a, "Account should not be null after saving"); + assertNotNull(a.getId(), "Account ID should not be null after saving"); id = a.getId(); } @@ -54,15 +53,22 @@ public void testAddAccount() { @Order(2) public void testFindAccount() { Optional optAcc = repository.findById(id); - assertTrue(optAcc.isPresent()); + assertTrue(optAcc.isPresent(), "Account should be found by ID"); + assertEquals("12345678909", optAcc.get().getNumber(), "Account number should match"); } @Test - @Order(2) + @Order(3) public void testFindAccountByNumber() { Account a = repository.findByNumber("12345678909"); - assertNotNull(a); - assertNotNull(a.getId()); + assertNotNull(a, "Account should not be null when found by number"); + assertEquals("12345678909", a.getNumber(), "Account number should match"); } + @Test + @Order(4) + public void testFindNonExistentAccount() { + Optional optAcc = repository.findById("non-existent-id"); + assertFalse(optAcc.isPresent(), "Account should not be found for a non-existent ID"); + } } diff --git a/customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerControllerTests.java b/customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerControllerTests.java index e552bc8..79ec51d 100644 --- a/customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerControllerTests.java +++ b/customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerControllerTests.java @@ -25,8 +25,7 @@ import static io.specto.hoverfly.junit.dsl.HoverflyDsl.service; import static io.specto.hoverfly.junit.dsl.ResponseCreators.success; import static io.specto.hoverfly.junit.dsl.matchers.HoverflyMatchers.startsWith; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { @@ -59,10 +58,13 @@ public void addCustomerTest() { c.setPesel("1234567890"); c.setName("Jan Testowy"); c = template.postForObject("/customers", c, Customer.class); + assertNotNull(c, "Customer should not be null after being added"); + assertNotNull(c.getId(), "Customer ID should not be null after being added"); + id = c.getId(); } -// @Test -// @Order(2) + @Test + @Order(2) public void findCustomerWithAccounts(Hoverfly hoverfly) { hoverfly.simulate( dsl(service("http://account-service") @@ -70,8 +72,11 @@ public void findCustomerWithAccounts(Hoverfly hoverfly) { .willReturn(success("[{\"id\":\"1\",\"number\":\"1234567890\"}]", "application/json")))); Customer c = template.getForObject("/customers/pesel/{pesel}", Customer.class, "1234567890"); + assertNotNull(c, "Customer should not be null when fetched by PESEL"); + assertEquals("1234567890", c.getPesel(), "Customer PESEL should match"); + Customer cc = template.getForObject("/customers/{id}", Customer.class, c.getId()); - assertNotNull(cc); - assertTrue(cc.getAccounts().size() > 0); + assertNotNull(cc, "Customer should not be null when fetched by ID"); + assertTrue(cc.getAccounts().size() > 0, "Customer should have associated accounts"); } } diff --git a/customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerRepositoryTests.java b/customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerRepositoryTests.java index 29b0d90..5de51f2 100644 --- a/customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerRepositoryTests.java +++ b/customer-service/src/test/java/pl/piomin/microservices/advanced/customer/CustomerRepositoryTests.java @@ -17,8 +17,7 @@ import java.util.Optional; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @DataMongoTest @Testcontainers @@ -47,8 +46,8 @@ public void testAddCustomer() { c.setPesel("1234567890"); c.setType(CustomerType.INDIVIDUAL); c = repository.save(c); - assertNotNull(c); - assertNotNull(c.getId()); + assertNotNull(c, "Customer should not be null after saving"); + assertNotNull(c.getId(), "Customer ID should not be null after saving"); id = c.getId(); } @@ -56,15 +55,22 @@ public void testAddCustomer() { @Order(2) public void testFindCustomer() { Optional optCus = repository.findById(id); - assertTrue(optCus.isPresent()); + assertTrue(optCus.isPresent(), "Customer should be found by ID"); + assertEquals("Test1", optCus.get().getName(), "Customer name should match"); } @Test - @Order(2) + @Order(3) public void testFindCustomerByPesel() { Customer c = repository.findByPesel("1234567890"); - assertNotNull(c); - assertNotNull(c.getId()); + assertNotNull(c, "Customer should not be null when found by PESEL"); + assertEquals("1234567890", c.getPesel(), "Customer PESEL should match"); } + @Test + @Order(4) + public void testFindNonExistentCustomer() { + Optional optCus = repository.findById("non-existent-id"); + assertFalse(optCus.isPresent(), "Customer should not be found for a non-existent ID"); + } } diff --git a/product-service/src/test/java/pl/piomin/microservices/advanced/product/ProductRepositoryTests.java b/product-service/src/test/java/pl/piomin/microservices/advanced/product/ProductRepositoryTests.java index 3fe1cce..378c399 100644 --- a/product-service/src/test/java/pl/piomin/microservices/advanced/product/ProductRepositoryTests.java +++ b/product-service/src/test/java/pl/piomin/microservices/advanced/product/ProductRepositoryTests.java @@ -18,8 +18,7 @@ import java.time.LocalDate; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @DataMongoTest @Testcontainers @@ -50,23 +49,31 @@ public void testAddProduct() { p.setBalance(10000); p.setDateOfStart(LocalDate.now()); p = repository.save(p); - assertNotNull(p); - assertNotNull(p.getId()); + assertNotNull(p, "Product should not be null after saving"); + assertNotNull(p.getId(), "Product ID should not be null after saving"); id = p.getId(); } @Test @Order(2) public void testFindProduct() { - Optional optCus = repository.findById(id); - assertTrue(optCus.isPresent()); + Optional optProd = repository.findById(id); + assertTrue(optProd.isPresent(), "Product should be found by ID"); + assertEquals("123", optProd.get().getAccountId(), "Product account ID should match"); } @Test - @Order(2) + @Order(3) public void testFindProductByAccountId() { Product p = repository.findByAccountId("123"); - assertNotNull(p); - assertNotNull(p.getId()); + assertNotNull(p, "Product should not be null when found by account ID"); + assertEquals("123", p.getAccountId(), "Product account ID should match"); + } + + @Test + @Order(4) + public void testFindNonExistentProduct() { + Optional optProd = repository.findById("non-existent-id"); + assertFalse(optProd.isPresent(), "Product should not be found for a non-existent ID"); } }