diff --git a/README.md b/README.md
index c174089e9f8..e52d38b6b31 100644
--- a/README.md
+++ b/README.md
@@ -68,6 +68,7 @@ You will find the source code here:
|-- wicket-auth-roles
|-- wicket-bean-validation
|-- wicket-cdi
+ |-- wicket-cdi-tests
|-- wicket-core
|-- wicket-tester
|-- wicket-core-tests
diff --git a/pom.xml b/pom.xml
index 556953b51e5..ea98ebd7e07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,6 +106,7 @@
wicket-extensions
wicket-ioc
wicket-cdi
+ wicket-cdi-tests
wicket-spring
wicket-velocity
wicket-auth-roles
@@ -145,7 +146,7 @@
3.26.3
1.79
1.15.10
- 4.2.0
+ 5.0.0-EA7
4.4
2.0.0-M2
2.17.0
@@ -572,6 +573,12 @@
+
+ io.github.cdi-unit
+ cdi-unit
+ ${cdi-unit.version}
+ test
+
org.apache.wicket
wicket-tester
@@ -637,12 +644,6 @@
-
- org.jglue.cdi-unit
- cdi-unit
- ${cdi-unit.version}
- test
-
org.junit.jupiter
junit-jupiter-engine
diff --git a/wicket-cdi-tests/pom.xml b/wicket-cdi-tests/pom.xml
new file mode 100644
index 00000000000..d04b2ac9cfa
--- /dev/null
+++ b/wicket-cdi-tests/pom.xml
@@ -0,0 +1,93 @@
+
+
+
+ 4.0.0
+
+ org.apache.wicket
+ wicket-parent
+ 10.3.0-SNAPSHOT
+ ../pom.xml
+
+ wicket-cdi-tests
+ jar
+ Wicket CDI tests
+
+ Provides tests for the Wicket and CDI module.
+
+
+ org.apache.wicket.cdi*;-noimport:=true
+ !java*,!kotlin*,!sun.nio.ch,org.slf4j*;version="[1.7,3)",*
+ true
+ true
+
+
+
+ jakarta.annotation
+ jakarta.annotation-api
+
+
+ jakarta.enterprise
+ jakarta.enterprise.cdi-api
+
+
+ jakarta.servlet
+ jakarta.servlet-api
+
+
+ org.apache.wicket
+ wicket-cdi
+
+
+ io.github.cdi-unit
+ cdi-unit
+
+
+ org.apache.wicket
+ wicket-tester
+
+
+ org.jboss.weld.module
+ weld-web
+ test
+
+
+ org.jboss.weld.se
+ weld-se-core
+ test
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ test-compile
+
+ testCompile
+
+
+ false
+
+
+
+
+
+
+
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
similarity index 67%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
index 0ee921bade6..47e23be9bd6 100644
--- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
+++ b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
@@ -16,22 +16,28 @@
*/
package org.apache.wicket.cdi;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
+import io.github.cdiunit.ActivatedAlternatives;
+import jakarta.enterprise.inject.spi.BeanManager;
+import jakarta.inject.Inject;
+import org.apache.wicket.Application;
+import org.apache.wicket.cdi.testapp.AlternativeTestAppScope;
+import org.apache.wicket.cdi.testapp.ModelWithInjectedDependency;
import org.apache.wicket.cdi.testapp.TestConversationPage;
import org.apache.wicket.cdi.testapp.TestPage;
-import org.apache.wicket.util.tester.WicketTester;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
* @author jsarman
*/
-// FIXME Wicket 10. Re-enable once cdi-unit is adapted to jakarta.**
-@Disabled
+@ActivatedAlternatives(AlternativeTestAppScope.class)
class CdiConfigurationTest extends WicketCdiTestCase
{
+ @Inject
+ BeanManager beanManager;
+
@Test
void testApplicationScope()
{
@@ -40,6 +46,14 @@ void testApplicationScope()
tester.assertLabel("appscope", "Test ok");
}
+ @Test
+ void testUsesCdiJUnitConfiguration()
+ {
+ configure(new CdiConfiguration().setBeanManager(beanManager));
+ tester.startPage(TestPage.class);
+ tester.assertLabel("appscope", "Alternative ok");
+ }
+
@Test
void testConversationScope()
{
@@ -52,6 +66,26 @@ void testConversationScope()
}
}
+ @Test
+ void testNotConfigured()
+ {
+ assertThrows(IllegalStateException.class, () -> {
+ new ModelWithInjectedDependency();
+ });
+
+ }
+
+ @Test
+ void testAlreadyConfigured()
+ {
+ configure(new CdiConfiguration());
+
+ assertThrows(IllegalStateException.class, () -> {
+ CdiConfiguration.get(Application.get()).setBeanManager(beanManager);
+ });
+
+ }
+
@Test
void testConfigureTwice()
{
@@ -66,13 +100,12 @@ void testConfigureTwice()
@Test
void testApplicationLevelConfiguration()
{
- WicketTester tester = new WicketTester();
CdiConfiguration config = new CdiConfiguration();
for (ConversationPropagation cp : ConversationPropagation.values())
{
config.setPropagation(cp);
assertEquals(cp, config.getPropagation());
}
- config.configure(tester.getApplication());
+ configure(config);
}
}
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java
similarity index 91%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java
index e4a4bc4d553..dad2c3a025f 100644
--- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java
+++ b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java
@@ -22,9 +22,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import jakarta.annotation.PreDestroy;
-import jakarta.inject.Inject;
-
import org.apache.wicket.Page;
import org.apache.wicket.core.request.handler.IPageRequestHandler;
import org.apache.wicket.protocol.http.WebApplication;
@@ -35,6 +32,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jakarta.annotation.PreDestroy;
+
/**
* @author jsarman
*/
@@ -43,16 +42,19 @@ public class CdiWicketTester extends WicketTester
private static final Pattern COUNT_PATTERN = Pattern.compile("COUNT=x([0-9]+)x");
private static final Logger logger = LoggerFactory.getLogger(CdiWicketTester.class);
- @Inject
ContextManager contextManager;
public CdiWicketTester(WebApplication app)
{
super(app);
- NonContextual.of(CdiWicketTester.class).inject(this);
getHttpSession().setTemporary(false);
}
+ public void setContextManager(ContextManager contextManager)
+ {
+ this.contextManager = contextManager;
+ }
+
/**
* Process the request by first activating the contexts on initial call. This call is called
* recursively in the super class so keep track of the topmost call and only activate and
@@ -92,24 +94,6 @@ public Url urlFor(IRequestHandler handler)
return ret;
}
- @PreDestroy
- public void finish()
- {
- try
- {
- logger.debug("Destroying Cdi Wicket Tester");
- if (getLastRequest() != null)
- {
- contextManager.deactivateContexts();
- }
- contextManager.destroy();
- destroy();
- }
- catch (Throwable t)
- {
- }
- }
-
/**
* Asserts that the response contains the right count. This can only be done by parsing the
* markup because models only contain valid values during a request, not after.
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ContextManager.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/ContextManager.java
similarity index 92%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/ContextManager.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/ContextManager.java
index 7017c963eb9..1a440498c27 100644
--- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ContextManager.java
+++ b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/ContextManager.java
@@ -16,6 +16,12 @@
*/
package org.apache.wicket.cdi;
+import org.jboss.weld.bean.builtin.BeanManagerProxy;
+import org.jboss.weld.module.web.servlet.HttpContextLifecycle;
+import org.jboss.weld.servlet.spi.helpers.AcceptingHttpContextActivationFilter;
+
+import io.github.cdiunit.internal.servlet.CdiUnitInitialListenerImpl;
+import io.github.cdiunit.internal.servlet.LifecycleAwareRequest;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.spi.BeanManager;
@@ -23,10 +29,6 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
-import org.jboss.weld.bean.builtin.BeanManagerProxy;
-import org.jboss.weld.module.web.servlet.HttpContextLifecycle;
-import org.jboss.weld.servlet.spi.helpers.AcceptingHttpContextActivationFilter;
-
/**
* @author jsarman
*/
@@ -72,8 +74,7 @@ public void activateContexts(HttpServletRequest request)
if (currentRequest != null)
return;
- // FIXME Wicket 10
- currentRequest = null;// new LifecycleAwareRequest(new CdiUnitInitialListenerImpl(), new javax.servlet.http.HttpServletRequest(request));
+ currentRequest = new LifecycleAwareRequest(new CdiUnitInitialListenerImpl(), request);
lifecycle.requestInitialized(currentRequest, null);
}
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
similarity index 97%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
index e18971cfd48..3bbc2addca8 100644
--- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
+++ b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
@@ -18,21 +18,18 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
-import jakarta.enterprise.context.Conversation;
-import jakarta.inject.Inject;
-
import org.apache.wicket.cdi.testapp.TestConversationPage;
import org.apache.wicket.cdi.testapp.TestConversationalPage;
import org.apache.wicket.core.request.mapper.MountedMapper;
import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import jakarta.enterprise.context.Conversation;
+import jakarta.inject.Inject;
+
/**
* @author jsarman
*/
-// FIXME Wicket 10. Re-enable once cdi-unit is adapted to jakarta.**
-@Disabled
class ConversationPropagatorTest extends WicketCdiTestCase
{
@Inject
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
similarity index 81%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
index b63b00c58b4..fb7829efcc2 100644
--- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
+++ b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
@@ -16,34 +16,32 @@
*/
package org.apache.wicket.cdi;
-import jakarta.inject.Inject;
-
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.ThreadContext;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
import org.apache.wicket.cdi.testapp.TestAppScope;
-import org.apache.wicket.cdi.testapp.TestCdiApplication;
import org.apache.wicket.cdi.testapp.TestConversationBean;
import org.apache.wicket.mock.MockApplication;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.tester.WicketTester;
-import org.jglue.cdiunit.AdditionalClasses;
-import org.jglue.cdiunit.CdiRunner;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.github.cdiunit.AdditionalClasses;
+import io.github.cdiunit.junit5.CdiJUnit5Extension;
+import jakarta.inject.Inject;
/**
* @author jsarman
*/
-@RunWith(CdiRunner.class) // TODO upgrade to junit 5 ExtendWith when Cdi project has Junit 5 support
+@ExtendWith(CdiJUnit5Extension.class)
@AdditionalClasses({ CdiWicketTester.class, BehaviorInjector.class, CdiConfiguration.class,
CdiShutdownCleaner.class, ComponentInjector.class, ConversationExpiryChecker.class,
ConversationPropagator.class, DetachEventEmitter.class, SessionInjector.class,
- TestAppScope.class, TestConversationBean.class, TestCdiApplication.class,
- AutoConversation.class })
+ TestAppScope.class, TestConversationBean.class, AutoConversation.class })
public abstract class WicketCdiTestCase
{
@Inject
@@ -53,7 +51,9 @@ public abstract class WicketCdiTestCase
protected CdiWicketTester newWicketTester(WebApplication app)
{
- return new CdiWicketTester(app);
+ CdiWicketTester cdiWicketTester = new CdiWicketTester(app);
+ cdiWicketTester.setContextManager(contextManager);
+ return cdiWicketTester;
}
public void configure(CdiConfiguration configuration)
@@ -61,7 +61,7 @@ public void configure(CdiConfiguration configuration)
configuration.configure(tester.getApplication());
}
- @After
+ @AfterEach
public void end()
{
if (contextManager.isRequestActive())
@@ -69,9 +69,13 @@ public void end()
contextManager.deactivateContexts();
contextManager.destroy();
}
+ tester.destroy();
+
+ // make sure no leaked BeanManager are present
+ BeanManagerLookup.detach();
}
- @Before
+ @BeforeEach
public void commonBefore()
{
// make sure no leaked threadlocals are present
@@ -90,17 +94,8 @@ protected WebApplication newApplication()
}
/**
- *
- */
- @After
- public void commonAfter()
- {
- tester.destroy();
- }
-
- /**
- * Use -Dwicket.replace.expected.results=true
to automatically
- * replace the expected output file.
+ * Use -Dwicket.replace.expected.results=true
to automatically replace the expected
+ * output file.
*
* @param
*
@@ -109,14 +104,14 @@ public void commonAfter()
* @throws Exception
*/
protected void executeTest(final Class pageClass, final String filename)
- throws Exception
+ throws Exception
{
tester.executeTest(getClass(), pageClass, filename);
}
/**
- * Use -Dwicket.replace.expected.results=true
to automatically
- * replace the expected output file.
+ * Use -Dwicket.replace.expected.results=true
to automatically replace the expected
+ * output file.
*
* @param page
* @param filename
@@ -128,8 +123,8 @@ protected void executeTest(final Page page, final String filename) throws Except
}
/**
- * Use -Dwicket.replace.expected.results=true
to automatically
- * replace the expected output file.
+ * Use -Dwicket.replace.expected.results=true
to automatically replace the expected
+ * output file.
*
* @param
*
@@ -138,8 +133,8 @@ protected void executeTest(final Page page, final String filename) throws Except
* @param filename
* @throws Exception
*/
- protected void executeTest(final Class pageClass,
- PageParameters parameters, final String filename) throws Exception
+ protected void executeTest(final Class pageClass, PageParameters parameters,
+ final String filename) throws Exception
{
tester.executeTest(getClass(), pageClass, parameters, filename);
}
@@ -151,7 +146,7 @@ protected void executeTest(final Class pageClass,
* @throws Exception
*/
protected void executeListener(final Component component, final String filename)
- throws Exception
+ throws Exception
{
tester.executeListener(getClass(), component, filename);
}
@@ -163,14 +158,14 @@ protected void executeListener(final Component component, final String filename)
* @throws Exception
*/
protected void executeBehavior(final AbstractAjaxBehavior behavior, final String filename)
- throws Exception
+ throws Exception
{
tester.executeBehavior(getClass(), behavior, filename);
}
/**
- * Returns the current Maven build directory taken from the basedir
- * system property, or null if not set
+ * Returns the current Maven build directory taken from the basedir system property, or
+ * null if not set
*
* @return path with a trailing slash
*/
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/AlternativeTestAppScope.java
similarity index 77%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/AlternativeTestAppScope.java
index 7b82203a3b0..045b762cd03 100644
--- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
+++ b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/AlternativeTestAppScope.java
@@ -16,24 +16,19 @@
*/
package org.apache.wicket.cdi.testapp;
-import org.apache.wicket.Page;
-import org.apache.wicket.protocol.http.WebApplication;
+import jakarta.enterprise.inject.Alternative;
/**
* @author jsarman
*/
-public class TestApplication extends WebApplication
+@Alternative
+public class AlternativeTestAppScope extends TestAppScope
{
@Override
- public Class extends Page> getHomePage()
+ public String test()
{
- return TestPage.class;
+ return "Alternative ok";
}
- @Override
- protected void init()
- {
- super.init();
- }
}
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/ModelWithInjectedDependency.java
similarity index 65%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/ModelWithInjectedDependency.java
index 95d70bbd7da..fb443880bc3 100644
--- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
+++ b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/ModelWithInjectedDependency.java
@@ -16,39 +16,25 @@
*/
package org.apache.wicket.cdi.testapp;
-import jakarta.inject.Inject;
+import org.apache.wicket.cdi.NonContextual;
+import org.apache.wicket.model.IModel;
-import org.apache.wicket.Page;
-import org.apache.wicket.cdi.CdiConfiguration;
-import org.apache.wicket.protocol.http.WebApplication;
+import jakarta.inject.Inject;
-/**
- * @author jsarman
- */
-public class TestCdiApplication extends WebApplication
+public class ModelWithInjectedDependency implements IModel
{
-
@Inject
- @TestQualifier
- String testString;
-
+ TestAppScope appScope;
- @Override
- public Class extends Page> getHomePage()
+ public ModelWithInjectedDependency()
{
- return TestPage.class;
+ NonContextual.of(ModelWithInjectedDependency.class).inject(this);
}
@Override
- protected void init()
- {
- super.init();
- new CdiConfiguration().configure(this);
- }
-
- public String getInjectedTestString()
+ public String getObject()
{
- return testString;
+ return "not used";
}
}
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java
diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java b/wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java
similarity index 100%
rename from wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java
rename to wicket-cdi-tests/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java
diff --git a/wicket-cdi/src/test/java/simplelogger.properties b/wicket-cdi-tests/src/test/java/simplelogger.properties
similarity index 100%
rename from wicket-cdi/src/test/java/simplelogger.properties
rename to wicket-cdi-tests/src/test/java/simplelogger.properties
diff --git a/wicket-cdi/pom.xml b/wicket-cdi/pom.xml
index e34624a5e64..cc231ea967b 100644
--- a/wicket-cdi/pom.xml
+++ b/wicket-cdi/pom.xml
@@ -37,10 +37,6 @@
!java*,!kotlin*,!sun.nio.ch,org.slf4j*;version="[1.7,3)",*
-
- org.apache.wicket
- wicket-tester
-
jakarta.annotation
jakarta.annotation-api
@@ -57,32 +53,6 @@
org.apache.wicket
wicket-core
-
- org.jboss.weld.module
- weld-web
- test
-
-
- org.jboss.weld.se
- weld-se-core
- test
-
-
- org.junit.vintage
- junit-vintage-engine
- ${junit.version}
- test
-
-
- org.jglue.cdi-unit
- cdi-unit
-
-
- org.jboss.spec.javax.annotation
- jboss-annotations-api_1.2_spec
-
-
-
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
index 34287fb7811..78228ddc289 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
@@ -26,12 +26,11 @@
import org.slf4j.LoggerFactory;
/**
- * Defines several strategies for looking up a CDI BeanManager in a portable
- * way. The following strategies are tried (in order):
+ * Defines several strategies for looking up a CDI BeanManager in a portable way. The following
+ * strategies are tried (in order):
*
* - JNDI under java:comp/BeanManager (default location)
- * - JNDI under java:comp/env/BeanManager (for servlet containers like Tomcat
- * and Jetty)
+ * - JNDI under java:comp/env/BeanManager (for servlet containers like Tomcat and Jetty)
* - CDI.current().getBeanManager() (portable lookup)
* - {@linkplain CdiConfiguration#getFallbackBeanManager() Fallback}
*
@@ -44,7 +43,21 @@ public final class BeanManagerLookup
{
private static final Logger log = LoggerFactory.getLogger(BeanManagerLookup.class);
- private enum BeanManagerLookupStrategy {
+ private enum BeanManagerLookupStrategy
+ {
+ CUSTOM {
+ @Override
+ public BeanManager lookup()
+ {
+ CdiConfiguration cdiConfiguration = CdiConfiguration.get(Application.get());
+
+ if (cdiConfiguration == null)
+ throw new IllegalStateException(
+ "NonContextual injection can only be used after a CdiConfiguration is set");
+
+ return cdiConfiguration.getBeanManager();
+ }
+ },
JNDI {
@Override
public BeanManager lookup()
@@ -99,7 +112,7 @@ public BeanManager lookup()
public abstract BeanManager lookup();
}
- private static BeanManagerLookupStrategy lastSuccessful = BeanManagerLookupStrategy.JNDI;
+ private static BeanManagerLookupStrategy lastSuccessful = BeanManagerLookupStrategy.CUSTOM;
private BeanManagerLookup()
{
@@ -122,7 +135,12 @@ public static BeanManager lookup()
}
throw new IllegalStateException(
- "No BeanManager found via the CDI provider and no fallback specified. Check your "
- + "CDI setup or specify a fallback BeanManager in the CdiConfiguration.");
+ "No BeanManager found via the CDI provider and no fallback specified. Check your "
+ + "CDI setup or specify a fallback BeanManager in the CdiConfiguration.");
+ }
+
+ static void detach()
+ {
+ lastSuccessful = BeanManagerLookupStrategy.CUSTOM;
}
}
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
index e3f9620464c..692e83d015c 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
@@ -37,6 +37,8 @@ public class CdiConfiguration
private IConversationPropagation propagation = ConversationPropagation.NONBOOKMARKABLE;
+ private BeanManager beanManager;
+
private BeanManager fallbackBeanManager;
/**
@@ -57,6 +59,28 @@ public CdiConfiguration setPropagation(IConversationPropagation propagation)
return this;
}
+ public BeanManager getBeanManager()
+ {
+ return beanManager;
+ }
+
+ /**
+ * Sets a BeanManager that should be used at first.
+ *
+ * @param beanManager
+ * @return this instance
+ */
+ public CdiConfiguration setBeanManager(BeanManager beanManager)
+ {
+
+ if (Application.exists() && CdiConfiguration.get(Application.get()) != null)
+ throw new IllegalStateException(
+ "A CdiConfiguration is already set for the application.");
+
+ this.beanManager = beanManager;
+ return this;
+ }
+
public BeanManager getFallbackBeanManager()
{
return fallbackBeanManager;