Skip to content

Commit

Permalink
Align Hibernate Reactive datasource tests on Hibernate ORM
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Sep 27, 2024
1 parent 789202f commit 2633fb6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.hibernate.reactive.config.datasource;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.reactive.config.MyEntity;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.test.QuarkusUnitTest;

public class EntitiesInDefaultPUWithExplicitDatasourceConfigActiveFalseTest {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClass(MyEntity.class))
.overrideConfigKey("quarkus.hibernate-orm.datasource", "ds-1")
.overrideConfigKey("quarkus.hibernate-orm.database.generation", "drop-and-create")
.overrideConfigKey("quarkus.datasource.\"ds-1\".active", "false")
// We need at least one build-time property for the datasource,
// otherwise it's considered unconfigured at build time...
.overrideConfigKey("quarkus.datasource.\"ds-1\".db-kind", "h2")
.assertException(t -> assertThat(t)
.isInstanceOf(ConfigurationException.class)
.hasMessageContainingAll(
// Hibernate Reactive doesn't support explicitly setting the datasource (yet),
// so it will just notice the default datasource is not configured!
"The default datasource must be configured for Hibernate Reactive",
"Refer to https://quarkus.io/guides/datasource for guidance."));

@Test
public void testInvalidConfiguration() {
// deployment exception should happen first
Assertions.fail();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.quarkus.hibernate.reactive.config.datasource;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.reactive.config.MyEntity;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.test.QuarkusUnitTest;

public class EntitiesInDefaultPUWithExplicitDatasourceConfigUrlMissingTest {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClass(MyEntity.class))
.overrideConfigKey("quarkus.hibernate-orm.datasource", "ds-1")
.overrideConfigKey("quarkus.hibernate-orm.database.generation", "drop-and-create")
// The URL won't be missing if dev services are enabled
.overrideConfigKey("quarkus.devservices.enabled", "false")
// We need at least one build-time property for the datasource,
// otherwise it's considered unconfigured at build time...
.overrideConfigKey("quarkus.datasource.ds-1.db-kind", "h2")
.assertException(t -> assertThat(t)
.isInstanceOf(ConfigurationException.class)
.hasMessageContainingAll(
// Hibernate Reactive doesn't support explicitly setting the datasource (yet),
// so it will just notice the default datasource is not configured!
"The default datasource must be configured for Hibernate Reactive",
"Refer to https://quarkus.io/guides/datasource for guidance."));

@Test
public void testInvalidConfiguration() {
// deployment exception should happen first
Assertions.fail();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.reactive.config.MyEntity;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.test.QuarkusUnitTest;

public class EntitiesInDefaultPUWithExplicitUnconfiguredDatasourceTest {
public class EntitiesInDefaultPUWithExplicitDatasourceMissingTest {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
Expand All @@ -19,12 +20,16 @@ public class EntitiesInDefaultPUWithExplicitUnconfiguredDatasourceTest {
.overrideConfigKey("quarkus.hibernate-orm.database.generation", "drop-and-create")
.assertException(t -> assertThat(t)
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining(
"The default datasource must be configured for Hibernate Reactive. Refer to https://quarkus.io/guides/datasource for guidance."));
.hasMessageContainingAll(
// Hibernate Reactive doesn't support explicitly setting the datasource (yet),
// so it will just notice the default datasource is not configured!
"The default datasource must be configured for Hibernate Reactive",
"Refer to https://quarkus.io/guides/datasource for guidance."));

@Test
public void testInvalidConfiguration() {
// bootstrap will succeed and ignore the fact that a datasource is unconfigured...
// deployment exception should happen first
Assertions.fail();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.reactive.config.MyEntity;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.test.QuarkusUnitTest;

public class EntitiesInDefaultPUWithImplicitUnconfiguredDatasourceTest {
public class EntitiesInDefaultPUWithImplicitDatasourceConfigUrlMissingTest {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClass(MyEntity.class))
// The datasource won't be truly "unconfigured" if dev services are enabled
// The URL won't be missing if dev services are enabled
.overrideConfigKey("quarkus.devservices.enabled", "false")
.assertException(t -> assertThat(t)
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining(
"The default datasource must be configured for Hibernate Reactive. Refer to https://quarkus.io/guides/datasource for guidance."));
.hasMessageContainingAll(
"The default datasource must be configured for Hibernate Reactive",
"Refer to https://quarkus.io/guides/datasource for guidance."));

@Test
public void testInvalidConfiguration() {
// bootstrap will succeed and ignore the fact that a datasource is unconfigured...
// deployment exception should happen first
Assertions.fail();
}

}

0 comments on commit 2633fb6

Please sign in to comment.