Skip to content

Commit 947a68c

Browse files
committed
feat: add isEditing field to Sale class and initialize in AppController; update test configurations
1 parent 27458c4 commit 947a68c

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

my-chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ v1:
1010
searchFeatureEnabled: "false"
1111
image:
1212
repository: ghcr.io/octodemo/java-springboot-demo
13-
tag: "273"
13+
tag: "366"
1414
resources:
1515
limits:
1616
cpu: "1"

src/main/java/net/codejava/AppController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class AppController {
6666

6767
// private static final Logger logger = Logger.getLogger(AppController.class.getName());
6868

69-
@Value("${enableSearchFeature}")
69+
@Value("${enableSearchFeature:true}")
7070
private boolean enableSearchFeature;
7171

7272
public boolean getEnableSearchFeature() {
@@ -109,6 +109,7 @@ public String viewHomePage(Model model , Principal principal, @RequestParam(defa
109109
public ModelAndView showNewForm() {
110110
ModelAndView mav = new ModelAndView("new_form");
111111
Sale sale = new Sale();
112+
sale.setEditing(false); // Initialize isEditing field for new records
112113
mav.addObject("sale", sale);
113114
mav.addObject("currentDate", LocalDate.now());
114115
mav.addObject("enableSearchFeature", enableSearchFeature);
@@ -257,6 +258,7 @@ public String uploadFile(@RequestParam("file") MultipartFile file, RedirectAttri
257258

258259
sale.setAmount((float) Double.parseDouble(fields[2].trim()));
259260
sale.setQuantity(Integer.parseInt(fields[3].trim()));
261+
sale.setEditing(false); // Initialize isEditing field
260262
sales.add(sale);
261263
}
262264

src/main/java/net/codejava/Sale.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import javax.persistence.Entity;
44
import javax.persistence.Id;
55
import javax.persistence.Table;
6+
import javax.persistence.Transient;
67
import org.springframework.format.annotation.DateTimeFormat;
78

89
import java.util.Date;
@@ -15,6 +16,8 @@ public class Sale {
1516
private String item;
1617
private int quantity;
1718
private float amount;
19+
20+
@Transient // UI state field - not persisted to database
1821
private boolean isEditing;
1922

2023
@DateTimeFormat(pattern = "yyyy-MM-dd")

src/main/java/net/codejava/SalesDAO.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public void save(Sale sale) throws DuplicateKeyException {
5050
throw new DuplicateKeyException("A record with the same serial number already exists.");
5151
}
5252

53-
// If no such record exists, insert the new record
54-
SimpleJdbcInsert insertActor =
55-
new SimpleJdbcInsert(jdbcTemplate != null ? jdbcTemplate : new JdbcTemplate());
53+
// If no such record exists, insert the new record
54+
SimpleJdbcInsert insertActor =
55+
new SimpleJdbcInsert(jdbcTemplate != null ? jdbcTemplate : new JdbcTemplate());
5656
insertActor.withTableName("sales").usingColumns("serial_number", "item", "quantity", "amount", "date");
5757
BeanPropertySqlParameterSource param = new BeanPropertySqlParameterSource(sale);
58-
58+
5959
insertActor.execute(param);
6060
} catch (DuplicateKeyException e) {
6161
throw e; // rethrow the exception to be handled by the caller

src/test/java/net/codejava/JUnit5ExampleTest11.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
import org.junit.jupiter.api.Test;
33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.boot.test.context.SpringBootTest;
5+
import org.springframework.test.context.ActiveProfiles;
6+
import org.springframework.test.context.TestPropertySource;
57
import static org.junit.jupiter.api.Assertions.assertEquals;
68
import java.util.Calendar;
79
import java.util.List;
810
import static org.junit.jupiter.api.Assertions.assertNotNull;
911

1012
@SpringBootTest
13+
@TestPropertySource(properties = {
14+
"enableSearchFeature=true",
15+
"spring.datasource.url=jdbc:h2:mem:testdb;Mode=PostgreSQL",
16+
"spring.jpa.hibernate.ddl-auto=create-drop"
17+
})
1118
public class JUnit5ExampleTest11 {
1219

1320
@Autowired
@@ -28,6 +35,7 @@ void testInsert() {
2835
String serialNumber = String.valueOf(System.currentTimeMillis());
2936

3037
Sale sale = new Sale(serialNumber, "Laptop", 1, 1500.00f, sqlDate);
38+
sale.setEditing(false); // Set the isEditing field to false for the test
3139
salesDAO.save(sale);
3240

3341
// list all the records
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Test Configuration for Sales Manager Application
2+
# This ensures tests run with consistent settings
3+
4+
# H2 in-memory database for testing
5+
spring.datasource.url=jdbc:h2:mem:testdb;Mode=PostgreSQL
6+
spring.datasource.username=sa
7+
spring.datasource.password=
8+
spring.datasource.driver-class-name=org.h2.Driver
9+
10+
# JPA/Hibernate settings for tests
11+
spring.jpa.hibernate.ddl-auto=create-drop
12+
spring.jpa.show-sql=false
13+
spring.jpa.properties.hibernate.format_sql=false
14+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
15+
16+
# Disable Liquibase for tests (using ddl-auto=create-drop instead)
17+
spring.liquibase.enabled=false
18+
19+
# Feature flag for testing - this should match the expected test value
20+
enableSearchFeature=true
21+
22+
# Disable Redis for tests
23+
spring.redis.host=localhost
24+
spring.redis.port=6379
25+
26+
# Test-specific server settings
27+
server.port=0
28+
29+
# Disable security for easier testing
30+
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration

0 commit comments

Comments
 (0)