You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2013/11/19 20:14:11 UTC
[5/5] git commit: moved wicket-cdi from core into parent
moved wicket-cdi from core into parent
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/ecf2c9fe
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/ecf2c9fe
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/ecf2c9fe
Branch: refs/heads/wicket-cdi-1.1-rewrite
Commit: ecf2c9fe26f2b814f7369054badc2f8515ce8508
Parents: 1593018
Author: Emond Papegaaij <em...@topicus.nl>
Authored: Tue Nov 19 17:56:42 2013 +0100
Committer: Emond Papegaaij <em...@topicus.nl>
Committed: Tue Nov 19 17:58:11 2013 +0100
----------------------------------------------------------------------
wicket-experimental/wicket-cdi-1.1/pom.xml | 34 +-
.../org/apache/wicket/cdi/AbstractInjector.java | 39 +++
.../org/apache/wicket/cdi/AutoConversation.java | 51 +++
.../apache/wicket/cdi/BeanManagerLookup.java | 40 +++
.../org/apache/wicket/cdi/BehaviorInjector.java | 42 +++
.../org/apache/wicket/cdi/CdiConfiguration.java | 101 ++++++
.../apache/wicket/cdi/CdiShutdownCleaner.java | 45 +++
.../apache/wicket/cdi/ComponentInjector.java | 43 +++
.../cdi/ConversationExpiredException.java | 52 +++
.../wicket/cdi/ConversationExpiryChecker.java | 68 ++++
.../wicket/cdi/ConversationPropagation.java | 69 ++++
.../wicket/cdi/ConversationPropagator.java | 347 +++++++++++++++++++
.../wicket/cdi/ConversationalComponent.java | 30 ++
.../java/org/apache/wicket/cdi/DetachEvent.java | 28 ++
.../apache/wicket/cdi/DetachEventEmitter.java | 75 ++++
.../cdi/ICdiAwareRequestCycleListener.java | 39 +++
.../wicket/cdi/IConversationPropagation.java | 38 ++
.../org/apache/wicket/cdi/NonContextual.java | 154 ++++++++
.../org/apache/wicket/cdi/SessionInjector.java | 42 +++
.../src/main/resources/META-INF/beans.xml | 4 +
.../java/org/apache/wicket/WicketTestCase.java | 161 +++++++++
.../wicket/cdi/ApacheLicenceHeaderTest.java | 41 +++
.../apache/wicket/cdi/CdiConfigurationTest.java | 68 ++++
.../wicket/cdi/ConversationPropagatorTest.java | 199 +++++++++++
.../apache/wicket/cdi/WicketCdiTestCase.java | 67 ++++
.../apache/wicket/cdi/testapp/TestAppScope.java | 40 +++
.../wicket/cdi/testapp/TestApplication.java | 39 +++
.../wicket/cdi/testapp/TestCdiApplication.java | 54 +++
.../cdi/testapp/TestConversationBean.java | 51 +++
.../cdi/testapp/TestConversationPage.html | 12 +
.../cdi/testapp/TestConversationPage.java | 89 +++++
.../cdi/testapp/TestConversationalPage.html | 12 +
.../cdi/testapp/TestConversationalPage.java | 82 +++++
.../testapp/TestNonAutoConversationalPage.html | 12 +
.../testapp/TestNonAutoConversationalPage.java | 88 +++++
.../cdi/testapp/TestNonConversationalPage.html | 11 +
.../cdi/testapp/TestNonConversationalPage.java | 59 ++++
.../org/apache/wicket/cdi/testapp/TestPage.html | 10 +
.../org/apache/wicket/cdi/testapp/TestPage.java | 40 +++
.../wicket/cdi/testapp/TestQualifier.java | 35 ++
.../wicket/cdi/util/tester/CdiWicketTester.java | 122 +++++++
.../wicket/cdi/util/tester/ContextManager.java | 105 ++++++
.../src/test/java/simplelogger.properties | 1 +
.../wicket-cdi-1.1/wicket-cdi-1.1-core/pom.xml | 58 ----
.../org/apache/wicket/cdi/AbstractInjector.java | 39 ---
.../org/apache/wicket/cdi/AutoConversation.java | 51 ---
.../apache/wicket/cdi/BeanManagerLookup.java | 40 ---
.../org/apache/wicket/cdi/BehaviorInjector.java | 42 ---
.../org/apache/wicket/cdi/CdiConfiguration.java | 101 ------
.../apache/wicket/cdi/CdiShutdownCleaner.java | 45 ---
.../apache/wicket/cdi/ComponentInjector.java | 43 ---
.../cdi/ConversationExpiredException.java | 52 ---
.../wicket/cdi/ConversationExpiryChecker.java | 68 ----
.../wicket/cdi/ConversationPropagation.java | 69 ----
.../wicket/cdi/ConversationPropagator.java | 347 -------------------
.../wicket/cdi/ConversationalComponent.java | 30 --
.../java/org/apache/wicket/cdi/DetachEvent.java | 28 --
.../apache/wicket/cdi/DetachEventEmitter.java | 75 ----
.../cdi/ICdiAwareRequestCycleListener.java | 39 ---
.../wicket/cdi/IConversationPropagation.java | 38 --
.../org/apache/wicket/cdi/NonContextual.java | 154 --------
.../org/apache/wicket/cdi/SessionInjector.java | 42 ---
.../src/main/resources/META-INF/beans.xml | 4 -
.../java/org/apache/wicket/WicketTestCase.java | 161 ---------
.../wicket/cdi/ApacheLicenceHeaderTest.java | 41 ---
.../apache/wicket/cdi/CdiConfigurationTest.java | 68 ----
.../wicket/cdi/ConversationPropagatorTest.java | 199 -----------
.../apache/wicket/cdi/WicketCdiTestCase.java | 67 ----
.../apache/wicket/cdi/testapp/TestAppScope.java | 40 ---
.../wicket/cdi/testapp/TestApplication.java | 39 ---
.../wicket/cdi/testapp/TestCdiApplication.java | 54 ---
.../cdi/testapp/TestConversationBean.java | 51 ---
.../cdi/testapp/TestConversationPage.html | 12 -
.../cdi/testapp/TestConversationPage.java | 89 -----
.../cdi/testapp/TestConversationalPage.html | 12 -
.../cdi/testapp/TestConversationalPage.java | 82 -----
.../testapp/TestNonAutoConversationalPage.html | 12 -
.../testapp/TestNonAutoConversationalPage.java | 88 -----
.../cdi/testapp/TestNonConversationalPage.html | 11 -
.../cdi/testapp/TestNonConversationalPage.java | 59 ----
.../org/apache/wicket/cdi/testapp/TestPage.html | 10 -
.../org/apache/wicket/cdi/testapp/TestPage.java | 40 ---
.../wicket/cdi/testapp/TestQualifier.java | 35 --
.../wicket/cdi/util/tester/CdiWicketTester.java | 122 -------
.../wicket/cdi/util/tester/ContextManager.java | 105 ------
.../src/test/java/simplelogger.properties | 1 -
86 files changed, 2734 insertions(+), 2768 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/pom.xml
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/pom.xml b/wicket-experimental/wicket-cdi-1.1/pom.xml
index ae75c0d..6bc08fb 100644
--- a/wicket-experimental/wicket-cdi-1.1/pom.xml
+++ b/wicket-experimental/wicket-cdi-1.1/pom.xml
@@ -24,11 +24,35 @@
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>wicket-cdi-1.1</artifactId>
+ <packaging>jar</packaging>
<version>0.2-SNAPSHOT</version>
- <packaging>pom</packaging>
<name>Wicket CDI 1.1</name>
- <description>Wicket CDI 1.1 Parent.</description>
- <modules>
- <module>wicket-cdi-1.1-core</module>
- </modules>
+ <description>
+ Provides integration between Wicket and CDI containers. Enables injection of
+ components and behaviors, as well as other non-contextual object instances.
+ Also enables propagation of conversations between wicket artifacts such as pages
+ and resources.
+ </description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.wicket</groupId>
+ <artifactId>wicket-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jglue.cdi-unit</groupId>
+ <artifactId>cdi-unit</artifactId>
+ <version>2.2.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AbstractInjector.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
new file mode 100644
index 0000000..c6c38b6
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+/**
+ * Base class for injectors
+ *
+ * @author igor
+ */
+class AbstractInjector
+{
+ public AbstractInjector()
+ {
+ }
+
+ protected <T> void postConstruct(T instance)
+ {
+ NonContextual.of(instance.getClass()).postConstruct(instance);
+ }
+
+ protected <T> void inject(T instance)
+ {
+ NonContextual.of(instance.getClass()).inject(instance);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversation.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversation.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversation.java
new file mode 100644
index 0000000..6138ac2
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversation.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import javax.enterprise.context.ConversationScoped;
+
+import org.apache.wicket.util.io.IClusterable;
+
+/**
+ * A bean that can be used to override whether the lifecycle of the conversation should be managed
+ * automatically or not. See {@link CdiConfiguration#setAutoConversationManagement(boolean)} for
+ * details.
+ *
+ * @author igor
+ */
+@ConversationScoped
+public class AutoConversation implements IClusterable
+{
+ private static final long serialVersionUID = 1L;
+
+ private boolean automatic;
+
+ public AutoConversation()
+ {
+ automatic = false;
+ }
+
+ public void setAutomatic(boolean automatic)
+ {
+ this.automatic = automatic;
+ }
+
+ public boolean isAutomatic()
+ {
+ return automatic;
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
new file mode 100644
index 0000000..d9051ba
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.CDI;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+public final class BeanManagerLookup
+{
+ private BeanManagerLookup()
+ {
+ }
+
+ public static BeanManager lookup() {
+ try
+ {
+ return InitialContext.doLookup("java:comp/BeanManager");
+ }
+ catch (NamingException e)
+ {
+ return CDI.current().getBeanManager();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
new file mode 100644
index 0000000..15979f6
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.IBehaviorInstantiationListener;
+import org.apache.wicket.behavior.Behavior;
+
+/**
+ * Injects components with CDI dependencies
+ *
+ * @author igor
+ *
+ */
+public class BehaviorInjector extends AbstractInjector implements IBehaviorInstantiationListener
+{
+ /**
+ * Constructor
+ */
+ public BehaviorInjector()
+ {
+ }
+
+ @Override
+ public void onInstantiation(Behavior behavior)
+ {
+ inject(behavior);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
new file mode 100644
index 0000000..93675f7
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.MetaDataKey;
+import org.apache.wicket.request.cycle.RequestCycleListenerCollection;
+
+/**
+ * Configures CDI integration
+ *
+ * @author igor
+ *
+ */
+public class CdiConfiguration
+{
+ private static final MetaDataKey<CdiConfiguration> CDI_CONFIGURATION_KEY = new MetaDataKey<CdiConfiguration>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
+
+ private IConversationPropagation propagation = ConversationPropagation.ALL;
+
+ /**
+ * Constructor
+ */
+ public CdiConfiguration()
+ {
+ }
+
+ public IConversationPropagation getPropagation()
+ {
+ return propagation;
+ }
+
+
+ public CdiConfiguration setPropagation(IConversationPropagation propagation)
+ {
+ this.propagation = propagation;
+ return this;
+ }
+
+
+ /**
+ * Configures the specified application
+ *
+ * @param application
+ * @return
+ */
+ public void configure(Application application)
+ {
+ if (application.getMetaData(CDI_CONFIGURATION_KEY) != null)
+ {
+ throw new IllegalStateException("Cdi already configured for this application");
+ }
+ application.setMetaData(CDI_CONFIGURATION_KEY, this);
+
+ RequestCycleListenerCollection listeners = new RequestCycleListenerCollection();
+ application.getRequestCycleListeners().add(listeners);
+
+ // enable conversation propagation
+ if (getPropagation() != ConversationPropagation.NONE)
+ {
+ listeners.add(new ConversationPropagator(application, getPropagation()));
+ application.getComponentPreOnBeforeRenderListeners().add(
+ new ConversationExpiryChecker());
+ }
+
+ // enable detach event
+ listeners.add(new DetachEventEmitter());
+
+ NonContextual.of(application.getClass()).postConstruct(application);
+
+ // enable injection of various framework components
+ application.getSessionListeners().add(new SessionInjector());
+ application.getComponentInstantiationListeners().add(new ComponentInjector());
+ application.getBehaviorInstantiationListeners().add(new BehaviorInjector());
+
+ // enable cleanup
+ application.getApplicationListeners().add(new CdiShutdownCleaner());
+ }
+
+ public static CdiConfiguration get(Application application)
+ {
+ return application.getMetaData(CDI_CONFIGURATION_KEY);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
new file mode 100644
index 0000000..8d2c97c
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.IApplicationListener;
+
+/**
+ * Listens to application shutdown and cleans up
+ *
+ * @author igor
+ */
+class CdiShutdownCleaner implements IApplicationListener
+{
+ public CdiShutdownCleaner()
+ {
+ }
+
+ @Override
+ public void onAfterInitialized(Application application)
+ {
+ // noop
+ }
+
+ @Override
+ public void onBeforeDestroyed(Application application)
+ {
+ NonContextual.of(application.getClass()).preDestroy(application);
+ NonContextual.undeploy();
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ComponentInjector.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
new file mode 100644
index 0000000..65a4879
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.application.IComponentInstantiationListener;
+
+/**
+ * Injects components with CDI dependencies
+ *
+ * @author igor
+ *
+ */
+class ComponentInjector extends AbstractInjector implements IComponentInstantiationListener
+{
+ /**
+ * Constructor
+ */
+ public ComponentInjector()
+ {
+ }
+
+ @Override
+ public void onInstantiation(Component component)
+ {
+ inject(component);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
new file mode 100644
index 0000000..a9c7eb1
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.request.IRequestHandler;
+
+public class ConversationExpiredException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+ private String cid;
+ private Page page;
+ private IRequestHandler handler;
+
+ public ConversationExpiredException(Throwable cause, String cid, Page page,
+ IRequestHandler handler)
+ {
+ super(cause);
+ this.cid = cid;
+ this.page = page;
+ this.handler = handler;
+ }
+
+ public String getCid()
+ {
+ return cid;
+ }
+
+ public Page getPage()
+ {
+ return page;
+ }
+
+ public IRequestHandler getHandler()
+ {
+ return handler;
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
new file mode 100644
index 0000000..e79f938
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import javax.enterprise.context.Conversation;
+import javax.inject.Inject;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.application.IComponentOnBeforeRenderListener;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.util.lang.Objects;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Checks for conversation expiration during page render and throws a
+ * {@link ConversationExpiredException} when an expired conversation is detected.
+ *
+ * For example a link that calls {@link Conversation#end()} but does not redirect to a
+ * non-conversation-dependent page will be caught by this listener.
+ *
+ * @author igor
+ *
+ */
+public class ConversationExpiryChecker implements IComponentOnBeforeRenderListener
+{
+ private static final Logger logger = LoggerFactory.getLogger(ConversationExpiryChecker.class);
+
+ @Inject
+ private Conversation conversation;
+
+ public ConversationExpiryChecker()
+ {
+ NonContextual.of(ConversationExpiryChecker.class).inject(this);
+ }
+
+ @Override
+ public void onBeforeRender(Component component)
+ {
+ if (component instanceof Page || RequestCycle.get().find(AjaxRequestTarget.class) != null)
+ {
+ Page page = component.getPage();
+ String cid = ConversationPropagator.getConversationIdFromPage(page);
+ if (cid != null && !Objects.isEqual(conversation.getId(), cid))
+ {
+ logger.info("Conversation {} has expired for {}", cid, page);
+ throw new ConversationExpiredException(null, cid, page, RequestCycle.get()
+ .getActiveRequestHandler());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
new file mode 100644
index 0000000..502b6e5
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import javax.enterprise.context.ConversationScoped;
+
+import org.apache.wicket.core.request.handler.BookmarkableListenerInterfaceRequestHandler;
+import org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler;
+import org.apache.wicket.request.IRequestHandler;
+
+/**
+ * Various modes of propagating persistent conversations across requests.
+ *
+ * @see ConversationScoped
+ *
+ * @author igor
+ */
+public enum ConversationPropagation implements IConversationPropagation {
+ /** No conversational propagation takes place */
+ NONE {
+ @Override
+ public boolean propagatesViaParameters(IRequestHandler handler)
+ {
+ return false;
+ }
+ },
+ /**
+ * Pesistent conversations are propagated between non-bookmarkable pages
+ * only
+ *
+ * @deprecated as of cdi-1.1, it is specified that conversations are
+ * propagated via the cid query parameter even for
+ * non-bookmarkable pages
+ */
+ @Deprecated
+ NONBOOKMARKABLE {
+ @Override
+ public boolean propagatesViaParameters(IRequestHandler handler)
+ {
+ return !(handler instanceof BookmarkableListenerInterfaceRequestHandler)
+ && !(handler instanceof BookmarkablePageRequestHandler);
+ }
+ },
+ /**
+ * Persistent conversations are propagated between bookmarkable and
+ * non-bookmarkable pages
+ */
+ ALL {
+ @Override
+ public boolean propagatesViaParameters(IRequestHandler handler)
+ {
+ return true;
+ }
+ };
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
new file mode 100644
index 0000000..690710b
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
@@ -0,0 +1,347 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
+import javax.inject.Inject;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.Component;
+import org.apache.wicket.MetaDataKey;
+import org.apache.wicket.Page;
+import org.apache.wicket.core.request.handler.BufferedResponseRequestHandler;
+import org.apache.wicket.core.request.handler.IPageClassRequestHandler;
+import org.apache.wicket.core.request.handler.IPageRequestHandler;
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.IRequestHandlerDelegate;
+import org.apache.wicket.request.Url;
+import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
+import org.apache.wicket.request.cycle.IRequestCycleListener;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.request.resource.PackageResourceReference;
+import org.apache.wicket.util.lang.Args;
+import org.apache.wicket.util.visit.IVisit;
+import org.apache.wicket.util.visit.IVisitor;
+import org.apache.wicket.util.visit.Visits;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A request cycle listener that takes care of propagating persistent
+ * conversations.
+ *
+ * @see ConversationScoped
+ *
+ * @author igor
+ */
+public class ConversationPropagator extends AbstractRequestCycleListener
+{
+ private static final Logger logger = LoggerFactory.getLogger(ConversationPropagator.class);
+
+ private static final MetaDataKey<Boolean> CONVERSATION_STARTED_KEY = new MetaDataKey<Boolean>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
+
+ private static final MetaDataKey<String> CONVERSATION_ID_KEY = new MetaDataKey<String>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
+
+ public static final String CID = "cid";
+
+ /** propagation mode to use */
+ private final IConversationPropagation propagation;
+
+ private final Application application;
+
+ @Inject
+ private Conversation conversation;
+
+ @Inject
+ private AutoConversation autoConversation;
+
+ /**
+ * Constructor
+ *
+ * @param container
+ * @param propagation
+ */
+ public ConversationPropagator(Application application, IConversationPropagation propagation)
+ {
+ Args.notNull(application, "application");
+ Args.notNull(propagation, "propagation");
+
+ if (propagation == ConversationPropagation.NONE)
+ {
+ throw new IllegalArgumentException(
+ "If propagation is NONE do not set up the propagator");
+ }
+
+ this.application = application;
+ this.propagation = propagation;
+
+ NonContextual.of(ConversationPropagator.class).postConstruct(this);
+ }
+
+ public IConversationPropagation getPropagation()
+ {
+ return propagation;
+ }
+
+ @Override
+ public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
+ {
+ if (activateForHandler(handler))
+ {
+ logger.debug("Activating conversation {}", conversation.getId());
+ fireOnAfterConversationStarted(cycle);
+ }
+ }
+
+ private void fireOnAfterConversationStarted(RequestCycle cycle)
+ {
+ cycle.setMetaData(CONVERSATION_STARTED_KEY, true);
+ for (IRequestCycleListener listener : application.getRequestCycleListeners())
+ {
+ if (listener instanceof ICdiAwareRequestCycleListener)
+ {
+ ((ICdiAwareRequestCycleListener)listener).onAfterConversationActivated(cycle);
+ }
+ }
+ }
+
+ @Override
+ public void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler)
+ {
+ Page page = getPage(handler);
+
+ if (page == null)
+ {
+ return;
+ }
+
+ // apply auto semantics
+
+ autoEndIfNecessary(page, handler, conversation);
+ autoBeginIfNecessary(page, handler, conversation);
+ }
+
+ @Override
+ public void onRequestHandlerScheduled(RequestCycle cycle, IRequestHandler handler)
+ {
+ // propagate current non-transient conversation to the newly scheduled
+ // page
+ if (conversation.isTransient())
+ {
+ return;
+ }
+
+ if (propagation.propagatesViaParameters(handler))
+ {
+ logger.debug(
+ "Propagating non-transient conversation {} via page parameters of handler {}",
+ conversation.getId(), handler);
+
+ PageParameters parameters = getPageParameters(handler);
+ if (parameters != null)
+ {
+ parameters.set(CID, conversation.getId());
+ markPageWithConversationId(handler, conversation.getId());
+ }
+ }
+ }
+
+
+ @Override
+ public void onUrlMapped(RequestCycle cycle, IRequestHandler handler, Url url)
+ {
+ // no need to propagate the conversation to packaged resources, they
+ // should never change
+ if (handler instanceof ResourceReferenceRequestHandler)
+ {
+ if (((ResourceReferenceRequestHandler)handler).getResourceReference() instanceof PackageResourceReference)
+ {
+ return;
+ }
+ }
+
+ if (conversation.isTransient())
+ {
+ return;
+ }
+
+ if (propagation.propagatesViaParameters(handler))
+ {
+ logger.debug("Propagating non-transient conversation {} via url", conversation.getId());
+ url.setQueryParameter(CID, conversation.getId());
+ markPageWithConversationId(handler, conversation.getId());
+ }
+ }
+
+ @Override
+ public void onDetach(RequestCycle cycle)
+ {
+ if (!Boolean.TRUE.equals(cycle.getMetaData(CONVERSATION_STARTED_KEY)))
+ {
+ return;
+ }
+
+ logger.debug("Deactivating conversation {}", conversation.getId());
+ for (IRequestCycleListener listener : application.getRequestCycleListeners())
+ {
+ if (listener instanceof ICdiAwareRequestCycleListener)
+ {
+ ((ICdiAwareRequestCycleListener)listener).onBeforeConversationDeactivated(cycle);
+ }
+ }
+ }
+
+ /**
+ * Determines whether or not a conversation should be activated fro the
+ * specified handler. This method is used to filter out conversation
+ * activation for utility handlers such as the
+ * {@link BufferedResponseRequestHandler}
+ *
+ * @param handler
+ * @return {@code true} iff a conversation should be activated
+ */
+ protected boolean activateForHandler(IRequestHandler handler)
+ {
+ if (handler != null)
+ {
+ if (handler instanceof BufferedResponseRequestHandler)
+ {
+ // we do not care about pages that are being rendered from a
+ // buffer
+ return false;
+ }
+ }
+ return true;
+ }
+
+ protected void autoBeginIfNecessary(Page page, IRequestHandler handler,
+ Conversation conversation)
+ {
+ if (conversation == null || !conversation.isTransient() || page == null
+ || !hasConversationalComponent(page))
+ {
+ return;
+ }
+
+ // auto activate conversation
+
+ conversation.begin();
+ autoConversation.setAutomatic(true);
+
+ logger.debug("Auto-began conversation {} for page {}", conversation.getId(), page);
+ }
+
+ protected void autoEndIfNecessary(Page page, IRequestHandler handler, Conversation conversation)
+ {
+ if (conversation == null || conversation.isTransient() || page == null
+ || hasConversationalComponent(page) || autoConversation.isAutomatic() == false)
+ {
+ return;
+ }
+
+ // auto de-activate conversation
+
+ String cid = conversation.getId();
+
+ autoConversation.setAutomatic(false);
+ conversation.end();
+
+ logger.debug("Auto-ended conversation {} for page {}", cid, page);
+ }
+
+
+ protected boolean hasConversationalComponent(Page page)
+ {
+ Boolean hasConversational = Visits.visit(page, new IVisitor<Component, Boolean>()
+ {
+ @Override
+ public void component(Component object, IVisit<Boolean> visit)
+ {
+ if (object instanceof ConversationalComponent)
+ {
+ visit.stop(true);
+ }
+ }
+ });
+
+ return hasConversational == null ? false : hasConversational;
+ }
+
+ public static void markPageWithConversationId(IRequestHandler handler, String cid)
+ {
+ Page page = getPage(handler);
+ if (page != null)
+ {
+ page.setMetaData(CONVERSATION_ID_KEY, cid);
+ }
+ }
+
+ public static String getConversationIdFromPage(Page page)
+ {
+ return page.getMetaData(CONVERSATION_ID_KEY);
+ }
+
+ /**
+ * Resolves a page instance from the request handler iff the page instance
+ * is already created
+ *
+ * @param handler
+ * @return page or {@code null} if none
+ */
+ public static Page getPage(IRequestHandler handler)
+ {
+ while (handler instanceof IRequestHandlerDelegate)
+ {
+ handler = ((IRequestHandlerDelegate)handler).getDelegateHandler();
+ }
+
+ if (handler instanceof IPageRequestHandler)
+ {
+ IPageRequestHandler pageHandler = (IPageRequestHandler)handler;
+ if (pageHandler.isPageInstanceCreated())
+ {
+ return (Page)pageHandler.getPage();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Resolves page parameters from a request handler
+ *
+ * @param handler
+ * @return page parameters or {@code null} if none
+ */
+ protected PageParameters getPageParameters(IRequestHandler handler)
+ {
+ if (handler instanceof IPageClassRequestHandler)
+ {
+ IPageClassRequestHandler pageHandler = (IPageClassRequestHandler)handler;
+ return pageHandler.getPageParameters();
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java
new file mode 100644
index 0000000..e041a87
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+/**
+ * Marks a component that requires a conversation. This marker is used by the automatic conversation
+ * management feature ({@link CdiConfiguration#setAutoConversationManagement(boolean)}) to
+ * automatically begin and end conversations based on the presence of these components in the
+ * component hierarchy of pages (can be applied to the page itself).
+ *
+ * @author igor
+ */
+public interface ConversationalComponent
+{
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEvent.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEvent.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEvent.java
new file mode 100644
index 0000000..ac99ec3
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEvent.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+/**
+ * Fired when request cycle is detached
+ *
+ * @author igor
+ *
+ */
+public class DetachEvent
+{
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java
new file mode 100644
index 0000000..601b155
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+
+import org.apache.wicket.MetaDataKey;
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Request cycle listener that fires the {@link DetachEvent} event
+ *
+ * @author igor
+ *
+ */
+public class DetachEventEmitter extends AbstractRequestCycleListener
+{
+ private static final Logger logger = LoggerFactory.getLogger(DetachEventEmitter.class);
+
+ private static final MetaDataKey<Boolean> DETACH_SCHEDULED_KEY = new MetaDataKey<Boolean>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
+
+ @Inject
+ Event<DetachEvent> detachEvent;
+
+ /**
+ * Constructor
+ */
+ public DetachEventEmitter()
+ {
+ NonContextual.of(DetachEventEmitter.class).postConstruct(this);
+ }
+
+ @Override
+ public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
+ {
+ // this is a wicket request, schedule detach event to be fired
+
+ cycle.setMetaData(DETACH_SCHEDULED_KEY, true);
+ }
+
+ @Override
+ public void onDetach(RequestCycle cycle)
+ {
+ if (Boolean.TRUE.equals(cycle.getMetaData(DETACH_SCHEDULED_KEY)))
+ {
+ logger.debug("Firing Detach event {}", cycle.getRequest().getUrl());
+
+ detachEvent.fire(new DetachEvent());
+
+ cycle.setMetaData(DETACH_SCHEDULED_KEY, null);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java
new file mode 100644
index 0000000..d3ded47
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.request.cycle.IRequestCycleListener;
+import org.apache.wicket.request.cycle.RequestCycle;
+
+public interface ICdiAwareRequestCycleListener extends IRequestCycleListener
+{
+ /**
+ * Called right after a conversation context for this request is activated
+ *
+ * @param cycle
+ * request cycle
+ */
+ void onAfterConversationActivated(RequestCycle cycle);
+
+ /**
+ * Called right before the current conversation context is deactivated
+ *
+ * @param cycle
+ * request cycle
+ */
+ void onBeforeConversationDeactivated(RequestCycle cycle);
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java
new file mode 100644
index 0000000..09e39a9
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.request.IRequestHandler;
+
+/**
+ * A strategy that specifies how conversations should be propagated between pages/resources.
+ * {@link ConversationPropagation} provides sensible default implementations of this interface.
+ *
+ * @author papegaaij
+ */
+public interface IConversationPropagation
+{
+ /**
+ * Indicates if the conversation should be propagated via url-parameters for the given request
+ * handler. This can either be a get parameter in a rendered url, or via page parameters.
+ *
+ * @param handler
+ * The current request handler
+ * @return true if the conversation should be propagated for the given request handler.
+ */
+ public boolean propagatesViaParameters(IRequestHandler handler);
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/NonContextual.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/NonContextual.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/NonContextual.java
new file mode 100644
index 0000000..4dea0ac
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/NonContextual.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+import org.apache.wicket.util.collections.ClassMetaCache;
+
+/**
+ * Manages lifecycle of non-contextual (non-CDI-managed) objects
+ *
+ * @param <T>
+ * @author igor
+ */
+public class NonContextual<T>
+{
+ private static final Object lock = new Object();
+ private static volatile Map<BeanManager, ClassMetaCache<NonContextual<?>>> cache = Collections
+ .emptyMap();
+
+ final InjectionTarget<T> it;
+
+ /**
+ * Undeploys specified bean manager from cache
+ *
+ * @param beanManager
+ */
+ public static void undeploy()
+ {
+ if (cache.containsKey(BeanManagerLookup.lookup()))
+ {
+ synchronized (lock)
+ {
+ // copy-on-write the cache
+ Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>(
+ cache);
+ newCache.remove(BeanManagerLookup.lookup());
+ cache = Collections.unmodifiableMap(newCache);
+ }
+ }
+ }
+
+ /**
+ * Factory method for creating noncontextual instances
+ *
+ * @param <T>
+ * @param clazz
+ * @param manager
+ * @return
+ */
+ public static <T> NonContextual<T> of(Class<? extends T> clazz)
+ {
+ ClassMetaCache<NonContextual<?>> meta = getCache();
+
+ @SuppressWarnings("unchecked")
+ NonContextual<T> nc = (NonContextual<T>)meta.get(clazz);
+
+ if (nc == null)
+ {
+ nc = new NonContextual<T>(clazz);
+ meta.put(clazz, nc);
+ }
+ return nc;
+ }
+
+ private static ClassMetaCache<NonContextual<?>> getCache()
+ {
+ ClassMetaCache<NonContextual<?>> meta = cache.get(BeanManagerLookup.lookup());
+ if (meta == null)
+ {
+ synchronized (lock)
+ {
+ BeanManager manager = BeanManagerLookup.lookup();
+ meta = cache.get(manager);
+ if (meta == null)
+ {
+ meta = new ClassMetaCache<NonContextual<?>>();
+
+ // copy-on-write the cache
+ Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>(
+ cache);
+ newCache.put(manager, meta);
+ cache = Collections.unmodifiableMap(newCache);
+ }
+ }
+ }
+ return meta;
+ }
+
+ @SuppressWarnings("unchecked")
+ private NonContextual(Class<? extends T> clazz)
+ {
+ BeanManager manager = BeanManagerLookup.lookup();
+ AnnotatedType<? extends T> type = manager.createAnnotatedType(clazz);
+ this.it = (InjectionTarget<T>)manager.createInjectionTarget(type);
+ }
+
+ /**
+ * Injects the instance and calls any {@link PostConstruct} methods
+ *
+ * @param instance
+ */
+ public void postConstruct(T instance)
+ {
+ CreationalContext<T> cc = BeanManagerLookup.lookup().createCreationalContext(null);
+ it.inject(instance, cc);
+ it.postConstruct(instance);
+ }
+
+ /**
+ * Injects the instance
+ *
+ * @param instance
+ */
+ public void inject(T instance)
+ {
+ CreationalContext<T> cc = BeanManagerLookup.lookup().createCreationalContext(null);
+ it.inject(instance, cc);
+ }
+
+ /**
+ * Calls any {@link PreDestroy} methods and destroys any injected
+ * dependencies that need to be destroyed.
+ *
+ * @param instance
+ */
+ public void preDestroy(T instance)
+ {
+ it.preDestroy(instance);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/SessionInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/SessionInjector.java b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/SessionInjector.java
new file mode 100644
index 0000000..a6fb4d2
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/SessionInjector.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.ISessionListener;
+import org.apache.wicket.Session;
+
+/**
+ * Injects components with CDI dependencies
+ *
+ * @author igor
+ *
+ */
+class SessionInjector extends AbstractInjector implements ISessionListener
+{
+ /**
+ * Constructor
+ */
+ public SessionInjector()
+ {
+ }
+
+ @Override
+ public void onCreated(Session session)
+ {
+ postConstruct(session);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/main/resources/META-INF/beans.xml b/wicket-experimental/wicket-cdi-1.1/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..6a2f1ec
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
+ version="1.1" bean-discovery-mode="annotated" />
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/WicketTestCase.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/WicketTestCase.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/WicketTestCase.java
new file mode 100644
index 0000000..eaed456
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/WicketTestCase.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket;
+
+import org.apache.wicket.behavior.AbstractAjaxBehavior;
+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.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+
+/**
+ * Base class for tests which require comparing wicket response with a file.
+ * <p>
+ * To create/replace the expected result file with the new content, define the system property like
+ * -Dwicket.replace.expected.results=true
+ */
+public abstract class WicketTestCase extends Assert
+{
+ /** */
+ protected WicketTester tester;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Before
+ public void commonBefore()
+ {
+ // make sure no leaked threadlocals are present
+ ThreadContext.detach();
+
+ WebApplication application = newApplication();
+ tester = newWicketTester(application);
+ }
+
+ /**
+ * @return the application that should be used for the test
+ */
+ protected WebApplication newApplication()
+ {
+ return new MockApplication();
+ }
+
+ /**
+ * In case you need to subclass WicketTester and want to be independent on possible changes in
+ * setUp().
+ *
+ * @param app
+ * @return WIcketTester
+ */
+ protected WicketTester newWicketTester(final WebApplication app)
+ {
+ return new WicketTester(app);
+ }
+
+ /**
+ *
+ */
+ @After
+ public void commonAfter()
+ {
+ tester.destroy();
+ }
+
+ /**
+ * Use <code>-Dwicket.replace.expected.results=true</code> to automatically replace the expected
+ * output file.
+ *
+ * @param <T>
+ *
+ * @param pageClass
+ * @param filename
+ * @throws Exception
+ */
+ protected <T extends Page> void executeTest(final Class<T> pageClass, final String filename)
+ throws Exception
+ {
+ tester.executeTest(getClass(), pageClass, filename);
+ }
+
+ /**
+ * Use <code>-Dwicket.replace.expected.results=true</code> to automatically replace the expected
+ * output file.
+ *
+ * @param page
+ * @param filename
+ * @throws Exception
+ */
+ protected void executeTest(final Page page, final String filename) throws Exception
+ {
+ tester.executeTest(getClass(), page, filename);
+ }
+
+ /**
+ * Use <code>-Dwicket.replace.expected.results=true</code> to automatically replace the expected
+ * output file.
+ *
+ * @param <T>
+ *
+ * @param pageClass
+ * @param parameters
+ * @param filename
+ * @throws Exception
+ */
+ protected <T extends Page> void executeTest(final Class<T> pageClass,
+ PageParameters parameters, final String filename) throws Exception
+ {
+ tester.executeTest(getClass(), pageClass, parameters, filename);
+ }
+
+ /**
+ *
+ * @param component
+ * @param filename
+ * @throws Exception
+ */
+ protected void executeListener(final Component component, final String filename)
+ throws Exception
+ {
+ tester.executeListener(getClass(), component, filename);
+ }
+
+ /**
+ *
+ * @param behavior
+ * @param filename
+ * @throws Exception
+ */
+ protected void executeBehavior(final AbstractAjaxBehavior behavior, final String filename)
+ throws Exception
+ {
+ tester.executeBehavior(getClass(), behavior, filename);
+ }
+
+ /**
+ * Returns the current Maven build directory taken from the <tt>basedir</tt> system property, or
+ * null if not set
+ *
+ * @return path with a trailing slash
+ */
+ public String getBasedir()
+ {
+ return WicketTester.getBasedir();
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
new file mode 100644
index 0000000..e612055
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import java.util.Arrays;
+
+import org.apache.wicket.util.license.ApacheLicenseHeaderTestCase;
+
+/**
+ * Test that the license headers are in place in this project. The tests are run
+ * from {@link ApacheLicenseHeaderTestCase}, but you can add project specific
+ * tests here if needed.
+ *
+ * @author Frank Bille Jensen (frankbille)
+ */
+public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase
+{
+ /**
+ * Construct.
+ */
+ public ApacheLicenceHeaderTest()
+ {
+ xmlIgnore.add(".settings");
+ xmlIgnore.add("src/main/resources/META-INF/beans.xml");
+ xmlPrologIgnore = Arrays.asList("src");
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
new file mode 100644
index 0000000..7e89c10
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.cdi.testapp.TestConversationPage;
+import org.apache.wicket.cdi.testapp.TestPage;
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Test;
+
+/**
+ * @author jsarman
+ */
+public class CdiConfigurationTest extends WicketCdiTestCase
+{
+ @Test
+ public void testApplicationScope()
+ {
+ configure(new CdiConfiguration());
+ tester.startPage(TestPage.class);
+ tester.assertLabel("appscope", "Test ok");
+ }
+
+ @Test
+ public void testConversationScope()
+ {
+ configure(new CdiConfiguration());
+ tester.startPage(TestConversationPage.class);
+ for (int i = 0; i < 20; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ }
+
+ @Test(expected = Exception.class)
+ public void testConfigureTwice()
+ {
+ configure(new CdiConfiguration());
+ new CdiConfiguration().configure(tester.getApplication());
+ }
+
+ @Test
+ public 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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
new file mode 100644
index 0000000..d827b11
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import org.apache.wicket.cdi.testapp.TestConversationPage;
+import org.apache.wicket.cdi.testapp.TestConversationalPage;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * @author jsarman
+ */
+public class ConversationPropagatorTest extends WicketCdiTestCase
+{
+ @Test
+ @Ignore("Testcase and auto conversations do not match")
+ public void testAutoConversationNonBookmarkable()
+ {
+ configure(new CdiConfiguration());
+
+ tester.startPage(TestConversationalPage.class);
+ int i;
+ for (i = 0; i < 3; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ tester.clickLink("next");
+ // at this point counter = 3, auto conversation is still enabled and
+ // remains enabled, because TestConversationalPage is part of this
+ // request
+ for (; i < 6; i++)
+ {
+ // first iteration: i == 3, counter == 3, conversation active
+ // second iteration: i == 4, counter == 4, conversation transient
+ // third iteration: i == 5, counter == 1: FAIL
+ tester.assertLabel("count", i + "");
+
+ // first iteration: conversation is still long-running, counter is
+ // incremented, after which auto conversation is disabled and the
+ // conversation ended
+
+ // second iteration: transient conversation, counter starts at 1,
+ // conversation remains transient
+ tester.clickLink("increment");
+
+ }
+
+ }
+
+ @Test
+ @Ignore("Testcase and auto conversations do not match")
+ public void testAutoConversationBookmarkable()
+ {
+ configure(new CdiConfiguration());
+
+ tester.startPage(TestConversationalPage.class,
+ new PageParameters().add("pageType", "bookmarkable"));
+
+ int i;
+ for (i = 0; i < 3; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ tester.clickLink("next");
+ // The conversation should auto end and not create another one
+ // so the next page just keeps getting 1 because the conversationscoped
+ // bean
+ // doesnt persist across requests.
+ for (i = 0; i < 3; i++)
+ {
+ tester.clickLink("increment");
+ tester.assertLabel("count", 1 + "");
+ }
+ }
+
+ @Test
+ public void testPropagationAllNonBookmarkable()
+ {
+ configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL));
+
+ tester.startPage(TestConversationPage.class);
+ int i;
+ for (i = 0; i < 3; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ tester.clickLink("next");
+ for (; i < 6; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+
+ }
+
+ @Test
+ public void testPropagationAllBookmarkable()
+ {
+ configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL));
+
+ tester.startPage(TestConversationPage.class,
+ new PageParameters().add("pageType", "bookmarkable"));
+ int i;
+ for (i = 0; i < 3; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ tester.clickLink("next");
+ for (; i < 6; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+
+ }
+
+ @Test
+ public void testPropagationNone()
+ {
+ configure(new CdiConfiguration().setPropagation(ConversationPropagation.NONE));
+
+ tester.startPage(TestConversationPage.class);
+ int i;
+ for (i = 0; i < 3; i++)
+ {
+ tester.clickLink("increment");
+ tester.assertLabel("count", "1");
+ }
+ tester.clickLink("next");
+ for (; i < 6; i++)
+ {
+ tester.clickLink("increment");
+ tester.assertLabel("count", "1");
+ }
+
+ }
+
+ @Test
+ @Ignore("Testcase and auto conversations do not match")
+ public void testGlobalAutoSettingNonBookmarkable()
+ {
+ configure(new CdiConfiguration());
+
+ tester.startPage(TestConversationPage.class, new PageParameters().add("auto", true));
+ int i;
+ for (i = 0; i < 3; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ tester.clickLink("next");
+ for (; i < 6; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ }
+
+ @Test
+ @Ignore("Testcase and auto conversations do not match")
+ public void testGlobalAutoSettingBookmarkable()
+ {
+ configure(new CdiConfiguration());
+
+ tester.startPage(TestConversationPage.class,
+ new PageParameters().add("auto", true).add("pageType", "bookmarkable"));
+ int i;
+ for (i = 0; i < 3; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ tester.clickLink("next");
+ for (i = 0; i < 3; i++)
+ {
+ tester.assertLabel("count", i + "");
+ tester.clickLink("increment");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
new file mode 100644
index 0000000..ef862c6
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi;
+
+import javax.inject.Inject;
+
+import org.apache.wicket.WicketTestCase;
+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.cdi.util.tester.CdiWicketTester;
+import org.apache.wicket.cdi.util.tester.ContextManager;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.util.tester.WicketTester;
+import org.jglue.cdiunit.AdditionalClasses;
+import org.jglue.cdiunit.CdiRunner;
+import org.junit.After;
+import org.junit.runner.RunWith;
+
+/**
+ * @author jsarman
+ */
+@RunWith(CdiRunner.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 })
+public abstract class WicketCdiTestCase extends WicketTestCase
+{
+ @Inject
+ private ContextManager contextManager;
+
+ @Override
+ protected WicketTester newWicketTester(WebApplication app)
+ {
+ return new CdiWicketTester(app);
+ }
+
+ public void configure(CdiConfiguration configuration)
+ {
+ configuration.configure(tester.getApplication());
+ }
+
+ @After
+ public void end()
+ {
+ if (contextManager.isRequestActive())
+ {
+ contextManager.deactivateContexts();
+ contextManager.destroy();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
new file mode 100644
index 0000000..b36f8a7
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi.testapp;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+
+/**
+ * @author jsarman
+ */
+@ApplicationScoped
+public class TestAppScope
+{
+
+ public String test()
+ {
+ return "Test ok";
+ }
+
+ public @Produces
+ @TestQualifier
+ String testString()
+ {
+ return "Test String";
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
new file mode 100644
index 0000000..7b82203
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi.testapp;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.protocol.http.WebApplication;
+
+/**
+ * @author jsarman
+ */
+public class TestApplication extends WebApplication
+{
+
+ @Override
+ public Class<? extends Page> getHomePage()
+ {
+ return TestPage.class;
+ }
+
+ @Override
+ protected void init()
+ {
+ super.init();
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
new file mode 100644
index 0000000..1bd8656
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi.testapp;
+
+import javax.inject.Inject;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.cdi.CdiConfiguration;
+import org.apache.wicket.protocol.http.WebApplication;
+
+/**
+ * @author jsarman
+ */
+public class TestCdiApplication extends WebApplication
+{
+
+ @Inject
+ @TestQualifier
+ String testString;
+
+
+ @Override
+ public Class<? extends Page> getHomePage()
+ {
+ return TestPage.class;
+ }
+
+ @Override
+ protected void init()
+ {
+ super.init();
+ new CdiConfiguration().configure(this);
+ }
+
+ public String getInjectedTestString()
+ {
+ return testString;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
new file mode 100644
index 0000000..ef61441
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.cdi.testapp;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.enterprise.context.ConversationScoped;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author jsarman
+ */
+@ConversationScoped
+public class TestConversationBean implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = LoggerFactory.getLogger(TestConversationBean.class);
+
+ private AtomicInteger counter = new AtomicInteger();
+
+ public int getCount()
+ {
+ logger.debug("Count = {}", counter.get());
+ return counter.get();
+ }
+
+ public void increment()
+ {
+
+ counter.incrementAndGet();
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/ecf2c9fe/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
new file mode 100644
index 0000000..e7f3de7
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html xmlns:wicket>
+<head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+</head>
+<body>
+<span wicket:id="count">100</span>
+<a wicket:id="increment">increment</a>
+<a wicket:id="next">Reset</a>
+</body>
+</html>