Skip to content

Commit 7358318

Browse files
Fix H2 database table creation in integration tests
- Configure H2 to use MySQL mode with case-insensitive identifiers - Ensure Hibernate creates tables with correct naming strategy - Add explicit FPL ID to test player data - Use saveAndFlush to ensure schema is created before tests
1 parent e6e5320 commit 7358318

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

backend/src/test/java/com/example/demo/integration/PlayerControllerIntegrationTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ class PlayerControllerIntegrationTest {
3434
void setUp() {
3535
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
3636

37-
// Create test data
37+
// Create test data - ensure schema is created first
3838
Player testPlayer = new Player();
3939
testPlayer.setName("Test Player");
4040
testPlayer.setPosition("MID");
4141
testPlayer.setTeam("Arsenal");
42-
testPlayer.setValue(50);
42+
testPlayer.setValue(50.0);
4343
testPlayer.setTotalPoints(100);
4444
testPlayer.setWeeklyPoints(10);
45-
playerRepository.save(testPlayer);
45+
testPlayer.setFplId(1L);
46+
playerRepository.saveAndFlush(testPlayer);
4647
}
4748

4849
@Test

backend/src/test/resources/application-test.properties

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Test profile configuration
22
spring.application.name=demo-test
33

4-
# Use H2 in-memory database for tests
5-
spring.datasource.url=jdbc:h2:mem:testdb
4+
# Use H2 in-memory database for tests (case-insensitive mode)
5+
spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE
66
spring.datasource.driver-class-name=org.h2.Driver
77
spring.datasource.username=sa
88
spring.datasource.password=
@@ -13,9 +13,14 @@ spring.flyway.enabled=false
1313
# Disable Redis for tests
1414
spring.cache.type=simple
1515

16-
# Disable JPA auto-ddl (use schema.sql instead if needed)
16+
# JPA configuration - create tables automatically
1717
spring.jpa.hibernate.ddl-auto=create-drop
1818
spring.jpa.show-sql=false
19+
spring.jpa.properties.hibernate.format_sql=false
20+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
21+
spring.jpa.properties.hibernate.globally_quoted_identifiers=false
22+
spring.jpa.properties.hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
23+
spring.jpa.properties.hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
1924

2025
# Disable logging for tests
2126
logging.level.root=WARN

0 commit comments

Comments
 (0)