...
Code Block |
---|
language | java |
---|
title | Unit Test |
---|
collapse | true |
---|
|
@Testcontainers
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ContextConfiguration(
initializers = DemoApplicationTests.Initializer.class,
classes = DemoApplication.class)
@TestPropertySource(locations = {"classpath:application_test.properties"})
class DemoApplicationTests {
@Test
void contextLoads() {
}
@Container
public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:latest")
.withDatabaseName("db_demo").withUsername("sa").withPassword("sa");
@Configuration
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues
.of("spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(),
"spring.datasource.username=" + postgreSQLContainer.getUsername(),
"spring.datasource.password=" + postgreSQLContainer.getPassword())
.applyTo(configurableApplicationContext.getEnvironment());
}
}
}
|
Item Table
db_demo=# \d item
Table "public.item"
Column | Type | Collation | Nullable | Default
------------+------------------------+-----------+----------+---------
key | character varying(255) | | not null |
document | jsonb | | not null |
properties | jsonb | | not null |
text | character varying(255) | | not null |
Indexes:
"item_pkey" PRIMARY KEY, btree (key)
Table of comparison
Type | DataStore | Validation | Query | Index |
---|
longtext | MariaDB | SELECT | Yes | No |
longtext | PostgreSQL | No | No | No |
json | PostgreSQL | INSERT / UPDATE | Yes | No |
jsonb | PostgreSQL | INSERT / UPDATE | Yes | Yes |
...