-
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.
support @decorated bean injection in decorator
- Loading branch information
Showing
11 changed files
with
283 additions
and
11 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
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
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
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
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
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
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
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
40 changes: 40 additions & 0 deletions
40
...ava/io/quarkus/arc/test/decorators/decorated/DecoratedBeanInjectedInNonDecoratorTest.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,40 @@ | ||
package io.quarkus.arc.test.decorators.decorated; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Decorated; | ||
import jakarta.enterprise.inject.spi.Bean; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class DecoratedBeanInjectedInNonDecoratorTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(InvalidBean.class) | ||
.shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testDecoration() { | ||
assertNotNull(container.getFailure()); | ||
assertTrue(container.getFailure().getMessage().startsWith( | ||
"Invalid injection of @Decorated Bean<T>, can only be injected into decorators but was detected in: " | ||
+ InvalidBean.class.getName() + "#decorated")); | ||
} | ||
|
||
@ApplicationScoped | ||
static class InvalidBean { | ||
|
||
@Inject | ||
@Decorated | ||
Bean<?> decorated; | ||
|
||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...uarkus/arc/test/decorators/decorated/DecoratedBeanInjectedWithWrongTypeParameterTest.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.arc.test.decorators.decorated; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Comparator; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.decorator.Decorator; | ||
import jakarta.decorator.Delegate; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.enterprise.inject.Any; | ||
import jakarta.enterprise.inject.Decorated; | ||
import jakarta.enterprise.inject.spi.Bean; | ||
import jakarta.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class DecoratedBeanInjectedWithWrongTypeParameterTest { | ||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(Converter.class, DecoratedBean.class, TrimConverterDecorator.class) | ||
.shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testDecoration() { | ||
assertNotNull(container.getFailure()); | ||
assertTrue(container.getFailure().getMessage().startsWith( | ||
"Injected @Decorated Bean<> has to use the delegate type as its type parameter. Problematic injection point: " | ||
+ TrimConverterDecorator.class.getName() + "#decorated")); | ||
} | ||
|
||
interface Converter<T> { | ||
T convert(T value); | ||
} | ||
|
||
@ApplicationScoped | ||
static class DecoratedBean implements Converter<String> { | ||
@Override | ||
public String convert(String value) { | ||
return "Replaced by the decorator"; | ||
} | ||
} | ||
|
||
@Dependent | ||
@Priority(1) | ||
@Decorator | ||
static class TrimConverterDecorator implements Converter<String> { | ||
@Inject | ||
@Any | ||
@Delegate | ||
Converter<String> delegate; | ||
|
||
@Inject | ||
@Decorated | ||
Bean<?> decorated; | ||
|
||
@Override | ||
public String convert(String value) { | ||
return decorated.getBeanClass().getName() + " " + decorated.getQualifiers().stream() | ||
.sorted(Comparator.comparing(a -> a.annotationType().getName())).toList(); | ||
} | ||
} | ||
} |
Oops, something went wrong.