From 583c45c85dd19387111b86b3483cbabe2528a8c9 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 28 Jul 2022 16:56:34 +0200 Subject: [PATCH] add first integration test based on Testcontainers --- .../hsadminng/RbacIntegrationTests.java | 26 +++++++++++++ src/test/resources/application.yml | 37 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/test/java/net/hostsharing/hsadminng/RbacIntegrationTests.java create mode 100644 src/test/resources/application.yml diff --git a/src/test/java/net/hostsharing/hsadminng/RbacIntegrationTests.java b/src/test/java/net/hostsharing/hsadminng/RbacIntegrationTests.java new file mode 100644 index 00000000..a6f39d89 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/RbacIntegrationTests.java @@ -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"); + } +} diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 00000000..addd94d1 --- /dev/null +++ b/src/test/resources/application.yml @@ -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