Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking Rest client does not work with 2.14.0.CR1 #29128

Closed
robp94 opened this issue Nov 8, 2022 · 11 comments · Fixed by #29155
Closed

Mocking Rest client does not work with 2.14.0.CR1 #29128

robp94 opened this issue Nov 8, 2022 · 11 comments · Fixed by #29155
Labels
area/arc Issue related to ARC (dependency injection) area/rest-client kind/bug Something isn't working
Milestone

Comments

@robp94
Copy link
Contributor

robp94 commented Nov 8, 2022

Describe the bug

Mocking a Client like this worked with 2.13.3

@Alternative()
@Priority(1)
@ApplicationScoped
@RestClient
public class ClientMock implements Client {

but does not with 2.14

Expected behavior

Mocking works.

Actual behavior

The mock is ignored.

How to Reproduce?

code-with-quarkus-client-mock.zip

There is a simple test included.

If you switch to 2.13.3 the test passes.

Output of uname -a or ver

windows/ubuntu

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.14.0.CR1

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@robp94 robp94 added the kind/bug Something isn't working label Nov 8, 2022
@quarkus-bot quarkus-bot bot added area/rest-client env/windows Impacts Windows machines labels Nov 8, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 8, 2022

/cc @Sgitario, @cescoffier, @geoand

@geoand
Copy link
Contributor

geoand commented Nov 8, 2022

@mkouba @Ladicek this seems to be an Arc issue. Essentially with Quarkus 2.13.z, io.quarkus.arc.processor.Types#getClassBeanTypeClosure would include Client for the ClientMock class of the reproducer.
However in 2.14.z Client is not included as one of the types of the bean.

I assume this is due to 7c77aa6

@geoand geoand added area/arc Issue related to ARC (dependency injection) and removed env/windows Impacts Windows machines labels Nov 8, 2022
@Ladicek
Copy link
Contributor

Ladicek commented Nov 8, 2022

That commit can safely be reverted with Jandex 3.0.1, but I would be surprised if that's what causes the issue. I'll take a look tomorrow if noone beats me to it.

@geoand
Copy link
Contributor

geoand commented Nov 8, 2022

The commit was just my best guess, I could certainly be off the mark

@mkouba
Copy link
Contributor

mkouba commented Nov 8, 2022

The commit was just my best guess, I could certainly be off the mark

I think that it's a regression caused by #28429.

CC @manovotn

@manovotn
Copy link
Contributor

manovotn commented Nov 8, 2022

The commit was just my best guess, I could certainly be off the mark

I think that it's a regression caused by #28429.

CC @manovotn

Yeah, that looks like a side effect of this issue.
Resteasy resources classes are @Typed to only the implementation class so that they work correctly with bean resolution in bean factories used (among others) in resteasy reactive.
Client class is affected because it has @Path annotation on it and I assume RR carries that over to the impl class somehow (since this is outside of CDI behavior).

So @Inject ClientMock should work but @Inject Client will fail.

@geoand
Copy link
Contributor

geoand commented Nov 8, 2022

We'll need to address this because this manual mocking won't work otherwise

@manovotn
Copy link
Contributor

manovotn commented Nov 8, 2022

I agree, I am just not sure how to do that yet :)

@geoand
Copy link
Contributor

geoand commented Nov 8, 2022

Let's figure it out tomorrow 😜

@geoand
Copy link
Contributor

geoand commented Nov 9, 2022

Client class is affected because it has @path annotation on it and I assume RR carries that over to the impl class somehow (since this is outside of CDI behavior)

I am not sure I understand this, can you elaborate please?

@manovotn
Copy link
Contributor

manovotn commented Nov 9, 2022

Client class is affected because it has @path annotation on it and I assume RR carries that over to the impl class somehow (since this is outside of CDI behavior)

I am not sure I understand this, can you elaborate please?

That is just a poorly formulated remnant of my brain trying to figure out how this works behind the scenes; feel free to disregard that :)

I discussed this with @mkouba and @Ladicek and while we haven't discovered any silver bullets, we could improve it by adding interfaces into bean types. It is a little but of extra processing but solves the issue presented here.
I've cobbled together a draft of that proposal in #29155
Comments and better ideas are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/rest-client kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants