-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial TCK tests for build compatible extensions
- Loading branch information
Showing
83 changed files
with
1,619 additions
and
1 deletion.
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
34 changes: 34 additions & 0 deletions
34
...k/tests/build/compatible/extensions/changeBeanQualifier/ChangeBeanQualifierExtension.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,34 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier; | ||
|
||
import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; | ||
import jakarta.enterprise.inject.build.compatible.spi.ClassConfig; | ||
import jakarta.enterprise.inject.build.compatible.spi.Discovery; | ||
import jakarta.enterprise.inject.build.compatible.spi.Enhancement; | ||
import jakarta.enterprise.inject.build.compatible.spi.FieldConfig; | ||
import jakarta.enterprise.inject.build.compatible.spi.ScannedClasses; | ||
|
||
public class ChangeBeanQualifierExtension implements BuildCompatibleExtension { | ||
@Discovery | ||
public void discovery(ScannedClasses scan) { | ||
scan.add("org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier.MyServiceFoo"); | ||
scan.add("org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier.MyServiceBar"); | ||
scan.add("org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier.MyServiceBaz"); | ||
} | ||
|
||
@Enhancement(types = MyServiceFoo.class) | ||
public void foo(ClassConfig clazz) { | ||
clazz.removeAnnotation(ann -> ann.name().equals(MyQualifier.class.getName())); | ||
} | ||
|
||
@Enhancement(types = MyServiceBar.class) | ||
public void bar(ClassConfig clazz) { | ||
clazz.addAnnotation(MyQualifier.class); | ||
} | ||
|
||
@Enhancement(types = MyOtherService.class) | ||
public void service(FieldConfig field) { | ||
if ("myService".equals(field.info().name())) { | ||
field.addAnnotation(MyQualifier.class); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...di/tck/tests/build/compatible/extensions/changeBeanQualifier/ChangeBeanQualifierTest.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,30 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.cdi.tck.AbstractTest; | ||
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.test.audit.annotations.SpecVersion; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertTrue; | ||
|
||
@SpecVersion(spec = "cdi", version = "4.0") | ||
public class ChangeBeanQualifierTest extends AbstractTest { | ||
@Deployment | ||
public static WebArchive createTestArchive() { | ||
// no beans.xml + an extension = not a bean archive, bean classes are added through the extension | ||
return new WebArchiveBuilder() | ||
.withTestClassPackage(ChangeBeanQualifierTest.class) | ||
.withBuildCompatibleExtension(ChangeBeanQualifierExtension.class) | ||
.build(); | ||
} | ||
|
||
@Test | ||
//@SpecAssertion(section = TODO, id = "TODO") | ||
public void test() { | ||
MyOtherService bean = getContextualReference(MyOtherService.class); | ||
// all beans are dependent, so there's no client proxy and direct field access and `instanceof` are OK | ||
assertTrue(bean.myService instanceof MyServiceBar); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...g/jboss/cdi/tck/tests/build/compatible/extensions/changeBeanQualifier/MyOtherService.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,10 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import org.jboss.arquillian.core.api.annotation.Inject; | ||
|
||
@Dependent | ||
public class MyOtherService { | ||
@Inject | ||
MyService myService; | ||
} |
11 changes: 11 additions & 0 deletions
11
.../org/jboss/cdi/tck/tests/build/compatible/extensions/changeBeanQualifier/MyQualifier.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,11 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Qualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface MyQualifier { | ||
} |
5 changes: 5 additions & 0 deletions
5
...va/org/jboss/cdi/tck/tests/build/compatible/extensions/changeBeanQualifier/MyService.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,5 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier; | ||
|
||
public interface MyService { | ||
String hello(); | ||
} |
13 changes: 13 additions & 0 deletions
13
...org/jboss/cdi/tck/tests/build/compatible/extensions/changeBeanQualifier/MyServiceBar.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,13 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class MyServiceBar implements MyService { | ||
private static final String VALUE = "bar"; | ||
|
||
@Override | ||
public String hello() { | ||
return VALUE; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...org/jboss/cdi/tck/tests/build/compatible/extensions/changeBeanQualifier/MyServiceBaz.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,11 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class MyServiceBaz implements MyService { | ||
@Override | ||
public String hello() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...org/jboss/cdi/tck/tests/build/compatible/extensions/changeBeanQualifier/MyServiceFoo.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,14 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeBeanQualifier; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
@MyQualifier | ||
public class MyServiceFoo implements MyService { | ||
private final String value = "foo"; | ||
|
||
@Override | ||
public String hello() { | ||
return value; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...tests/build/compatible/extensions/changeInjectionPoint/ChangeInjectionPointExtension.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,16 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInjectionPoint; | ||
|
||
import jakarta.enterprise.inject.build.compatible.spi.AnnotationBuilder; | ||
import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; | ||
import jakarta.enterprise.inject.build.compatible.spi.ClassConfig; | ||
import jakarta.enterprise.inject.build.compatible.spi.Enhancement; | ||
|
||
public class ChangeInjectionPointExtension implements BuildCompatibleExtension { | ||
@Enhancement(types = MyOtherService.class) | ||
public void service(ClassConfig clazz) { | ||
clazz.fields() | ||
.stream() | ||
.filter(it -> "myService".equals(it.info().name())) | ||
.forEach(field -> field.addAnnotation(AnnotationBuilder.of(MyQualifier.class).build())); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../tck/tests/build/compatible/extensions/changeInjectionPoint/ChangeInjectionPointTest.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,30 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInjectionPoint; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.cdi.tck.AbstractTest; | ||
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.test.audit.annotations.SpecVersion; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertTrue; | ||
|
||
@SpecVersion(spec = "cdi", version = "4.0") | ||
public class ChangeInjectionPointTest extends AbstractTest { | ||
@Deployment | ||
public static WebArchive createTestArchive() { | ||
// no beans.xml + an extension = not a bean archive, bean classes are added through the extension | ||
return new WebArchiveBuilder() | ||
.withTestClassPackage(ChangeInjectionPointTest.class) | ||
.withBuildCompatibleExtension(ChangeInjectionPointExtension.class) | ||
.build(); | ||
} | ||
|
||
@Test | ||
//@SpecAssertion(section = TODO, id = "TODO") | ||
public void test() { | ||
MyOtherService bean = getContextualReference(MyOtherService.class); | ||
// all beans are dependent, so there's no client proxy and direct field access and `instanceof` are OK | ||
assertTrue(bean.myService instanceof MyServiceBar); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../jboss/cdi/tck/tests/build/compatible/extensions/changeInjectionPoint/MyOtherService.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,10 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInjectionPoint; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
import jakarta.inject.Inject; | ||
|
||
@Dependent | ||
public class MyOtherService { | ||
@Inject | ||
MyService myService; | ||
} |
11 changes: 11 additions & 0 deletions
11
...org/jboss/cdi/tck/tests/build/compatible/extensions/changeInjectionPoint/MyQualifier.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,11 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInjectionPoint; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Qualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface MyQualifier { | ||
} |
5 changes: 5 additions & 0 deletions
5
...a/org/jboss/cdi/tck/tests/build/compatible/extensions/changeInjectionPoint/MyService.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,5 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInjectionPoint; | ||
|
||
public interface MyService { | ||
String hello(); | ||
} |
12 changes: 12 additions & 0 deletions
12
...rg/jboss/cdi/tck/tests/build/compatible/extensions/changeInjectionPoint/MyServiceBar.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,12 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInjectionPoint; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
@MyQualifier | ||
public class MyServiceBar implements MyService { | ||
@Override | ||
public String hello() { | ||
return "bar"; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rg/jboss/cdi/tck/tests/build/compatible/extensions/changeInjectionPoint/MyServiceFoo.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,11 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeInjectionPoint; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class MyServiceFoo implements MyService { | ||
@Override | ||
public String hello() { | ||
return "foo"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...build/compatible/extensions/changeObserverQualifier/ChangeObserverQualifierExtension.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,27 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeObserverQualifier; | ||
|
||
import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; | ||
import jakarta.enterprise.inject.build.compatible.spi.Discovery; | ||
import jakarta.enterprise.inject.build.compatible.spi.Enhancement; | ||
import jakarta.enterprise.inject.build.compatible.spi.MethodConfig; | ||
import jakarta.enterprise.inject.build.compatible.spi.ScannedClasses; | ||
|
||
public class ChangeObserverQualifierExtension implements BuildCompatibleExtension { | ||
@Discovery | ||
public void discovery(ScannedClasses scan) { | ||
scan.add("org.jboss.cdi.tck.tests.build.compatible.extensions.changeObserverQualifier.MyConsumer"); | ||
scan.add("org.jboss.cdi.tck.tests.build.compatible.extensions.changeObserverQualifier.MyProducer"); | ||
} | ||
|
||
@Enhancement(types = MyConsumer.class) | ||
public void consumer(MethodConfig method) { | ||
switch (method.info().name()) { | ||
case "consume": | ||
method.parameters().get(0).addAnnotation(MyQualifier.class); | ||
break; | ||
case "noConsume": | ||
method.parameters().get(0).removeAllAnnotations(); | ||
break; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ests/build/compatible/extensions/changeObserverQualifier/ChangeObserverQualifierTest.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,34 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeObserverQualifier; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.cdi.tck.AbstractTest; | ||
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.jboss.test.audit.annotations.SpecVersion; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Set; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
@SpecVersion(spec = "cdi", version = "4.0") | ||
public class ChangeObserverQualifierTest extends AbstractTest { | ||
@Deployment | ||
public static WebArchive createTestArchive() { | ||
// no beans.xml + an extension = not a bean archive, bean classes are added through the extension | ||
return new WebArchiveBuilder() | ||
.withTestClassPackage(ChangeObserverQualifierTest.class) | ||
.withBuildCompatibleExtension(ChangeObserverQualifierExtension.class) | ||
.build(); | ||
} | ||
|
||
@Test | ||
//@SpecAssertion(section = TODO, id = "TODO") | ||
public void test() { | ||
MyProducer producer = getContextualReference(MyProducer.class); | ||
producer.produce(); | ||
|
||
assertEquals(MyConsumer.events, Set.of("qualified")); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...g/jboss/cdi/tck/tests/build/compatible/extensions/changeObserverQualifier/MyConsumer.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 org.jboss.cdi.tck.tests.build.compatible.extensions.changeObserverQualifier; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@ApplicationScoped | ||
public class MyConsumer { | ||
static final Set<String> events = new HashSet<>(); | ||
|
||
void consume(@Observes MyEvent event) { | ||
events.add(event.payload); | ||
} | ||
|
||
void noConsume(@Observes MyEvent event) { | ||
events.add("must-not-happen-" + event.payload); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../org/jboss/cdi/tck/tests/build/compatible/extensions/changeObserverQualifier/MyEvent.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,9 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeObserverQualifier; | ||
|
||
public class MyEvent { | ||
final String payload; | ||
|
||
public MyEvent(String payload) { | ||
this.payload = payload; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...g/jboss/cdi/tck/tests/build/compatible/extensions/changeObserverQualifier/MyProducer.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 org.jboss.cdi.tck.tests.build.compatible.extensions.changeObserverQualifier; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Event; | ||
import jakarta.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class MyProducer { | ||
@Inject | ||
Event<MyEvent> unqualified; | ||
|
||
@Inject | ||
@MyQualifier | ||
Event<MyEvent> qualified; | ||
|
||
void produce() { | ||
unqualified.fire(new MyEvent("unqualified")); | ||
qualified.fire(new MyEvent("qualified")); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../jboss/cdi/tck/tests/build/compatible/extensions/changeObserverQualifier/MyQualifier.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,11 @@ | ||
package org.jboss.cdi.tck.tests.build.compatible.extensions.changeObserverQualifier; | ||
|
||
import jakarta.inject.Qualifier; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Qualifier | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface MyQualifier { | ||
} |
Oops, something went wrong.