-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Weld-2772 Allow to register BCE in Weld SE without discovery
- Loading branch information
Showing
8 changed files
with
219 additions
and
7 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
39 changes: 39 additions & 0 deletions
39
...g/jboss/weld/environment/se/test/extension/build/compatible/registered/DiscoveredBce.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,39 @@ | ||
package org.jboss.weld.environment.se.test.extension.build.compatible.registered; | ||
|
||
import jakarta.enterprise.inject.build.compatible.spi.BeanInfo; | ||
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.Registration; | ||
import jakarta.enterprise.inject.build.compatible.spi.Synthesis; | ||
import jakarta.enterprise.inject.build.compatible.spi.Validation; | ||
import jakarta.enterprise.lang.model.declarations.ClassInfo; | ||
|
||
public class DiscoveredBce implements BuildCompatibleExtension { | ||
public static int TIMES_INVOKED = 0; | ||
|
||
@Discovery | ||
public void discovery() { | ||
TIMES_INVOKED++; | ||
} | ||
|
||
@Enhancement(types = SomeBean.class) | ||
public void enhancement(ClassInfo c) { | ||
TIMES_INVOKED++; | ||
} | ||
|
||
@Registration(types = SomeBean.class) | ||
public void registration(BeanInfo b) { | ||
TIMES_INVOKED++; | ||
} | ||
|
||
@Synthesis | ||
public void synthesis() { | ||
TIMES_INVOKED++; | ||
} | ||
|
||
@Validation | ||
public void validation() { | ||
TIMES_INVOKED++; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...onment/se/test/extension/build/compatible/registered/ExtensionRegisteredManuallyTest.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 org.jboss.weld.environment.se.test.extension.build.compatible.registered; | ||
|
||
import org.jboss.arquillian.container.se.api.ClassPath; | ||
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.environment.se.Weld; | ||
import org.jboss.weld.environment.se.WeldContainer; | ||
import org.jboss.weld.lite.extension.translator.LiteExtensionTranslator; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Arquillian.class) | ||
public class ExtensionRegisteredManuallyTest { | ||
|
||
@Deployment | ||
public static Archive<?> getDeployment() { | ||
return ClassPath.builder() | ||
.add(ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(ExtensionRegisteredManuallyTest.class)) | ||
.addPackage(ExtensionRegisteredManuallyTest.class.getPackage())) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testManuallyAddedBce() { | ||
ManuallyRegisteredBce.TIMES_INVOKED = 0; | ||
try (WeldContainer container = new Weld().addBuildCompatibleExtensions(ManuallyRegisteredBce.class).initialize()) { | ||
// assert the deployment is fine, DummyBean should be resolvable | ||
Assert.assertTrue(container.select(SomeBean.class).isResolvable()); | ||
// LiteExtensionTranslator should be present | ||
Assert.assertTrue(container.select(LiteExtensionTranslator.class).isResolvable()); | ||
// assert that BCE was invoked correctly | ||
Assert.assertEquals(5, ManuallyRegisteredBce.TIMES_INVOKED); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...weld/environment/se/test/extension/build/compatible/registered/ManuallyRegisteredBce.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,39 @@ | ||
package org.jboss.weld.environment.se.test.extension.build.compatible.registered; | ||
|
||
import jakarta.enterprise.inject.build.compatible.spi.BeanInfo; | ||
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.Registration; | ||
import jakarta.enterprise.inject.build.compatible.spi.Synthesis; | ||
import jakarta.enterprise.inject.build.compatible.spi.Validation; | ||
import jakarta.enterprise.lang.model.declarations.ClassInfo; | ||
|
||
public class ManuallyRegisteredBce implements BuildCompatibleExtension { | ||
public static int TIMES_INVOKED = 0; | ||
|
||
@Discovery | ||
public void discovery() { | ||
TIMES_INVOKED++; | ||
} | ||
|
||
@Enhancement(types = SomeBean.class) | ||
public void enhancement(ClassInfo c) { | ||
TIMES_INVOKED++; | ||
} | ||
|
||
@Registration(types = SomeBean.class) | ||
public void registration(BeanInfo b) { | ||
TIMES_INVOKED++; | ||
} | ||
|
||
@Synthesis | ||
public void synthesis() { | ||
TIMES_INVOKED++; | ||
} | ||
|
||
@Validation | ||
public void validation() { | ||
TIMES_INVOKED++; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
.../se/test/extension/build/compatible/registered/RegisteredAndDiscoveredExtensionsTest.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,63 @@ | ||
package org.jboss.weld.environment.se.test.extension.build.compatible.registered; | ||
|
||
import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; | ||
|
||
import org.jboss.arquillian.container.se.api.ClassPath; | ||
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.environment.se.Weld; | ||
import org.jboss.weld.environment.se.WeldContainer; | ||
import org.jboss.weld.lite.extension.translator.LiteExtensionTranslator; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Arquillian.class) | ||
public class RegisteredAndDiscoveredExtensionsTest { | ||
|
||
@Deployment | ||
public static Archive<?> getDeployment() { | ||
return ClassPath.builder() | ||
.add(ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(ExtensionRegisteredManuallyTest.class)) | ||
.addPackage(ExtensionRegisteredManuallyTest.class.getPackage()) | ||
.addAsServiceProvider(BuildCompatibleExtension.class, DiscoveredBce.class)) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testDiscoveryAndExplicitAddition() { | ||
ManuallyRegisteredBce.TIMES_INVOKED = 0; | ||
DiscoveredBce.TIMES_INVOKED = 0; | ||
try (WeldContainer container = new Weld().addBuildCompatibleExtensions(ManuallyRegisteredBce.class).initialize()) { | ||
// assert the deployment is fine, DummyBean should be resolvable | ||
Assert.assertTrue(container.select(SomeBean.class).isResolvable()); | ||
// LiteExtensionTranslator should be present | ||
Assert.assertTrue(container.select(LiteExtensionTranslator.class).isResolvable()); | ||
// assert that manually added BCE was invoked correctly | ||
Assert.assertEquals(5, ManuallyRegisteredBce.TIMES_INVOKED); | ||
// assert that discovered BCE was invoked correctly | ||
Assert.assertEquals(5, DiscoveredBce.TIMES_INVOKED); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAddingAlreadyDiscoveredExtension() { | ||
ManuallyRegisteredBce.TIMES_INVOKED = 0; | ||
DiscoveredBce.TIMES_INVOKED = 0; | ||
try (WeldContainer container = new Weld().addBuildCompatibleExtensions(DiscoveredBce.class, ManuallyRegisteredBce.class) | ||
.initialize()) { | ||
// assert the deployment is fine, DummyBean should be resolvable | ||
Assert.assertTrue(container.select(SomeBean.class).isResolvable()); | ||
// LiteExtensionTranslator should be present | ||
Assert.assertTrue(container.select(LiteExtensionTranslator.class).isResolvable()); | ||
// assert that manually added BCE was invoked correctly | ||
Assert.assertEquals(5, ManuallyRegisteredBce.TIMES_INVOKED); | ||
// despite being added manually and also discovered, it should only use a single instance of this extension | ||
Assert.assertEquals(5, DiscoveredBce.TIMES_INVOKED); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...va/org/jboss/weld/environment/se/test/extension/build/compatible/registered/SomeBean.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,7 @@ | ||
package org.jboss.weld.environment.se.test.extension.build.compatible.registered; | ||
|
||
import jakarta.enterprise.context.Dependent; | ||
|
||
@Dependent | ||
public class SomeBean { | ||
} |
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