-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42190 from peuBouzon/fix-41992
Improve error message when multiple hibernate interceptors are found
- Loading branch information
Showing
6 changed files
with
208 additions
and
16 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...nt/src/test/java/io/quarkus/hibernate/orm/boot/AmbiguousPersistenceUnitExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.hibernate.orm.boot; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hibernate.Interceptor; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.MyEntity; | ||
import io.quarkus.hibernate.orm.PersistenceUnitExtension; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class AmbiguousPersistenceUnitExtensionTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(MyEntity.class) | ||
.addClass(PersistenceUnitInterceptor.class) | ||
.addClass(AnotherPersistenceUnitInterceptor.class)) | ||
.withConfigurationResource("application.properties") | ||
.assertException(throwable -> assertThat(throwable) | ||
.hasNoSuppressedExceptions() | ||
.rootCause() | ||
.hasMessageContainingAll("Multiple instances of Interceptor were found for persistence unit <default>.", | ||
"At most one instance can be assigned to each persistence unit. Instances found:", | ||
"io.quarkus.hibernate.orm.boot.AmbiguousPersistenceUnitExtensionTest.PersistenceUnitInterceptor", | ||
"io.quarkus.hibernate.orm.boot.AmbiguousPersistenceUnitExtensionTest.AnotherPersistenceUnitInterceptor")); | ||
|
||
@PersistenceUnitExtension | ||
public static class PersistenceUnitInterceptor implements Interceptor { | ||
} | ||
|
||
@PersistenceUnitExtension | ||
public static class AnotherPersistenceUnitInterceptor implements Interceptor { | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Assertions.fail("Startup should have failed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...io/quarkus/hibernate/search/orm/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.test.boot; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
|
||
import org.hibernate.search.engine.reporting.EntityIndexingFailureContext; | ||
import org.hibernate.search.engine.reporting.FailureContext; | ||
import org.hibernate.search.engine.reporting.FailureHandler; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.search.orm.elasticsearch.SearchExtension; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class AmbiguousSearchExtensionTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(MyEntity.class) | ||
.addClass(SearchFailureHandler.class) | ||
.addClass(AnotherSearchFailureHandler.class) | ||
.addAsResource("application.properties")) | ||
.assertException(throwable -> assertThat(throwable) | ||
.hasNoSuppressedExceptions() | ||
.rootCause() | ||
.hasMessageContainingAll( | ||
"Multiple instances of FailureHandler were found for Hibernate Search in persistence unit <default>.", | ||
"At most one instance can be assigned to each persistence unit. Instances found:", | ||
"io.quarkus.hibernate.search.orm.elasticsearch.test.boot.AmbiguousSearchExtensionTest.SearchFailureHandler", | ||
"io.quarkus.hibernate.search.orm.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler")); | ||
|
||
@Entity | ||
@Indexed | ||
static class MyEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
} | ||
|
||
@SearchExtension | ||
public static class SearchFailureHandler implements FailureHandler { | ||
@Override | ||
public void handle(FailureContext failureContext) { | ||
} | ||
|
||
@Override | ||
public void handle(EntityIndexingFailureContext entityIndexingFailureContext) { | ||
} | ||
} | ||
|
||
@SearchExtension | ||
public static class AnotherSearchFailureHandler implements FailureHandler { | ||
@Override | ||
public void handle(FailureContext failureContext) { | ||
} | ||
|
||
@Override | ||
public void handle(EntityIndexingFailureContext entityIndexingFailureContext) { | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Assertions.fail("Startup should have failed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...kus/hibernate/search/standalone/elasticsearch/test/boot/AmbiguousSearchExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.quarkus.hibernate.search.standalone.elasticsearch.test.boot; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hibernate.search.engine.reporting.EntityIndexingFailureContext; | ||
import org.hibernate.search.engine.reporting.FailureContext; | ||
import org.hibernate.search.engine.reporting.FailureHandler; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.SearchEntity; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.search.standalone.elasticsearch.SearchExtension; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class AmbiguousSearchExtensionTest { | ||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(MyEntity.class) | ||
.addClass(SearchFailureHandler.class) | ||
.addClass(AnotherSearchFailureHandler.class) | ||
.addAsResource("application.properties")) | ||
.assertException(throwable -> assertThat(throwable) | ||
.hasNoSuppressedExceptions() | ||
.rootCause() | ||
.hasMessageContainingAll( | ||
"Multiple instances of FailureHandler were found for Hibernate Search Standalone.", | ||
"At most one instance can be assigned. Instances found:", | ||
"io.quarkus.hibernate.search.standalone.elasticsearch.test.boot.AmbiguousSearchExtensionTest.SearchFailureHandler", | ||
"io.quarkus.hibernate.search.standalone.elasticsearch.test.boot.AmbiguousSearchExtensionTest.AnotherSearchFailureHandler")); | ||
|
||
@SearchEntity | ||
@Indexed | ||
public static class MyEntity { | ||
@DocumentId | ||
private Long id; | ||
} | ||
|
||
@SearchExtension | ||
public static class SearchFailureHandler implements FailureHandler { | ||
@Override | ||
public void handle(FailureContext failureContext) { | ||
} | ||
|
||
@Override | ||
public void handle(EntityIndexingFailureContext entityIndexingFailureContext) { | ||
} | ||
} | ||
|
||
@SearchExtension | ||
public static class AnotherSearchFailureHandler implements FailureHandler { | ||
@Override | ||
public void handle(FailureContext failureContext) { | ||
} | ||
|
||
@Override | ||
public void handle(EntityIndexingFailureContext entityIndexingFailureContext) { | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Assertions.fail("Startup should have failed"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters