add first integration test based on Testcontainers

This commit is contained in:
Michael Hoennig 2022-07-28 16:56:34 +02:00
parent d234ac3227
commit 583c45c85d
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package net.hostsharing.hsadminng;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
@DataJpaTest
class RbacIntegrationTests {
@PersistenceContext
private EntityManager em;
@Test
@Transactional
void currentUser() {
em.createNativeQuery("SET LOCAL hsadminng.currentUser = 'mike@hostsharing.net';").executeUpdate();
em.createNativeQuery("SET LOCAL hsadminng.assumedRoles = '';").executeUpdate();
final var result = em.createNativeQuery("select currentUser()").getSingleResult();
Assertions.assertThat(result).isEqualTo("mike@hostsharing.net");
}
}

View File

@ -0,0 +1,37 @@
spring:
sql:
init:
platform: postgres
datasource:
url: jdbc:tc:postgresql:12.9-alpine:///spring_boot_testcontainers
username: postgres
password: password
jpa:
properties:
hibernate:
default_schema: public
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: none
show-sql: true
test:
database:
replace: none
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.yaml
contexts: test
logging:
level:
liquibase: INFO
# spring.datasource.driver-class-name=org.postgresql.Driver
# spring.datasource.url=${DB_URL}
# spring.datasource.username=${DB_USERNAME}
# spring.datasource.password=${DB_PASSWORD}
# spring.jpa.properties.hibernate.default-schema=public