1 package org.seasar.cubby.controller.impl; 2 3 import java.util.Arrays; 4 import java.util.Calendar; 5 import java.util.Date; 6 import java.util.List; 7 8 import org.seasar.cubby.controller.FormWrapper; 9 import org.seasar.cubby.controller.FormWrapperFactory; 10 import org.seasar.extension.unit.S2TestCase; 11 12 public class FormWrapperFactoryImplTest extends S2TestCase { 13 14 public FormWrapperFactory formWrapperFactory; 15 16 @Override 17 protected void setUp() throws Exception { 18 super.setUp(); 19 include(getClass().getName().replace('.', '/') + ".dicon"); 20 } 21 22 public void testBeanToMap() { 23 Calendar cal = Calendar.getInstance(); 24 cal.set(2006, 0, 1); 25 26 TestBean bean = new TestBean(); 27 bean.setDate(cal.getTime()); 28 bean.setNum1(5); 29 bean.setNum2(new Integer[] { 2, 3, 4 }); 30 bean.setNum3(Arrays.asList(new String[] { "abc", "def" })); 31 32 FormWrapper formWrapper = formWrapperFactory.create(bean); 33 String[] date = formWrapper.getValues("date"); 34 assertEquals(1, date.length); 35 assertEquals("2006-01-01", date[0]); 36 37 String[] num1 = formWrapper.getValues("num1"); 38 assertEquals(1, num1.length); 39 assertEquals("5", num1[0]); 40 41 String[] num2 = formWrapper.getValues("num2"); 42 assertEquals(3, num2.length); 43 assertEquals("2", num2[0]); 44 assertEquals("3", num2[1]); 45 assertEquals("4", num2[2]); 46 47 String[] num3 = formWrapper.getValues("num3"); 48 assertEquals(2, num3.length); 49 assertEquals("abc", num3[0]); 50 assertEquals("def", num3[1]); 51 52 String[] noprop = formWrapper.getValues("noprop"); 53 assertNull(noprop); 54 } 55 56 public static class TestBean { 57 58 Date date; 59 60 Integer num1; 61 62 Integer[] num2; 63 64 List<String> num3; 65 66 public Date getDate() { 67 return new Date(date.getTime()); 68 } 69 70 public void setDate(Date date) { 71 this.date = new Date(date.getTime()); 72 } 73 74 public Integer getNum1() { 75 return num1; 76 } 77 78 public void setNum1(Integer num1) { 79 this.num1 = num1; 80 } 81 82 public Integer[] getNum2() { 83 return num2 == null ? null : num2.clone(); 84 } 85 86 public void setNum2(Integer[] num2) { 87 this.num2 = num2 == null ? null : num2.clone(); 88 } 89 90 public List<String> getNum3() { 91 return num3; 92 } 93 94 public void setNum3(List<String> num3) { 95 this.num3 = num3; 96 } 97 98 } 99 100 }