Repository: wicket Updated Branches: refs/heads/master 056d726a5 -> 057c402b4
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java index e041a87..16d9fc1 100644 --- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java +++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java @@ -17,14 +17,14 @@ 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). + * Marks a component that requires a conversation. This marker is used by the + * automatic conversation management feature 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/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java index 3ac27fa..b141236 100644 --- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java +++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java @@ -23,7 +23,6 @@ import org.apache.wicket.MetaDataKey; import org.apache.wicket.request.IRequestHandler; import org.apache.wicket.request.cycle.IRequestCycleListener; import org.apache.wicket.request.cycle.RequestCycle; -import org.apache.wicket.util.lang.Args; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +38,7 @@ public class DetachEventEmitter implements IRequestCycleListener private static final MetaDataKey<Boolean> DETACH_SCHEDULED_KEY = new MetaDataKey<Boolean>() { + private static final long serialVersionUID = 1L; }; @Inject @@ -46,13 +46,10 @@ public class DetachEventEmitter implements IRequestCycleListener /** * Constructor - * - * @param container */ - public DetachEventEmitter(CdiContainer container) + public DetachEventEmitter() { - Args.notNull(container, "container"); - container.getNonContextualManager().postConstruct(this); + NonContextual.of(DetachEventEmitter.class).postConstruct(this); } @Override @@ -71,7 +68,7 @@ public class DetachEventEmitter implements IRequestCycleListener 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/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java index f2086a8..b9eb1e3 100644 --- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java +++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java @@ -17,35 +17,31 @@ package org.apache.wicket.cdi; import org.apache.wicket.Page; +import org.apache.wicket.core.request.handler.IPageRequestHandler; 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. + * A strategy that specifies how conversations should be propagated between + * pages/resources. {@link ConversationPropagation} provides sensible default + * implementations of this interface. * * @author papegaaij */ +@FunctionalInterface 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 - * @return true if the conversation should be propagated to the given page instance. - */ - boolean propagatesViaPage(Page page, IRequestHandler handler); - - /** - * 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. + * Indicates if the conversation should be propagated via url-parameters for + * the given request handler and page (if any). A conversation is always + * propagated via the cid query parameter. * * @param handler * The current request handler - * @return true if the conversation should be propagated for the given request handler. + * @param page + * The page associated with the request handler, or null if the + * handler is not an {@link IPageRequestHandler}. + * @return true if the conversation should be propagated for the given + * request handler. */ - boolean propagatesViaParameters(IRequestHandler handler); + boolean propagatesVia(IRequestHandler handler, Page page); } http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/INonContextualManager.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/INonContextualManager.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/INonContextualManager.java deleted file mode 100644 index 7a7c6dc..0000000 --- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/INonContextualManager.java +++ /dev/null @@ -1,55 +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.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -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 - */ - <T> void postConstruct(T instance); - - /** - * Invokes any {@link PreDestroy} callbacks and cleans up - * - * @param <T> - * @param instance - */ - <T> void preDestroy(T instance); -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextual.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextual.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextual.java index 3a2f8c6..b596f53 100644 --- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextual.java +++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextual.java @@ -1,168 +1,164 @@ -/* - * 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 - * - * @author igor - * - * @param <T> - */ -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; - final BeanManager manager; - - /** - * Undeploys specified bean manager from cache - * - * @param beanManager - */ - public static void undeploy(BeanManager beanManager) - { - if (cache.containsKey(beanManager)) - { - synchronized (lock) - { - // copy-on-write the cache - Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<>( - cache); - newCache.remove(beanManager); - cache = Collections.unmodifiableMap(newCache); - } - } - } - - /** - * Convenience factory method for an instance, see {@link #of(Class, BeanManager). - * - * @param <T> - * @param beanManager - * @return The NonContextual for the instance's class managed by the given manager - */ - @SuppressWarnings("unchecked") - public static <T> NonContextual<T> of(T t, BeanManager beanManager) - { - // cast is necessary for Eclipse compiler :/ - return (NonContextual<T>)of(t.getClass(), beanManager); - } - - /** - * Factory method for creating noncontextual instances - * - * @param <T> - * @param clazz - * @param manager - * @return The NonContextual for the given class managed by the given manager - */ - public static <T> NonContextual<T> of(Class<? extends T> clazz, BeanManager manager) - { - ClassMetaCache<NonContextual<?>> meta = getCache(manager); - - @SuppressWarnings("unchecked") - NonContextual<T> nc = (NonContextual<T>)meta.get(clazz); - - if (nc == null) - { - nc = new NonContextual<>(manager, clazz); - meta.put(clazz, nc); - } - return nc; - } - - private static ClassMetaCache<NonContextual<?>> getCache(BeanManager manager) - { - ClassMetaCache<NonContextual<?>> meta = cache.get(manager); - if (meta == null) - { - synchronized (lock) - { - meta = cache.get(manager); - if (meta == null) - { - meta = new ClassMetaCache<>(); - - // copy-on-write the cache - Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<>( - cache); - newCache.put(manager, meta); - cache = Collections.unmodifiableMap(newCache); - } - } - } - return meta; - } - - @SuppressWarnings("unchecked") - private NonContextual(BeanManager manager, Class<? extends T> clazz) - { - this.manager = manager; - 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 = manager.createCreationalContext(null); - it.inject(instance, cc); - it.postConstruct(instance); - } - - /** - * Injects the instance - * - * @param instance - */ - public void inject(T instance) - { - CreationalContext<T> cc = manager.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); - } -} +/* + * 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 the looked up bean manager from cache + */ + 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); + } + } + } + + /** + * Convenience factory method for an instance, see {@link #of(Class). + * + * @param <T> + * @param clazz + * @return The NonContextual for the instance's class + */ + @SuppressWarnings("unchecked") + public static <T> NonContextual<T> of(T t) { + // cast is necessary for Eclipse compiler :/ + return (NonContextual<T>)of(t.getClass()); + } + + /** + * Factory method for creating non-contextual instances + * + * @param <T> + * @param clazz + * @return The NonContextual for the given class + */ + 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/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextualManager.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextualManager.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextualManager.java deleted file mode 100644 index a5c63d0..0000000 --- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/NonContextualManager.java +++ /dev/null @@ -1,78 +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.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.enterprise.inject.spi.BeanManager; - -import org.apache.wicket.util.lang.Args; - -/** - * Default implementation of {@link INonContextualManager} using {@link NonContextual} helper - * - * @author igor - * - */ -class NonContextualManager implements INonContextualManager -{ - private final BeanManager beanManager; - - /** - * Constructor - * - * @param beanManager - */ - public NonContextualManager(BeanManager beanManager) - { - Args.notNull(beanManager, "beanManager"); - - this.beanManager = beanManager; - } - - /** - * Performs dependency injection on the noncontextual instance - */ - @Override - public <T> void inject(T instance) - { - Args.notNull(instance, "instance"); - NonContextual.of(instance, beanManager).inject(instance); - } - - /** - * Performs dependency injection on the noncontextual instance and invokes any - * {@link PostConstruct} callbacks - */ - @Override - public <T> void postConstruct(T instance) - { - Args.notNull(instance, "instance"); - NonContextual.of(instance, beanManager).postConstruct(instance); - } - - /** - * Invokes any {@link PreDestroy} callbacks and cleans up any injected dependencies - */ - @Override - public <T> void preDestroy(T instance) - { - Args.notNull(instance, "instance"); - NonContextual.of(instance, beanManager).preDestroy(instance); - } - -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/SessionInjector.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/SessionInjector.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/SessionInjector.java index d81d62a..a6fb4d2 100644 --- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/SessionInjector.java +++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/SessionInjector.java @@ -29,12 +29,9 @@ class SessionInjector extends AbstractInjector implements ISessionListener { /** * Constructor - * - * @param container */ - public SessionInjector(CdiContainer container) + public SessionInjector() { - super(container); } @Override http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/resources/META-INF/beans.xml ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/main/resources/META-INF/beans.xml b/wicket-cdi/src/main/resources/META-INF/beans.xml index e69de29..6a2f1ec 100644 --- a/wicket-cdi/src/main/resources/META-INF/beans.xml +++ b/wicket-cdi/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/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java index 92efb73..3a3f7bf 100644 --- a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java @@ -21,8 +21,9 @@ 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. + * 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) */ @@ -35,6 +36,7 @@ public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase { xmlIgnore.add(".settings"); xmlIgnore.add("src/main/resources/META-INF/beans.xml"); + xmlIgnore.add("src/test/java/simplelogger.properties"); xmlPrologIgnore = Arrays.asList("src"); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java new file mode 100644 index 0000000..723db16 --- /dev/null +++ b/wicket-cdi/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.assertCount(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/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java new file mode 100644 index 0000000..275a9bc --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java @@ -0,0 +1,129 @@ +/* + * 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 org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.annotation.PreDestroy; +import javax.inject.Inject; + +import org.apache.wicket.Page; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; +import org.apache.wicket.request.IRequestHandler; +import org.apache.wicket.request.Url; +import org.apache.wicket.util.tester.WicketTester; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author jsarman + */ +public class CdiWicketTester extends WicketTester +{ + private static final Pattern COUNT_PATTERN = Pattern.compile("COUNT=x([0-9]+)x"); + private static final Logger logger = LoggerFactory.getLogger(CdiWicketTester.class); + + @Inject + ContextManager contextManager; + + public CdiWicketTester(WebApplication app) + { + super(app); + NonContextual.of(CdiWicketTester.class).inject(this); + getHttpSession().setTemporary(false); + } + + /** + * 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 (getLastRequest() != null) + { + contextManager.deactivateContexts(); + } + contextManager.activateContexts(forcedRequest == null ? getRequest() : forcedRequest); + return super.processRequest(forcedRequest, forcedRequestHandler, redirect); + } + + @Override + public Url urlFor(IRequestHandler handler) + { + Url ret = super.urlFor(handler); + final CdiConfiguration configuration = CdiConfiguration.get(getApplication()); + Page page = ConversationPropagator.getPage(handler); + if (configuration.getPropagation().propagatesVia(handler, page)) + { + if (page != null) + { + String cid = ConversationPropagator.getConversationIdFromPage(page); + ret.addQueryParameter(ConversationPropagator.CID, cid); + } + } + return ret; + } + + @PreDestroy + public void finish() + { + try + { + logger.debug("Destroying Cdi Wicket Tester"); + if (getLastRequest() != null) + { + contextManager.deactivateContexts(); + } + contextManager.destroy(); + destroy(); + } + catch (Throwable t) + { + } + } + + /** + * Asserts that the response contains the right count. This can only be done + * by parsing the markup because models only contain valid values during a + * request, not after. + * + * @param count + * TODO + */ + public void assertCount(int count) + { + assertTrue("Response does not contain a count", + getLastResponseAsString().contains("COUNT=x")); + Matcher matcher = COUNT_PATTERN.matcher(getLastResponseAsString()); + assertTrue(matcher.find()); + assertEquals(Integer.toString(count), matcher.group(1)); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ContextManager.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ContextManager.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ContextManager.java new file mode 100644 index 0000000..6a8a49e --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ContextManager.java @@ -0,0 +1,106 @@ +/* + * 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.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.module.web.servlet.HttpContextLifecycle; +import org.jboss.weld.servlet.spi.helpers.AcceptingHttpContextActivationFilter; +import org.jglue.cdiunit.internal.CdiUnitInitialListenerImpl; +import org.jglue.cdiunit.internal.servlet.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, false, 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(new CdiUnitInitialListenerImpl(), request); + lifecycle.requestInitialized(currentRequest, null); + } + + public void deactivateContexts() + { + lifecycle.requestDestroyed(currentRequest); + currentSession = currentRequest.getSession(false); + currentRequest = null; + } + + public void destroy() + { + if (currentRequest != null) + { + currentSession = currentRequest.getSession(false); + } + + if (currentSession != null) + { + lifecycle.sessionDestroyed(currentSession); + currentSession = null; + } + } + + public boolean isRequestActive() + { + return currentRequest != null; + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java new file mode 100644 index 0000000..945c9cf --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java @@ -0,0 +1,202 @@ +/* + * 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.cdi.testapp.TestConversationPage; +import org.apache.wicket.cdi.testapp.TestConversationalPage; +import org.apache.wicket.core.request.mapper.MountedMapper; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.hamcrest.CoreMatchers; +import org.junit.Test; + +/** + * @author jsarman + */ +public class ConversationPropagatorTest extends WicketCdiTestCase +{ + @Inject + Conversation conversation; + + @Test + public void testAutoConversationNonBookmarkable() + { + configure(new CdiConfiguration()); + + tester.startPage(TestConversationalPage.class); + int i; + for (i = 0; i < 3; i++) + { + tester.assertCount(i); + tester.clickLink("increment"); + } + tester.clickLink("next"); + for (; i < 6; i++) + { + tester.clickLink("increment"); + tester.assertCount(1); + } + } + + @Test + public void testAutoConversationBookmarkable() + { + configure(new CdiConfiguration()); + + tester.startPage(TestConversationalPage.class, + new PageParameters().add("pageType", "bookmarkable")); + + int i; + for (i = 0; i < 3; i++) + { + tester.assertCount(i); + tester.clickLink("increment"); + } + tester.clickLink("next"); + for (i = 0; i < 3; i++) + { + tester.clickLink("increment"); + tester.assertCount(1); + } + } + + @Test + public void testPropagationAllNonBookmarkable() + { + configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL)); + + tester.startPage(TestConversationPage.class); + int i; + for (i = 0; i < 3; i++) + { + tester.assertCount(i); + tester.clickLink("increment"); + } + tester.clickLink("next"); + for (; i < 6; i++) + { + tester.assertCount(i); + tester.clickLink("increment"); + } + } + + @Test + public void testPropagationAllHybrid() + { + configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL)); + tester.getApplication().getRootRequestMapperAsCompound().add(new MountedMapper("segment/${pageType}", TestConversationPage.class)); + + tester.startPage(TestConversationPage.class, new PageParameters().add("pageType", "hybrid")); + + int i; + for (i = 0; i < 3; i++) + { + tester.assertCount(i); + tester.clickLink("increment"); + } + tester.clickLink("next"); + for (; i < 6; i++) + { + tester.assertCount(i); + tester.clickLink("increment"); + } + } + + /** + * https://issues.apache.org/jira/browse/WICKET-6257 + */ + @Test + public void testPropagationAllHybridRefresh() + { + configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL)); + tester.getApplication().getRootRequestMapperAsCompound().add(new MountedMapper("segment/${pageType}", TestConversationPage.class)); + + tester.startPage(TestConversationPage.class, new PageParameters().add("pageType", "hybrid")); + + String pageId = tester.getLastRenderedPage().getId(); + String cid = conversation.getId(); + + tester.executeUrl("segment/hybrid?"+pageId+"&cid="+cid); + + assertThat(tester.getLastRenderedPage().getId(), CoreMatchers.is(pageId)); + } + + @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.assertCount(i); + tester.clickLink("increment"); + } + tester.clickLink("next"); + for (; i < 6; i++) + { + tester.assertCount(i); + tester.clickLink("increment"); + } + } + + @Test + public void testPropagationNonBookmarkable() + { + configure(new CdiConfiguration()); + + tester.startPage(TestConversationPage.class, + new PageParameters().add("pageType", "bookmarkable")); + int i; + for (i = 0; i < 3; i++) + { + tester.assertCount(i); + tester.clickLink("increment"); + } + tester.clickLink("next"); + for (; i < 6; i++) + { + tester.clickLink("increment"); + tester.assertCount(1); + } + } + + @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.assertCount(1); + } + tester.clickLink("next"); + for (; i < 6; i++) + { + tester.clickLink("increment"); + tester.assertCount(1); + } + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java new file mode 100644 index 0000000..3f82075 --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java @@ -0,0 +1,185 @@ +/* + * 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.Component; +import org.apache.wicket.Page; +import org.apache.wicket.ThreadContext; +import org.apache.wicket.behavior.AbstractAjaxBehavior; +import org.apache.wicket.cdi.testapp.TestAppScope; +import org.apache.wicket.cdi.testapp.TestCdiApplication; +import org.apache.wicket.cdi.testapp.TestConversationBean; +import org.apache.wicket.mock.MockApplication; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.util.tester.WicketTester; +import org.jglue.cdiunit.AdditionalClasses; +import org.jglue.cdiunit.CdiRunner; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +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, + AutoConversation.class }) +public abstract class WicketCdiTestCase extends Assert +{ + @Inject + private ContextManager contextManager; + /** */ + protected CdiWicketTester tester; + + protected CdiWicketTester 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(); + } + } + + /** + * @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(); + } + + /** + * + */ + @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/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java new file mode 100644 index 0000000..b36f8a7 --- /dev/null +++ b/wicket-cdi/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/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java new file mode 100644 index 0000000..7b82203 --- /dev/null +++ b/wicket-cdi/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/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java new file mode 100644 index 0000000..1bd8656 --- /dev/null +++ b/wicket-cdi/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/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java new file mode 100644 index 0000000..140ecdb --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java @@ -0,0 +1,56 @@ +/* + * 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 String getCountStr() + { + return "COUNT=x" + getCount() + "x"; + } + + public void increment() + { + + counter.incrementAndGet(); + + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html new file mode 100644 index 0000000..e7f3de7 --- /dev/null +++ b/wicket-cdi/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> http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java new file mode 100644 index 0000000..c6cc8bc --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.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 javax.enterprise.context.Conversation; +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.apache.wicket.request.mapper.parameter.PageParameters; + + +/** + * @author jsarman + */ +public class TestConversationPage extends WebPage +{ + private static final long serialVersionUID = 1L; + + @Inject + Conversation conversation; + + @Inject + TestConversationBean counter; + + public TestConversationPage() + { + this(new PageParameters()); + } + + public TestConversationPage(final PageParameters parameters) + { + super(parameters); + + conversation.begin(); + System.out.println("Opened Conversion with id = " + conversation.getId()); + + add(new Label("count", new PropertyModel<String>(this, "counter.countStr"))); + + 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 = parameters.get("pageType").toString("nonbookmarkable"); + if ("bookmarkable".equals(pageType.toLowerCase())) + setResponsePage(TestNonConversationalPage.class); + else if ("hybrid".equals(pageType.toLowerCase())) + setResponsePage(TestConversationPage.this); + else + setResponsePage(new TestNonConversationalPage()); + } + }); + + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html new file mode 100644 index 0000000..b3550f1 --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.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">next</a> +</body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java new file mode 100644 index 0000000..5e41fd5 --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java @@ -0,0 +1,78 @@ +/* + * 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.cdi.ConversationalComponent; +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 + */ +public class TestConversationalPage extends WebPage implements ConversationalComponent +{ + private static final long serialVersionUID = 1L; + + private static final Logger logger = LoggerFactory.getLogger(TestConversationPage.class); + @Inject + TestConversationBean counter; + + public TestConversationalPage() + { + this(new PageParameters()); + } + + + public TestConversationalPage(final PageParameters pp) + { + logger.debug("Starting TestConversationalPage"); + + add(new Label("count", new PropertyModel<String>(this, "counter.countStr"))); + + 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/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html new file mode 100644 index 0000000..fd58f2d --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html @@ -0,0 +1,11 @@ +<!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> +</body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java new file mode 100644 index 0000000..7728e81 --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java @@ -0,0 +1,55 @@ +/* + * 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.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; + + public TestNonConversationalPage() + { + logger.debug("Starting TestConversationalPage"); + add(new Label("count", new PropertyModel<String>(this, "counter.countStr"))); + + 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/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html new file mode 100644 index 0000000..4689c49 --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html xmlns:wicket> +<head> + <title></title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +</head> +<body> +<div wicket:id="appscope">Fail</div> +</body> +</html> http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java new file mode 100644 index 0000000..cf5108b --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestPage.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.inject.Inject; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; + +/** + * @author jsarman + */ +public class TestPage extends WebPage +{ + private static final long serialVersionUID = 1L; + + @Inject + TestAppScope appScope; + + public TestPage() + { + + add(new Label("appscope", appScope.test())); + } + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java new file mode 100644 index 0000000..dcd0289 --- /dev/null +++ b/wicket-cdi/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java @@ -0,0 +1,35 @@ +/* + * 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.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * @author jsarman + */ +@Qualifier +@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestQualifier { + +} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/test/java/simplelogger.properties ---------------------------------------------------------------------- diff --git a/wicket-cdi/src/test/java/simplelogger.properties b/wicket-cdi/src/test/java/simplelogger.properties new file mode 100644 index 0000000..17c5fe6 --- /dev/null +++ b/wicket-cdi/src/test/java/simplelogger.properties @@ -0,0 +1 @@ +org.slf4j.simpleLogger.log.org.apache.wicket.cdi=info \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-examples/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-examples/pom.xml b/wicket-examples/pom.xml index bc010a3..98bc936 100644 --- a/wicket-examples/pom.xml +++ b/wicket-examples/pom.xml @@ -105,7 +105,7 @@ </dependency> <dependency> <groupId>org.apache.wicket</groupId> - <artifactId>wicket-cdi-1.1</artifactId> + <artifactId>wicket-cdi</artifactId> </dependency> <dependency> <groupId>org.apache.wicket</groupId> @@ -150,7 +150,7 @@ </dependency> <dependency> <groupId>org.jboss.weld.servlet</groupId> - <artifactId>weld-servlet</artifactId> + <artifactId>weld-servlet-core</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-ioc/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-ioc/pom.xml b/wicket-ioc/pom.xml index d2eba4f..5eaa0ab 100644 --- a/wicket-ioc/pom.xml +++ b/wicket-ioc/pom.xml @@ -15,7 +15,9 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.wicket</groupId> @@ -58,6 +60,11 @@ <artifactId>asm-util</artifactId> </dependency> <dependency> + <groupId>org.jboss.weld.se</groupId> + <artifactId>weld-se-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> </dependency>
