You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/06/18 01:57:56 UTC

svn commit: r955793 [2/4] - in /myfaces/tomahawk/trunk/core12/src/test: java/org/apache/myfaces/component/ java/org/apache/myfaces/component/html/ java/org/apache/myfaces/component/html/ext/ java/org/apache/myfaces/convert/ java/org/apache/myfaces/cust...

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/HtmlDateRenderCactus.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/HtmlDateRenderCactus.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/HtmlDateRenderCactus.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/HtmlDateRenderCactus.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,198 @@
+/*
+ * 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.custom.date;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ViewHandler;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.cactus.WebRequest;
+import org.apache.myfaces.custom.date.AbstractHtmlInputDate.UserData;
+
+public class HtmlDateRenderCactus extends ServletTestCase {
+  private FacesContext facesContext;
+  private UIViewRoot viewRoot;
+  
+  public void setUp() throws Exception {
+    FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder
+        .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+    LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
+        .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+    Lifecycle lifecycle = lifecycleFactory
+        .getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+    facesContext = facesContextFactory.getFacesContext(this.config
+        .getServletContext(), request, response, lifecycle);
+    assertNotNull(facesContext);
+    Application application = facesContext.getApplication();
+    ViewHandler viewHandler = application.getViewHandler();
+    String viewId = "/index.jsp";
+    viewRoot = viewHandler.createView(facesContext, viewId);
+    viewRoot.setViewId(viewId);
+    facesContext.setViewRoot(viewRoot);
+  }
+
+  public void beginDecodeDate(WebRequest request) {
+    request.addParameter("test.day", "14");
+    request.addParameter("test.month", "1");
+    request.addParameter("test.year", "2005");
+  }
+  
+  public void testDecodeDate() {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("date");
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("14", data.getDay());
+    assertEquals("1", data.getMonth());
+    assertEquals("2005", data.getYear());
+  }
+  
+  public void beginDecodeWithSubmittedValue(WebRequest request) {
+    request.addParameter("test.day", "14");
+    request.addParameter("test.month", "1");
+    request.addParameter("test.year", "2005");
+  }
+  
+  public void testDecodeWithSubmittedValue() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("date");
+    Date today = new Date();
+    inputDate.setSubmittedValue(new UserData(today, Locale.ENGLISH, null,false, "date"));
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("14", data.getDay());
+    assertEquals("1", data.getMonth());
+    assertEquals("2005", data.getYear());
+  }
+
+  public void beginDecodeTime(WebRequest request) {
+    request.addParameter("test.hours", "12");
+    request.addParameter("test.minutes", "15");
+    request.addParameter("test.seconds", "35");
+  }
+  public void testDecodeTime() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("time");
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("12", data.getHours());
+    assertEquals("15", data.getMinutes());
+    assertEquals("35", data.getSeconds());
+  }
+
+  public void beginDecodeFull(WebRequest request) {
+    request.addParameter("test.day", "14");
+    request.addParameter("test.month", "1");
+    request.addParameter("test.year", "2005");
+    request.addParameter("test.hours", "12");
+    request.addParameter("test.minutes", "15");
+    request.addParameter("test.seconds", "35");
+  }
+
+  public void testDecodeFull() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("full");
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("14", data.getDay());
+    assertEquals("1", data.getMonth());
+    assertEquals("2005", data.getYear());
+    assertEquals("12", data.getHours());
+    assertEquals("15", data.getMinutes());
+    assertEquals("35", data.getSeconds());
+  }
+
+  public void beginDecodeFlorp(WebRequest request) {
+    request.addParameter("test.day", "14");
+    request.addParameter("test.month", "1");
+    request.addParameter("test.year", "2005");
+    request.addParameter("test.hours", "12");
+    request.addParameter("test.minutes", "15");
+  }
+
+  public void testDecodeFlorp() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    // is this correct? Should it parse correctly if the type is not valid?
+    inputDate.setType("florp");
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("14", data.getDay());
+    assertEquals("1", data.getMonth());
+    assertEquals("2005", data.getYear());
+    assertEquals("12", data.getHours());
+    assertEquals("15", data.getMinutes());
+  }
+
+  public void beginDecodeDisabled(WebRequest request) {
+    request.addParameter("test.day", "14");
+    request.addParameter("test.month", "1");
+    request.addParameter("test.year", "2005");
+  }
+
+  public void testDecodeDisabled() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("date");
+    inputDate.setDisabled(true);
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // decode - when disabled currently defaults to today
+    // JIRA Issue #233 requests that the default be null
+    // and the control handle data that is not required
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    Calendar cal = GregorianCalendar.getInstance();
+    assertEquals(cal.get(Calendar.DATE) + "", data.getDay());
+    // different bases - cal starts at 0 in January, UserData starts at 1 in
+    // January
+    assertEquals((cal.get(Calendar.MONTH) + 1) + "", data.getMonth());
+    assertEquals(cal.get(Calendar.YEAR) + "", data.getYear());
+  }
+
+  public void tearDown() {
+    facesContext = null;
+    viewRoot = null;
+  }
+}

Modified: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/HtmlDateRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/HtmlDateRendererTest.java?rev=955793&r1=955792&r2=955793&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/HtmlDateRendererTest.java (original)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/HtmlDateRendererTest.java Thu Jun 17 23:57:54 2010
@@ -19,15 +19,45 @@
 
 package org.apache.myfaces.custom.date;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.render.RenderKitFactory;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.myfaces.application.ApplicationFactoryImpl;
+import org.apache.myfaces.custom.date.AbstractHtmlInputDate.UserData;
+import org.apache.myfaces.shared_tomahawk.util.MessageUtils;
 import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
 import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
 import org.apache.myfaces.test.utils.HtmlRenderedAttr;
 import org.apache.shale.test.mock.MockResponseWriter;
+import org.easymock.MockControl;
+import org.easymock.classextension.MockClassControl;
 
 public class HtmlDateRendererTest extends AbstractTomahawkViewControllerTestCase {
+//  public static void main(String[] args) {
+//    junit.textui.TestRunner.run(HtmlDateRendererTest.class);
+//  }
    
   public HtmlDateRendererTest(String name) {
     super(name);
@@ -39,12 +69,442 @@ public class HtmlDateRendererTest extend
 
   protected void setUp() throws Exception {
     super.setUp();
+    FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
+        MockHtmlDateRendererTestRenderKitFactory.class.getName());
+    FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
+        ApplicationFactoryImpl.class.getName());
   }
 
   protected void tearDown() throws Exception {
     super.tearDown();
   }
 
+  /*
+   * Test method for
+   * 'org.apache.myfaces.custom.date.HtmlDateRenderer.decode(FacesContext,
+   * UIComponent)'
+   */
+  public void testDecodeDate() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("date");
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // setup the request map
+    Map map = new HashMap();
+    map.put("test.day", "14");
+    map.put("test.month", "1");
+    map.put("test.year", "2005");
+    FacesContext facesContext = mockupForDecodeCall(map);
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("14", data.getDay());
+    assertEquals("1", data.getMonth());
+    assertEquals("2005", data.getYear());
+  }
+
+  public void testDecodeWithSubmittedValue() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("date");
+    Date today = new Date();
+    inputDate.setSubmittedValue(new UserData(today, Locale.ENGLISH, null, true, "date"));
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // setup the request map
+    Map map = new HashMap();
+    map.put("test.day", "14");
+    map.put("test.month", "1");
+    map.put("test.year", "2005");
+    FacesContext facesContext = mockupForDecodeCall(map);
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("14", data.getDay());
+    assertEquals("1", data.getMonth());
+    assertEquals("2005", data.getYear());
+  }
+
+  public void testDecodeTime() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("time");
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // setup the request map
+    Map map = new HashMap();
+    map.put("test.hours", "12");
+    map.put("test.minutes", "15");
+    map.put("test.seconds", "35");
+    FacesContext facesContext = mockupForDecodeCall(map);
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("12", data.getHours());
+    assertEquals("15", data.getMinutes());
+    assertEquals("35", data.getSeconds());
+  }
+
+  public void testDecodeFull() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("full");
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // setup the request map
+    Map map = new HashMap();
+    map.put("test.day", "14");
+    map.put("test.month", "1");
+    map.put("test.year", "2005");
+    map.put("test.hours", "12");
+    map.put("test.minutes", "15");
+    map.put("test.seconds", "3");
+    FacesContext facesContext = mockupForDecodeCall(map);
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("14", data.getDay());
+    assertEquals("1", data.getMonth());
+    assertEquals("2005", data.getYear());
+    assertEquals("12", data.getHours());
+    assertEquals("15", data.getMinutes());
+    assertEquals("03", data.getSeconds());
+  }
+
+  public void testDecodeFlorp() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    // is this correct? Should it parse correctly if the type is not valid?
+    inputDate.setType("florp");
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // setup the request map
+    Map map = new HashMap();
+    map.put("test.day", "14");
+    map.put("test.month", "1");
+    map.put("test.year", "2005");
+    map.put("test.hours", "12");
+    map.put("test.minutes", "15");
+    FacesContext facesContext = mockupForDecodeCall(map);
+    // decode
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    assertEquals("14", data.getDay());
+    assertEquals("1", data.getMonth());
+    assertEquals("2005", data.getYear());
+    assertEquals("12", data.getHours());
+    assertEquals("15", data.getMinutes());
+  }
+
+  public void testDecodeDisabled() throws Exception {
+    HtmlInputDate inputDate = new HtmlInputDate();
+    inputDate.setId("test");
+    inputDate.setType("date");
+    inputDate.setDisabled(true);
+    HtmlDateRenderer subject = new HtmlDateRenderer();
+    // setup the request map
+    Map map = new HashMap();
+    map.put("test.day", "14");
+    map.put("test.month", "1");
+    map.put("test.year", "2005");
+    FacesContext facesContext = mockupForDecodeCall(map);
+    // decode - when disabled currently defaults to today
+    // JIRA Issue #233 requests that the default be null
+    // and the control handle data that is not required
+    subject.decode(facesContext, inputDate);
+    UserData data = inputDate.getUserData(Locale.ENGLISH);
+    Calendar cal = GregorianCalendar.getInstance();
+    assertEquals(cal.get(Calendar.DATE) + "", data.getDay());
+    // different bases - cal starts at 0 in January, UserData starts at 1 in
+    // January
+    assertEquals((cal.get(Calendar.MONTH) + 1) + "", data.getMonth());
+    assertEquals(cal.get(Calendar.YEAR) + "", data.getYear());
+  }
+
+  public static class DateTestConverter implements Converter
+  {
+
+    public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String submittedValue)
+            throws ConverterException
+    {
+        HtmlInputDate inputDate = (HtmlInputDate) uiComponent;
+        String type = inputDate.getType();
+        Properties props = new Properties();
+        try
+        {
+            props.load(new ByteArrayInputStream(submittedValue.getBytes()));
+        }catch(IOException e)
+        {
+        }
+        UserData userData = inputDate.getUserData(facesContext.getViewRoot().getLocale());
+        if( ! (type.equals( "time" ) || type.equals( "short_time" )) )
+        {
+            userData.setYear(props.getProperty("year"));
+            userData.setMonth(props.getProperty("month"));
+            userData.setDay(props.getProperty("day"));
+        }
+        
+        if( ! type.equals( "date" ) ){
+            userData.setHours(props.getProperty("hours"));
+            userData.setMinutes(props.getProperty("minutes"));
+            if (type.equals("full") || type.equals("time"))
+            {
+                userData.setSeconds(props.getProperty("seconds"));
+            }
+            if (inputDate.isAmpm()) {
+                userData.setAmpm(props.getProperty("ampm"));
+            }
+        }
+        try {
+            return userData.parse();
+        } catch (ParseException e) {
+            Object[] args = {uiComponent.getId()};
+            throw new ConverterException("Error Parsing");
+        }  
+    }
+
+    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object submitValue)
+            throws ConverterException
+    {
+        HtmlInputDate inputDate = (HtmlInputDate) uiComponent;
+        String type = inputDate.getType();
+        UserData value = new UserData((Date) submitValue, 
+                facesContext.getViewRoot().getLocale(), 
+                inputDate.getTimeZone(), inputDate.isAmpm(), inputDate.getType());        
+        
+        StringBuffer submittedValue = new StringBuffer();
+        if( ! (type.equals( "time" ) || type.equals( "short_time" )) )
+        {
+            submittedValue.append("year=");
+            submittedValue.append((String) value.getYear() );
+            submittedValue.append("\n");
+
+            submittedValue.append("month=");
+            submittedValue.append((String) value.getMonth());
+            submittedValue.append("\n");
+            
+            submittedValue.append("day=");
+            submittedValue.append((String) value.getDay() );
+            submittedValue.append("\n");                
+        }
+        
+        if( ! type.equals( "date" ) )
+        {
+            submittedValue.append("hours=");
+            submittedValue.append((String) value.getHours() );
+            submittedValue.append("\n");
+            
+            submittedValue.append("minutes=");
+            submittedValue.append((String) value.getMinutes() );
+            submittedValue.append("\n");
+
+            if (type.equals("full") || type.equals("time"))
+            {
+                submittedValue.append("seconds=");
+                submittedValue.append((String) value.getSeconds() );
+                submittedValue.append("\n");                    
+            }
+            
+            if (inputDate.isAmpm())
+            {
+                submittedValue.append("ampm=");
+                submittedValue.append((String) value.getAmpm() );
+                submittedValue.append("\n");
+            }
+        }
+        if (submittedValue.charAt(submittedValue.length()-1) == '\n' )
+        {
+            submittedValue.deleteCharAt(submittedValue.length()-1);
+        }
+        
+        return submittedValue.toString();
+    }
+      
+  }
+  
+  public void testDecodeConverterDate() throws Exception {
+      HtmlInputDate inputDate = new HtmlInputDate();
+      inputDate.setId("test");
+      inputDate.setType("date");
+      inputDate.setConverter(new DateTestConverter());
+      HtmlDateRenderer subject = new HtmlDateRenderer();
+      // setup the request map
+      Map map = new HashMap();
+      map.put("test.day", "14");
+      map.put("test.month", "1");
+      map.put("test.year", "2005");
+      FacesContext facesContext = mockupForDecodeCall(map);
+      // decode
+      subject.decode(facesContext, inputDate);
+      //With converter, the submitted value is a String
+      assertTrue(inputDate.getSubmittedValue() instanceof String);
+      // converter
+      inputDate.validate(facesContext);
+      
+      UserData data = inputDate.getUserData(Locale.ENGLISH);
+      assertEquals("14", data.getDay());
+      assertEquals("1", data.getMonth());
+      assertEquals("2005", data.getYear());
+    }
+  
+  public void testDecodeConverterWithSubmittedValue() throws Exception {
+      HtmlInputDate inputDate = new HtmlInputDate();
+      inputDate.setId("test");
+      inputDate.setType("date");
+      inputDate.setConverter(new DateTestConverter());
+      Date today = new Date();
+      inputDate.setSubmittedValue(new UserData(today, Locale.ENGLISH, null, true, "date"));
+      HtmlDateRenderer subject = new HtmlDateRenderer();
+      // setup the request map
+      Map map = new HashMap();
+      map.put("test.day", "14");
+      map.put("test.month", "1");
+      map.put("test.year", "2005");
+      FacesContext facesContext = mockupForDecodeCall(map);
+      // decode
+      subject.decode(facesContext, inputDate);
+      //With converter, the submitted value is a String
+      assertTrue(inputDate.getSubmittedValue() instanceof String);
+      // converter
+      inputDate.validate(facesContext);
+      
+      UserData data = inputDate.getUserData(Locale.ENGLISH);
+      assertEquals("14", data.getDay());
+      assertEquals("1", data.getMonth());
+      assertEquals("2005", data.getYear());
+    }
+  
+  public void testDecodeConverterTime() throws Exception {
+      HtmlInputDate inputDate = new HtmlInputDate();
+      inputDate.setId("test");
+      inputDate.setType("time");
+      HtmlDateRenderer subject = new HtmlDateRenderer();
+      // setup the request map
+      Map map = new HashMap();
+      map.put("test.hours", "12");
+      map.put("test.minutes", "15");
+      map.put("test.seconds", "35");
+      FacesContext facesContext = mockupForDecodeCall(map);
+      // decode
+      subject.decode(facesContext, inputDate);
+      //With converter, the submitted value is a String
+      assertTrue(inputDate.getSubmittedValue() instanceof String);
+      // converter
+      inputDate.validate(facesContext);
+      
+      UserData data = inputDate.getUserData(Locale.ENGLISH);
+      assertEquals("12", data.getHours());
+      assertEquals("15", data.getMinutes());
+      assertEquals("35", data.getSeconds());
+    }
+
+  public void testDecodeConverterFull() throws Exception {
+      HtmlInputDate inputDate = new HtmlInputDate();
+      inputDate.setId("test");
+      inputDate.setType("full");
+      HtmlDateRenderer subject = new HtmlDateRenderer();
+      // setup the request map
+      Map map = new HashMap();
+      map.put("test.day", "14");
+      map.put("test.month", "1");
+      map.put("test.year", "2005");
+      map.put("test.hours", "12");
+      map.put("test.minutes", "15");
+      map.put("test.seconds", "3");
+      FacesContext facesContext = mockupForDecodeCall(map);
+      // decode
+      subject.decode(facesContext, inputDate);
+      //With converter, the submitted value is a String
+      assertTrue(inputDate.getSubmittedValue() instanceof String);
+      // converter
+      inputDate.validate(facesContext);
+      UserData data = inputDate.getUserData(Locale.ENGLISH);
+      assertEquals("14", data.getDay());
+      assertEquals("1", data.getMonth());
+      assertEquals("2005", data.getYear());
+      assertEquals("12", data.getHours());
+      assertEquals("15", data.getMinutes());
+      assertEquals("03", data.getSeconds());
+    }
+
+    public void testDecodeConverterFlorp() throws Exception {
+      HtmlInputDate inputDate = new HtmlInputDate();
+      inputDate.setId("test");
+      // is this correct? Should it parse correctly if the type is not valid?
+      inputDate.setType("florp");
+      HtmlDateRenderer subject = new HtmlDateRenderer();
+      // setup the request map
+      Map map = new HashMap();
+      map.put("test.day", "14");
+      map.put("test.month", "1");
+      map.put("test.year", "2005");
+      map.put("test.hours", "12");
+      map.put("test.minutes", "15");
+      FacesContext facesContext = mockupForDecodeCall(map);
+      // decode
+      subject.decode(facesContext, inputDate);
+      //With converter, the submitted value is a String
+      assertTrue(inputDate.getSubmittedValue() instanceof String);
+      // converter
+      inputDate.validate(facesContext);
+      UserData data = inputDate.getUserData(Locale.ENGLISH);
+      assertEquals("14", data.getDay());
+      assertEquals("1", data.getMonth());
+      assertEquals("2005", data.getYear());
+      assertEquals("12", data.getHours());
+      assertEquals("15", data.getMinutes());
+    }
+
+  /*
+   * Test method for
+   * 'org.apache.myfaces.custom.date.HtmlDateRenderer.encodeEnd(FacesContext,
+   * UIComponent)'
+   */
+  public void testEncodeEnd() throws Exception {
+    
+  }
+
+  /*
+   * Test method for
+   * 'org.apache.myfaces.custom.date.HtmlDateRenderer.getConvertedValue(FacesContext,
+   * UIComponent, Object)'
+   */
+  public void testGetConvertedValue() throws Exception {
+  }
+
+  private FacesContext mockupForDecodeCall(Map requestParameterMap) {
+    // mock FacesContext
+    MockControl contextControl = MockClassControl
+        .createControl(FacesContext.class);
+    FacesContext facesContext = (FacesContext) contextControl.getMock();
+    // mock UIViewRoot
+    MockControl viewControl = MockClassControl.createControl(UIViewRoot.class);
+    UIViewRoot viewRoot = (UIViewRoot) viewControl.getMock();
+    // mock ExternalContext
+    MockControl externalContextControl = MockClassControl
+        .createControl(ExternalContext.class);
+    ExternalContext externalContext = (ExternalContext) externalContextControl
+        .getMock();
+    // set the view root
+    facesContext.getViewRoot();
+    contextControl.setReturnValue(viewRoot);
+    // called twice
+    facesContext.getViewRoot();
+    contextControl.setReturnValue(viewRoot);
+    // set the external context
+    facesContext.getExternalContext();
+    contextControl.setReturnValue(externalContext);
+    // set the locale
+    viewRoot.getLocale();
+    viewControl.setReturnValue(Locale.ENGLISH);
+    // set the render kit id
+    viewRoot.getRenderKitId();
+    viewControl.setReturnValue(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+    externalContext.getRequestParameterMap();
+    externalContextControl.setReturnValue(requestParameterMap);
+    // prepare
+    contextControl.replay();
+    viewControl.replay();
+    externalContextControl.replay();
+    return facesContext;
+  }
+
   public void testHtmlPropertyPassTru() throws Exception
   {
       HtmlInputDate inputDate = new HtmlInputDate();

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/MockHtmlDateRendererTestRenderKit.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/MockHtmlDateRendererTestRenderKit.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/MockHtmlDateRendererTestRenderKit.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/MockHtmlDateRendererTestRenderKit.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.custom.date;
+
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+import javax.faces.render.Renderer;
+import javax.faces.render.ResponseStateManager;
+
+public class MockHtmlDateRendererTestRenderKit extends RenderKit {
+  private Map renderers = new HashMap();
+  
+  public MockHtmlDateRendererTestRenderKit() {
+    addRenderer("javax.faces.Input", "org.apache.myfaces.Date", new HtmlDateRenderer());
+  }
+  
+  public void addRenderer(String family, String rendererType, Renderer renderer) {
+    Map sub = (Map)renderers.get(family);
+    if(null == sub) {
+      sub = new HashMap();
+      renderers.put(family, sub);
+    }
+    sub.put(rendererType, renderer);
+  }
+
+  public Renderer getRenderer(String family, String rendererType) {
+    Renderer renderer = null;
+    Map sub = (Map)renderers.get(family);
+    if(null != sub) {
+      renderer = (Renderer)sub.get(rendererType);
+    }
+    return renderer;
+  }
+
+  public ResponseStateManager getResponseStateManager() {
+    return null;
+  }
+
+  public ResponseWriter createResponseWriter(Writer writer,
+      String contentTypeList, String characterEncoding) {
+    return null;
+  }
+
+  public ResponseStream createResponseStream(OutputStream out) {
+    return null;
+  }
+
+}

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/MockHtmlDateRendererTestRenderKitFactory.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/MockHtmlDateRendererTestRenderKitFactory.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/MockHtmlDateRendererTestRenderKitFactory.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/MockHtmlDateRendererTestRenderKitFactory.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.custom.date;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+
+public class MockHtmlDateRendererTestRenderKitFactory extends RenderKitFactory {
+  private Map renderKits = new HashMap();
+
+  public MockHtmlDateRendererTestRenderKitFactory() {
+    addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, new MockHtmlDateRendererTestRenderKit());
+  }
+  
+  public void addRenderKit(String renderKitId, RenderKit renderKit) {
+    renderKits.put(renderKitId, renderKit);
+  }
+
+  public RenderKit getRenderKit(FacesContext context, String renderKitId) {
+    return (RenderKit)renderKits.get(renderKitId);
+  }
+
+  public Iterator getRenderKitIds() {
+    List ids = new ArrayList();
+    ids.add(RenderKitFactory.HTML_BASIC_RENDER_KIT);
+    return ids.iterator();
+  }
+
+}

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/TestBean.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/TestBean.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/TestBean.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/TestBean.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,39 @@
+/*
+ * 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.custom.date;
+
+import java.util.Date;
+
+public class TestBean {
+  private Date date;
+
+  public TestBean() {
+    super();
+  }
+
+  public Date getDate() {
+    return date;
+  }
+
+  public void setDate(Date date) {
+    this.date = date;
+  }
+
+}

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/UserDataTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/UserDataTest.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/UserDataTest.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/date/UserDataTest.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,215 @@
+package org.apache.myfaces.custom.date;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
+import java.util.Date;
+import java.util.Locale;
+
+import org.apache.myfaces.custom.date.AbstractHtmlInputDate.UserData;
+
+import junit.framework.TestCase;
+
+public class UserDataTest extends TestCase {
+    
+    private UserData userData;
+    
+    private String getDefaultTimeZoneId() {
+        return TimeZone.getDefault().getID();
+    }
+    
+    public void testConstructorDoesNotSetDateVariablesWhenTheDateIsNull() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId() , false, "date");
+        assertNull(userData.getYear());
+        assertNull(userData.getDay());
+        assertNull(userData.getHours());
+    }
+    
+    public void testParseReturnsNullWhenTypeIsDateAndComponentNotUsed() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), false, "date");
+        userData.setDay("");
+        userData.setMonth("-1");
+        userData.setYear("");
+        try {
+            Date date = userData.parse();
+            assertNull(date);
+        } catch (ParseException e) {
+            fail();
+        }
+    }
+    
+    public void testParseThrowsParseExceptionWhenInvalidDataIsEnteredForTypeDate() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), false, "date");
+        userData.setDay("40");
+        userData.setMonth("-1");
+        userData.setYear("2005");
+        try {
+            userData.parse();
+            fail();
+        } catch (ParseException e) {
+        }
+    }
+    
+    public void testParseGivesCorrectDateWhenValidDataIsEnteredForTypeDate() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), false, "date");
+        userData.setDay("20");
+        userData.setMonth("7");
+        userData.setYear("2006");
+        
+        Calendar calendar = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
+        calendar.set(Calendar.DAY_OF_MONTH, 20);
+        calendar.set(Calendar.MONTH, 6);
+        calendar.set(Calendar.YEAR, 2006);
+        
+        //only day, month and year is considered for equality
+        SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");        
+        try {
+            Date date1 = userData.parse();
+            Date date2 = calendar.getTime();
+            assertEquals(formatter.format(date1), formatter.format(date2));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
+    
+    public void testParseReturnsNullWhenTypeIsTimeAndComponentNotUsed() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), false, "time");
+        userData.setHours("");
+        userData.setMinutes("");
+        userData.setSeconds("");
+        
+        try {
+            assertNull(userData.parse());
+        } catch (ParseException e) {
+            fail();
+        }
+    }
+    
+    public void testParseThrowsParseExceptionWhenInvalidDataIsEnteredForTypeTime() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), false, "time");
+        userData.setHours("25");
+        userData.setMinutes("");
+        userData.setSeconds("10");
+        
+        try {
+            userData.parse();
+            fail();
+        } catch (ParseException e) {
+        }
+    }
+    
+    public void testParseGivesCorrectDateWhenValidDataIsEnteredForTypeTime() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), false, "time");
+        userData.setHours("10");
+        userData.setMinutes("50");
+        userData.setSeconds("30");
+        
+        Calendar calendar = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
+        calendar.set(Calendar.HOUR_OF_DAY, 10);
+        calendar.set(Calendar.MINUTE, 50);
+        calendar.set(Calendar.SECOND, 30);
+        
+        //hour, minute, seconds is considered for equality
+        SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");        
+        try {
+            Date date1 = userData.parse();
+            Date date2 = calendar.getTime();
+            assertEquals(formatter.format(date1), formatter.format(date2));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+    }
+    
+    public void testParseReturnsNullWhenTypeIsFullAndComponentNotUsed() {
+        userData = new UserData(null, Locale.ENGLISH, "GMT+2:00", true, "full");
+        userData.setDay("");
+        userData.setMonth("-1");
+        userData.setYear("");
+        userData.setHours("");
+        userData.setMinutes("");
+        userData.setSeconds("");
+        userData.setAmpm("-1");
+        
+        try {
+            assertNull(userData.parse());
+        } catch (ParseException e) {
+            fail();
+        }
+    }
+    
+    public void testParseThrowsParseExceptionWhenInvalidDataIsEnteredForTypeFullCase1() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), true, "full");
+        //date is used, time is not
+        userData.setDay("40");
+        userData.setMonth("-1");
+        userData.setYear("");
+        userData.setHours("");
+        userData.setMinutes("");
+        userData.setSeconds("");
+        userData.setAmpm("-1");
+        
+        try {
+            userData.parse();
+            fail();
+        } catch (ParseException e) {
+        }
+    }
+    
+    public void testParseThrowsParseExceptionWhenInvalidDataIsEnteredForTypeFullCase2() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), true, "full");
+        //date is used time is not
+        userData.setDay("");
+        userData.setMonth("0");
+        userData.setYear("2005");
+        userData.setHours("");
+        userData.setMinutes("");
+        userData.setSeconds("");
+        userData.setAmpm("-1");
+        
+        try {
+            userData.parse();
+            fail();
+        } catch (ParseException e) {
+        }
+    }
+    
+    public void testParseThrowsParseExceptionWhenInvalidDataIsEnteredForTypeFullCase3() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), true, "full");
+        //date is used time is not
+        userData.setDay("5");
+        userData.setMonth("10");
+        userData.setYear("2005");
+        userData.setHours("");
+        userData.setMinutes("");
+        userData.setSeconds("");
+        userData.setAmpm("-1");
+        
+        try {
+            userData.parse();
+            fail();
+        } catch (ParseException e) {
+        }
+    }
+    
+    public void testParseThrowsParseExceptionWhenInvalidDataIsEnteredForTypeFullCase4() {
+        userData = new UserData(null, Locale.getDefault(), getDefaultTimeZoneId(), true, "full");
+        //date is not used but time is
+        userData.setDay("");
+        userData.setMonth("-1");
+        userData.setYear("");
+        userData.setHours("");
+        userData.setMinutes("30");
+        userData.setSeconds("");
+        userData.setAmpm("-1");
+        
+        try {
+            userData.parse();
+            fail();
+        } catch (ParseException e) {
+        }
+    }
+    
+    
+
+}

Modified: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRendererTest.java?rev=955793&r1=955792&r2=955793&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRendererTest.java (original)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/fileupload/HtmlFileUploadRendererTest.java Thu Jun 17 23:57:54 2010
@@ -18,13 +18,24 @@
  */
 package org.apache.myfaces.custom.fileupload;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.disk.DiskFileItem;
 import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
 import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
 import org.apache.myfaces.test.utils.HtmlRenderedAttr;
 import org.apache.shale.test.mock.MockResponseWriter;
+import org.easymock.MockControl;
 
 public class HtmlFileUploadRendererTest extends AbstractTomahawkViewControllerTestCase
 {
@@ -65,4 +76,81 @@ public class HtmlFileUploadRendererTest 
             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
         }
     }
