You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/06/16 14:16:03 UTC

svn commit: r955214 [3/3] - in /myfaces: core/trunk/api/src/main/java/javax/faces/component/ shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/ shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/ tomahawk/trunk/c...

Added: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlListboxRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlListboxRendererTest.java?rev=955214&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlListboxRendererTest.java (added)
+++ myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlListboxRendererTest.java Wed Jun 16 12:16:02 2010
@@ -0,0 +1,142 @@
+/*
+ * 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.myfaces.renderkit.html.ext;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Collection;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.component.UISelectItem;
+
+import org.apache.myfaces.component.html.ext.HtmlSelectManyListbox;
+import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.el.MockValueExpression;
+import org.apache.shale.test.mock.MockResponseWriter;
+
+/**
+ * Test cases for HtmlListboxRenderer.
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class HtmlListboxRendererTest extends AbstractJsfTestCase
+{
+
+    private HtmlListboxRenderer _renderer;
+    private MockResponseWriter _writer;
+    private StringWriter _stringWriter;
+    
+    public HtmlListboxRendererTest(String name)
+    {
+        super(name);
+    }
+    
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        _renderer = new HtmlListboxRenderer();
+        _stringWriter = new StringWriter();
+        _writer = new MockResponseWriter(_stringWriter, "text/html", "utf-8");
+        
+        facesContext.setResponseWriter(_writer);
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        _renderer = null;
+        _stringWriter = null;
+        _writer = null;
+        
+        super.tearDown();
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testValueTypeRender() throws IOException
+    {
+        TestBean bean = new TestBean();
+        externalContext.getApplicationMap().put("bean", bean);
+        ValueExpression beanVE = new MockValueExpression("#{bean.values}", Object.class);
+        
+        // create UISelectMany component
+        HtmlSelectManyListbox selectMany = new HtmlSelectManyListbox();
+        selectMany.setValueExpression("value", beanVE);
+        selectMany.setValueType(Integer.class.getName());
+        
+        // create the select item
+        UISelectItem item = new UISelectItem();
+        item.setItemValue("1");
+        selectMany.getChildren().add(item);
+        
+        // register the converter
+        application.addConverter(Integer.class, TestIntegerConverter.class.getName());
+        
+        // Render the component (only encodeEnd is used in this renderer)
+        _renderer.encodeEnd(facesContext, selectMany);
+        final String output = _stringWriter.toString();
+        
+        // we expect a rendered value of 11, because the Converter adds 10 to
+        // the given value in getAsString(). Thus we verify that the converter was called.
+        assertTrue(output.contains("value=\"11\""));
+    }
+    
+    @SuppressWarnings({ "unchecked", "serial" })
+    public void testValueTypeSubmit() throws IOException
+    {
+        TestBean bean = new TestBean();
+        externalContext.getApplicationMap().put("bean", bean);
+        ValueExpression beanVE = new MockValueExpression("#{bean.values}", Object.class)
+        {
+
+            @Override
+            public Class getType(ELContext context)
+            {
+                // to simulate the behavior when a bean property has a null value,
+                // but the getter has a return value of Collection
+                return Collection.class;
+            }
+              
+        };
+        
+        // create UISelectMany component
+        HtmlSelectManyListbox selectMany = new HtmlSelectManyListbox();
+        selectMany.setValueExpression("value", beanVE);
+        selectMany.setValueType(Integer.class.getName());
+        
+        // create the select item
+        UISelectItem item = new UISelectItem();
+        item.setItemValue("1");
+        selectMany.getChildren().add(item);
+        
+        // get the converted value
+        Object convertedValue = _renderer.getConvertedValue(facesContext, selectMany, new String[] {"1"});
+        
+        // the value must be a Collection
+        assertTrue(convertedValue instanceof Collection);
+        
+        // the first element of the Collection must be the _Integer_ 1
+        // (without the valueType attribute it would be the String "1")
+        assertEquals(1, ((Collection) convertedValue).iterator().next());
+    }
+    
+}

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlListboxRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlListboxRendererTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlListboxRendererTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlMenuRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlMenuRendererTest.java?rev=955214&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlMenuRendererTest.java (added)
+++ myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlMenuRendererTest.java Wed Jun 16 12:16:02 2010
@@ -0,0 +1,142 @@
+/*
+ * 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.myfaces.renderkit.html.ext;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Collection;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.component.UISelectItem;
+
+import org.apache.myfaces.component.html.ext.HtmlSelectManyMenu;
+import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.el.MockValueExpression;
+import org.apache.shale.test.mock.MockResponseWriter;
+
+/**
+ * Test cases for HtmlMenuRenderer.
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class HtmlMenuRendererTest extends AbstractJsfTestCase
+{
+
+    private HtmlMenuRenderer _renderer;
+    private MockResponseWriter _writer;
+    private StringWriter _stringWriter;
+    
+    public HtmlMenuRendererTest(String name)
+    {
+        super(name);
+    }
+    
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        _renderer = new HtmlMenuRenderer();
+        _stringWriter = new StringWriter();
+        _writer = new MockResponseWriter(_stringWriter, "text/html", "utf-8");
+        
+        facesContext.setResponseWriter(_writer);
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        _renderer = null;
+        _stringWriter = null;
+        _writer = null;
+        
+        super.tearDown();
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testValueTypeRender() throws IOException
+    {
+        TestBean bean = new TestBean();
+        externalContext.getApplicationMap().put("bean", bean);
+        ValueExpression beanVE = new MockValueExpression("#{bean.values}", Object.class);
+        
+        // create UISelectMany component
+        HtmlSelectManyMenu selectMany = new HtmlSelectManyMenu();
+        selectMany.setValueExpression("value", beanVE);
+        selectMany.setValueType(Integer.class.getName());
+        
+        // create the select item
+        UISelectItem item = new UISelectItem();
+        item.setItemValue("1");
+        selectMany.getChildren().add(item);
+        
+        // register the converter
+        application.addConverter(Integer.class, TestIntegerConverter.class.getName());
+        
+        // Render the component (only encodeEnd is used in this renderer)
+        _renderer.encodeEnd(facesContext, selectMany);
+        final String output = _stringWriter.toString();
+        
+        // we expect a rendered value of 11, because the Converter adds 10 to
+        // the given value in getAsString(). Thus we verify that the converter was called.
+        assertTrue(output.contains("value=\"11\""));
+    }
+    
+    @SuppressWarnings({ "unchecked", "serial" })
+    public void testValueTypeSubmit() throws IOException
+    {
+        TestBean bean = new TestBean();
+        externalContext.getApplicationMap().put("bean", bean);
+        ValueExpression beanVE = new MockValueExpression("#{bean.values}", Object.class)
+        {
+
+            @Override
+            public Class getType(ELContext context)
+            {
+                // to simulate the behavior when a bean property has a null value,
+                // but the getter has a return value of Collection
+                return Collection.class;
+            }
+              
+        };
+        
+        // create UISelectMany component
+        HtmlSelectManyMenu selectMany = new HtmlSelectManyMenu();
+        selectMany.setValueExpression("value", beanVE);
+        selectMany.setValueType(Integer.class.getName());
+        
+        // create the select item
+        UISelectItem item = new UISelectItem();
+        item.setItemValue("1");
+        selectMany.getChildren().add(item);
+        
+        // get the converted value
+        Object convertedValue = _renderer.getConvertedValue(facesContext, selectMany, new String[] {"1"});
+        
+        // the value must be a Collection
+        assertTrue(convertedValue instanceof Collection);
+        
+        // the first element of the Collection must be the _Integer_ 1
+        // (without the valueType attribute it would be the String "1")
+        assertEquals(1, ((Collection) convertedValue).iterator().next());
+    }
+    
+}

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlMenuRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlMenuRendererTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/HtmlMenuRendererTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestBean.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestBean.java?rev=955214&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestBean.java (added)
+++ myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestBean.java Wed Jun 16 12:16:02 2010
@@ -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.myfaces.renderkit.html.ext;
+
+import java.util.Collection;
+
+
+/**
+ * A bean for the test cases.
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class TestBean
+{
+
+    private Collection<Integer> values;
+
+    public Collection<Integer> getValues()
+    {
+        return values;
+    }
+
+    public void setValues(Collection<Integer> values)
+    {
+        this.values = values;
+    }
+    
+}

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestIntegerConverter.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestIntegerConverter.java?rev=955214&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestIntegerConverter.java (added)
+++ myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestIntegerConverter.java Wed Jun 16 12:16:02 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.myfaces.renderkit.html.ext;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+
+/**
+ * A converter for Integer that changes the integer a bit.
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class TestIntegerConverter implements Converter
+{
+    
+    public Object getAsObject(FacesContext context, UIComponent component,
+            String value) throws ConverterException
+    {
+        return (new Integer(value) - 10);
+    }
+
+    public String getAsString(FacesContext context, UIComponent component,
+            Object value) throws ConverterException
+    {
+        if (value instanceof String)
+        {
+            value = new Integer((String) value);
+        }
+        return (((Integer) value) + 10) + "";
+    }
+
+}

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestIntegerConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestIntegerConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tomahawk/trunk/core20/src/test/java/org/apache/myfaces/renderkit/html/ext/TestIntegerConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain