You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/06/28 10:53:55 UTC
[8/9] git commit: Rename MockContainer to MockCdiContainer. Extract
base test case for CDI tests
Rename MockContainer to MockCdiContainer.
Extract base test case for CDI tests
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f5d586b9
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f5d586b9
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f5d586b9
Branch: refs/heads/5257-css-settings
Commit: f5d586b9b039a4b16e6e856f1a5d9947ce737074
Parents: 6a3d865
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Fri Jun 28 10:03:42 2013 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Fri Jun 28 10:03:42 2013 +0300
----------------------------------------------------------------------
.../apache/wicket/cdi/CdiConfigurationTest.java | 52 +------------
.../wicket/cdi/ComponentInjectorTest.java | 60 +--------------
.../org/apache/wicket/cdi/MockCdiContainer.java | 70 ++++++++++++++++++
.../org/apache/wicket/cdi/MockContainer.java | 70 ------------------
.../apache/wicket/cdi/WicketCdiTestCase.java | 78 ++++++++++++++++++++
5 files changed, 152 insertions(+), 178 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/f5d586b9/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
index 2461e05..5b0bed6 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java
@@ -17,69 +17,21 @@
package org.apache.wicket.cdi;
import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
import org.apache.wicket.cdi.testapp.TestAppScope;
-import org.apache.wicket.cdi.testapp.TestApplication;
import org.apache.wicket.cdi.testapp.TestConversationBean;
import org.apache.wicket.cdi.testapp.TestConversationPage;
-import org.apache.wicket.util.tester.WicketTester;
import org.jglue.cdiunit.AdditionalClasses;
-import org.jglue.cdiunit.CdiRunner;
-import org.jglue.cdiunit.ContextController;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
/**
* @author jsarman
*/
-@RunWith(CdiRunner.class)
-@AdditionalClasses({BehaviorInjector.class,
- CdiConfiguration.class,
- CdiShutdownCleaner.class,
- ComponentInjector.class,
- ConversationExpiryChecker.class,
- ConversationPropagator.class,
- DetachEventEmitter.class,
- NonContextualManager.class,
- SessionInjector.class,
- MockContainer.class,
- TestAppScope.class,
- TestConversationBean.class})
-public class CdiConfigurationTest extends Assert
+@AdditionalClasses({TestAppScope.class, TestConversationBean.class})
+public class CdiConfigurationTest extends WicketCdiTestCase
{
-
- private WicketTester tester;
- @Inject
- ContextController contextController;
@Inject
ConversationPropagator conversationPropagator;
- @Inject
- ComponentInjector componentInjector;
-
- @Before
- public void before()
- {
- tester = new WicketTester(new TestApplication());
- prepareRequest(tester.getRequest());
- }
-
- @After
- public void after()
- {
- tester.destroy();
- tester = null;
- }
-
- public void prepareRequest(HttpServletRequest request)
- {
- contextController.openRequest(request);
- contextController.openSession(request);
- contextController.openConversation(request);
- }
@Test
public void testApplicationScope()
http://git-wip-us.apache.org/repos/asf/wicket/blob/f5d586b9/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
index fb1210e..e093ae2 100644
--- 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
@@ -17,82 +17,26 @@
package org.apache.wicket.cdi;
import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
import org.apache.wicket.cdi.testapp.TestAppScope;
-import org.apache.wicket.cdi.testapp.TestApplication;
import org.apache.wicket.cdi.testapp.TestConversationBean;
-import org.apache.wicket.cdi.testapp.TestConversationPage;
import org.apache.wicket.cdi.testapp.TestQualifier;
-
import org.apache.wicket.markup.html.WebComponent;
-import org.apache.wicket.util.tester.WicketTester;
import org.jglue.cdiunit.AdditionalClasses;
-import org.jglue.cdiunit.CdiRunner;
-import org.jglue.cdiunit.ContextController;
-import org.junit.After;
-import org.junit.Assert;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
/**
* Tests for ComponentInjector
*/
-@RunWith(CdiRunner.class)
-@AdditionalClasses({
- BehaviorInjector.class,
- CdiConfiguration.class,
- CdiShutdownCleaner.class,
- ComponentInjector.class,
- ConversationExpiryChecker.class,
- ConversationPropagator.class,
- DetachEventEmitter.class,
- NonContextualManager.class,
- SessionInjector.class,
- MockContainer.class,
- TestAppScope.class,
- TestConversationBean.class})
-public class ComponentInjectorTest extends Assert
+@AdditionalClasses({TestAppScope.class, TestConversationBean.class})
+public class ComponentInjectorTest extends WicketCdiTestCase
{
-
- private WicketTester tester;
- @Inject
- ContextController contextController;
- @Inject
- ComponentInjector componentInjector;
-
- @Before
- public void before()
- {
- tester = new WicketTester(new TestApplication());
- prepareRequest(tester.getRequest());
- }
-
- @After
- public void after()
- {
- tester.destroy();
- tester = null;
- }
-
- public void prepareRequest(HttpServletRequest request)
- {
- contextController.openRequest(request);
- contextController.openSession(request);
- contextController.openConversation(request);
- }
-
/**
* https://issues.apache.org/jira/browse/WICKET-5226
*/
@Test
public void innerNonStaticClass()
{
-
TestNonStaticComponent component = new TestNonStaticComponent("someId");
assertNull(component.dependency);
componentInjector.onInstantiation(component);
http://git-wip-us.apache.org/repos/asf/wicket/blob/f5d586b9/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java
new file mode 100644
index 0000000..92977ca
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockCdiContainer.java
@@ -0,0 +1,70 @@
+/*
+ * 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.ApplicationScoped;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.jboss.weld.context.http.HttpConversationContext;
+
+/**
+ * @author jsarman
+ */
+@ApplicationScoped
+public class MockCdiContainer extends AbstractCdiContainer
+{
+
+ @Inject
+ private Instance<HttpConversationContext> conversationContextSource;
+
+ @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)
+ {
+ 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/f5d586b9/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockContainer.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockContainer.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockContainer.java
deleted file mode 100644
index dc1ddd1..0000000
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/MockContainer.java
+++ /dev/null
@@ -1,70 +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.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.jboss.weld.context.http.HttpConversationContext;
-
-/**
- * @author jsarman
- */
-@ApplicationScoped
-public class MockContainer extends AbstractCdiContainer
-{
-
- @Inject
- private Instance<HttpConversationContext> conversationContextSource;
-
- @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)
- {
- 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/f5d586b9/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
new file mode 100644
index 0000000..6d66c29
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.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;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.wicket.cdi.testapp.TestApplication;
+import org.apache.wicket.util.tester.WicketTester;
+import org.jglue.cdiunit.AdditionalClasses;
+import org.jglue.cdiunit.CdiRunner;
+import org.jglue.cdiunit.ContextController;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+
+/**
+ * Base class for all CDI unit tests
+ */
+@RunWith(CdiRunner.class)
+@AdditionalClasses({
+ BehaviorInjector.class,
+ CdiConfiguration.class,
+ CdiShutdownCleaner.class,
+ ComponentInjector.class,
+ ConversationExpiryChecker.class,
+ ConversationPropagator.class,
+ DetachEventEmitter.class,
+ NonContextualManager.class,
+ SessionInjector.class,
+ MockCdiContainer.class})
+public class WicketCdiTestCase extends Assert
+{
+ protected WicketTester tester;
+
+ @Inject
+ protected ContextController contextController;
+
+ @Inject
+ protected ComponentInjector componentInjector;
+
+ @Before
+ public void before()
+ {
+ tester = new WicketTester(new TestApplication());
+ prepareRequest(tester.getRequest());
+ }
+
+ @After
+ public void after()
+ {
+ tester.destroy();
+ tester = null;
+ }
+
+ private void prepareRequest(HttpServletRequest request)
+ {
+ contextController.openRequest(request);
+ contextController.openSession(request);
+ contextController.openConversation(request);
+ }
+
+}