profileShare

rasmusjy / tasteprint

Read-only snapshot

No repository description.

main default branch 169 files Expires Sep 13, 2026, 9:06 AM
PostgresCompatibilityTest.java 2,481 bytes
1 package com.tasteprint;
2
3 import static org.assertj.core.api.Assertions.assertThat;
4
5 import java.time.LocalDate;
6 import java.util.UUID;
7
8 import com.tasteprint.account.AccountService;
9 import com.tasteprint.account.AuthSession;
10 import com.tasteprint.account.RegisterRequest;
11 import com.tasteprint.progress.ProgressService;
12 import com.tasteprint.tasting.SaveTastingRequest;
13 import com.tasteprint.tasting.TastingService;
14 import org.junit.jupiter.api.Test;
15 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.boot.test.context.SpringBootTest;
17 import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
18 import org.springframework.jdbc.core.JdbcTemplate;
19 import org.testcontainers.containers.PostgreSQLContainer;
20 import org.testcontainers.junit.jupiter.Container;
21 import org.testcontainers.junit.jupiter.Testcontainers;
22
23 @SpringBootTest
24 @Testcontainers(disabledWithoutDocker = true)
25 class PostgresCompatibilityTest {
26
27 @Container
28 @ServiceConnection
29 static final PostgreSQLContainer<?> POSTGRES = new PostgreSQLContainer<>("postgres:17-alpine");
30
31 @Autowired
32 private JdbcTemplate jdbc;
33
34 @Autowired
35 private AccountService accounts;
36
37 @Autowired
38 private TastingService tastings;
39
40 @Autowired
41 private ProgressService progress;
42
43 @Test
44 void migrationsAndCoreWriteFlowWorkOnPostgres() throws Exception {
45 assertThat(jdbc.getDataSource()).isNotNull();
46 try (var connection = jdbc.getDataSource().getConnection()) {
47 assertThat(connection.getMetaData().getDatabaseProductName()).isEqualTo("PostgreSQL");
48 }
49 assertThat(jdbc.queryForObject("select count(*) from destination", Integer.class)).isEqualTo(12);
50 assertThat(jdbc.queryForObject("select count(*) from dish", Integer.class)).isEqualTo(72);
51
52 AuthSession session = accounts.register(new RegisterRequest(
53 "Postgres Traveler",
54 "postgres+" + UUID.randomUUID() + "@example.com",
55 "safe-password-42"
56 ));
57 tastings.record(session.user().id(), new SaveTastingRequest(
58 "ramen", "Test counter", "Tokyo", "JP", LocalDate.now(), 5,
59 "Verified on PostgreSQL.", null, null, null
60 ));
61
62 assertThat(progress.snapshot(session.user().id()).stats().totalTastings()).isEqualTo(1);
63 assertThat(progress.snapshot(session.user().id()).stats().countriesTasted()).isEqualTo(1);
64 }
65 }
66