Updated Branches: refs/heads/master e75eeaa25 -> a3e57603f
http://git-wip-us.apache.org/repos/asf/wicket/blob/befbf9c7/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 new file mode 100644 index 0000000..5e002e3 --- /dev/null +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/ComponentInjectorTest.java @@ -0,0 +1,133 @@ +/* + * 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.mockito.Mockito.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import javax.enterprise.inject.spi.BeanManager; +import javax.inject.Inject; + +import org.apache.wicket.markup.html.WebComponent; +import org.apache.wicket.util.tester.WicketTester; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +/** + * Tests for ComponentInjector + */ +public class ComponentInjectorTest extends Assert +{ + private WicketTester tester; + + @Before + public void before() + { + // starts an application so we can instantiate components + tester = new WicketTester(); + } + + @After + public void after() + { + tester.destroy(); + tester = null; + } + + /** + * https://issues.apache.org/jira/browse/WICKET-5226 + */ + @Test + public void innerNonStaticClass() + { + //Disabled for now +// BeanManager beanManager = mock(BeanManager.class); +// INonContextualManager nonContextualManager = mock(INonContextualManager.class); +// AbstractCdiContainer cdiContainer = new AbstractCdiContainer(beanManager, nonContextualManager); +// ComponentInjector injector = new ComponentInjector(cdiContainer); +// +// TestNonStaticComponent component = new TestNonStaticComponent("someId"); +// assertNull(component.dependency); +// +// injector.onInstantiation(component); +// +// verify(nonContextualManager, never()).inject(any()); + } + + /** + * https://issues.apache.org/jira/browse/WICKET-5226 + */ + @Test + public void innerStaticClass() + { + //Disabled for now need to add injectable test dependencies +// BeanManager beanManager = mock(BeanManager.class); +// INonContextualManager nonContextualManager = mock(INonContextualManager.class); +// final String expectedValue = "injected"; +// +// doAnswer(new Answer<Void>() +// { +// @Override +// public Void answer(InvocationOnMock invocation) throws Throwable +// { +// TestStaticComponent component = (TestStaticComponent) invocation.getArguments()[0]; +// component.dependency = expectedValue; +// +// return null; +// } +// }).when(nonContextualManager).inject(any(TestStaticComponent.class)); +// +// AbstractCdiContainer cdiContainer = new AbstractCdiContainer(beanManager, nonContextualManager); +// ComponentInjector injector = new ComponentInjector(cdiContainer); +// +// TestStaticComponent component = new TestStaticComponent("someId"); +// assertNull(component.dependency); +// +// injector.onInstantiation(component); +// +// assertEquals(expectedValue, component.dependency); + } + + private class TestNonStaticComponent extends WebComponent + { + @Inject + private String dependency; + + public TestNonStaticComponent(String id) + { + super(id); + } + } + + private static class TestStaticComponent extends WebComponent + { + @Inject + private String dependency; + + public TestStaticComponent(String id) + { + super(id); + } + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/befbf9c7/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 new file mode 100644 index 0000000..9c657e2 --- /dev/null +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/pom.xml @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<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.1-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>wicket-cdi-1.1-weld</artifactId> + <packaging>jar</packaging> + <version>0.1-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.1-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/befbf9c7/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 new file mode 100644 index 0000000..e290847 --- /dev/null +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/java/org/apache/wicket/cdi/weld/WeldCdiContainer.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.weld; + +import javax.enterprise.context.ApplicationScoped; +import org.apache.wicket.cdi.*; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; +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 + Instance<HttpConversationContext> conversationContextSource; + + @Inject + INonContextualManager nonContextualManager; + + /** + * Constructor + */ + public WeldCdiContainer() + { + + } + + @Override + protected INonContextualManager getNonContextualManager() + { + return nonContextualManager; + } + + /** + * Deactivates conversational context + * + * @param cycle + */ + @Override + public void deactivateConversationalContext(RequestCycle cycle) + { + HttpConversationContext conversationContext = conversationContextSource.get(); + conversationContext.deactivate(); + conversationContext.dissociate(getRequest(cycle)); + } + + /** + * Activates the conversational context and starts the conversation with the specified cid + * + * @param cycle + * @param cid + */ + @Override + public void activateConversationalContext(RequestCycle cycle, String cid) + { + // Force a session created if one does not exist + // Glassfish does not have a session initially to store the transactions + // so it gets lost in the request. + getRequest(cycle).getSession(true); + 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); + } + } + else + { + conversationContext.activate(cid); + } + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/befbf9c7/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/resources/META-INF/beans.xml ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/resources/META-INF/beans.xml b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/wicket/blob/befbf9c7/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 new file mode 100644 index 0000000..92efb73 --- /dev/null +++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-weld/src/test/java/org/apache/wicket/cdi/weld/ApacheLicenceHeaderTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.cdi; + +import java.util.Arrays; + +import org.apache.wicket.util.license.ApacheLicenseHeaderTestCase; + +/** + * Test that the license headers are in place in this project. The tests are run from + * {@link ApacheLicenseHeaderTestCase}, but you can add project specific tests here if needed. + * + * @author Frank Bille Jensen (frankbille) + */ +public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase +{ + /** + * Construct. + */ + public ApacheLicenceHeaderTest() + { + xmlIgnore.add(".settings"); + xmlIgnore.add("src/main/resources/META-INF/beans.xml"); + xmlPrologIgnore = Arrays.asList("src"); + } +}