+    
+    public void testUploadedFileDefaultFileImplSerializable() throws Exception
+    {
+        String fieldName = "inputFile";
+        String contentType = "someType";
+        boolean isFormField = true;
+        String fileName = "tempFile";
+        int sizeThreshold = 10000;
+        File repository = new File(System.getProperty("java.io.tmpdir"));
+        DiskFileItem item = new DiskFileItem(fieldName, contentType, isFormField, fileName, sizeThreshold, repository);
+
+        UploadedFileDefaultFileImpl original = new UploadedFileDefaultFileImpl(item);
+        
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(out);
+        oos.writeObject(original);
+        oos.close();
+
+        byte[] serializedArray = out.toByteArray();
+        InputStream in = new ByteArrayInputStream(serializedArray);
+        ObjectInputStream ois = new ObjectInputStream(in);
+        UploadedFileDefaultFileImpl copy = (UploadedFileDefaultFileImpl) ois.readObject();
+        
+        assertEquals(original.getName(), copy.getName());
+        assertEquals(original.getContentType(), copy.getContentType());
+        assertEquals(copy.getSize(),0);
+        
+        copy.getStorageStrategy().deleteFileContents();
+    }
+    
+    public void testUploadedFileDefaultMemoryImplSerializable() throws Exception
+    {
+        String fieldName = "inputFile";
+        String contentType = "someType";
+        
+        MockControl control = MockControl.createControl(FileItem.class);
+        FileItem item = (FileItem) control.getMock();
+        
+        item.getName();
+        control.setReturnValue(fieldName,1);
+        item.getContentType();
+        control.setReturnValue(contentType,1);
+        item.getSize();
+        control.setReturnValue(0,1);
+        item.getInputStream();
+        control.setReturnValue(new InputStream()
+        {
+            public int read() throws IOException
+            {
+                return -1;
+            }
+        },1);
+
+        item.delete();
+        control.setVoidCallable(1);
+        
+        control.replay();
+        
+        UploadedFileDefaultMemoryImpl original = new UploadedFileDefaultMemoryImpl(item);
+        
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(out);
+        oos.writeObject(original);
+        oos.close();
+
+        byte[] serializedArray = out.toByteArray();
+        InputStream in = new ByteArrayInputStream(serializedArray);
+        ObjectInputStream ois = new ObjectInputStream(in);
+        UploadedFileDefaultMemoryImpl copy = (UploadedFileDefaultMemoryImpl) ois.readObject();
+        
+        assertEquals(original.getName(), copy.getName());
+        assertEquals(original.getContentType(), copy.getContentType());
+        assertEquals(copy.getSize(),0);
+        
+        copy.getStorageStrategy().deleteFileContents();
+    }
+
 }

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/savestate/SaveStateTestBean.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/savestate/SaveStateTestBean.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/savestate/SaveStateTestBean.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/savestate/SaveStateTestBean.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,74 @@
+/*
+ * 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.custom.savestate;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author cagatay
+ * Test bean for UISaveStateTest
+ */
+public class SaveStateTestBean implements Serializable, StateHolder {
+
+    private LinkedList linkedList;
+
+    private String name;
+
+    public LinkedList getLinkedList() {
+        if(linkedList == null)
+            linkedList = new LinkedList();
+        return linkedList;
+    }
+
+    public void setLinkedList(LinkedList linkedList) {
+        this.linkedList = linkedList;
+    }
+
+    public boolean isTransient() {
+        return false;
+    }
+
+    public void restoreState(FacesContext context, Object state) {
+        Object values[] = (Object[])state;
+        name = (String)values[0];
+    }
+
+    public Object saveState(FacesContext context) {
+        Object values[] = new Object[1];
+        values[0] = name;
+        return values;
+    }
+
+    public void setTransient(boolean newTransientValue) {
+        
+    }
+
+    public String name() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+}

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/savestate/UISaveStateTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/savestate/UISaveStateTest.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/savestate/UISaveStateTest.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/savestate/UISaveStateTest.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,95 @@
+package org.apache.myfaces.custom.savestate;
+
+/*
+ * 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.
+ */
+import java.util.LinkedList;
+
+import javax.faces.el.ValueBinding;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
+
+/**
+ * @author cagatay
+ * Tests for UISaveState
+ */
+public class UISaveStateTest extends AbstractTomahawkViewControllerTestCase{
+
+    private UISaveState saveState;
+    private SaveStateTestBean saveStateTestBean;
+
+    public UISaveStateTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        return new TestSuite(UISaveStateTest.class);
+    }
+
+    public void setUp() throws Exception{
+        super.setUp();
+        saveState = new UISaveState();
+        saveStateTestBean = new SaveStateTestBean();
+        facesContext.getExternalContext().getRequestMap().put("testBean", saveStateTestBean);
+    }
+
+    public void tearDown() throws Exception{
+        saveState = null;
+        saveStateTestBean = null;
+        super.tearDown();
+    }
+
+    public void testWorksWithLinkedList() {
+        ValueBinding valueBinding = facesContext.getApplication().createValueBinding("#{testBean.linkedList}");
+        saveState.setValueBinding("value", valueBinding);
+
+        LinkedList linkedList = (LinkedList) valueBinding.getValue(facesContext);
+
+        try {
+            Object state = saveState.saveState(facesContext);
+            Object values[] = (Object[])state;
+            assertEquals(values[2], linkedList);
+
+            saveState.restoreState(facesContext, state);
+            
+        }catch(Exception exception) {
+            fail();
+        }
+    }
+
+    public void testWorksWithStateHolder() {
+        ValueBinding valueBinding = facesContext.getApplication().createValueBinding("#{testBean}");
+        saveState.setValueBinding("value", valueBinding);
+
+        SaveStateTestBean testBean = (SaveStateTestBean) valueBinding.getValue(facesContext);
+
+        try {
+            Object state = saveState.saveState(facesContext);
+            Object values[] = (Object[])state;
+            assertNotSame(values[2], testBean); //values[2] should be a type of "javax.faces.component._AttachedStateWrapper"
+
+            saveState.restoreState(facesContext, state);
+        }catch(Exception exception) {
+            fail();
+        }
+    }
+
+}

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,112 @@
+/*
+ * 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.custom.stylesheet;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import javax.faces.FacesException;
+
+import junit.framework.Test;
+
+import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
+import org.apache.shale.test.mock.MockResponseWriter;
+
+public class StylesheetRendererTest extends AbstractTomahawkViewControllerTestCase
+{
+
+    private MockResponseWriter writer ;
+    private Stylesheet stylesheet ;
+    
+    public StylesheetRendererTest(String name)
+    {
+        super(name);
+    }
+    
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        stylesheet = new Stylesheet();
+        stylesheet.setPath("test.css");
+        stylesheet.setMedia("printer");
+        writer = new MockResponseWriter(new StringWriter(), null, null);
+        facesContext.setResponseWriter(writer);
+//        facesContext.getRenderKit().addRenderer(
+//                stylesheet.getFamily(), 
+//                stylesheet.getRendererType(), 
+//                new StylesheetRenderer());
+    }
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        writer = null;
+        stylesheet = null;
+    }
+
+    public static Test suite()
+    {
+        return null; // keep this method or maven won't run it
+    }
+
+    /*
+     * Test method for 'org.apache.myfaces.custom.stylesheet.StylesheetRenderer.encodeEnd(FacesContext, UIComponent)'
+     */
+    public void testInline() throws IOException
+    {
+        stylesheet.setInline(true);
+        stylesheet.setPath("/styles/test.css");
+        stylesheet.encodeEnd(facesContext);
+        facesContext.renderResponse();
+
+        String output = writer.getWriter().toString();
+        
+        assertTrue("looking for a <style>", output.trim().startsWith("<style"));
+    }
+
+    /*
+     * Test method for 'org.apache.myfaces.custom.stylesheet.StylesheetRenderer.encodeEnd(FacesContext, UIComponent)'
+     */
+    public void testInlineInvalid() throws IOException
+    {
+        stylesheet.setInline(true);
+        try
+        {
+            stylesheet.encodeEnd(facesContext);
+            fail("No exception was thrown for an invalid stylesheet path");
+        }
+        catch(FacesException e)
+        {
+            // expected
+        }
+    }
+
+    public void testLink() throws IOException
+    {
+
+        stylesheet.encodeEnd(facesContext);
+        facesContext.renderResponse();
+
+        String output = writer.getWriter().toString();
+        
+        assertTrue("looking for a <link>", output.trim().startsWith("<link"));
+    }
+
+}

