1 16 17 package test.types; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.types.Day; 21 22 import java.text.NumberFormat ; 23 24 27 public class TestDay extends TestCase { 28 29 public TestDay(String name) { 30 super(name); 31 } 32 33 36 private void runFailTest(int day, String tz) throws Exception { 37 Day oDay = null; 38 try { 39 oDay = new Day(day, tz); 40 } 41 catch (Exception e) { } 43 assertNull("validation restriction failed [ day=" + String.valueOf(day) + 45 ",tz=" + tz + "]. did not restrict bad value.", oDay); 46 } 47 48 private void runFailTest(String source) throws Exception { 49 Day oDay = null; 50 try { 51 oDay = new Day(source); 52 } 53 catch (Exception e) { } 55 assertNull("validation restriction failed [ " + source + 57 "]. did not restrict bad value.", oDay); 58 } 59 60 63 private void runPassTest(int day, String tz) throws Exception { 64 Day oDay = null; 65 try { 66 oDay = new Day(day, tz); 67 } 68 catch (Exception e) { assertTrue("Validation exception thrown on valid input", false); 70 } 71 assertEquals("Day day not equal", day, oDay.getDay()); 72 assertEquals("Day timezone not equal", tz, oDay.getTimezone()); 73 } 74 75 private void runPassTest(String source) throws Exception { 76 Day oDay = null; 77 try { 78 oDay = new Day(source); 79 } 80 catch (Exception e) { assertTrue("Validation exception thrown on valid input", false); 82 } 83 assertEquals("Day.toString() not equal", source, oDay.toString()); 84 } 85 86 89 public void testNormal() throws Exception { 90 for (int d=1; d < 32; d++) { 92 runPassTest(d, null); 93 } 94 } 95 public void testNormalString() throws Exception { 96 NumberFormat nf = NumberFormat.getInstance(); 99 nf.setMinimumIntegerDigits(2); 100 for (int d=1; d < 13; d++) { 101 String s = "---" + nf.format(d); 102 runPassTest(s); 103 } 104 } 105 public void testNormalString2() throws Exception { 106 runPassTest("---01"); 108 } 109 public void testNormalTimezone() throws Exception { 110 runPassTest("---01Z"); 111 } 112 public void testNormalPositiveTimezone() throws Exception { 113 runPassTest("---11+05:00"); 114 } 115 public void testNormalNegativeTimezone() throws Exception { 116 runPassTest("---11-11:00"); 117 } 118 119 122 public void testBadString() throws Exception { 123 runFailTest("13Z"); 124 runFailTest("-13"); 125 runFailTest("--13"); 126 runFailTest("xxx13"); 127 runFailTest("garbage"); 128 } 129 130 131 134 public void testBadDay() throws Exception { 135 runFailTest(32, null); 136 } 137 public void testBadDayString() throws Exception { 138 runFailTest("---32"); 139 } 140 public void testBadDayString2() throws Exception { 141 runFailTest("---1"); 142 } 143 144 147 public void testBadTimezone() throws Exception { 148 runFailTest( 31, "badzone"); 149 } 150 public void testBadTimezoneString() throws Exception { 151 runFailTest("---23+EDT"); 152 } 153 154 155 } 156 | Popular Tags |