Updated Branches: refs/heads/wicket-6.x 92a5bdbdb -> 62fed8f5f
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/TestCdiConfiguration.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestCdiConfiguration.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestCdiConfiguration.java new file mode 100644 index 0000000..0fd63f5 --- /dev/null +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestCdiConfiguration.java @@ -0,0 +1,87 @@ +/* + * 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.Alternative; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.Specializes; + +import org.apache.wicket.Application; +import org.apache.wicket.cdi.Auto; +import org.apache.wicket.cdi.CdiConfiguration; +import org.apache.wicket.cdi.ConfigurationParameters; +import org.apache.wicket.cdi.IConversationPropagation; +import org.apache.wicket.cdi.IgnoreList; +import org.apache.wicket.cdi.Propagation; + +/** + * Specializes the CdiConfigration to allow the ConfigurationParams key to be + * remapped after the Application is used to construct the WicketTester. + * This is needed because WicketTester generates the ApplicationKey during construction + * and does not contain a mechanism to override the name. In the normal code the WicketFilter + * sets the key to the filtername so remapping is not necessary. + * + * @author jsarman + */ +@ApplicationScoped +@Alternative +@Specializes +public class TestCdiConfiguration extends CdiConfiguration +{ + + @PostConstruct + @Override + public void init() + { + super.init(); + } + + public + @Produces + @Propagation + IConversationPropagation getPropagation() + { + return super.getPropagation(); + } + + + public + @Produces + @Auto + @Override + Boolean isAutoConversationManagement() + { + return super.isAutoConversationManagement(); + } + + public + @Produces + @IgnoreList + @Override + String[] getPackagesToIgnore() + { + return super.getPackagesToIgnore(); + } + + public void remapApplicationKey(String key, Application app) + { + ConfigurationParameters cp = parameters.remove(key); + parameters.put(app.getApplicationKey(), cp); + } +} 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/TestComponentInjector.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestComponentInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestComponentInjector.java new file mode 100644 index 0000000..d43448e --- /dev/null +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestComponentInjector.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.Component; +import org.apache.wicket.cdi.ComponentInjector; + +/** + * Injects components with CDI dependencies + * + * @author igor + */ +@ApplicationScoped +@Alternative +@Specializes +public class TestComponentInjector extends ComponentInjector +{ + + @Override + public void onInstantiation(Component component) + { + Class instanceClass = component.getClass(); + if (instanceClass.isAnonymousClass() || + (instanceClass.isMemberClass() && Modifier.isStatic(instanceClass.getModifiers()) == false)) + { + return; + } + inject(component); + } +} 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/TestFilterConfig.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestFilterConfig.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestFilterConfig.java new file mode 100644 index 0000000..27a2238 --- /dev/null +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/util/tester/TestFilterConfig.java @@ -0,0 +1,89 @@ +/* + * 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.Enumeration; +import java.util.Map; +import java.util.TreeMap; +import java.util.UUID; + +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; + +/** + * @author jsarman + */ +public class TestFilterConfig implements FilterConfig +{ + + private String filterName = "CdiApp" + UUID.randomUUID(); + private Map<String, String> params; + + public TestFilterConfig() + { + this(null); + } + + public TestFilterConfig(Map<String, String> initialParams) + { + this.params = new TreeMap<String, String>(); + this.params.put("applicationName", "mockApp"); + if (initialParams != null) + { + this.params.putAll(initialParams); + } + } + + public void put(String paramName, String value) + { + params.put(paramName, value); + } + + public void remove(String paramName) + { + params.remove(paramName); + } + + public void putAll(Map<String, String> additionalParams) + { + params.putAll(additionalParams); + } + + @Override + public String getFilterName() + { + return filterName; + } + + @Override + public ServletContext getServletContext() + { + throw new UnsupportedOperationException("This is not supported."); + } + + @Override + public String getInitParameter(String name) + { + return params.get(name); + } + + @Override + public Enumeration<String> getInitParameterNames() + { + throw new UnsupportedOperationException("This is not Supported."); + } +} 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/simplelogger.properties ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/simplelogger.properties b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/simplelogger.properties new file mode 100644 index 0000000..17c5fe6 --- /dev/null +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/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/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/pom.xml b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/pom.xml index ddd1ae6..98f8b3f 100644 --- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/pom.xml +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/pom.xml @@ -15,73 +15,74 @@ 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"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket-cdi-1.1</artifactId> - <version>0.2-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>wicket-cdi-1.1-weld</artifactId> - <packaging>jar</packaging> +<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> + <artifactId>wicket-cdi-1.1</artifactId> <version>0.2-SNAPSHOT</version> - <name>Wicket CDI 1.1 Weld</name> - <description> - Provides integration between Wicket and CDI containers. Adds support for weld - based containers. - </description> - <dependencies> - <dependency> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket-cdi-1.1-core</artifactId> - <version>0.2-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.jboss.weld</groupId> - <artifactId>weld-api</artifactId> - <version>2.0.Final</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>javax.el</groupId> - <artifactId>javax.el-api</artifactId> - <version>2.2.4</version> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>clirr-maven-plugin</artifactId> - <executions> - <execution> - <id>clirr-check</id> - <phase>compile</phase> - <goals> - <goal>check</goal> - </goals> - <configuration> - <comparisonVersion>6.1.0</comparisonVersion> - <failOnError>true</failOnError> - <logResults>true</logResults> - </configuration> - </execution> - </executions> - <configuration> - <comparisonVersion>6.1.0</comparisonVersion> - <failOnError>true</failOnError> - <logResults>true</logResults> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>wicket-cdi-1.1-weld</artifactId> + <packaging>jar</packaging> + <version>0.2-SNAPSHOT</version> + <name>Wicket CDI 1.1 Weld</name> + <description> + Provides integration between Wicket and CDI containers. Adds support for weld + based containers. + </description> + <dependencies> + <dependency> + <groupId>org.apache.wicket</groupId> + <artifactId>wicket-cdi-1.1-core</artifactId> + <version>0.2-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.jboss.weld</groupId> + <artifactId>weld-api</artifactId> + <version>2.0.Final</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>javax.el</groupId> + <artifactId>javax.el-api</artifactId> + <version>2.2.4</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>clirr-maven-plugin</artifactId> + <executions> + <execution> + <id>clirr-check</id> + <phase>compile</phase> + <goals> + <goal>check</goal> + </goals> + <configuration> + <comparisonVersion>6.1.0</comparisonVersion> + <failOnError>true</failOnError> + <logResults>true</logResults> + </configuration> + </execution> + </executions> + <configuration> + <comparisonVersion>6.1.0</comparisonVersion> + <failOnError>true</failOnError> + <logResults>true</logResults> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> </project> http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/java/org/apache/wicket/cdi/weld/WeldCdiContainer.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/java/org/apache/wicket/cdi/weld/WeldCdiContainer.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/java/org/apache/wicket/cdi/weld/WeldCdiContainer.java index 61ea380..6289074 100644 --- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/java/org/apache/wicket/cdi/weld/WeldCdiContainer.java +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/java/org/apache/wicket/cdi/weld/WeldCdiContainer.java @@ -17,61 +17,49 @@ package org.apache.wicket.cdi.weld; import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Instance; +import javax.enterprise.context.Conversation; import javax.inject.Inject; + import org.apache.wicket.cdi.AbstractCdiContainer; import org.apache.wicket.request.cycle.RequestCycle; import org.jboss.weld.context.http.HttpConversationContext; /** * Provides access to CDI features from inside a Wicket request - * + * * @author jsarman - * */ @ApplicationScoped public class WeldCdiContainer extends AbstractCdiContainer -{ - @Inject - private Instance<HttpConversationContext> conversationContextSource; - - /** - * Deactivates conversational context - * - * @param cycle - */ - @Override - public void deactivateConversationalContext(RequestCycle cycle) - { - HttpConversationContext conversationContext = conversationContextSource.get(); - conversationContext.deactivate(); - conversationContext.dissociate(getRequest(cycle)); - } +{ + @Inject + private HttpConversationContext conversationContext; /** * Activates the conversational context and starts the conversation with the specified cid - * + * * @param cycle * @param cid */ @Override public void activateConversationalContext(RequestCycle cycle, String cid) { - HttpConversationContext conversationContext = conversationContextSource.get(); - conversationContext.associate(getRequest(cycle)); - if(conversationContext.isActive()) + 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); - } - } - else + conversationContext.invalidate(); + conversationContext.deactivate(); + conversationContext.activate(cid); + } else { - conversationContext.activate(cid); + 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-weld/src/test/java/org/apache/wicket/cdi/weld/ApacheLicenceHeaderTest.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/test/java/org/apache/wicket/cdi/weld/ApacheLicenceHeaderTest.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/test/java/org/apache/wicket/cdi/weld/ApacheLicenceHeaderTest.java index bb5a6de..2c10f27 100644 --- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/test/java/org/apache/wicket/cdi/weld/ApacheLicenceHeaderTest.java +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/test/java/org/apache/wicket/cdi/weld/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
