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/11 09:36:22 UTC
[2/3] Merged pull request #50
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java
index 09aa73c..e832347 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java
@@ -17,9 +17,11 @@
package org.apache.wicket.cdi;
import java.io.Serializable;
+
import javax.enterprise.context.SessionScoped;
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;
@@ -29,9 +31,8 @@ import org.slf4j.LoggerFactory;
/**
* Request cycle listener that fires the {@link DetachEvent} event
- *
+ *
* @author igor
- *
*/
@SessionScoped
public class DetachEventEmitter extends AbstractRequestCycleListener implements Serializable
@@ -46,14 +47,14 @@ public class DetachEventEmitter extends AbstractRequestCycleListener implements
@Inject
Event<DetachEvent> detachEvent;
-
+
/**
* Constructor
- *
+ *
* @param container
*/
public DetachEventEmitter()
- {
+ {
}
@Override
@@ -72,7 +73,7 @@ public class DetachEventEmitter extends AbstractRequestCycleListener implements
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/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java
deleted file mode 100644
index c8cb1ca..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java
index 154b077..34077fc 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java
@@ -22,7 +22,7 @@ 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
@@ -30,11 +30,9 @@ public interface IConversationPropagation
/**
* Indicates if the conversation should be propagated via page metadata (on an instance) for the
* given page and request handler.
- *
- * @param page
- * The page on which the tag will be set.
- * @param handler
- * The current request handler
+ *
+ * @param page The page on which the tag will be set.
+ * @param handler The current request handler
* @return true if the conversation should be propagated to the given page instance.
*/
public boolean propagatesViaPage(Page page, IRequestHandler handler);
@@ -42,9 +40,8 @@ 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
+ *
+ * @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/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/INonContextualManager.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/INonContextualManager.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/INonContextualManager.java
index ab95807..47898ec 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/INonContextualManager.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/INonContextualManager.java
@@ -23,23 +23,22 @@ import org.apache.wicket.Component;
/**
* Manages lifecycle of non-contextual objects like {@link Component} instances, etc
- *
+ *
* @author igor
- *
*/
public interface INonContextualManager
{
/**
* Inject a noncontextual instance
- *
+ *
* @param <T>
* @param instance
*/
<T> void inject(T instance);
-
+
/**
* Inject a noncontextual instance and invokes any {@link PostConstruct} callbacks
- *
+ *
* @param <T>
* @param instance
*/
@@ -47,7 +46,7 @@ public interface INonContextualManager
/**
* Invokes any {@link PreDestroy} callbacks and cleans up
- *
+ *
* @param <T>
* @param instance
*/
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IgnoreList.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IgnoreList.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IgnoreList.java
index 9b106fb..becf3ee 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IgnoreList.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/IgnoreList.java
@@ -21,17 +21,18 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+
import javax.inject.Qualifier;
/**
- * Qualifier for injecting the Ignore Package List
- *
+ * Qualifier for injecting the Ignore Package List
+ *
* @author jsarman
*/
@Qualifier
-@Target( { ElementType.TYPE,ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD })
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
-public @interface IgnoreList
+public @interface IgnoreList
{
-
+
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextual.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextual.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextual.java
index 1112f4f..4dea0ac 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextual.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextual.java
@@ -32,17 +32,17 @@ import org.apache.wicket.util.collections.ClassMetaCache;
/**
* Manages lifecycle of non-contextual (non-CDI-managed) objects
*
- * @author igor
- *
* @param <T>
+ * @author igor
*/
-public class NonContextual <T>
+public class NonContextual<T>
{
private static final Object lock = new Object();
- private static volatile Map<BeanManager, ClassMetaCache<NonContextual<?>>> cache = Collections.emptyMap();
+ private static volatile Map<BeanManager, ClassMetaCache<NonContextual<?>>> cache = Collections
+ .emptyMap();
final InjectionTarget<T> it;
-
+
/**
* Undeploys specified bean manager from cache
*
@@ -56,7 +56,7 @@ public class NonContextual <T>
{
// copy-on-write the cache
Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>(
- cache);
+ cache);
newCache.remove(BeanManagerLookup.lookup());
cache = Collections.unmodifiableMap(newCache);
}
@@ -101,7 +101,7 @@ public class NonContextual <T>
// copy-on-write the cache
Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>(
- cache);
+ cache);
newCache.put(manager, meta);
cache = Collections.unmodifiableMap(newCache);
}
@@ -129,7 +129,7 @@ public class NonContextual <T>
it.inject(instance, cc);
it.postConstruct(instance);
}
-
+
/**
* Injects the instance
*
@@ -142,8 +142,8 @@ public class NonContextual <T>
}
/**
- * Calls any {@link PreDestroy} methods and destroys any injected dependencies that need to be
- * destroyed.
+ * Calls any {@link PreDestroy} methods and destroys any injected
+ * dependencies that need to be destroyed.
*
* @param instance
*/
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextualManager.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextualManager.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextualManager.java
index 9289f9d..1004feb 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextualManager.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/NonContextualManager.java
@@ -24,19 +24,18 @@ import org.apache.wicket.util.lang.Args;
/**
* Default implementation of {@link INonContextualManager} using {@link NonContextual} helper
- *
+ *
* @author igor
- *
*/
@ApplicationScoped
class NonContextualManager implements INonContextualManager
{
-
+
/**
* Constructor
*/
public NonContextualManager()
- {
+ {
}
/**
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Propagation.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Propagation.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Propagation.java
index 0fb1c30..e752346 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Propagation.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Propagation.java
@@ -20,16 +20,16 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+
import javax.inject.Qualifier;
/**
- * Qualifier used to inject the Propagation Method
- *
+ * Qualifier used to inject the Propagation Method
+ *
* @author jsarman
- *
*/
@Qualifier
-@Target( { ElementType.TYPE,ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD })
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Propagation
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/SessionInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/SessionInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/SessionInjector.java
index 4bfb433..c2f0bf2 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/SessionInjector.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/SessionInjector.java
@@ -23,9 +23,8 @@ import org.apache.wicket.Session;
/**
* Injects components with CDI dependencies
- *
+ *
* @author igor
- *
*/
@ApplicationScoped
class SessionInjector extends AbstractInjector<Session> implements ISessionListener
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/WicketApp.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/WicketApp.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/WicketApp.java
new file mode 100644
index 0000000..0d3ebb4
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/WicketApp.java
@@ -0,0 +1,49 @@
+/*
+ * 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 static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Typed;
+import javax.inject.Qualifier;
+
+import org.apache.wicket.protocol.http.WebApplication;
+
+/**
+ * Bean Qualifier for Cdi enable WebApplication. This Qualifier allows for the WebApplication
+ * to be named so that the CdiApplicationFactory can select the WebApplication when multiple
+ * WebApplication exist in the ClassLoader. This Annotation also marks the WebApplication as Dependent.
+ * This prevents the WebApplication from being proxied, which will cause failures in an EE container.
+ *
+ * @author jsarman
+ */
+@Qualifier
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
+@Retention(RUNTIME)
+@Documented
+@Dependent
+@Typed(WebApplication.class)
+public @interface WicketApp
+{
+ String value() default "";
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/AbstractInjectorTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/AbstractInjectorTest.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/AbstractInjectorTest.java
new file mode 100644
index 0000000..edff13f
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/AbstractInjectorTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.Any;
+import javax.inject.Inject;
+
+import org.junit.Test;
+
+/**
+ * @author jsarman
+ */
+public class AbstractInjectorTest extends WicketCdiTestCase
+{
+
+ @Inject
+ ConversationPropagator conversationPropagator;
+ @Inject
+ @Any
+ AbstractInjector abstractInjector;
+
+
+ @Test
+ public void testIgnore()
+ {
+ CdiConfiguration.get().addClassesToIgnore(Object.class);
+ assertTrue(abstractInjector.ignore(Object.class));
+
+ CdiConfiguration.get().removeClassesToIgnore(Object.class);
+ assertFalse(abstractInjector.ignore(Object.class));
+
+ CdiConfiguration.get().addPackagesToIgnore("java.lang");
+ assertTrue(abstractInjector.ignore(Object.class));
+ assertTrue(abstractInjector.ignore(Runtime.class));
+
+ CdiConfiguration.get().removePackagesToIgnore("java.lang");
+ assertFalse(abstractInjector.ignore(Object.class));
+ assertFalse(abstractInjector.ignore(Runtime.class));
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
index 92efb73..b0d574b 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java
@@ -23,7 +23,7 @@ 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
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
index 5b0bed6..7ac3be9 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
@@ -16,33 +16,57 @@
*/
package org.apache.wicket.cdi;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+
import javax.inject.Inject;
-import org.apache.wicket.cdi.testapp.TestAppScope;
-import org.apache.wicket.cdi.testapp.TestConversationBean;
+import org.apache.wicket.cdi.testapp.TestCdiAdditionApplication;
+import org.apache.wicket.cdi.testapp.TestCdiApplication;
import org.apache.wicket.cdi.testapp.TestConversationPage;
+import org.apache.wicket.cdi.testapp.TestPage;
+import org.apache.wicket.cdi.util.tester.CdiWicketTester;
+import org.apache.wicket.util.tester.WicketTester;
import org.jglue.cdiunit.AdditionalClasses;
+import org.junit.Ignore;
import org.junit.Test;
/**
* @author jsarman
*/
-@AdditionalClasses({TestAppScope.class, TestConversationBean.class})
+@AdditionalClasses({ TestCdiAdditionApplication.class })
public class CdiConfigurationTest extends WicketCdiTestCase
{
+
@Inject
ConversationPropagator conversationPropagator;
+ @Inject
+ ComponentInjector componentInjector;
+ @Inject
+ CdiConfiguration cdiConfiguration;
+
+ @Override
+ public void init()
+ {
+
+ }
+
@Test
public void testApplicationScope()
{
- tester.startPage(tester.getApplication().getHomePage());
+ CdiWicketTester tester = getTester();
+ tester.startPage(TestPage.class);
tester.assertLabel("appscope", "Test ok");
}
@Test
public void testConversationScope()
{
+ CdiWicketTester tester = getTester();
tester.startPage(TestConversationPage.class);
for (int i = 0; i < 20; i++)
{
@@ -51,27 +75,174 @@ public class CdiConfigurationTest extends WicketCdiTestCase
}
}
+ @SuppressWarnings("deprecation")
+ @Test(expected = Exception.class)
+ public void testConfigureTwice()
+ {
+ CdiWicketTester tester = getTester();
+ tester.configure();
+ CdiConfiguration.get().configure(tester.getApplication());
+ }
+
@Test
- public void testDynamicConfigureChange()
- {
- // CdiConfiguration is configured at begin auto is false
- assertEquals(false, conversationPropagator.getAuto());
- // set auto to true in configuration
- CdiConfiguration.get().setAutoConversationManagement(true);
- assertEquals(true, conversationPropagator.getAuto());
- // Test Changing Propagation
- for (ConversationPropagation propagation : ConversationPropagation.values())
+ @SuppressWarnings("deprecation")
+ public void testDeprecatedApplicationLevelConfiguration()
+ {
+ WicketTester tester = new WicketTester();
+ CdiConfiguration config = CdiConfiguration.get();
+ config.setAutoConversationManagement(true);
+ assertTrue(config.isAutoConversationManagement());
+ config.setAutoConversationManagement(false);
+ assertFalse(config.isAutoConversationManagement());
+ config.setInjectApplication(false);
+ assertFalse(config.isInjectApplication());
+ config.setInjectApplication(true);
+ assertTrue(config.isInjectApplication());
+ config.setInjectBehaviors(false);
+ assertFalse(config.isInjectBehaviors());
+ config.setInjectBehaviors(true);
+ assertTrue(config.isInjectBehaviors());
+ config.setInjectComponents(false);
+ assertFalse(config.isInjectComponents());
+ config.setInjectComponents(true);
+ assertTrue(config.isInjectComponents());
+ config.setInjectSession(false);
+ assertFalse(config.isInjectSession());
+ config.setInjectSession(true);
+ assertTrue(config.isInjectSession());
+ for (ConversationPropagation cp : ConversationPropagation.values())
{
- CdiConfiguration.get().setPropagation(propagation);
- assertEquals(propagation, conversationPropagator.getPropagation());
+ config.setPropagation(cp);
+ assertEquals(cp, config.getPropagation());
}
+ config.configure(tester.getApplication());
+ assertTrue(config.isConfigured());
+ }
- int ignoreCnt = componentInjector.getIgnorePackages().length;
+ @Test
+ public void testFilterInitWithInitParam()
+ {
- CdiConfiguration.get().addPackagesToIgnore("test1", "test2", "test3");
- assertEquals(ignoreCnt + 3, componentInjector.getIgnorePackages().length);
+ assertEquals("Test String",
+ ((TestCdiApplication)getTester().getApplication()).getInjectedTestString());
+ }
- CdiConfiguration.get().removePackagesToIgnore("test1", "test2");
- assertEquals(ignoreCnt + 1, componentInjector.getIgnorePackages().length);
+ @Test(expected = Exception.class)
+ public void testFilterInitWithoutInitParam()
+ {
+ filterConfigProducer.removeParameter(CdiWebApplicationFactory.WICKET_APP_NAME);
+ getTester();
+ }
+
+ /**
+ * Bring up two different apps that are uniquely configured and verify they
+ * do not affect the application dependent global settings.
+ */
+ @Test
+ @Ignore("The beanmanager cannot be resolved from a different thread")
+ public void testMultiAppLoad()
+ {
+ getTester(); // Bring up app with name mockApp : the default
+ try
+ {
+ Executors.newSingleThreadExecutor().submit(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Map<String, String> params = new TreeMap<String, String>();
+ params.put(CdiWebApplicationFactory.WICKET_APP_NAME, "test2");
+ // change global default for auto to true
+ params.put(CdiWebApplicationFactory.AUTO_CONVERSATION, "true");
+
+ getTester(true, params); // bring up app 2 with name test2
+ assertTrue(cdiConfiguration.isAutoConversationManagement());
+ }
+
+ }).get();
+ }
+ catch (InterruptedException ex)
+ {
+ fail(ex.getMessage());
+ }
+ catch (ExecutionException ex)
+ {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ // now check that app1 auto is still false after app2's auto was set to
+ // true
+ assertFalse(cdiConfiguration.isAutoConversationManagement());
}
+
+ @Test
+ public void testFilterParamsBooleansTrue()
+ {
+ testFilterParamsBooleans(true);
+ }
+
+ @Test
+ public void testFilterParamsBooleansFalse()
+ {
+ testFilterParamsBooleans(true);
+ }
+
+ @Test
+ public void testFilterParamPropagationNone()
+ {
+ testFilterParamPropagation(ConversationPropagation.NONE);
+ }
+
+ @Test
+ public void testFilterParamPropagationNonBookmarkable()
+ {
+ testFilterParamPropagation(ConversationPropagation.NONBOOKMARKABLE);
+ }
+
+ @Test
+ public void testFilterParamPropagationAll()
+ {
+ testFilterParamPropagation(ConversationPropagation.ALL);
+ }
+
+ @Test(expected = Exception.class)
+ public void testInvalidNameInFilter()
+ {
+ Map<String, String> params = Collections.singletonMap(
+ CdiWebApplicationFactory.WICKET_APP_NAME, "0xDEADBEEF");
+ getTester(params);
+ }
+
+ public void testFilterParamsBooleans(Boolean val)
+ {
+ Map<String, String> params = new TreeMap<String, String>();
+ params.put(CdiWebApplicationFactory.AUTO_CONVERSATION, val.toString());
+ params.put(CdiWebApplicationFactory.INJECT_APP, val.toString());
+ params.put(CdiWebApplicationFactory.INJECT_BEHAVIOR, val.toString());
+ params.put(CdiWebApplicationFactory.INJECT_COMPONENT, val.toString());
+ params.put(CdiWebApplicationFactory.INJECT_SESSION, val.toString());
+
+ getTester(params);
+ CdiConfiguration cc = CdiConfiguration.get();
+
+ assertFalse(cc.isInjectApplication()); // This is false bacause app is
+ // injected in Filter.
+ assertEquals(val, cc.isInjectBehaviors());
+ assertEquals(val, cc.isInjectComponents());
+ assertEquals(val, cc.isInjectSession());
+ assertEquals(val, cc.isAutoConversationManagement());
+
+ }
+
+ public void testFilterParamPropagation(ConversationPropagation propagation)
+ {
+ Map<String, String> params = Collections.singletonMap(CdiWebApplicationFactory.PROPAGATION,
+ propagation.name());
+ getTester(params);
+ CdiConfiguration cc = CdiConfiguration.get();
+
+ assertEquals(propagation, cc.getPropagation());
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ComponentInjectorTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ComponentInjectorTest.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ComponentInjectorTest.java
deleted file mode 100644
index 360ff33..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ComponentInjectorTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.cdi.testapp.TestAppScope;
-import org.apache.wicket.cdi.testapp.TestConversationBean;
-import org.apache.wicket.cdi.testapp.TestQualifier;
-import org.apache.wicket.markup.html.WebComponent;
-import org.jglue.cdiunit.AdditionalClasses;
-import org.junit.Test;
-
-/**
- * Tests for ComponentInjector
- */
-@AdditionalClasses({TestAppScope.class, TestConversationBean.class})
-public class ComponentInjectorTest extends WicketCdiTestCase
-{
- /**
- * https://issues.apache.org/jira/browse/WICKET-5226
- */
- @Test
- public void innerNonStaticClass()
- {
- TestNonStaticComponent component = new TestNonStaticComponent("someId");
- assertEquals(component.dependency, "Test String");
- }
-
- /**
- * https://issues.apache.org/jira/browse/WICKET-5226
- */
- @Test
- public void innerStaticClass()
- {
- TestStaticComponent component = new TestStaticComponent("someId");
- assertEquals(component.dependency, "Test String");
- }
-
- @Test
- public void anonymousInnerClass()
- {
-
- WebComponent component = new WebComponent("someId")
- {
- private static final long serialVersionUID = 1L;
-
- @Inject
- @TestQualifier
- private String dependency;
-
- @Override
- public String toString()
- {
- return dependency;
- }
- };
- assertEquals(component.toString(), "Test String");
- }
-
- private class TestNonStaticComponent extends WebComponent
- {
- private static final long serialVersionUID = 1L;
-
- @Inject
- @TestQualifier
- private String dependency;
-
- public TestNonStaticComponent(String id)
- {
- super(id);
- }
- }
-
- private static class TestStaticComponent extends WebComponent
- {
- private static final long serialVersionUID = 1L;
-
- @Inject
- @TestQualifier
- private String dependency;
-
- public TestStaticComponent(String id)
- {
- super(id);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ConversationManagerTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ConversationManagerTest.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ConversationManagerTest.java
new file mode 100644
index 0000000..dc60f66
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ConversationManagerTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.junit.Test;
+
+/**
+ * @author jsarman
+ */
+public class ConversationManagerTest extends WicketCdiTestCase
+{
+
+ @Inject
+ ConversationManager conversationManager;
+ @Inject
+ CdiConfiguration cdiConfiguration;
+ @Inject
+ Conversation conversation;
+
+ @Test
+ public void testConverationManagerWithConversation()
+ {
+ conversation.begin();
+
+ assertTrue(testConversationManagerConversationManagement(!cdiConfiguration.isAutoConversationManagement()));
+ assertTrue(testConversationManagerConversationManagement(cdiConfiguration.isAutoConversationManagement()));
+ for (ConversationPropagation cp : ConversationPropagation.values())
+ {
+ assertTrue(testConversationManagerPropagation(cp));
+ }
+ conversation.end();
+ }
+
+ @Test
+ public void testConverationManagerWithoutConversation()
+ {
+ // Transient conversation results in conversationManager using global so test should return false
+ assertFalse(testConversationManagerConversationManagement(!cdiConfiguration.isAutoConversationManagement()));
+ for (ConversationPropagation cp : ConversationPropagation.values())
+ {
+ //Skip no change test
+ if (cp != cdiConfiguration.getPropagation())
+ {
+ // Transient conversation results in conversationManager using global is test returns false
+ assertFalse(testConversationManagerPropagation(cp));
+ }
+ }
+ }
+
+ @Test(expected = Exception.class)
+ public void testConversationManagerNullPropagation()
+ {
+ testConversationManagerPropagation(null);
+ }
+
+ public boolean testConversationManagerConversationManagement(boolean manage)
+ {
+ boolean passed;
+ Boolean globalAuto = cdiConfiguration.isAutoConversationManagement();
+ cdiConfiguration.setAutoConversationManagement(manage);
+ passed = globalAuto == cdiConfiguration.isAutoConversationManagement();
+ passed &= manage == conversationManager.getManageConversation();
+ return passed;
+ }
+
+ public boolean testConversationManagerPropagation(ConversationPropagation propagation)
+ {
+ boolean passed;
+ IConversationPropagation globalPropagation = cdiConfiguration.getPropagation();
+ cdiConfiguration.setPropagation(propagation);
+ passed = globalPropagation == cdiConfiguration.getPropagation();
+ passed &= propagation == conversationManager.getPropagation();
+ return passed;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
new file mode 100644
index 0000000..1cfa80a
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
@@ -0,0 +1,211 @@
+/*
+ * 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 javax.inject.Inject;
+
+import org.apache.wicket.cdi.testapp.TestConversationPage;
+import org.apache.wicket.cdi.testapp.TestConversationalPage;
+import org.apache.wicket.cdi.util.tester.CdiWicketTester;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.junit.Test;
+
+/**
+ * @author jsarman
+ */
+public class ConversationPropagatorTest extends WicketCdiTestCase
+{
+
+ @Inject
+ CdiConfiguration cdiConfiguration;
+
+ @Override
+ public void init()
+ {
+ //override so we do not initialize tester
+ }
+
+ @Test
+ public void testAutoConversationNonBookmarkable()
+ {
+
+ CdiWicketTester tester = getTester();
+ tester.startPage(TestConversationalPage.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 testAutoConversationBookmarkable()
+ {
+ CdiWicketTester tester = getTester();
+ 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()
+ {
+
+ Map<String, String> params =
+ Collections.singletonMap(CdiWebApplicationFactory.PROPAGATION,
+ ConversationPropagation.ALL.name());
+
+ CdiWicketTester tester = getTester(params);
+
+ 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()
+ {
+ Map<String, String> params =
+ Collections.singletonMap(CdiWebApplicationFactory.PROPAGATION,
+ ConversationPropagation.ALL.name());
+
+ CdiWicketTester tester = getTester(params);
+
+ 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()
+ {
+ Map<String, String> params =
+ Collections.singletonMap(CdiWebApplicationFactory.PROPAGATION,
+ ConversationPropagation.NONE.name());
+
+ CdiWicketTester tester = getTester(params);
+
+ 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
+ public void testGlobalAutoSettingNonBookmarkable()
+ {
+
+ Map<String, String> params = Collections.singletonMap(CdiWebApplicationFactory.AUTO_CONVERSATION, "true");
+
+ CdiWicketTester tester = getTester(params);
+ 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
+ public void testGlobalAutoSettingBookmarkable()
+ {
+ Map<String, String> params = Collections.singletonMap(CdiWebApplicationFactory.AUTO_CONVERSATION, "true");
+
+ CdiWicketTester tester = getTester(params);
+ 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/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java
index 92977ca..6b31bf3 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java
@@ -17,11 +17,13 @@
package org.apache.wicket.cdi;
import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Instance;
+import javax.enterprise.context.Conversation;
import javax.inject.Inject;
import org.apache.wicket.request.cycle.RequestCycle;
import org.jboss.weld.context.http.HttpConversationContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author jsarman
@@ -29,17 +31,10 @@ import org.jboss.weld.context.http.HttpConversationContext;
@ApplicationScoped
public class MockCdiContainer extends AbstractCdiContainer
{
+ private static final Logger logger = LoggerFactory.getLogger(MockCdiContainer.class);
@Inject
- private Instance<HttpConversationContext> conversationContextSource;
-
- @Override
- public void deactivateConversationalContext(RequestCycle cycle)
- {
- HttpConversationContext conversationContext = conversationContextSource.get();
- conversationContext.deactivate();
- conversationContext.dissociate(getRequest(cycle));
- }
+ private HttpConversationContext conversationContext;
/**
* Activates the conversational context and starts the conversation with the
@@ -51,20 +46,22 @@ public class MockCdiContainer extends AbstractCdiContainer
@Override
public void activateConversationalContext(RequestCycle cycle, String cid)
{
- HttpConversationContext conversationContext = conversationContextSource.get();
conversationContext.associate(getRequest(cycle));
if (conversationContext.isActive())
{
- // Only reactivate if transient and cid is set
- if (conversationContext.getCurrentConversation().isTransient()
- && cid != null && !cid.isEmpty())
- {
- conversationContext.deactivate();
- conversationContext.activate(cid);
- }
+ conversationContext.invalidate();
+ conversationContext.deactivate();
+ conversationContext.activate(cid);
} else
{
conversationContext.activate(cid);
}
}
+
+ @Override
+ public Conversation getCurrentConversation()
+ {
+ return conversationContext.getCurrentConversation();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
index 1f16a58..c18292e 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
@@ -16,62 +16,117 @@
*/
package org.apache.wicket.cdi;
+import java.util.Map;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.inject.Instance;
import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import org.apache.wicket.cdi.testapp.TestApplication;
-import org.apache.wicket.util.tester.WicketTester;
+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.FilterConfigProducer;
+import org.apache.wicket.cdi.util.tester.TestBehaviorInjector;
+import org.apache.wicket.cdi.util.tester.TestCdiConfiguration;
+import org.apache.wicket.cdi.util.tester.TestComponentInjector;
+import org.jglue.cdiunit.ActivatedAlternatives;
import org.jglue.cdiunit.AdditionalClasses;
import org.jglue.cdiunit.CdiRunner;
-import org.jglue.cdiunit.ContextController;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.runner.RunWith;
/**
- * Base class for all CDI unit tests
+ * @author jsarman
*/
@RunWith(CdiRunner.class)
+@ActivatedAlternatives({TestBehaviorInjector.class, TestComponentInjector.class, TestCdiConfiguration.class})
@AdditionalClasses({
+ CdiWicketTester.class,
BehaviorInjector.class,
CdiConfiguration.class,
CdiShutdownCleaner.class,
ComponentInjector.class,
ConversationExpiryChecker.class,
ConversationPropagator.class,
+ ConversationManager.class,
DetachEventEmitter.class,
NonContextualManager.class,
SessionInjector.class,
- MockCdiContainer.class})
-public class WicketCdiTestCase extends Assert
+ MockCdiContainer.class,
+ TestAppScope.class,
+ TestConversationBean.class,
+ FilterConfigProducer.class,
+ TestCdiApplication.class,
+ CdiWebApplicationFactory.class})
+public abstract class WicketCdiTestCase extends Assert
{
- protected WicketTester tester;
+ @Inject
+ private Instance<CdiWicketTester> testers;
+
+ private CdiWicketTester instantiatedTester;
@Inject
- protected ContextController contextController;
+ Conversation conversation;
@Inject
- protected ComponentInjector componentInjector;
+ FilterConfigProducer filterConfigProducer;
- @Before
- public void before()
+ public CdiWicketTester getTester()
{
- tester = new WicketTester(new TestApplication());
- prepareRequest(tester.getRequest());
+ if (instantiatedTester == null)
+ {
+ instantiatedTester = testers.get();
+ }
+ return instantiatedTester;
}
- @After
- public void after()
+ public CdiWicketTester getTester(boolean newTest)
+ {
+ if (newTest)
+ {
+ return testers.get();
+ }
+ return getTester();
+ }
+
+ public CdiWicketTester getTester(Map<String, String> customParamters)
{
- tester.destroy();
- tester = null;
- contextController.closeRequest();
+ if (instantiatedTester != null)
+ {
+ throw new IllegalStateException("The Wicket Tester is already initialized.");
+ }
+ filterConfigProducer.addParameters(customParamters);
+ return getTester();
}
- private void prepareRequest(HttpServletRequest request)
+ public CdiWicketTester getTester(boolean newTest, Map<String, String> customParamters)
{
- contextController.openRequest(request);
+ if (newTest)
+ {
+ filterConfigProducer.addParameters(customParamters);
+ return testers.get();
+ }
+ return getTester(customParamters);
}
+ @Before
+ public void init()
+ {
+ getTester();
+ }
+
+ @After
+ public void end()
+ {
+ if (instantiatedTester != null)
+ {
+ if (!conversation.isTransient())
+ {
+ conversation.end();
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
index e70d3a7..7c92a1e 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
@@ -18,6 +18,7 @@ package org.apache.wicket.cdi.testapp;
import org.apache.wicket.Page;
import org.apache.wicket.cdi.CdiConfiguration;
+import org.apache.wicket.cdi.ConversationPropagation;
import org.apache.wicket.protocol.http.WebApplication;
/**
@@ -36,7 +37,15 @@ public class TestApplication extends WebApplication
protected void init()
{
super.init();
- CdiConfiguration.get().configure(this);
+ //Configure everything to default just to hit that code.
+ CdiConfiguration.get()
+ .setAutoConversationManagement(false)
+ .setInjectApplication(true)
+ .setInjectBehaviors(true)
+ .setInjectComponents(true)
+ .setInjectSession(true)
+ .setPropagation(ConversationPropagation.NONBOOKMARKABLE)
+ .configure(this);
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestCdiAdditionApplication.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestCdiAdditionApplication.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestCdiAdditionApplication.java
new file mode 100644
index 0000000..1f8bfed
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestCdiAdditionApplication.java
@@ -0,0 +1,58 @@
+/*
+ * 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.annotation.PostConstruct;
+import javax.inject.Inject;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.cdi.WicketApp;
+import org.apache.wicket.protocol.http.WebApplication;
+
+/**
+ * @author jsarman
+ */
+@WicketApp("test2")
+public class TestCdiAdditionApplication extends WebApplication
+{
+
+ @Inject
+ @TestQualifier
+ String testString;
+
+
+ @Override
+ public Class<? extends Page> getHomePage()
+ {
+ return TestPage.class;
+ }
+
+
+ @PostConstruct
+ @Override
+ protected void init()
+ {
+ super.init();
+
+ }
+
+ public String getInjectedTestString()
+ {
+ return testString;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
new file mode 100644
index 0000000..71248c9
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
@@ -0,0 +1,58 @@
+/*
+ * 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.annotation.PostConstruct;
+import javax.inject.Inject;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.cdi.WicketApp;
+import org.apache.wicket.protocol.http.WebApplication;
+
+/**
+ * @author jsarman
+ */
+@WicketApp("mockApp")
+public class TestCdiApplication extends WebApplication
+{
+
+ @Inject
+ @TestQualifier
+ String testString;
+
+
+ @Override
+ public Class<? extends Page> getHomePage()
+ {
+ return TestPage.class;
+ }
+
+
+ @PostConstruct
+ @Override
+ protected void init()
+ {
+ super.init();
+
+ }
+
+ public String getInjectedTestString()
+ {
+ return testString;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
index 3253370..4407efb 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
@@ -21,6 +21,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.enterprise.context.ConversationScoped;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* @author jsarman
*/
@@ -28,16 +31,21 @@ import javax.enterprise.context.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/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
index b6753b3..e7f3de7 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
@@ -7,6 +7,6 @@
<body>
<span wicket:id="count">100</span>
<a wicket:id="increment">increment</a>
-<a wicket:id="reset">Reset</a>
+<a wicket:id="next">Reset</a>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
index 8357ed7..cb0138d 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
@@ -16,6 +16,8 @@
*/
package org.apache.wicket.cdi.testapp;
+import java.util.Random;
+
import javax.enterprise.context.Conversation;
import javax.inject.Inject;
@@ -23,6 +25,8 @@ import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
/**
* @author jsarman
@@ -37,11 +41,23 @@ public class TestConversationPage extends WebPage
@Inject
TestConversationBean counter;
+ Random random = new Random();
+
public TestConversationPage()
{
+ this(new PageParameters());
+ }
+
+ public TestConversationPage(final PageParameters parameters)
+ {
+ super(parameters);
- conversation.begin();
+ if (!parameters.get("auto").toBoolean())
+ {
+ conversation.begin();
+ System.out.println("Opened Conversion with id = " + conversation.getId());
+ }
add(new Label("count", new PropertyModel<Integer>(this, "counter.count")));
add(new Link<Void>("increment")
@@ -54,18 +70,20 @@ public class TestConversationPage extends WebPage
counter.increment();
}
});
- add(new Link<Void>("reset")
+ add(new Link<Void>("next")
{
private static final long serialVersionUID = 1L;
@Override
public void onClick()
{
- conversation.end();
- setResponsePage(TestPage.class);
+ String pageType = parameters.get("pageType").toString("nonbookmarkable");
+ if ("bookmarkable".equals(pageType.toLowerCase()))
+ setResponsePage(TestNonConversationalPage.class);
+ else
+ setResponsePage(new TestNonConversationalPage());
}
});
}
-
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
new file mode 100644
index 0000000..dfd545d
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<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">next</a>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
new file mode 100644
index 0000000..e421cfc
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
@@ -0,0 +1,84 @@
+/*
+ * 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.util.Random;
+
+import javax.inject.Inject;
+
+import org.apache.wicket.cdi.Conversational;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * @author jsarman
+ */
+@Conversational
+public class TestConversationalPage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = LoggerFactory.getLogger(TestConversationPage.class);
+ @Inject
+ TestConversationBean counter;
+
+ Random random = new Random();
+
+ public TestConversationalPage()
+ {
+ this(new PageParameters());
+ }
+
+
+ public TestConversationalPage(final PageParameters pp)
+ {
+ logger.debug("Starting TestConversationalPage");
+
+ add(new Label("count", new PropertyModel<Integer>(this, "counter.count")));
+
+ add(new Link<Void>("increment")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick()
+ {
+ counter.increment();
+ }
+ });
+ add(new Link<Void>("next")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick()
+ {
+ String pageType = pp.get("pageType").toString("nonbookmarkable");
+ if ("bookmarkable".equals(pageType.toLowerCase()))
+ setResponsePage(TestNonConversationalPage.class);
+ else
+ setResponsePage(new TestNonConversationalPage());
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonAutoConversationalPage.html
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonAutoConversationalPage.html b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonAutoConversationalPage.html
new file mode 100644
index 0000000..dfd545d
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonAutoConversationalPage.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<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">next</a>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonAutoConversationalPage.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonAutoConversationalPage.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonAutoConversationalPage.java
new file mode 100644
index 0000000..4380fbe
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonAutoConversationalPage.java
@@ -0,0 +1,92 @@
+/*
+ * 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.util.Random;
+
+import javax.enterprise.context.Conversation;
+import javax.inject.Inject;
+
+import org.apache.wicket.cdi.ConversationPropagation;
+import org.apache.wicket.cdi.Conversational;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * @author jsarman
+ */
+@Conversational(auto = false, prop = ConversationPropagation.ALL)
+public class TestNonAutoConversationalPage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+ private static final Logger logger = LoggerFactory.getLogger(TestConversationPage.class);
+ @Inject
+ TestConversationBean counter;
+
+ @Inject
+ Conversation conversation;
+
+ Random random = new Random();
+
+ public TestNonAutoConversationalPage()
+ {
+ this(new PageParameters());
+ }
+
+
+ public TestNonAutoConversationalPage(final PageParameters pp)
+ {
+ if (pp.get("startConveration").toBoolean(true))
+ {
+ conversation.begin();
+ }
+ logger.debug("Starting TestConversationalPage");
+
+ add(new Label("count", new PropertyModel<Integer>(this, "counter.count")));
+
+ add(new Link<Void>("increment")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick()
+ {
+ counter.increment();
+ }
+ });
+ add(new Link<Void>("next")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick()
+ {
+ String pageType = pp.get("pageType").toString("nonbookmarkable");
+ if ("bookmarkable".equals(pageType.toLowerCase()))
+ setResponsePage(TestNonConversationalPage.class);
+ else
+ setResponsePage(new TestNonConversationalPage());
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
new file mode 100644
index 0000000..9857fca
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<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>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
new file mode 100644
index 0000000..8af7bac
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
@@ -0,0 +1,59 @@
+/*
+ * 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.util.Random;
+
+import javax.inject.Inject;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.model.PropertyModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * @author jsarman
+ */
+public class TestNonConversationalPage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+ private static final Logger logger = LoggerFactory.getLogger(TestConversationPage.class);
+ @Inject
+ TestConversationBean counter;
+
+ Random random = new Random();
+
+ public TestNonConversationalPage()
+ {
+ logger.debug("Starting TestConversationalPage");
+ add(new Label("count", new PropertyModel<Integer>(this, "counter.count")));
+
+ add(new Link<Void>("increment")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick()
+ {
+ counter.increment();
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/CdiWicketTester.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/CdiWicketTester.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/CdiWicketTester.java
new file mode 100644
index 0000000..bd442e0
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/CdiWicketTester.java
@@ -0,0 +1,137 @@
+/*
+ * 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.util.tester;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.Dependent;
+import javax.inject.Inject;
+import javax.servlet.FilterConfig;
+
+import org.apache.wicket.cdi.CdiWebApplicationFactory;
+import org.apache.wicket.protocol.http.WicketFilter;
+import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.util.tester.WicketTester;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author jsarman
+ */
+@Dependent
+public class CdiWicketTester extends WicketTester
+{
+
+ private static final Logger logger = LoggerFactory.getLogger(CdiWicketTester.class);
+ @Inject
+ ContextManager contextManager;
+
+ TestCdiConfiguration cdiConfiguration;
+ FilterConfig filterConfig;
+
+
+ @Inject
+ public CdiWicketTester(TestCdiConfiguration cdiConfiguration, CdiWebApplicationFactory factory, @ConfigurationFilter final FilterConfig filterConfig)
+ {
+ super(factory.createApplication(new WicketFilter()
+ {
+
+ @Override
+ public FilterConfig getFilterConfig()
+ {
+ return filterConfig;
+ }
+
+ }));
+ this.cdiConfiguration = cdiConfiguration;
+ this.filterConfig = filterConfig;
+ }
+
+ @PostConstruct
+ public void initializeApp()
+ {
+ logger.debug("Initialized Cdi Wicket Tester");
+ cdiConfiguration.remapApplicationKey(filterConfig.getFilterName(), getApplication());
+ contextManager.activateContexts(getRequest()); //Start up contexts in case no requests are performed
+ }
+
+
+ public void configure()
+ {
+ if (!cdiConfiguration.isConfigured())
+ {
+ cdiConfiguration.configure(getApplication());
+ }
+ }
+
+ private AtomicInteger count = new AtomicInteger();
+
+ /**
+ * 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 deactivate the contexts during that time.
+ *
+ * @param forcedRequest
+ * @param forcedRequestHandler
+ * @param redirect
+ * @return
+ */
+ @Override
+ protected boolean processRequest(final MockHttpServletRequest forcedRequest,
+ final IRequestHandler forcedRequestHandler, final boolean redirect)
+ {
+ if (count.getAndIncrement() == 0)
+ {
+
+ if (getLastRequest() != null)
+ {
+ contextManager.deactivateContexts(getLastRequest());
+ } else
+ {
+ configure();//make sure we are configured for cdi
+ }
+ contextManager.activateContexts(getRequest());
+ }
+ try
+ {
+ return super.processRequest(forcedRequest, forcedRequestHandler, redirect);
+ } finally
+ {
+ count.decrementAndGet();
+ }
+ }
+
+ @PreDestroy
+ public void finish()
+ {
+ try
+ {
+ logger.debug("Destroying Cdi Wicket Tester");
+ if (getLastRequest() != null)
+ {
+ contextManager.deactivateContexts(getLastRequest());
+ }
+ contextManager.destroy(getHttpSession());
+ destroy();
+ } catch (Throwable t)
+ {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/ConfigurationFilter.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/ConfigurationFilter.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/ConfigurationFilter.java
new file mode 100644
index 0000000..d7113a8
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/ConfigurationFilter.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.util.tester;
+
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for injecting the FilterConfiguration for testing
+ *
+ * @author jsarman
+ */
+@Qualifier
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ConfigurationFilter
+{
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/ContextManager.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/ContextManager.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/ContextManager.java
new file mode 100644
index 0000000..7eec3c4
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/ContextManager.java
@@ -0,0 +1,98 @@
+/*
+ * 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.util.tester;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.jboss.weld.bean.builtin.BeanManagerProxy;
+import org.jboss.weld.servlet.HttpContextLifecycle;
+import org.jboss.weld.servlet.spi.helpers.AcceptingHttpContextActivationFilter;
+import org.jglue.cdiunit.internal.LifecycleAwareRequest;
+
+/**
+ * @author jsarman
+ */
+@ApplicationScoped
+public class ContextManager
+{
+ private HttpServletRequest currentRequest;
+
+ @Inject
+ private BeanManager beanManager;
+
+ private HttpContextLifecycle lifecycle;
+
+ private HttpSession currentSession;
+
+ @PostConstruct
+ public void setup()
+ {
+ try
+ {
+ lifecycle = new HttpContextLifecycle(BeanManagerProxy.unwrap(beanManager),
+ AcceptingHttpContextActivationFilter.INSTANCE, true, true);
+ }
+ catch (NoSuchMethodError e)
+ {
+ try
+ {
+ lifecycle = HttpContextLifecycle.class.getConstructor(BeanManager.class,
+ AcceptingHttpContextActivationFilter.class).newInstance(
+ BeanManagerProxy.unwrap(beanManager),
+ AcceptingHttpContextActivationFilter.INSTANCE);
+ }
+ catch (Exception e1)
+ {
+ throw new RuntimeException(e1);
+ }
+ }
+ lifecycle.setConversationActivationEnabled(true);
+ }
+
+ public void activateContexts(HttpServletRequest request)
+ {
+ if (currentRequest != null)
+ return;
+
+ currentRequest = new LifecycleAwareRequest(lifecycle, request, currentSession);
+ lifecycle.requestInitialized(currentRequest, null);
+ }
+
+ public void deactivateContexts(HttpServletRequest request)
+ {
+ lifecycle.requestDestroyed(currentRequest);
+ currentSession = currentRequest.getSession(false);
+ currentRequest = null;
+ }
+
+ public void destroy(HttpSession session)
+ {
+ if(currentRequest != null) {
+ currentSession = currentRequest.getSession(false);
+ }
+
+ if(currentSession != null) {
+ lifecycle.sessionDestroyed(currentSession);
+ currentSession = null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/FilterConfigProducer.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/FilterConfigProducer.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/FilterConfigProducer.java
new file mode 100644
index 0000000..4f99bf2
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/FilterConfigProducer.java
@@ -0,0 +1,62 @@
+/*
+ * 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.util.tester;
+
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.servlet.FilterConfig;
+
+/**
+ * @author jsarman
+ */
+@ApplicationScoped
+public class FilterConfigProducer
+{
+
+ TestFilterConfig config;
+
+ @PostConstruct
+ public void init()
+ {
+ config = new TestFilterConfig();
+ }
+
+ @Produces
+ @ConfigurationFilter
+ public FilterConfig getConfig()
+ {
+ return config;
+ }
+
+ public void addParameter(String paramName, String value)
+ {
+ config.put(paramName, value);
+ }
+
+ public void removeParameter(String paramName)
+ {
+ config.remove(paramName);
+ }
+
+ public void addParameters(Map<String, String> params)
+ {
+ config.putAll(params);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestBehaviorInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestBehaviorInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestBehaviorInjector.java
new file mode 100644
index 0000000..01ad94f
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestBehaviorInjector.java
@@ -0,0 +1,50 @@
+/*
+ * 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.util.tester;
+
+import java.lang.reflect.Modifier;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.Specializes;
+
+import org.apache.wicket.behavior.Behavior;
+import org.apache.wicket.cdi.BehaviorInjector;
+
+/**
+ * Injects components with CDI dependencies
+ *
+ * @author igor
+ */
+@ApplicationScoped
+@Alternative
+@Specializes
+public class TestBehaviorInjector extends BehaviorInjector
+{
+
+ @Override
+ public void onInstantiation(Behavior behavior)
+ {
+ Class instanceClass = behavior.getClass();
+ if (instanceClass.isAnonymousClass() ||
+ (instanceClass.isMemberClass() && Modifier.isStatic(instanceClass.getModifiers()) == false))
+ {
+ return;
+ }
+ inject(behavior);
+ }
+}