Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
...rc/test/java/org/jboss/weld/tests/contexts/sessionInvalidation/InvalidateSessionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.contexts.sessionInvalidation; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.jboss.testharness.impl.packaging.Artifact; | ||
import org.jboss.testharness.impl.packaging.Classes; | ||
import org.jboss.testharness.impl.packaging.IntegrationTest; | ||
import org.jboss.testharness.impl.packaging.Resource; | ||
import org.jboss.testharness.impl.packaging.Resources; | ||
import org.jboss.testharness.impl.packaging.war.WarArtifactDescriptor; | ||
import org.jboss.weld.test.AbstractWeldTest; | ||
import org.testng.annotations.Test; | ||
|
||
import com.gargoylesoftware.htmlunit.WebClient; | ||
import com.gargoylesoftware.htmlunit.html.HtmlElement; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; | ||
|
||
/** | ||
* <p>Check what happens when session.invalidate() is called.</p> | ||
* | ||
* @author Pete Muir | ||
* | ||
*/ | ||
@Artifact(addCurrentPackage=false) | ||
@Classes({Storm.class}) | ||
@IntegrationTest(runLocally=true) | ||
@Resources({ | ||
@Resource(destination=WarArtifactDescriptor.WEB_XML_DESTINATION, source="web.xml"), | ||
@Resource(destination="storm.jspx", source="storm.jsf"), | ||
@Resource(destination="/WEB-INF/faces-config.xml", source="faces-config.xml") | ||
}) | ||
public class InvalidateSessionTest extends AbstractWeldTest | ||
{ | ||
@Test(description = "WELD-380") | ||
public void testInvalidateSessionCalled() throws Exception | ||
{ | ||
WebClient client = new WebClient(); | ||
client.setThrowExceptionOnFailingStatusCode(false); | ||
|
||
HtmlPage page = client.getPage(getPath("/storm.jsf")); | ||
HtmlSubmitInput invalidateSessionButton = getFirstMatchingElement(page, HtmlSubmitInput.class, "invalidateSessionButton"); | ||
page = invalidateSessionButton.click(); | ||
} | ||
|
||
protected <T> Set<T> getElements(HtmlElement rootElement, Class<T> elementClass) | ||
{ | ||
Set<T> result = new HashSet<T>(); | ||
|
||
for (HtmlElement element : rootElement.getAllHtmlChildElements()) | ||
{ | ||
result.addAll(getElements(element, elementClass)); | ||
} | ||
|
||
if (elementClass.isInstance(rootElement)) | ||
{ | ||
result.add(elementClass.cast(rootElement)); | ||
} | ||
return result; | ||
|
||
} | ||
|
||
protected <T extends HtmlElement> T getFirstMatchingElement(HtmlPage page, Class<T> elementClass, String id) | ||
{ | ||
|
||
Set<T> inputs = getElements(page.getBody(), elementClass); | ||
for (T input : inputs) | ||
{ | ||
if (input.getId().contains(id)) | ||
{ | ||
return input; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
tests/src/test/java/org/jboss/weld/tests/contexts/sessionInvalidation/Storm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.contexts.sessionInvalidation; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.servlet.http.HttpSession; | ||
|
||
@Named | ||
public class Storm | ||
{ | ||
|
||
@Inject HttpSession session; | ||
|
||
public String invalidateSession() | ||
{ | ||
session.invalidate(); | ||
return "success"; | ||
} | ||
|
||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...test/resources/org/jboss/weld/tests/contexts/sessionInvalidation/.faces-config.xml.jsfdia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<PROCESS model-entity="JSFProcess"/> |
7 changes: 7 additions & 0 deletions
7
tests/src/test/resources/org/jboss/weld/tests/contexts/sessionInvalidation/faces-config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<faces-config version="1.2" | ||
xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"> | ||
|
||
</faces-config> |
23 changes: 23 additions & 0 deletions
23
tests/src/test/resources/org/jboss/weld/tests/contexts/sessionInvalidation/storm.jsf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0"?> | ||
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" | ||
xmlns:h="http://java.sun.com/jsf/html" | ||
xmlns:f="http://java.sun.com/jsf/core" | ||
xmlns:s="http://jboss.com/products/seam/taglib" | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
version="2.0"> | ||
<jsp:output doctype-root-element="html" | ||
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> | ||
<jsp:directive.page contentType="text/html"/> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<f:view> | ||
<h:form id="form"> | ||
<h:commandButton action="#{storm.invalidateSession}" value="Invalidate Session" id="invalidateSessionButton"/> | ||
</h:form> | ||
</f:view> | ||
</body> | ||
</html> | ||
</jsp:root> |
27 changes: 27 additions & 0 deletions
27
tests/src/test/resources/org/jboss/weld/tests/contexts/sessionInvalidation/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> | ||
<display-name>Weld Core Tests</display-name> | ||
|
||
<context-param> | ||
<param-name>javax.faces.DEFAULT_SUFFIX</param-name> | ||
<param-value>.jspx</param-value> | ||
</context-param> | ||
<!-- JSF --> | ||
<servlet> | ||
<servlet-name>Faces Servlet</servlet-name> | ||
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> | ||
<load-on-startup>1</load-on-startup> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>Faces Servlet</servlet-name> | ||
<url-pattern>*.jsf</url-pattern> | ||
</servlet-mapping> | ||
|
||
<session-config> | ||
<session-timeout>10</session-timeout> | ||
</session-config> | ||
|
||
</web-app> |