Skip to content

Commit

Permalink
Merge branch 'main' into SIS-39
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblykat authored Mar 25, 2024
2 parents 90c6a8f + 1d19abc commit 0568129
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 56 deletions.
24 changes: 24 additions & 0 deletions src/main/java/sg/com/smartinventory/utility/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,6 +62,20 @@ public void loadData() {
Customer customer5 = customerRepository
.save(new Customer("David", "Wilson", "Germany", "654 Pine Rd", 987655, 36985214,
"[email protected]"));
// =======
// public void generateFakeData() {
// // Create fake data.
// customerRepository.save(new Customer("John", "Doe", "USA", "123 Main St", 123456, 12345678,
// "[email protected]"));
// customerRepository.save(new Customer("Alice", "Smith", "Canada", "456 Maple Ave", 543210, 98765432,
// "[email protected]"));
// customerRepository.save(new Customer("Michael", "Johnson", "UK", "789 Oak Rd", 567890, 98761234,
// "[email protected]"));
// customerRepository.save(new Customer("Emily", "Brown", "Australia", "321 Elm St", 135790, 45678912,
// "[email protected]"));
// customerRepository.save(new Customer("David", "Wilson", "Germany", "654 Pine Rd", 987655, 36985214,
// "[email protected]"));
// >>>>>>> main

// = = = REVIEW DATA = = =
// Adding review data (note that the "same" review object is being used in all,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() + ". ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {

Expand All @@ -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("[email protected]").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {

Expand All @@ -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();
Expand Down
Loading

0 comments on commit 0568129

Please sign in to comment.