Describe the bug
If the class implementing PanacheRepository is injected into @QuarkusTest, the test will throw infamous "This method is normally automatically overridden in subclasses: did you forget to annotate your entity with @Entity?"
Expected behavior
PanacheRepository implementor is injected and can be used to manipulate entities.
Actual behavior
Throws
Caused by: java.lang.IllegalStateException: This method is normally automatically overridden in subclasses: did you forget to annotate your entity with @Entity?
at io.quarkus.hibernate.orm.panache.runtime.JpaOperations.implementationInjectionMissing(JpaOperations.java:408)
To Reproduce
Steps to reproduce the behavior:
Configuration
quarkus.datasource.driver = org.h2.Driver
quarkus.datasource.url=jdbc:h2:mem:test"
quarkus.datasource.username=sa
quarkus.datasource.password=sa
quarkus.hibernate-orm.database.generation=drop-and-create
Screenshots
(If applicable, add screenshots to help explain your problem.)
Environment (please complete the following information):
uname -a or ver: Microsoft Windows [Version 10.0.19041.1]java -version: java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
GraalVM version (if different from Java): not tested
Quarkus version or git rev: 1.1.0.Final
Additional context
Maven project: rest.zip
I think this is a duplicate of #1724 but I'll let @FroMage confirm
It could be, but in my case workaround with @PostConstruct does not work. This is a very basic test case so I am a bit worried about usability of the Quarkus platform, especially if the problem is known since March.
The issue is known and is being worked on as we speak.
The issue is complicated by how junit 5 deals with classloaders, but a solution will be land soon enough.
It would be amazing if you crack this, as Arquillian or other complicated solutions will not be needed anymore.
@stuartwdouglas is working in it IIRC
I have got same error message just by declaring test class variable with entity.
This was driving me crazy .... now I see I'm not alone.
Any progress on this @geoand ?
This should now be fixed in master. Can you give it a try?
I've tried with 1.1.1.Final and happens the same @geoand
@jonathanvila @geoand asked to try with master, not 1.1.1.Final. Even in 1.2, this issue isn't fixed.
Try with the latest snapshots 999-SNAPSHOT published here: https://oss.sonatype.org/content/repositories/snapshots/io/quarkus/ .
Thanks.
Yep, I know he said master.
What I would like is to "fix" this as a "regular" user..... and with a
stable release. So from your words I see this needs to wait until be
released.
So, I will move to a workaround and remain at 1.1.1
On Fri, Jan 24, 2020 at 7:01 PM Guillaume Smet notifications@github.com
wrote:
@jonathanvila https://github.com/jonathanvila @geoand
https://github.com/geoand asked to try with master, not 1.1.1.Final.
Even in 1.2, this issue isn't fixed.Try with the latest snapshots 999-SNAPSHOT published here:
https://oss.sonatype.org/content/repositories/snapshots/io/quarkus/ .Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/quarkusio/quarkus/issues/6349?email_source=notifications&email_token=AAOALEV33GTTG24D3XKDNKDQ7MUJNA5CNFSM4J77MDO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ3TAUI#issuecomment-578236497,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAOALERTFGHN3WO5N3SSJXTQ7MUJNANCNFSM4J77MDOQ
.
No workaround possible :( I tried the indirect injection with wrappers, but is not possible apparently due to the kind of test.
@gsmet Tried with sonatype repo and I have errors on downloading artifacts :
[ERROR] Plugin io.quarkus:quarkus-maven-plugin:999-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact io.quarkus:quarkus-maven-plugin:jar:999-SNAPSHOT in quarkus (https://oss.sonatype.org/content/repositories/snapshots/io/quarkus/) -> [Help 1]
org.apache.maven.plugin.PluginResolutionException: Plugin io.quarkus:quarkus-maven-plugin:999-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact io.quarkus:quarkus-maven-plugin:jar:999-SNAPSHOT in quarkus (https://oss.sonatype.org/content/repositories/snapshots/io/quarkus/)
Now I will try to clone quarkus and build it locally
@gsmet @geoand
Tried with master with no luck :(
This is the repository & branch : https://github.com/jonathanvila/spring-petclinic-rest/tree/quarkus
This is the command to test : mvn clean test -Dtest=ClinicServiceTests
@jonathanvila I tried it and got:
Expecting actual not to be null
I didn't really look at the code but are you sure it's due to this issue? I didn't see anything in the output indicating it
Yes
This is the test class :
@QuarkusTest
@QuarkusTestResource(H2DatabaseTestResource.class)
public class ClinicServiceTests {
@Inject
ClinicService clinicService;
@Inject
JpaPetTypeRepository petTypeRepository;
@Inject
JpaVetRepository vetRepository;
@Test
public void shouldFindPetTypeById(){
assertThat(this.clinicService).isNotNull();
assertThat(((ClinicServiceImpl) this.clinicService).petTypeRepository).isNotNull(); // This fails
assertThat(((ClinicServiceImpl) this.clinicService).petTypeRepository.listAll().size()).isGreaterThan(0);
PetType petType = this.clinicService.findPetTypeById(1);
assertThat(petType.getName()).isEqualTo("cat");
}
I added 3 asserts before the real test code in order to see the value for the injections , and the service injected is not null, but the repository injected in it appears to be null
We got the same Issue in two independent implementations.
I'm guessing this has nothing to do with Panache specifically and everything to do with injecting of resources? I have a test injecting a service that doesn't work (same error). Works fine within IntelliJ, but through Maven it blows up.
Panache is OK and error is fixed in 1.3.0.Alpha1
Most helpful comment
The issue is known and is being worked on as we speak.
The issue is complicated by how junit 5 deals with classloaders, but a solution will be land soon enough.