-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from nhkhai/main
SIS-22 & SIS-30: Removed the invalid duplicate foreign keys based on the updated ER diagram and added Spring Boot profiles support.
- Loading branch information
Showing
18 changed files
with
290 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,16 +36,16 @@ public void loadData() { | |
|
||
// Create fake data. | ||
customerRepository.save(new Customer("John", "Doe", "USA", "123 Main St", 123456, 12345678, | ||
"[email protected]", 101)); | ||
"[email protected]")); | ||
|
||
customerRepository.save(new Customer("Alice", "Smith", "Canada", "456 Maple Ave", 543210, 98765432, | ||
"[email protected]", 102)); | ||
"[email protected]")); | ||
customerRepository.save(new Customer("Michael", "Johnson", "UK", "789 Oak Rd", 567890, 98761234, | ||
"[email protected]", 103)); | ||
"[email protected]")); | ||
customerRepository.save(new Customer("Emily", "Brown", "Australia", "321 Elm St", 135790, 45678912, | ||
"[email protected]", 104)); | ||
"[email protected]")); | ||
customerRepository.save(new Customer("David", "Wilson", "Germany", "654 Pine Rd", 987655, 36985214, | ||
"[email protected]", 105)); | ||
"[email protected]")); | ||
|
||
productRepository.save(new Product("Electronics", "Smartphone", | ||
"High-end smartphone with advanced features. ", 999.99, 100, 101)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
spring.application.name=smart-inventory | ||
|
||
# Server Configuration. | ||
# Server Port Configuration. | ||
# The default server port is 8080. | ||
server.port=9090 | ||
|
||
# Database Configuration. | ||
# PostgreSQL | ||
# PostgreSQL. | ||
spring.datasource.url=jdbc:postgresql://localhost:5432/smart_inventory | ||
# For WSL, use postgres. | ||
# For Mac, use your Mac username. | ||
spring.datasource.username=postgres | ||
# Password can be blank if we set it to trust in pg_hba.conf | ||
# Password can be blank if we set it to trust in pg_hba.conf. | ||
spring.datasource.password= | ||
|
||
# Database platform to use. | ||
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect | ||
|
||
# Hibernate Database Initialization Method. | ||
# This will drop and create tables again. | ||
spring.jpa.hibernate.ddl-auto=create | ||
# This can be used to update tables. | ||
|
@@ -22,28 +26,45 @@ spring.jpa.hibernate.ddl-auto=create | |
# Application logging configuration. | ||
# logging.level.root=INFO | ||
# logging.file.name=logs/application.log | ||
|
||
# Database logging configuration. | ||
# The Spring/Hibernate classes, which generate SQL statements and set the parameters, already contain the code for logging them. | ||
# However, the level of those log statements is set to DEBUG and TRACE respectively, which is lower than the default level in Spring Boot — INFO. | ||
# By adding these properties, we are just setting those loggers to the required level. | ||
# For logging statements. | ||
# logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG | ||
|
||
# For logging parameters of prepared statements. | ||
# logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE | ||
# Set up a profile-specific configuration for tests. | ||
|
||
# Set up a profile-specific configuration for tests. For example a <testloglevel> profile. | ||
# logging.config=classpath:logback-testloglevel.xml | ||
|
||
# SpringDoc Configuration. | ||
# The OpenAPI descriptions are at /v3/api-docs, which is the default path: http://localhost:8080/v3/api-docs. | ||
# For a custom path of the OpenAPI documentation in Json format, | ||
# add the custom springdoc property /api-docs endpoint custom path to get the path: http://localhost:8080/api-docs. | ||
springdoc.api-docs.path=/api-docs | ||
|
||
# The OpenAPI definitions are in JSON format by default. For yaml format, we can obtain the definitions at: http://localhost:8080/api-docs.yaml. | ||
# To disable api-docs springdoc-openapi endpoints. | ||
# springdoc.api-docs.enabled=false | ||
|
||
# The springdoc-openapi dependency already includes Swagger UI, to integrate springdoc-openapi with Swagger UI to interact with our API specification and exercise the endpoints.# We can access the API documentation at: http://localhost:8080/swagger-ui/index.html. | ||
# Using swagger-ui properties, to customize the path of the swagger-ui API documentation swagger-ui-custom.html to get the path: http://localhost:8080/swagger-ui-custom.html. | ||
# springdoc.swagger-ui.path=/swagger-ui-custom.html | ||
springdoc.swagger-ui.path=/swagger-ui.html | ||
|
||
# To sort the API paths according to their HTTP methods with the springdoc.swagger-ui.operationsSorter property. | ||
# springdoc.swagger-ui.operationsSorter=method | ||
# springdoc.swagger-ui.operationsSorter=method | ||
|
||
# Profile management. | ||
# Spring Boot will always read the application.properties file. | ||
# Other's profile files, such as application-development.properties only will complement and replace the properties defined before. | ||
# The application.properties, and just this file, must have this line. | ||
# [email protected]@ | ||
# Set the default active profile. | ||
# Use the command to activate: mvn spring-boot:run -Dspring.profiles.active=development. | ||
spring.profiles.active=development | ||
# Set the default default profile. This is the profile that is used on any bean if you don't specify the @Profile annotation to be a certain profile. | ||
# spring.profiles.default=development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,10 @@ | |
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
@@ -16,7 +18,6 @@ | |
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import sg.com.smartinventory.SmartInventoryApplication; | ||
import sg.com.smartinventory.entities.Customer; | ||
|
||
@SpringBootTest | ||
|
@@ -28,7 +29,10 @@ public class CustomerControllerTest { | |
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
// Name this according to your class name. | ||
/// Name this according to your class name. | ||
// The Logback library defines 5 log levels in order of priority: TRACE, DEBUG, | ||
// INFO, WARN, ERROR, with each of these having a corresponding logging method: | ||
// trace(), debug(), info(), warn(), error(). | ||
private static final Logger test_logger = LoggerFactory.getLogger(CustomerControllerTest.class); | ||
|
||
@DisplayName("Create customer") | ||
|
@@ -38,9 +42,8 @@ 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(); | ||
.address("123 HK St").postalCode(654321).mobileNumber(87654321) | ||
.email("[email protected]").build(); | ||
|
||
// Step 2: Convert the Java object to JSON using ObjectMapper. | ||
String newCustomerAsJSON = objectMapper.writeValueAsString(newCustomer); | ||
|
@@ -51,7 +54,8 @@ public void createCustomerTest() throws Exception { | |
.content(newCustomerAsJSON); | ||
|
||
// Step 4: Perform the request and get the response and assert. | ||
mockMvc.perform(request).andExpect(status().isCreated()) | ||
mockMvc.perform(request) | ||
.andExpect(status().isCreated()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.firstName").value("Jackie")) | ||
.andExpect(jsonPath("$.lastName").value("Chan")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.