From 26cf5a2e4657a3c6d7b61bf0fa081d825070e818 Mon Sep 17 00:00:00 2001 From: "nhkhai@gmail.com" Date: Wed, 20 Mar 2024 05:01:17 +0800 Subject: [PATCH] Updated folder names to be in plural form. --- .../sg/com/smartinventory/DataLoader.java | 12 ++-- .../controllers/CustomerController.java | 2 +- .../{entity => entities}/Customer.java | 2 +- .../{entity => entities}/Product.java | 2 +- .../{entity => entities}/Review.java | 2 +- .../CustomerRepository.java | 4 +- .../ProductRepository.java | 4 +- .../ReviewRepository.java | 4 +- .../serviceImpls/CustomerServiceImpl.java | 4 +- .../services/CustomerService.java | 2 +- .../CustomerControllerTest.java | 57 ++++++++++--------- .../CustomerServiceImplTest.java | 4 +- .../SmartInventoryApplicationTests.java | 1 + 13 files changed, 52 insertions(+), 48 deletions(-) rename src/main/java/sg/com/smartinventory/{entity => entities}/Customer.java (97%) rename src/main/java/sg/com/smartinventory/{entity => entities}/Product.java (96%) rename src/main/java/sg/com/smartinventory/{entity => entities}/Review.java (96%) rename src/main/java/sg/com/smartinventory/{repository => repositories}/CustomerRepository.java (74%) rename src/main/java/sg/com/smartinventory/{repository => repositories}/ProductRepository.java (60%) rename src/main/java/sg/com/smartinventory/{repository => repositories}/ReviewRepository.java (60%) diff --git a/src/main/java/sg/com/smartinventory/DataLoader.java b/src/main/java/sg/com/smartinventory/DataLoader.java index 618aa2f..4d33d6f 100644 --- a/src/main/java/sg/com/smartinventory/DataLoader.java +++ b/src/main/java/sg/com/smartinventory/DataLoader.java @@ -4,12 +4,12 @@ import org.springframework.stereotype.Component; import jakarta.annotation.PostConstruct; -import sg.com.smartinventory.entity.Customer; -import sg.com.smartinventory.entity.Product; -import sg.com.smartinventory.entity.Review; -import sg.com.smartinventory.repository.CustomerRepository; -import sg.com.smartinventory.repository.ProductRepository; -import sg.com.smartinventory.repository.ReviewRepository; +import sg.com.smartinventory.entities.Customer; +import sg.com.smartinventory.entities.Product; +import sg.com.smartinventory.entities.Review; +import sg.com.smartinventory.repositories.CustomerRepository; +import sg.com.smartinventory.repositories.ProductRepository; +import sg.com.smartinventory.repositories.ReviewRepository; @Component public class DataLoader { diff --git a/src/main/java/sg/com/smartinventory/controllers/CustomerController.java b/src/main/java/sg/com/smartinventory/controllers/CustomerController.java index 58567c1..3349324 100644 --- a/src/main/java/sg/com/smartinventory/controllers/CustomerController.java +++ b/src/main/java/sg/com/smartinventory/controllers/CustomerController.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestController; import jakarta.validation.Valid; -import sg.com.smartinventory.entity.Customer; +import sg.com.smartinventory.entities.Customer; import sg.com.smartinventory.services.CustomerService; @RestController diff --git a/src/main/java/sg/com/smartinventory/entity/Customer.java b/src/main/java/sg/com/smartinventory/entities/Customer.java similarity index 97% rename from src/main/java/sg/com/smartinventory/entity/Customer.java rename to src/main/java/sg/com/smartinventory/entities/Customer.java index 6c0e758..46bd745 100644 --- a/src/main/java/sg/com/smartinventory/entity/Customer.java +++ b/src/main/java/sg/com/smartinventory/entities/Customer.java @@ -1,4 +1,4 @@ -package sg.com.smartinventory.entity; +package sg.com.smartinventory.entities; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/sg/com/smartinventory/entity/Product.java b/src/main/java/sg/com/smartinventory/entities/Product.java similarity index 96% rename from src/main/java/sg/com/smartinventory/entity/Product.java rename to src/main/java/sg/com/smartinventory/entities/Product.java index 6c4268d..944ba16 100644 --- a/src/main/java/sg/com/smartinventory/entity/Product.java +++ b/src/main/java/sg/com/smartinventory/entities/Product.java @@ -1,4 +1,4 @@ -package sg.com.smartinventory.entity; +package sg.com.smartinventory.entities; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/sg/com/smartinventory/entity/Review.java b/src/main/java/sg/com/smartinventory/entities/Review.java similarity index 96% rename from src/main/java/sg/com/smartinventory/entity/Review.java rename to src/main/java/sg/com/smartinventory/entities/Review.java index f42ad88..0423a5b 100644 --- a/src/main/java/sg/com/smartinventory/entity/Review.java +++ b/src/main/java/sg/com/smartinventory/entities/Review.java @@ -1,4 +1,4 @@ -package sg.com.smartinventory.entity; +package sg.com.smartinventory.entities; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/sg/com/smartinventory/repository/CustomerRepository.java b/src/main/java/sg/com/smartinventory/repositories/CustomerRepository.java similarity index 74% rename from src/main/java/sg/com/smartinventory/repository/CustomerRepository.java rename to src/main/java/sg/com/smartinventory/repositories/CustomerRepository.java index 0bbe59b..4b9d4d1 100644 --- a/src/main/java/sg/com/smartinventory/repository/CustomerRepository.java +++ b/src/main/java/sg/com/smartinventory/repositories/CustomerRepository.java @@ -1,8 +1,8 @@ -package sg.com.smartinventory.repository; +package sg.com.smartinventory.repositories; import org.springframework.data.jpa.repository.JpaRepository; -import sg.com.smartinventory.entity.Customer; +import sg.com.smartinventory.entities.Customer; //CustomerRepository simply extends JpaRepository, giving us a lot of default methods to access db without the hardwork public interface CustomerRepository extends JpaRepository { diff --git a/src/main/java/sg/com/smartinventory/repository/ProductRepository.java b/src/main/java/sg/com/smartinventory/repositories/ProductRepository.java similarity index 60% rename from src/main/java/sg/com/smartinventory/repository/ProductRepository.java rename to src/main/java/sg/com/smartinventory/repositories/ProductRepository.java index 3c702ab..ceae975 100644 --- a/src/main/java/sg/com/smartinventory/repository/ProductRepository.java +++ b/src/main/java/sg/com/smartinventory/repositories/ProductRepository.java @@ -1,8 +1,8 @@ -package sg.com.smartinventory.repository; +package sg.com.smartinventory.repositories; import org.springframework.data.jpa.repository.JpaRepository; -import sg.com.smartinventory.entity.Product; +import sg.com.smartinventory.entities.Product; public interface ProductRepository extends JpaRepository { diff --git a/src/main/java/sg/com/smartinventory/repository/ReviewRepository.java b/src/main/java/sg/com/smartinventory/repositories/ReviewRepository.java similarity index 60% rename from src/main/java/sg/com/smartinventory/repository/ReviewRepository.java rename to src/main/java/sg/com/smartinventory/repositories/ReviewRepository.java index 09fb7fa..faf78e5 100644 --- a/src/main/java/sg/com/smartinventory/repository/ReviewRepository.java +++ b/src/main/java/sg/com/smartinventory/repositories/ReviewRepository.java @@ -1,8 +1,8 @@ -package sg.com.smartinventory.repository; +package sg.com.smartinventory.repositories; import org.springframework.data.jpa.repository.JpaRepository; -import sg.com.smartinventory.entity.Review; +import sg.com.smartinventory.entities.Review; public interface ReviewRepository extends JpaRepository { diff --git a/src/main/java/sg/com/smartinventory/serviceImpls/CustomerServiceImpl.java b/src/main/java/sg/com/smartinventory/serviceImpls/CustomerServiceImpl.java index 39082f8..70170a3 100644 --- a/src/main/java/sg/com/smartinventory/serviceImpls/CustomerServiceImpl.java +++ b/src/main/java/sg/com/smartinventory/serviceImpls/CustomerServiceImpl.java @@ -2,8 +2,8 @@ import org.springframework.stereotype.Service; -import sg.com.smartinventory.entity.Customer; -import sg.com.smartinventory.repository.CustomerRepository; +import sg.com.smartinventory.entities.Customer; +import sg.com.smartinventory.repositories.CustomerRepository; import sg.com.smartinventory.services.CustomerService; @Service diff --git a/src/main/java/sg/com/smartinventory/services/CustomerService.java b/src/main/java/sg/com/smartinventory/services/CustomerService.java index bcd40f8..d621136 100644 --- a/src/main/java/sg/com/smartinventory/services/CustomerService.java +++ b/src/main/java/sg/com/smartinventory/services/CustomerService.java @@ -1,6 +1,6 @@ package sg.com.smartinventory.services; -import sg.com.smartinventory.entity.Customer; +import sg.com.smartinventory.entities.Customer; public interface CustomerService { Customer createCustomer(Customer customer); diff --git a/src/test/java/sg/com/smartinventory/CustomerControllerTest.java b/src/test/java/sg/com/smartinventory/CustomerControllerTest.java index 8381ac3..52e472a 100644 --- a/src/test/java/sg/com/smartinventory/CustomerControllerTest.java +++ b/src/test/java/sg/com/smartinventory/CustomerControllerTest.java @@ -14,35 +14,38 @@ import com.fasterxml.jackson.databind.ObjectMapper; -import sg.com.smartinventory.entity.Customer; +import sg.com.smartinventory.entities.Customer; @SpringBootTest @AutoConfigureMockMvc public class CustomerControllerTest { - @Autowired - private MockMvc mockMvc; - - @Autowired - private ObjectMapper objectMapper; - - @DisplayName("Create customer") - @Test - public void createCustomerTest() throws Exception { - // Step 1: Create a Customer object - Customer newCustomer = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") - .address("123 HK St") - .postalCode(654321).mobileNumber(87654321).email("jackie.chan@example.com").reviewId(110).build(); - - // Step 2: Convert the Java object to JSON using ObjectMapper. - String newCustomerAsJSON = objectMapper.writeValueAsString(newCustomer); - - // Step 3: Build the request. - RequestBuilder request = MockMvcRequestBuilders.post("/customers").contentType(MediaType.APPLICATION_JSON) - .content(newCustomerAsJSON); - - // Step 4: Perform the request and get the response and assert. - mockMvc.perform(request).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.firstName").value("Jackie")).andExpect(jsonPath("$.lastName").value("Chan")); - } + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @DisplayName("Create customer") + @Test + public void createCustomerTest() throws Exception { + // Step 1: Create a Customer object + Customer newCustomer = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") + .address("123 HK St") + .postalCode(654321).mobileNumber(87654321).email("jackie.chan@example.com") + .reviewId(110).build(); + + // Step 2: Convert the Java object to JSON using ObjectMapper. + String newCustomerAsJSON = objectMapper.writeValueAsString(newCustomer); + + // Step 3: Build the request. + RequestBuilder request = MockMvcRequestBuilders.post("/customers") + .contentType(MediaType.APPLICATION_JSON) + .content(newCustomerAsJSON); + + // Step 4: Perform the request and get the response and assert. + mockMvc.perform(request).andExpect(status().isCreated()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$.firstName").value("Jackie")) + .andExpect(jsonPath("$.lastName").value("Chan")); + } } \ No newline at end of file diff --git a/src/test/java/sg/com/smartinventory/CustomerServiceImplTest.java b/src/test/java/sg/com/smartinventory/CustomerServiceImplTest.java index 12aa3ee..3acbf20 100644 --- a/src/test/java/sg/com/smartinventory/CustomerServiceImplTest.java +++ b/src/test/java/sg/com/smartinventory/CustomerServiceImplTest.java @@ -10,8 +10,8 @@ import org.mockito.Mock; import org.springframework.boot.test.context.SpringBootTest; -import sg.com.smartinventory.entity.Customer; -import sg.com.smartinventory.repository.CustomerRepository; +import sg.com.smartinventory.entities.Customer; +import sg.com.smartinventory.repositories.CustomerRepository; import sg.com.smartinventory.serviceImpls.CustomerServiceImpl; @SpringBootTest diff --git a/src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.java b/src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.java index 74e01b9..329dc5e 100644 --- a/src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.java +++ b/src/test/java/sg/com/smartinventory/SmartInventoryApplicationTests.java @@ -7,5 +7,6 @@ class SmartInventoryApplicationTests { @Test void contextLoads() { + } } \ No newline at end of file