diff --git a/src/main/java/sg/com/smartinventory/utility/DataLoader.java b/src/main/java/sg/com/smartinventory/utility/DataLoader.java index 7601ab1..6c2a5ba 100644 --- a/src/main/java/sg/com/smartinventory/utility/DataLoader.java +++ b/src/main/java/sg/com/smartinventory/utility/DataLoader.java @@ -31,11 +31,21 @@ public DataLoader(CustomerRepository customerRepository, ProductRepository produ @PostConstruct public void loadData() { + // Clear all data. + clearTableData(); + + // Create fake data. + generateFakeData(); + } + + public void clearTableData() { // Clear all data. customerRepository.deleteAll(); productRepository.deleteAll(); reviewRepository.deleteAll(); + } +// <<<<<<< SIS-39 // = = = CUSTOMER DATA = = = Customer customer1 = customerRepository .save(new Customer("John", "Doe", "USA", "123 Main St", 123456, 12345678, @@ -52,6 +62,20 @@ public void loadData() { Customer customer5 = customerRepository .save(new Customer("David", "Wilson", "Germany", "654 Pine Rd", 987655, 36985214, "david.wilson@example.com")); +// ======= +// public void generateFakeData() { +// // Create fake data. +// customerRepository.save(new Customer("John", "Doe", "USA", "123 Main St", 123456, 12345678, +// "john.doe@example.com")); +// customerRepository.save(new Customer("Alice", "Smith", "Canada", "456 Maple Ave", 543210, 98765432, +// "alice.smith@example.com")); +// customerRepository.save(new Customer("Michael", "Johnson", "UK", "789 Oak Rd", 567890, 98761234, +// "michael.johnson@example.com")); +// customerRepository.save(new Customer("Emily", "Brown", "Australia", "321 Elm St", 135790, 45678912, +// "emily.brown@example.com")); +// customerRepository.save(new Customer("David", "Wilson", "Germany", "654 Pine Rd", 987655, 36985214, +// "david.wilson@example.com")); +// >>>>>>> main // = = = REVIEW DATA = = = // Adding review data (note that the "same" review object is being used in all, diff --git a/src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.java b/src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.java index 3558490..95d480f 100644 --- a/src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.java +++ b/src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.java @@ -4,6 +4,10 @@ import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -19,6 +23,27 @@ class SmartInventoryApplicationTests { // trace(), debug(), info(), warn(), error(). private static final Logger test_logger = LoggerFactory.getLogger(SmartInventoryApplicationTests.class); + // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + + @BeforeEach + void init() { + + } + + @AfterEach + void teardown() { + + } + @Test void contextLoads() { test_logger.info("Starting test: " + getCurrentMethodName() + ". "); diff --git a/src/test/java/sg/com/smartinventory/controllers/CustomerControllerTest.java b/src/test/java/sg/com/smartinventory/controllers/CustomerControllerTest.java index bcaffb1..98b3ab7 100644 --- a/src/test/java/sg/com/smartinventory/controllers/CustomerControllerTest.java +++ b/src/test/java/sg/com/smartinventory/controllers/CustomerControllerTest.java @@ -6,7 +6,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -42,6 +44,16 @@ public class CustomerControllerTest { private static final Logger test_logger = LoggerFactory.getLogger(CustomerControllerTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { @@ -57,7 +69,7 @@ void teardown() { public void createCustomerTest() throws Exception { test_logger.info("Starting test: " + getCurrentMethodName() + ". "); - // Step 1: Create a Customer object + // Step 1: Create a Customer object. Customer newCustomer = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chan@example.com").build(); diff --git a/src/test/java/sg/com/smartinventory/controllers/ProductControllerTest.java b/src/test/java/sg/com/smartinventory/controllers/ProductControllerTest.java index 2d38633..35aa14d 100644 --- a/src/test/java/sg/com/smartinventory/controllers/ProductControllerTest.java +++ b/src/test/java/sg/com/smartinventory/controllers/ProductControllerTest.java @@ -6,7 +6,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -42,6 +44,16 @@ public class ProductControllerTest { private static final Logger test_logger = LoggerFactory.getLogger(ProductControllerTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { @@ -57,7 +69,7 @@ void teardown() { public void createProductTest() throws Exception { test_logger.info("Starting test: " + getCurrentMethodName() + ". "); - // Step 1: Create a Product object + // Step 1: Create a Product object. Product newProduct = Product.builder().category("Electronics").name("Smartphone") .description("High-end smartphone with advanced features. ") .price(999.99).stockQuantity(100).build(); diff --git a/src/test/java/sg/com/smartinventory/controllers/ReviewControllerTest.java b/src/test/java/sg/com/smartinventory/controllers/ReviewControllerTest.java index d63ab29..8acdef4 100644 --- a/src/test/java/sg/com/smartinventory/controllers/ReviewControllerTest.java +++ b/src/test/java/sg/com/smartinventory/controllers/ReviewControllerTest.java @@ -6,7 +6,9 @@ import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -46,6 +48,16 @@ public class ReviewControllerTest { private static final Logger test_logger = LoggerFactory.getLogger(ReviewControllerTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { @@ -63,6 +75,7 @@ void teardown() { private ReviewServiceImpl reviewService; @Test +//<<<<<<< SIS-39 @DisplayName("Get Review Test by Id") public void getReviewTest() throws Exception { // Setup @@ -70,6 +83,36 @@ public void getReviewTest() throws Exception { // Build the GET request RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/reviews/2"); +//======= // = = = DATA INTEGRITY VIOLATION EXCEPTION = = = + public void createReviewTest() throws Exception { + test_logger.info("Starting test: " + getCurrentMethodName() + ". "); + + // Step 1: Create a Review object. + Review newReview = Review.builder().category("Electronics") + .reviewContent("Great smartphone with excellent features. ").rating(5).customerId(1) + .productId(2).build(); + + // Step 2: Convert the Java object to JSON using ObjectMapper. + String newReviewAsJSON = objectMapper.writeValueAsString(newReview); + + // Step 3: Build the request. + RequestBuilder request = MockMvcRequestBuilders.post("/reviews") + .contentType(MediaType.APPLICATION_JSON) + .content(newReviewAsJSON); + + // Step 4: Perform the request and get the response and assert. + mockMvc.perform(request) + // MvcResult Result = mockMvc.perform(request) + // .andDo(print -> test_logger.error("Starting Request: createReviewTest. ")) + .andExpect(status().isCreated()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.category").value("Electronics")) + .andExpect(jsonPath("$.rating").value(5)); + // .andDo(print -> test_logger.error("Customer's id: {}", + // print.getResponse().getContentAsString())) + // .andDo(print -> test_logger.error("Starting Request: createReviewTest. ")) + // .andReturn(); +// >>>>>>> main // when(reviewService.getReview(2L)).thenReturn(testReview); @@ -79,53 +122,127 @@ public void getReviewTest() throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(2)); } - // = = = DATA INTEGRITY VIOLATION EXCEPTION = = = - // /** - // * Test the creation of a Review. - // * - // * @throws Exception - // */ - // @DisplayName("Create Review") - // @Test - // public void createReviewTest() throws Exception { - // test_logger.info("Starting test: " + getCurrentMethodName() + ". "); - - // Customer customer = - // Customer.builder().firstName("John").lastName("Doe").country("USA") - // .address("123 Main St").postalCode(123456).phoneNumber(12345678) - // .email("john.doe@example.com").build(); - - // // Step 1: Create a Review object - // Review newReview = Review.builder().category("Electronics") - // .reviewContent("Great smartphone with excellent features. ").rating(5) - // .productId(2).build(); - - // newReview.setCustomer(customer); - - // // Step 2: Convert the Java object to JSON using ObjectMapper. - // String newReviewAsJSON = objectMapper.writeValueAsString(newReview); - - // // Step 3: Build the request. - // RequestBuilder request = MockMvcRequestBuilders.post("/reviews") - // .contentType(MediaType.APPLICATION_JSON) - // .content(newReviewAsJSON); - - // // Step 4: Perform the request and get the response and assert. - // mockMvc.perform(request) - // // MvcResult Result = mockMvc.perform(request) - // // .andDo(print -> test_logger.error("Starting Request: createReviewTest. ")) - // .andExpect(status().isCreated()) - // .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - // .andExpect(jsonPath("$.category").value("Electronics")) - // .andExpect(jsonPath("$.rating").value(5)); - // // .andDo(print -> test_logger.error("Customer's id: {}", - // // print.getResponse().getContentAsString())) - // // .andDo(print -> test_logger.error("Starting Request: createReviewTest. ")) - // // .andReturn(); - - // // Review ReviewObject = fromJsonResult(Result, Review.class); - - // // test_logger.error("Ending test: createReviewTest. "); - // test_logger.info("Ending test: " + getCurrentMethodName() + ". "); - // } +//<<<<<<< SIS-39 +// ======= + + @DisplayName("Get All Reviews") + @Test + public void getAllReviewsTest() throws Exception { + test_logger.info("Starting test: " + getCurrentMethodName() + ". "); + + // Step 1: Create a Review objects. + Review newReview = Review.builder().category("Electronics") + .reviewContent("Great smartphone with excellent features. ").rating(5).customerId(1) + .productId(2).build(); + + // Step 2: Convert the Java object to JSON using ObjectMapper. + String newReviewAsJSON = objectMapper.writeValueAsString(newReview); + + // Step 3: Build the request. + RequestBuilder request = MockMvcRequestBuilders.post("/reviews") + .contentType(MediaType.APPLICATION_JSON) + .content(newReviewAsJSON); + + // Step 4: Perform the request and get the response and assert. + mockMvc.perform(request) + // MvcResult Result = mockMvc.perform(request) + // .andDo(print -> test_logger.error("Starting Request: createReviewTest. ")) + .andExpect(status().isCreated()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.category").value("Electronics")) + .andExpect(jsonPath("$.rating").value(5)); + + test_logger.info("Ending test: " + getCurrentMethodName() + ". "); + } + + @DisplayName("Get One Review") + @Test + public void getOneReviewTest() throws Exception { + test_logger.info("Starting test: " + getCurrentMethodName() + ". "); + + // Step 1: Create a Review object. + Review newReview = Review.builder().category("Electronics") + .reviewContent("Great smartphone with excellent features. ").rating(5).customerId(1) + .productId(2).build(); + + // Step 2: Convert the Java object to JSON using ObjectMapper. + String newReviewAsJSON = objectMapper.writeValueAsString(newReview); + + // Step 3: Build the request. + RequestBuilder request = MockMvcRequestBuilders.post("/reviews") + .contentType(MediaType.APPLICATION_JSON) + .content(newReviewAsJSON); + + // Step 4: Perform the request and get the response and assert. + mockMvc.perform(request) + // MvcResult Result = mockMvc.perform(request) + // .andDo(print -> test_logger.error("Starting Request: createReviewTest. ")) + .andExpect(status().isCreated()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.category").value("Electronics")) + .andExpect(jsonPath("$.rating").value(5)); + + test_logger.info("Ending test: " + getCurrentMethodName() + ". "); + } + + @DisplayName("Update Review") + @Test + public void updateReviewTest() throws Exception { + test_logger.info("Starting test: " + getCurrentMethodName() + ". "); + + // Step 1: Create a Review object. + Review newReview = Review.builder().category("Electronics") + .reviewContent("Great smartphone with excellent features. ").rating(5).customerId(1) + .productId(2).build(); + + // Step 2: Convert the Java object to JSON using ObjectMapper. + String newReviewAsJSON = objectMapper.writeValueAsString(newReview); + + // Step 3: Build the request. + RequestBuilder request = MockMvcRequestBuilders.post("/reviews") + .contentType(MediaType.APPLICATION_JSON) + .content(newReviewAsJSON); + + // Step 4: Perform the request and get the response and assert. + mockMvc.perform(request) + // MvcResult Result = mockMvc.perform(request) + // .andDo(print -> test_logger.error("Starting Request: createReviewTest. ")) + .andExpect(status().isCreated()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.category").value("Electronics")) + .andExpect(jsonPath("$.rating").value(5)); + + test_logger.info("Ending test: " + getCurrentMethodName() + ". "); + } + + @DisplayName("Delete Review") + @Test + public void deleteReviewTest() throws Exception { + test_logger.info("Starting test: " + getCurrentMethodName() + ". "); + + // Step 1: Create a Review object. + Review newReview = Review.builder().category("Electronics") + .reviewContent("Great smartphone with excellent features. ").rating(5).customerId(1) + .productId(2).build(); + + // Step 2: Convert the Java object to JSON using ObjectMapper. + String newReviewAsJSON = objectMapper.writeValueAsString(newReview); + + // Step 3: Build the request. + RequestBuilder request = MockMvcRequestBuilders.post("/reviews") + .contentType(MediaType.APPLICATION_JSON) + .content(newReviewAsJSON); + + // Step 4: Perform the request and get the response and assert. + mockMvc.perform(request) + // MvcResult Result = mockMvc.perform(request) + // .andDo(print -> test_logger.error("Starting Request: createReviewTest. ")) + .andExpect(status().isCreated()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.category").value("Electronics")) + .andExpect(jsonPath("$.rating").value(5)); + + test_logger.info("Ending test: " + getCurrentMethodName() + ". "); + } +// >>>>>>> main } diff --git a/src/test/java/sg/com/smartinventory/entities/CustomerTest.java b/src/test/java/sg/com/smartinventory/entities/CustomerTest.java index b8d16f2..8011297 100644 --- a/src/test/java/sg/com/smartinventory/entities/CustomerTest.java +++ b/src/test/java/sg/com/smartinventory/entities/CustomerTest.java @@ -4,7 +4,9 @@ import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -32,6 +34,16 @@ public class CustomerTest { private static final Logger test_logger = LoggerFactory.getLogger(CustomerTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { diff --git a/src/test/java/sg/com/smartinventory/entities/ErrorResponseTest.java b/src/test/java/sg/com/smartinventory/entities/ErrorResponseTest.java index e77bd62..549e723 100644 --- a/src/test/java/sg/com/smartinventory/entities/ErrorResponseTest.java +++ b/src/test/java/sg/com/smartinventory/entities/ErrorResponseTest.java @@ -4,7 +4,9 @@ import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -23,6 +25,16 @@ public class ErrorResponseTest { private static final Logger test_logger = LoggerFactory.getLogger(ErrorResponseTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { diff --git a/src/test/java/sg/com/smartinventory/entities/ProductTest.java b/src/test/java/sg/com/smartinventory/entities/ProductTest.java index 1ec09a1..15f0e73 100644 --- a/src/test/java/sg/com/smartinventory/entities/ProductTest.java +++ b/src/test/java/sg/com/smartinventory/entities/ProductTest.java @@ -4,7 +4,9 @@ import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -32,6 +34,16 @@ public class ProductTest { private static final Logger test_logger = LoggerFactory.getLogger(ProductTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { diff --git a/src/test/java/sg/com/smartinventory/entities/ReviewTest.java b/src/test/java/sg/com/smartinventory/entities/ReviewTest.java index 43479ff..ea1a174 100644 --- a/src/test/java/sg/com/smartinventory/entities/ReviewTest.java +++ b/src/test/java/sg/com/smartinventory/entities/ReviewTest.java @@ -4,7 +4,9 @@ import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -32,6 +34,16 @@ public class ReviewTest { private static final Logger test_logger = LoggerFactory.getLogger(ReviewTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { diff --git a/src/test/java/sg/com/smartinventory/integration/IntegrationTest.java b/src/test/java/sg/com/smartinventory/integration/IntegrationTest.java index 8e9f383..145f396 100644 --- a/src/test/java/sg/com/smartinventory/integration/IntegrationTest.java +++ b/src/test/java/sg/com/smartinventory/integration/IntegrationTest.java @@ -10,7 +10,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -57,6 +59,16 @@ public class IntegrationTest { private static final Logger test_logger = LoggerFactory.getLogger(IntegrationTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { @@ -77,7 +89,7 @@ public void createCustomerTest() { .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chan@example.com").build(); - // mock the save method of the customer repository + // Mock the save method of the customer repository. when((customerRepository.save(testObject1))).thenReturn(testObject1); // 2. Execution. diff --git a/src/test/java/sg/com/smartinventory/services/CustomerServiceImplTest.java b/src/test/java/sg/com/smartinventory/services/CustomerServiceImplTest.java index e60a73c..46d13de 100644 --- a/src/test/java/sg/com/smartinventory/services/CustomerServiceImplTest.java +++ b/src/test/java/sg/com/smartinventory/services/CustomerServiceImplTest.java @@ -8,7 +8,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,6 +41,16 @@ public class CustomerServiceImplTest { private static final Logger test_logger = LoggerFactory.getLogger(CustomerServiceImplTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { @@ -53,7 +65,7 @@ void teardown() { public void createCustomerTest() { test_logger.info("Starting test: " + getCurrentMethodName() + ". "); - // 1. SETUP + // 1. SETUP. // Create a new customer. Customer customer = Customer.builder().firstName("John").lastName("Wick").country("USA").address("123 Main St") .postalCode(123456).phoneNumber(12345678).email("john.wick@example.com").build(); diff --git a/src/test/java/sg/com/smartinventory/services/ProductServiceImplTest.java b/src/test/java/sg/com/smartinventory/services/ProductServiceImplTest.java index 9f2b3e7..40b1010 100644 --- a/src/test/java/sg/com/smartinventory/services/ProductServiceImplTest.java +++ b/src/test/java/sg/com/smartinventory/services/ProductServiceImplTest.java @@ -8,7 +8,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,6 +41,16 @@ public class ProductServiceImplTest { private static final Logger test_logger = LoggerFactory.getLogger(ProductServiceImplTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { @@ -53,7 +65,7 @@ void teardown() { public void createProductTest() { test_logger.info("Starting test: " + getCurrentMethodName() + ". "); - // 1. SETUP + // 1. SETUP. // Create a new product. Product product = Product.builder().category("Electronics").name("Smartphone") .description("High-end smartphone with advanced features. ") diff --git a/src/test/java/sg/com/smartinventory/services/ReviewServiceImplTest.java b/src/test/java/sg/com/smartinventory/services/ReviewServiceImplTest.java index 9a0d44e..6d38c1d 100644 --- a/src/test/java/sg/com/smartinventory/services/ReviewServiceImplTest.java +++ b/src/test/java/sg/com/smartinventory/services/ReviewServiceImplTest.java @@ -8,7 +8,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,6 +41,16 @@ public class ReviewServiceImplTest { private static final Logger test_logger = LoggerFactory.getLogger(ReviewServiceImplTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { @@ -53,7 +65,7 @@ void teardown() { public void createReviewTest() { test_logger.info("Starting test: " + getCurrentMethodName() + ". "); - // 1. SETUP + // 1. SETUP. // Create a new review. Review review = Review.builder().category("Electronics") .reviewContent("Great smartphone with excellent features. ").rating(5) diff --git a/src/test/java/sg/com/smartinventory/useCases/UseCaseTest.java b/src/test/java/sg/com/smartinventory/useCases/UseCaseTest.java index 12c80a0..da9fe02 100644 --- a/src/test/java/sg/com/smartinventory/useCases/UseCaseTest.java +++ b/src/test/java/sg/com/smartinventory/useCases/UseCaseTest.java @@ -10,7 +10,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -57,6 +59,16 @@ public class UseCaseTest { private static final Logger test_logger = LoggerFactory.getLogger(UseCaseTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() { @@ -77,7 +89,7 @@ public void createCustomerTest() { .address("123 HK St").postalCode(654321).phoneNumber(87654321) .email("jackie.chan@example.com").build(); - // mock the save method of the customer repository + // Mock the save method of the customer repository. when((customerRepository.save(testObject1))).thenReturn(testObject1); // 2. Execution. diff --git a/src/test/java/sg/com/smartinventory/utility/DataLoaderTest.java b/src/test/java/sg/com/smartinventory/utility/DataLoaderTest.java index 36fb8e6..f19b575 100644 --- a/src/test/java/sg/com/smartinventory/utility/DataLoaderTest.java +++ b/src/test/java/sg/com/smartinventory/utility/DataLoaderTest.java @@ -4,7 +4,9 @@ import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -40,6 +42,16 @@ public class DataLoaderTest { private static final Logger test_logger = LoggerFactory.getLogger(DataLoaderTest.class); // Test Setup and Teardown configuration. + @BeforeAll + static void initAll() { + + } + + @AfterAll + static void teardownAll() { + + } + @BeforeEach void init() {