1 16 17 package test.types; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.types.MonthDay; 21 22 import java.text.NumberFormat ; 23 24 27 public class TestMonthDay extends TestCase { 28 29 public TestMonthDay(String name) { 30 super(name); 31 } 32 33 36 private void runFailTest(int month, int day, String tz) throws Exception { 37 MonthDay oMonthDay = null; 38 try { 39 oMonthDay = new MonthDay(month, day, tz); 40 } 41 catch (Exception e) { } 43 assertNull("validation restriction failed [ month=" + 45 String.valueOf(month) + ",day=" + String.valueOf(day) + 46 ",tz=" + tz + "]. did not restrict bad value.", oMonthDay); 47 } 48 49 private void runFailTest(String source) throws Exception { 50 MonthDay oMonthDay = null; 51 try { 52 oMonthDay = new MonthDay(source); 53 } 54 catch (Exception e) { } 56 assertNull("validation restriction failed [ " + source + 58 "]. did not restrict bad value.", oMonthDay); 59 } 60 61 64 private void runPassTest(int month, int day, String tz) throws Exception { 65 MonthDay oMonthDay = null; 66 try { 67 oMonthDay = new MonthDay(month, day, tz); 68 } 69 catch (Exception e) { assertTrue("Validation exception thrown on valid input", false); 71 } 72 assertEquals("MonthDay month not equal", month, oMonthDay.getMonth()); 73 assertEquals("MonthDay day not equal", day, oMonthDay.getDay()); 74 assertEquals("MonthDay timezone not equal", tz, oMonthDay.getTimezone()); 75 } 76 77 private void runPassTest(String source) throws Exception { 78 MonthDay oMonthDay = null; 79 try { 80 oMonthDay = new MonthDay(source); 81 } 82 catch (Exception e) { assertTrue("Validation exception thrown on valid input", false); 84 } 85 assertEquals("MonthDay.toString() not equal", source, oMonthDay.toString()); 86 } 87 88 91 public void testNormal() throws Exception { 92 for (int m=1; m < 13; m++) { 94 runPassTest(m, m, null); 95 } 96 } 97 public void testNormalString() throws Exception { 98 NumberFormat nf = NumberFormat.getInstance(); 101 nf.setMinimumIntegerDigits(2); 102 for (int m=1; m < 13; m++) { 103 String s = "--" + nf.format(m) + "-05"; 104 runPassTest(s); 105 } 106 } 107 public void testNormalString2() throws Exception { 108 runPassTest("--01-01"); 110 } 111 public void testNormalTimezone() throws Exception { 112 runPassTest("--01-01Z"); 113 } 114 public void testNormalPositiveTimezone() throws Exception { 115 runPassTest("--02-11+05:00"); 116 } 117 public void testNormalNegativeTimezone() throws Exception { 118 runPassTest("--03-11-11:00"); 119 } 120 121 124 public void testBadString() throws Exception { 125 runFailTest("07-13Z"); 126 runFailTest("-07-13"); 127 runFailTest("xx07-13"); 128 runFailTest("garbage"); 129 } 130 131 134 public void testBadMonth() throws Exception { 135 runFailTest(13, 20, null); 136 } 137 public void testBadMonthString() throws Exception { 138 runFailTest("--13-13"); 139 } 140 public void testBadMonthString2() throws Exception { 141 runFailTest("--1-01"); 142 } 143 144 147 public void testBadDay() throws Exception { 148 runFailTest(1, 32, null); 149 } 150 public void testBadDayString() throws Exception { 151 runFailTest("--08-32"); 152 } 153 public void testBadDayString2() throws Exception { 154 runFailTest("--1-01"); 155 } 156 public void testEndOfMonthDays() throws Exception { 157 runFailTest(1, 32, null); 158 runPassTest(1, 31, null); 159 runFailTest(2, 30, null); 160 runPassTest(2, 29, null); 161 runFailTest(3, 32, null); 162 runPassTest(3, 31, null); 163 runFailTest(4, 31, null); 164 runPassTest(4, 30, null); 165 runFailTest(5, 32, null); 166 runPassTest(5, 30, null); 167 runFailTest(6, 31, null); 168 runPassTest(6, 30, null); 169 runFailTest(7, 32, null); 170 runPassTest(7, 31, null); 171 runFailTest(8, 32, null); 172 runPassTest(8, 31, null); 173 runFailTest(9, 31, null); 174 runPassTest(9, 30, null); 175 runFailTest(10, 32, null); 176 runPassTest(10, 31, null); 177 runFailTest(11, 31, null); 178 runPassTest(11, 30, null); 179 runFailTest(12, 32, null); 180 runPassTest(12, 31, null); 181 } 182 183 186 public void testBadTimezone() throws Exception { 187 runFailTest(12, 31, "badzone"); 188 } 189 public void testBadTimezoneString() throws Exception { 190 runFailTest("--07-23+EDT"); 191 } 192 193 194 } 195 | Popular Tags |