|
| 1 | +/* |
| 2 | + * The MIT License Copyright (c) 2012 Microsoft Corporation |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
| 5 | + * associated documentation files (the "Software"), to deal in the Software without restriction, |
| 6 | + * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| 7 | + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 8 | + * furnished to do so, subject to the following conditions: |
| 9 | + * |
| 10 | + * The above copyright notice and this permission notice shall be included in all copies or |
| 11 | + * substantial portions of the Software. |
| 12 | + * |
| 13 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT |
| 14 | + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 15 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 16 | + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 18 | + */ |
| 19 | + |
| 20 | + |
| 21 | +package microsoft.exchange.webservices.data.property.complex; |
| 22 | + |
| 23 | +import java.util.Calendar; |
| 24 | +import java.util.TimeZone; |
| 25 | + |
| 26 | +import javax.xml.bind.DatatypeConverter; |
| 27 | + |
| 28 | +import microsoft.exchange.webservices.data.core.EwsUtilities; |
| 29 | +import microsoft.exchange.webservices.data.misc.Time; |
| 30 | + |
| 31 | +import org.junit.Assert; |
| 32 | +import org.junit.Test; |
| 33 | +import org.junit.runner.RunWith; |
| 34 | +import org.junit.runners.JUnit4; |
| 35 | + |
| 36 | +@RunWith(JUnit4.class) |
| 37 | +public class TimeChangeTest { |
| 38 | + |
| 39 | + private static String time = "03:00:00"; |
| 40 | + private static String time_fail1 = "21:32"; |
| 41 | + private static String time_fail2 = "25:25:10"; |
| 42 | + private static String time_fail3 = "-10:00:00"; |
| 43 | + |
| 44 | + private static String dateUTC = "2001-10-27Z"; |
| 45 | + private static String date_fail1 = "2001-10-32"; |
| 46 | + private static String date_fail2 = "2001-13-26+02:00"; |
| 47 | + private static String date_fail3 = "01-10-26"; |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testDateUTC() { |
| 51 | + Assert.assertEquals("2001-10-27Z", testDate(dateUTC)); |
| 52 | + } |
| 53 | + |
| 54 | + private String testDate(String value) { |
| 55 | + Calendar cal = DatatypeConverter.parseDate(value); |
| 56 | + cal.setTimeZone(TimeZone.getTimeZone("UTC")); |
| 57 | + String XSDate = EwsUtilities.dateTimeToXSDate(cal.getTime()); |
| 58 | + return XSDate; |
| 59 | + } |
| 60 | + |
| 61 | + @Test(expected = IllegalArgumentException.class) |
| 62 | + public void testDateFail1() { |
| 63 | + testDate(date_fail1); |
| 64 | + } |
| 65 | + |
| 66 | + @Test(expected = IllegalArgumentException.class) |
| 67 | + public void testDateFail2() { |
| 68 | + testDate(date_fail2); |
| 69 | + } |
| 70 | + |
| 71 | + @Test(expected = IllegalArgumentException.class) |
| 72 | + public void testDateFail3() { |
| 73 | + testDate(date_fail3); |
| 74 | + } |
| 75 | + |
| 76 | + private String testTime(String value) { |
| 77 | + Calendar cal = DatatypeConverter.parseTime(value); |
| 78 | + Time time = new Time(cal.getTime()); |
| 79 | + return time.toXSTime(); |
| 80 | + } |
| 81 | + |
| 82 | + @Test(expected = IllegalArgumentException.class) |
| 83 | + public void testTimeFail1() { |
| 84 | + testTime(time_fail1); |
| 85 | + } |
| 86 | + |
| 87 | + @Test(expected = IllegalArgumentException.class) |
| 88 | + public void testTimeFail2() { |
| 89 | + testTime(time_fail2); |
| 90 | + } |
| 91 | + |
| 92 | + @Test(expected = IllegalArgumentException.class) |
| 93 | + public void testTimeFail3() { |
| 94 | + testTime(time_fail3); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testTimeValues() { |
| 99 | + Assert.assertEquals("{0:00}:{1:00}:{2:00},3,0,0", testTime(time)); |
| 100 | + } |
| 101 | + |
| 102 | +} |
0 commit comments