-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly support lookup with qualifiers, create test coverage for it
- Loading branch information
Showing
18 changed files
with
368 additions
and
28 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
5 changes: 3 additions & 2 deletions
5
impl/src/main/java/org/jboss/weld/invokable/InvokerBuilderImpl.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
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
5 changes: 3 additions & 2 deletions
5
impl/src/main/java/org/jboss/weld/invokable/InvokerInfoBuilder.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
44 changes: 44 additions & 0 deletions
44
tests-arquillian/src/test/java/org/jboss/weld/tests/invokable/lookup/BeanProducer.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,44 @@ | ||
package org.jboss.weld.tests.invokable.lookup; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
|
||
@ApplicationScoped | ||
public class BeanProducer { | ||
|
||
@Produces | ||
@MyQualifier1("foo") | ||
@MyQualifier4("binding") | ||
public String produce1 () { | ||
return MyQualifier1.class.getSimpleName() + MyQualifier4.class.getSimpleName(); | ||
} | ||
|
||
@Produces | ||
@MyQualifier2 | ||
public String produce2 () { | ||
return MyQualifier2.class.getSimpleName(); | ||
} | ||
|
||
@Produces | ||
@MyQualifier5 | ||
public String produceAmbig1 () { | ||
throw new IllegalStateException("Ambiguous producer should never be invoked"); | ||
} | ||
|
||
@Produces | ||
@MyQualifier5 | ||
public String produceAmbig2 () { | ||
throw new IllegalStateException("Ambiguous producer should never be invoked"); | ||
} | ||
|
||
@Produces | ||
public String producePlain () { | ||
throw new IllegalStateException("No qualifier producer should never be invoked"); | ||
} | ||
|
||
@Produces | ||
@ToBeQualifier | ||
public String produceQualified () { | ||
return ToBeQualifier.class.getSimpleName(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests-arquillian/src/test/java/org/jboss/weld/tests/invokable/lookup/InvokableBean.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,32 @@ | ||
package org.jboss.weld.tests.invokable.lookup; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.invoke.Invokable; | ||
|
||
@ApplicationScoped | ||
@MyQualifier1("myBean") | ||
@Invokable | ||
public class InvokableBean { | ||
|
||
public String instanceLookup() { | ||
return InvokableBean.class.getSimpleName(); | ||
} | ||
|
||
// there are two producers providing a bean for the first argument | ||
public String ambiguousLookup(@MyQualifier5 String a) { | ||
return a; | ||
} | ||
|
||
// there is no bean with @MyQualifier3 | ||
public String unsatisfiedLookup(@MyQualifier3 String a) { | ||
return a; | ||
} | ||
|
||
public String correctLookup (@MyQualifier1("noMatter") @MyQualifier4("binding") String a, @MyQualifier2 String b) { | ||
return a + b; | ||
} | ||
|
||
public String lookupWithRegisteredQualifier (@ToBeQualifier String a) { | ||
return a; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...illian/src/test/java/org/jboss/weld/tests/invokable/lookup/InvokableMethodLookupTest.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,77 @@ | ||
package org.jboss.weld.tests.invokable.lookup; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import jakarta.enterprise.inject.AmbiguousResolutionException; | ||
import jakarta.enterprise.inject.UnsatisfiedResolutionException; | ||
import jakarta.enterprise.inject.spi.Extension; | ||
import jakarta.inject.Inject; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.BeanArchive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Arquillian.class) | ||
public class InvokableMethodLookupTest { | ||
|
||
@Deployment | ||
public static Archive getDeployment() { | ||
return ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(InvokableMethodLookupTest.class)) | ||
.addPackage(InvokableMethodLookupTest.class.getPackage()) | ||
.addAsServiceProvider(Extension.class, InvokerRegistreringExtension.class); | ||
} | ||
|
||
@Inject | ||
InvokerRegistreringExtension extension; | ||
|
||
@Inject | ||
@MyQualifier1("abc") | ||
InvokableBean bean; | ||
|
||
@Test | ||
public void testInstanceLookupWithQualifiers() { | ||
Object invokerResult = extension.getInstanceLookupInvoker().invoke(null, new Object[]{}); | ||
assertTrue(invokerResult instanceof String); | ||
assertEquals(InvokableBean.class.getSimpleName(), invokerResult); | ||
} | ||
|
||
@Test | ||
public void testCorrectArqLookupWithQualifiers() { | ||
Object invokerResult = extension.getCorrectLookupInvoker().invoke(bean, new Object[]{null, null}); | ||
assertTrue(invokerResult instanceof String); | ||
assertEquals(MyQualifier1.class.getSimpleName() + MyQualifier4.class.getSimpleName() + MyQualifier2.class.getSimpleName(), invokerResult); | ||
} | ||
|
||
@Test | ||
public void testLookupWithRegisteredQualifier() { | ||
Object invokerResult = extension.getLookupWithRegisteredQualifier().invoke(bean, new Object[]{null}); | ||
assertTrue(invokerResult instanceof String); | ||
assertEquals(ToBeQualifier.class.getSimpleName(), invokerResult); | ||
} | ||
|
||
@Test | ||
public void testUnsatisfiedLookupWithQualifier() { | ||
try { | ||
Object invokerResult = extension.getUnsatisfiedLookupInvoker().invoke(bean, new Object[]{null}); | ||
fail(); | ||
} catch (UnsatisfiedResolutionException e) { | ||
// expected | ||
} | ||
} | ||
|
||
@Test | ||
public void testAmbigLookupWithQualifiers() { | ||
try { | ||
Object invokerResult = extension.getAmbiguousLookupInvoker().invoke(bean, new Object[]{null}); | ||
fail(); | ||
} catch (AmbiguousResolutionException e) { | ||
// expected | ||
} | ||
} | ||
} |
Oops, something went wrong.