Modified: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/toggle/TogglePanelRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/toggle/TogglePanelRendererTest.java?rev=955793&r1=955792&r2=955793&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/toggle/TogglePanelRendererTest.java (original)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/toggle/TogglePanelRendererTest.java Thu Jun 17 23:57:54 2010
@@ -61,7 +61,8 @@ public class TogglePanelRendererTest ext
         {
             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
         }
-    }    
+    } 
+    
     
     public void testHtmlPropertyPassTruNotRendered() throws Exception
     {

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/transform/ManagedFoo.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/transform/ManagedFoo.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/transform/ManagedFoo.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/transform/ManagedFoo.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,96 @@
+/*
+ * 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.custom.transform;
+
+import java.io.InputStream;
+
+/**
+ * Simple class to be used as a ManagedBean in testing.
+ *
+ * @author Sean Schofield
+ */
+public class ManagedFoo
+{
+    private String content;
+    private String stylesheet;
+    private String contentLocation;
+    private String stylesheetLocation;
+    private InputStream contentStream;
+    private InputStream styleStream;
+
+    public String getContent()
+    {
+        return content;
+    }
+
+    public void setContent(String content)
+    {
+        this.content = content;
+    }
+
+    public String getStylesheet()
+    {
+        return stylesheet;
+    }
+
+    public void setStylesheet(String stylesheet)
+    {
+        this.stylesheet = stylesheet;
+    }
+
+    public String getContentLocation()
+    {
+        return contentLocation;
+    }
+
+    public void setContentLocation(String contentLocation)
+    {
+        this.contentLocation = contentLocation;
+    }
+
+    public String getStylesheetLocation()
+    {
+        return stylesheetLocation;
+    }
+
+    public void setStylesheetLocation(String stylesheetLocation)
+    {
+        this.stylesheetLocation = stylesheetLocation;
+    }
+
+    public InputStream getContentStream()
+    {
+        return contentStream;
+    }
+
+    public void setContentStream(InputStream contentStream)
+    {
+        this.contentStream = contentStream;
+    }
+
+    public InputStream getStyleStream()
+    {
+        return styleStream;
+    }
+
+    public void setStyleStream(InputStream styleStream)
+    {
+        this.styleStream = styleStream;
+    }
+}

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/transform/XmlTransformTest.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/transform/XmlTransformTest.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/transform/XmlTransformTest.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/transform/XmlTransformTest.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,398 @@
+/*
+ * 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.custom.transform;
+
+import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.mock.MockResponseWriter;
+import org.apache.shale.test.mock.MockRenderKitFactory;
+import org.apache.shale.test.mock.MockHttpServletRequest;
+import org.apache.shale.test.mock.MockValueBinding;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import java.io.*;
+import java.net.URL;
+import java.net.URI;
+
+/**
+ * Test case for XmlTransform
+ *
+ * @author Sean Schofield
+ */
+public class XmlTransformTest extends AbstractJsfTestCase
+{
+    private static final String PETS_STYLESHEET = "pets.xsl";
+    private static final String PETS_CONTENT = "pets.xml";
+    private static final String EXPECTED_TEXT = "Iguana";
+
+    private XmlTransform xmlTransform;
+    private ManagedFoo fooBean;
+    private String stylesheet;
+    private String stylesheetLocation = PETS_STYLESHEET;
+    private InputStream styleStream;
+    private String content;
+    private String contentLocation = PETS_CONTENT;
+    private InputStream contentStream;
+
+    private StringWriter mockWriter = new StringWriter();
+
+    /**
+     * Constructor
+     * @param name String
+     */
+    public XmlTransformTest(String name)
+    {
+        super(name);
+    }
+
+    /**
+     * See abstract class
+     */
+    public void setUp() throws Exception
+    {
+        super.setUp();
+
+        xmlTransform = new XmlTransform();
+
+        // additional setup not provided automatically by the shale mock stuff
+        facesContext.setResponseWriter(new MockResponseWriter(mockWriter, null, null));
+
+        // TODO remove these two lines once shale-test goes alpha, see MYFACES-1155
+        facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
+
+        fooBean = new ManagedFoo();
+        fooBean.setContentLocation(PETS_CONTENT);
+        fooBean.setStylesheetLocation(PETS_STYLESHEET);
+
+        // put the foo bean in the request scope
+        MockHttpServletRequest request = (MockHttpServletRequest)facesContext.getExternalContext().getRequest();
+        request.setAttribute("foo", fooBean);
+
+        // setup input stream to be used in some of the test cases
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        if (loader == null)
+        {
+            loader = XmlTransform.class.getClassLoader();
+        }
+
+        URL url = loader.getResource(PETS_CONTENT);
+        try
+        {
+            contentStream = new FileInputStream(new File(URI.create(url.toString())));
+
+            // now also populate the String variable for certain test cases
+            FileInputStream cs = new FileInputStream(new File(URI.create(url.toString())));
+            int x= cs.available();
+            byte b[]= new byte[x];
+            //noinspection ResultOfMethodCallIgnored
+            cs.read(b);
+            content = new String(b);
+        }
+        catch (IOException io)
+        {}  // do nothing - test will fail eventually
+
+        // setup stylesheet text to be used in some of the test cases
+        url = loader.getResource(PETS_STYLESHEET);
+        try
+        {
+            styleStream = new FileInputStream(new File(URI.create(url.toString())));
+
+            // now also populate the String variable for certain test cases
+            FileInputStream ss = new FileInputStream(new File(URI.create(url.toString())));
+            int x= ss.available();
+            byte b[]= new byte[x];
+            //noinspection ResultOfMethodCallIgnored
+            ss.read(b);
+            stylesheet = new String(b);
+        }
+        catch (IOException io)
+        {}  // do nothing - test will fail eventually
+
+        fooBean.setContent(content);
+        fooBean.setStylesheet(stylesheet);
+        fooBean.setContentStream(contentStream);
+        fooBean.setStyleStream(styleStream);
+    }
+
+    /**
+     * Test the save and restore state methods.
+     */
+    public void testSaveAndRestoreState()
+    {
+        /**
+         * NOTE: Normally you would not set all of these properties together in the component, but for the
+         * purposes of testing, we want to make sure all fields are saved and restored properly.
+         */
+        xmlTransform.setContent(content);
+        xmlTransform.setContentLocation(contentLocation);
+        xmlTransform.setStylesheet(stylesheet);
+        xmlTransform.setStylesheetLocation(stylesheetLocation);
+        xmlTransform.setContentStream(contentStream);
+        xmlTransform.setStyleStream(styleStream);
+
+        Object state = xmlTransform.saveState(facesContext);
+        xmlTransform = new XmlTransform();
+        xmlTransform.restoreState(facesContext, state);
+
+        assertEquals(content, xmlTransform.getContent());
+        assertEquals(contentLocation, xmlTransform.getContentLocation());
+        assertEquals(stylesheet, xmlTransform.getStylesheet());
+        assertEquals(stylesheetLocation, xmlTransform.getStylesheetLocation());
+        assertNull("contentStream should be null since it cannot be serialized", xmlTransform.getContentStream());
+        assertNull("styleStream should be null since it cannot be serialized", xmlTransform.getStyleStream());
+    }
+
+    /**
+     * Test the save and restore state methods with all values as value binding expressions.  This also tests
+     * the value bindings themselves to make sure they are working.
+     */
+    public void testSaveAndRestoreStateValueBinding()
+    {
+        /**
+         * NOTE: Normally you would not set all of these properties together in the component, but for the
+         * purposes of testing, we want to make sure all fields are saved and restored properly.
+         */
+        xmlTransform.setValueBinding("content", new MockValueBinding(application, "#{foo.content}"));
+        xmlTransform.setValueBinding("contentLocation", new MockValueBinding(application, "#{foo.contentLocation}"));
+        xmlTransform.setValueBinding("stylesheet", new MockValueBinding(application, "#{foo.stylesheet}"));
+        xmlTransform.setValueBinding("stylesheetLocation", new MockValueBinding(application, "#{foo.stylesheetLocation}"));
+        xmlTransform.setValueBinding("contentStream", new MockValueBinding(application, "#{foo.contentStream}"));
+        xmlTransform.setValueBinding("styleStream", new MockValueBinding(application, "#{foo.styleStream}"));
+
+        Object state = xmlTransform.saveState(facesContext);
+        xmlTransform = new XmlTransform();
+        xmlTransform.restoreState(facesContext, state);
+
+        assertEquals(content, xmlTransform.getContent());
+        assertEquals(contentLocation, xmlTransform.getContentLocation());
+        assertEquals(stylesheet, xmlTransform.getStylesheet());
+        assertEquals(stylesheetLocation, xmlTransform.getStylesheetLocation());
+        assertEquals(contentStream, xmlTransform.getContentStream());
+    }
+
+    public void testSetContent()
+    {
+        xmlTransform.setContent("foo");
+        assertEquals("foo", xmlTransform.getContent());
+
+        // reset property so we can test value binding
+        xmlTransform.setContent(null);
+        xmlTransform.setValueBinding("content", new MockValueBinding(application, "#{foo.content}"));
+        assertEquals(fooBean.getContent(), xmlTransform.getContent());
+    }
+
+    public void testSetContentStream()
+    {
+        xmlTransform.setContentStream(fooBean.getContentStream());
+        assertEquals(fooBean.getContentStream(), xmlTransform.getContentStream());
+    }
+
+    public void testSetContentStreamValueBinding()
+    {
+        xmlTransform.setValueBinding("contentStream", new MockValueBinding(application, "#{foo.contentStream}"));
+        assertEquals(fooBean.getContentStream(), xmlTransform.getContentStream());
+    }
+
+    public void testSetStylesheet()
+    {
+        xmlTransform.setStylesheet("foo");
+        assertEquals("foo", xmlTransform.getStylesheet());
+
+        // reset property so we can test value binding
+        xmlTransform.setStylesheet(null);
+        xmlTransform.setValueBinding("stylesheet", new MockValueBinding(application, "#{foo.stylesheet}"));
+        assertEquals(fooBean.getStylesheet(), xmlTransform.getStylesheet());
+    }
+
+    /**
+     * Component should throw NPE if no stylesheet or Transform is provided
+     */
+    public void testNoTransformInfo() throws IOException
+    {
+        try
+        {
+            xmlTransform.encodeBegin(facesContext);
+        }
+        catch (NullPointerException e)
+        {
+            return;
+        }
+
+        fail("Expected exception when no Transform or stylesheet provided");
+    }
+
+    /**
+     * Component should throw NPE if no content is provided
+     */
+    public void testStylesheetNoContent() throws IOException
+    {
+        // stylesheet is not sufficient, content must be provided
+        xmlTransform.setStylesheet("blah");
+
+        try
+        {
+            xmlTransform.encodeBegin(facesContext);
+        }
+        catch (NullPointerException e)
+        {
+            return;
+        }
+
+        fail("Expected exception when stylesheet but no content provided");
+    }
+
+    public void testStyleSheet() throws IOException
+    {
+        xmlTransform.setContentLocation(contentLocation);
+        xmlTransform.setStylesheet(stylesheet);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testStyleSheetValueBinding() throws IOException
+    {
+        xmlTransform.setContent(content);
+        xmlTransform.setValueBinding("stylesheet", new MockValueBinding(application, "#{foo.stylesheet}"));
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testStylesheetLocation() throws IOException
+    {
+        xmlTransform.setContent(content);
+        xmlTransform.setStylesheetLocation(stylesheetLocation);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testStylesheetLocationValueBinding() throws IOException
+    {
+        xmlTransform.setContent(content);
+        xmlTransform.setValueBinding("stylesheetLocation", new MockValueBinding(application, "#{foo.stylesheetLocation}"));
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testStylesheetStream() throws IOException
+    {
+        xmlTransform.setStyleStream(styleStream);
+        xmlTransform.setContent(content);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testStylesheetStreamValueBinding() throws IOException
+    {
+        xmlTransform.setValueBinding("styleStream", new MockValueBinding(application, "#{foo.styleStream}"));
+        xmlTransform.setContent(content);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testContent() throws IOException
+    {
+        xmlTransform.setContent(content);
+        xmlTransform.setStylesheet(stylesheet);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testContentValueBinding() throws IOException
+    {
+        xmlTransform.setValueBinding("content", new MockValueBinding(application, "#{foo.content}"));
+        xmlTransform.setStylesheet(stylesheet);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testContentLocation() throws IOException
+    {
+        xmlTransform.setContentLocation(contentLocation);
+        xmlTransform.setStylesheet(stylesheet);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public void testContentLocationValueBinding() throws IOException
+    {
+        xmlTransform.setValueBinding("contentLocation", new MockValueBinding(application, "#{foo.contentLocation}"));
+        xmlTransform.setStylesheet(stylesheet);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    /**
+     * Tests the actual transformation process using an InputStream as the source for content.
+     * @throws IOException
+     */
+    public void testContentStream() throws IOException
+    {
+        xmlTransform.setContentStream(contentStream);
+        xmlTransform.setStylesheet(stylesheet);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    /**
+     * Tests the actual transformation process using an InputStream as the source for content.  This test
+     * sets the property to a value binding (as you would through use of XmlTransformTag) instead of setting
+     * the value of the contentStream on the component directly.
+     *
+     * @throws IOException
+     */
+    public void testContentStreamValueBinding() throws IOException
+    {
+        xmlTransform.setValueBinding("contentStream", new MockValueBinding(application, "#{foo.contentStream}"));
+        xmlTransform.setStylesheetLocation(stylesheetLocation);
+        xmlTransform.encodeBegin(facesContext);
+
+        String responseText = mockWriter.toString();
+        assertEquals("Unexpected response text from content transformation", EXPECTED_TEXT, responseText);
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite(XmlTransformTest.class);
+    }
+
+}

Added: myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/tree2/AbstractTreeTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/tree2/AbstractTreeTestCase.java?rev=955793&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/tree2/AbstractTreeTestCase.java (added)
+++ myfaces/tomahawk/trunk/core12/src/test/java/org/apache/myfaces/custom/tree2/AbstractTreeTestCase.java Thu Jun 17 23:57:54 2010
@@ -0,0 +1,143 @@
+/*
+ * 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.custom.tree2;
+
+import java.io.IOException;
+import java.util.Stack;
+
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
+
+/**
+ * An abstract test case that sets up a Tree2 for testing using the structure below.
+ *
+ * - .. Root (0)
+ * |
+ * - .. A (0:0)
+ * |    |
+ * |    + .. AA (0:0:0)
+ * |    |
+ * |    + .. AB (0:0:1)
+ * |    |
+ * |    + .. AC (0:0:2)
+ * |         | .. aca (0:0:2:0)
+ * |         | .. acb (0:0:2:1)
+ * |
+ * + .. B (0:1)
+ * |    |
+ * |    + .. BA (0:1:0)
+ * |    |
+ * |    + .. BB (0:1:1)
+ * |
+ * | .. C (0:2)
+ * |
+ * | .. d (0:3)
+ */
+
+public class AbstractTreeTestCase extends AbstractTomahawkViewControllerTestCase
+{
+    static final String DEFAULT_NODE_TYPE = "default";
+    static final String TREE_ID = "some_foo_tree";
+
+    HtmlTree tree;
+    TreeNodeBase rootNode;
+
+    /**
+     * Constructor
+     * @param name String
+     */
+    public AbstractTreeTestCase(String name)
+    {
+        super(name);
+    }
+
+    /**
+     * See abstract class
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        tree = new HtmlTree();
+        tree.setId(TREE_ID);
+
+        // set up the test tree with the standard data
+        rootNode = new TreeNodeBase(DEFAULT_NODE_TYPE, "Root", "Root", false);
+
+        TreeNodeBase A_node = new TreeNodeBase(DEFAULT_NODE_TYPE, "A", "A", false);
+        A_node.getChildren().add(new TreeNodeBase(DEFAULT_NODE_TYPE, "AA", "AA", false));
+        A_node.getChildren().add(new TreeNodeBase(DEFAULT_NODE_TYPE, "AB", "AB", false));
+        TreeNodeBase AC_node = new TreeNodeBase(DEFAULT_NODE_TYPE, "AC", "AC", false);
+        AC_node.getChildren().add(new TreeNodeBase(DEFAULT_NODE_TYPE, "aca", "aca", true));
+        AC_node.getChildren().add(new TreeNodeBase(DEFAULT_NODE_TYPE, "acb", "acb", true));
+        A_node.getChildren().add(AC_node);
+        rootNode.getChildren().add(A_node);
+
+        TreeNodeBase B_node = new TreeNodeBase(DEFAULT_NODE_TYPE, "B", "B", false);
+        B_node.getChildren().add(new TreeNodeBase(DEFAULT_NODE_TYPE, "BA", "BA", false));
+        B_node.getChildren().add(new TreeNodeBase(DEFAULT_NODE_TYPE, "BB", "BB", false));
+        rootNode.getChildren().add(B_node);
+
+        TreeNodeBase C_node = new TreeNodeBase(DEFAULT_NODE_TYPE, "C", "C", false);
+        rootNode.getChildren().add(C_node);
+
+        TreeNodeBase d_node = new TreeNodeBase(DEFAULT_NODE_TYPE, "d", "d", true);
+        rootNode.getChildren().add(d_node);
+
+        tree.setValue(rootNode);
+    }
+
+    /**
+     * Instead of using UIText or whatever inside the tree we use this special "simulator."
+     * This way we can keep track of when the renderer is asking the node to render itself.
+     */
+    static final class NodeSimulator extends UIComponentBase
+    {
+        private static final String COMPONENT_FAMILY = "Foo";
+        private Stack nodeStack = new Stack();
+
+        public String getFamily()
+        {
+            return COMPONENT_FAMILY;
+        }
+
+        public void encodeBegin(FacesContext context) throws IOException
+        {
+            HtmlTree tree = (HtmlTree)super.getParent();
+            nodeStack.push(tree.getNode());
+        }
+
+        public Stack getNodeStack()
+        {
+            return nodeStack;
+        }
+    }
+
+    // Return the tests included in this test case.
+    public static Test suite()
+    {
+        return (new TestSuite());
+    }
+}