Skip to content

Commit

Permalink
Updated folder names to be in plural form.
Browse files Browse the repository at this point in the history
  • Loading branch information
nhkhai committed Mar 19, 2024
1 parent dca28d3 commit 26cf5a2
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 48 deletions.
12 changes: 6 additions & 6 deletions src/main/java/sg/com/smartinventory/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sg.com.smartinventory.entity;
package sg.com.smartinventory.entities;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sg.com.smartinventory.entity;
package sg.com.smartinventory.entities;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sg.com.smartinventory.entity;
package sg.com.smartinventory.entities;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Customer, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Product, Long> {

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Review, Long> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
57 changes: 30 additions & 27 deletions src/test/java/sg/com/smartinventory/CustomerControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]").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("[email protected]")
.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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
class SmartInventoryApplicationTests {
@Test
void contextLoads() {

}
}

0 comments on commit 26cf5a2

Please sign in to comment.