1 /* 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package datatype; 25 26 import javax.xml.datatype.DatatypeConfigurationException; 27 import javax.xml.datatype.DatatypeFactory; 28 import javax.xml.datatype.XMLGregorianCalendar; 29 30 import org.testng.Assert; 31 import org.testng.annotations.Test; 32 33 /* 34 * @bug 6320118 35 * @summary Test xml datatype XMLGregorianCalendar. 36 */ 37 public class Bug6320118 { 38 39 DatatypeFactory df; 40 41 @Test 42 public void test1() { 43 try { 44 df = DatatypeFactory.newInstance(); 45 } catch (DatatypeConfigurationException e) { 46 Assert.fail(e.getMessage()); 47 } 48 49 try { 50 XMLGregorianCalendar calendar = df.newXMLGregorianCalendar(1970, 1, 1, 24, 0, 0, 0, 0); 51 } catch (IllegalArgumentException e) { 52 Assert.fail(e.getMessage()); 53 } 54 } 55 56 @Test 57 public void test2() { 58 try { 59 df = DatatypeFactory.newInstance(); 60 } catch (DatatypeConfigurationException e) { 61 Assert.fail(e.getMessage()); 62 } 63 64 try { 65 XMLGregorianCalendar calendar = df.newXMLGregorianCalendarTime(24, 0, 0, 0); 66 } catch (IllegalArgumentException e) { 67 Assert.fail(e.getMessage()); 68 } 69 } 70 71 @Test 72 public void test3() { 73 try { 74 df = DatatypeFactory.newInstance(); 75 } catch (DatatypeConfigurationException e) { 76 Assert.fail(e.getMessage()); 77 } 78 try { 79 XMLGregorianCalendar calendar = df.newXMLGregorianCalendar(); 80 // Must fail as other params are not 0 but undefined 81 calendar.setHour(24); 82 Assert.fail("test3() - Expected IllegalArgumentException not thrown"); 83 } catch (IllegalArgumentException e) { 84 // falls through 85 } 86 } 87 88 @Test 89 public void test4() { 90 try { 91 df = DatatypeFactory.newInstance(); 92 } catch (DatatypeConfigurationException e) { 93 Assert.fail(e.getMessage()); 94 } 95 96 try { 97 XMLGregorianCalendar calendar = df.newXMLGregorianCalendar(); 98 calendar.setTime(24, 0, 0, 0); 99 } catch (IllegalArgumentException e) { 100 Assert.fail(e.getMessage()); 101 } 102 } 103 104 }