I have been looking at this problem now for hours and I know it's something silly.
My Spring Boot integration test can't find my Postgres table (relation) while the REST API works fine.
org.postgresql.util.PSQLException: ERROR: relation "data_source" does not exist
The DB is Postgres in Docker container (not using in mem container).
Here relevant code.
Any help will be much appreciated !
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</dependency>
</dependencies>
test/resources/application.properties
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL95Dialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.initialization-mode=always
spring.datasource.initialize=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
# parses java variables in camel case to data base naming convention with underscores
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
@SpringBootTest
@AutoConfigureMockMvc
public class TrainingDataServiceIT {
@Autowired
private MockMvc mockMvc;
@Autowired
private ObjectMapper objectMapper;
@Autowired
DataSourceRepository dataSourceRepository;
@Test
public void myTest() throws Exception {
mockMvc.perform(post("/get-ds")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content()
.contentTypeCompatibleWith(MediaType.APPLICATION_JSON));
}
EDIT to add my entity (columns emitted):
@Entity
@DynamicUpdate
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "data_source")
public class DataSourceEntity {
EDIT
postgres=# \dn
List of schemas
Name | Owner
--------+----------
public | postgres
(1 row)
Edit:
version: '3'
services:
postgres:
image: postgres:10.15-alpine
container_name: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
ports:
- 5432:5432