You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/10/15 09:20:09 UTC
git commit: CDI-279 add a unit test for our JSF-2-CDI scope mapping
Updated Branches:
refs/heads/master 9682dce0f -> 9f3095892
CDI-279 add a unit test for our JSF-2-CDI scope mapping
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/9f309589
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/9f309589
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/9f309589
Branch: refs/heads/master
Commit: 9f3095892e2f404db70063380a02f78e41271a7c
Parents: 9682dce
Author: Mark Struberg <st...@apache.org>
Authored: Mon Oct 15 09:15:25 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Mon Oct 15 09:15:25 2012 +0200
----------------------------------------------------------------------
.../impl/scope/mapped/MappedJsfContextTest.java | 83 +++++++++++++++
.../beans/JsfApplicationScopedBackingBean.java | 45 ++++++++
.../mapped/beans/JsfRequestScopedBackingBean.java | 45 ++++++++
.../mapped/beans/JsfSessionScopedBackingBean.java | 45 ++++++++
.../test/resources/mappedJsfContextTest/page.xhtml | 43 ++++++++
5 files changed, 261 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9f309589/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/MappedJsfContextTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/MappedJsfContextTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/MappedJsfContextTest.java
new file mode 100644
index 0000000..7da680f
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/MappedJsfContextTest.java
@@ -0,0 +1,83 @@
+/*
+* 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.deltaspike.test.jsf.impl.scope.mapped;
+
+
+import java.net.URL;
+
+import org.apache.deltaspike.test.category.WebProfileCategory;
+import org.apache.deltaspike.test.jsf.impl.scope.mapped.beans.JsfApplicationScopedBackingBean;
+import org.apache.deltaspike.test.jsf.impl.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.drone.api.annotation.Drone;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.arquillian.warp.WarpTest;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+
+
+/**
+ * Test for the DeltaSpike ViewScoped context
+ */
+@WarpTest
+@RunWith(Arquillian.class)
+@Category(WebProfileCategory.class)
+public class MappedJsfContextTest
+{
+ @Drone
+ private WebDriver driver;
+
+ @ArquillianResource
+ private URL contextPath;
+
+ @Deployment
+ public static WebArchive deploy()
+ {
+ return ShrinkWrap
+ .create(WebArchive.class, "mappedJsfContetxtTest.war")
+ .addPackage(JsfApplicationScopedBackingBean.class.getPackage())
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJsfArchive())
+ .addAsWebInfResource("default/WEB-INF/web.xml", "web.xml")
+ .addAsWebResource("mappedJsfContextTest/page.xhtml", "page.xhtml")
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+
+ @Test
+ @RunAsClient
+ public void testViewScopedContext() throws Exception
+ {
+ driver.get(new URL(contextPath, "page.xhtml?req=47&sess=48&app=49").toString());
+
+ Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("test:reqValue"), "47").apply(driver));
+ Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("test:sessValue"), "48").apply(driver));
+ Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("test:appValue"), "49").apply(driver));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9f309589/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfApplicationScopedBackingBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfApplicationScopedBackingBean.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfApplicationScopedBackingBean.java
new file mode 100644
index 0000000..d2ab01a
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfApplicationScopedBackingBean.java
@@ -0,0 +1,45 @@
+/*
+* 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.deltaspike.test.jsf.impl.scope.mapped.beans;
+
+import javax.faces.bean.ApplicationScoped;
+import javax.inject.Named;
+import java.io.Serializable;
+
+/**
+ * JSF ApplicationScoped sample backing bean.
+ * This Bean will get mapped to it's corresponding CDI scope
+ * via our {@link org.apache.deltaspike.jsf.impl.scope.mapped.MappedJsf2ScopeExtension}
+ */
+@ApplicationScoped
+@Named
+public class JsfApplicationScopedBackingBean implements Serializable
+{
+ private int i = 0;
+
+ public int getI()
+ {
+ return i;
+ }
+
+ public void setI(int i)
+ {
+ this.i = i;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9f309589/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfRequestScopedBackingBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfRequestScopedBackingBean.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfRequestScopedBackingBean.java
new file mode 100644
index 0000000..de75dc8
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfRequestScopedBackingBean.java
@@ -0,0 +1,45 @@
+/*
+* 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.deltaspike.test.jsf.impl.scope.mapped.beans;
+
+import javax.faces.bean.RequestScoped;
+import javax.inject.Named;
+import java.io.Serializable;
+
+/**
+ * JSF RequestScoped sample backing bean.
+ * This Bean will get mapped to it's corresponding CDI scope
+ * via our {@link org.apache.deltaspike.jsf.impl.scope.mapped.MappedJsf2ScopeExtension}
+ */
+@RequestScoped
+@Named
+public class JsfRequestScopedBackingBean implements Serializable
+{
+ private int i = 0;
+
+ public int getI()
+ {
+ return i;
+ }
+
+ public void setI(int i)
+ {
+ this.i = i;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9f309589/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfSessionScopedBackingBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfSessionScopedBackingBean.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfSessionScopedBackingBean.java
new file mode 100644
index 0000000..c8db16d
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/scope/mapped/beans/JsfSessionScopedBackingBean.java
@@ -0,0 +1,45 @@
+/*
+* 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.deltaspike.test.jsf.impl.scope.mapped.beans;
+
+import javax.faces.bean.SessionScoped;
+import javax.inject.Named;
+import java.io.Serializable;
+
+/**
+ * JSF SessionScoped sample backing bean.
+ * This Bean will get mapped to it's corresponding CDI scope
+ * via our {@link org.apache.deltaspike.jsf.impl.scope.mapped.MappedJsf2ScopeExtension}
+ */
+@SessionScoped
+@Named
+public class JsfSessionScopedBackingBean implements Serializable
+{
+ private int i = 0;
+
+ public int getI()
+ {
+ return i;
+ }
+
+ public void setI(int i)
+ {
+ this.i = i;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/9f309589/deltaspike/modules/jsf/impl/src/test/resources/mappedJsfContextTest/page.xhtml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/resources/mappedJsfContextTest/page.xhtml b/deltaspike/modules/jsf/impl/src/test/resources/mappedJsfContextTest/page.xhtml
new file mode 100644
index 0000000..bfde13c
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/test/resources/mappedJsfContextTest/page.xhtml
@@ -0,0 +1,43 @@
+<?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.
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+<body>
+<f:view>
+ <f:metadata>
+ <f:viewParam name="req" id="req" value="#{jsfRequestScopedBackingBean.i}"/>
+ <f:viewParam name="sess" id="sess" value="#{jsfSessionScopedBackingBean.i}"/>
+ <f:viewParam name="app" id="app" value="#{jsfApplicationScopedBackingBean.i}"/>
+ </f:metadata>
+ <div>
+
+ <h:form id="test">
+ <h:outputText id="reqValue" value="#{jsfRequestScopedBackingBean.i}"/><br/>
+ <h:outputText id="sessValue" value="#{jsfSessionScopedBackingBean.i}"/><br/>
+ <h:outputText id="appValue" value="#{jsfApplicationScopedBackingBean.i}"/><br/>
+ </h:form>
+ </div>
+</f:view>
+</body>
+</html>