Author: pete.muir(a)jboss.org
Date: 2010-01-26 11:09:57 -0500 (Tue, 26 Jan 2010)
New Revision: 5633
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/User.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/faces-config.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/view.xhtml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/web.xml
Log:
verify bug report in forum post
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java 2010-01-26
16:09:57 UTC (rev 5633)
@@ -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.producer.field.named;
+
+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)
+(a)Classes({User.class, NewUserAction.class})
+@IntegrationTest(runLocally=true)
+@Resources({
+ @Resource(destination=WarArtifactDescriptor.WEB_XML_DESTINATION,
source="web.xml"),
+ @Resource(destination="view.xhtml", source="view.xhtml"),
+ @Resource(destination="/WEB-INF/faces-config.xml",
source="faces-config.xml")
+})
+public class NamedProducerTest extends AbstractWeldTest
+{
+ @Test(description = "forum post")
+ public void testNamedProducerWorks() throws Exception
+ {
+ WebClient client = new WebClient();
+ client.setThrowExceptionOnFailingStatusCode(false);
+
+ HtmlPage page = client.getPage(getPath("/view.jsf"));
+ // Check the page rendered ok
+ assert getFirstMatchingElement(page, HtmlSubmitInput.class, "saveButton")
!= null;
+ }
+
+ 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;
+ }
+
+}
Property changes on:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NamedProducerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java
===================================================================
---
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java 2010-01-26
16:09:57 UTC (rev 5633)
@@ -0,0 +1,20 @@
+package org.jboss.weld.tests.producer.field.named;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+@RequestScoped
+@Named
+public class NewUserAction
+{
+
+ @Produces
+ @Named("newUser")
+ private User newUser = new User();
+
+ public void persist()
+ {
+ System.out.println("new user's name: " + newUser.getName());
+ }
+}
\ No newline at end of file
Property changes on:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/User.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/User.java
(rev 0)
+++
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/User.java 2010-01-26
16:09:57 UTC (rev 5633)
@@ -0,0 +1,16 @@
+package org.jboss.weld.tests.producer.field.named;
+
+public class User
+{
+ private String name;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+}
\ No newline at end of file
Property changes on:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/User.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/faces-config.xml
===================================================================
---
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/faces-config.xml
(rev 0)
+++
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/faces-config.xml 2010-01-26
16:09:57 UTC (rev 5633)
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<faces-config version="2.0"
+
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_2_0.xsd">
+
+</faces-config>
Property changes on:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/faces-config.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/view.xhtml
===================================================================
---
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/view.xhtml
(rev 0)
+++
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/view.xhtml 2010-01-26
16:09:57 UTC (rev 5633)
@@ -0,0 +1,16 @@
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html">
+ <h:head>
+ <title>Facelet Title</title>
+ </h:head>
+ <h:body>
+ Hello from Facelets
+ <h:form id="form">
+ <h:panelGrid columns="2">
+ <h:outputLabel value="Name:" />
+ <h:inputText value="#{newUser.name}"
id="userNameInput" />
+ <h:commandButton action="#{newUserAction.persist}"
value="Save" id="saveButton" />
+ </h:panelGrid>
+ </h:form>
+ </h:body>
+</html>
\ No newline at end of file
Property changes on:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/view.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/web.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/web.xml
(rev 0)
+++
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/web.xml 2010-01-26
16:09:57 UTC (rev 5633)
@@ -0,0 +1,23 @@
+<?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>
+
+ <!-- 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>
Property changes on:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/producer/field/named/web.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain