-
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 #29155 from manovotn/issue29128
Include interfaces as bean types of RR resources
- Loading branch information
Showing
9 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
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
4 changes: 4 additions & 0 deletions
4
...nt-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/beanTypes/Alpha.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,4 @@ | ||
package io.quarkus.rest.client.reactive.beanTypes; | ||
|
||
public interface Alpha extends Delta { | ||
} |
4 changes: 4 additions & 0 deletions
4
...ent-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/beanTypes/Beta.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,4 @@ | ||
package io.quarkus.rest.client.reactive.beanTypes; | ||
|
||
public interface Beta extends Delta { | ||
} |
4 changes: 4 additions & 0 deletions
4
...-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/beanTypes/Charlie.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,4 @@ | ||
package io.quarkus.rest.client.reactive.beanTypes; | ||
|
||
public interface Charlie extends Beta { | ||
} |
17 changes: 17 additions & 0 deletions
17
...t-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/beanTypes/Client.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,17 @@ | ||
package io.quarkus.rest.client.reactive.beanTypes; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@Path("/") | ||
@RegisterRestClient(configKey = "hello2") | ||
public interface Client extends Alpha { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
String test(); | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...active/deployment/src/test/java/io/quarkus/rest/client/reactive/beanTypes/ClientMock.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,20 @@ | ||
package io.quarkus.rest.client.reactive.beanTypes; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Alternative; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
import io.quarkus.arc.Priority; | ||
|
||
@Alternative() | ||
@Priority(1) | ||
@ApplicationScoped | ||
@RestClient | ||
public class ClientMock implements Client, Charlie { | ||
|
||
@Override | ||
public String test() { | ||
return "hello from " + ClientMock.class; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...nt-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/beanTypes/Delta.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,4 @@ | ||
package io.quarkus.rest.client.reactive.beanTypes; | ||
|
||
public interface Delta { | ||
} |
18 changes: 18 additions & 0 deletions
18
...t-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/beanTypes/MyBean.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,18 @@ | ||
package io.quarkus.rest.client.reactive.beanTypes; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@ApplicationScoped | ||
public class MyBean { | ||
|
||
@Inject | ||
@RestClient | ||
Client client; | ||
|
||
String test() { | ||
return client.test(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...loyment/src/test/java/io/quarkus/rest/client/reactive/beanTypes/ResourceBeanTypeTest.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,47 @@ | ||
package io.quarkus.rest.client.reactive.beanTypes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Set; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Tests that resources processed by RR have bean types equivalent to that of the impl class plus all interfaces in | ||
* their hierarchy | ||
*/ | ||
public class ResourceBeanTypeTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Client.class, ClientMock.class, MyBean.class, Alpha.class, Beta.class, | ||
Charlie.class, Delta.class)); | ||
|
||
@Inject | ||
MyBean myBean; | ||
|
||
@Test | ||
void shouldHaveAllInterfaceTypes() { | ||
// firstly, sanity check | ||
assertThat(myBean.test()).isEqualTo("hello from " + ClientMock.class); | ||
|
||
// now see what types does the Client bean have - the impl class and all interfaces should be in place | ||
BeanManager beanManager = Arc.container().beanManager(); | ||
Set<Bean<?>> beans = beanManager.getBeans(Client.class, RestClient.LITERAL); | ||
Bean<?> resolvedBean = beanManager.resolve(beans); | ||
assertThat(resolvedBean.getScope()).isEqualTo(ApplicationScoped.class); | ||
assertThat(resolvedBean.getTypes()).contains(Client.class, ClientMock.class, Alpha.class, Beta.class, Charlie.class, | ||
Delta.class); | ||
} | ||
} |