1 /* 2 * Copyright (c) 2014, 2016, 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.Listeners; 32 import org.testng.annotations.Test; 33 34 /* 35 * @bug 6320118 36 * @summary Test xml datatype XMLGregorianCalendar. 37 */ 38 @Listeners({jaxp.library.BasePolicy.class}) 39 public class Bug6320118 { 40 41 DatatypeFactory df; 42 43 @Test 44 public void test1() { 45 try { 46 df = DatatypeFactory.newInstance(); 47 } catch (DatatypeConfigurationException e) { 48 Assert.fail(e.getMessage()); 49 } 50 51 try { 52 XMLGregorianCalendar calendar = df.newXMLGregorianCalendar(1970, 1, 1, 24, 0, 0, 0, 0); 53 } catch (IllegalArgumentException e) { 54 Assert.fail(e.getMessage()); 55 } 56 } 57 58 @Test 59 public void test2() { 60 try { 61 df = DatatypeFactory.newInstance(); 62 } catch (DatatypeConfigurationException e) { 63 Assert.fail(e.getMessage()); 64 } 65 66 try { 67 XMLGregorianCalendar calendar = df.newXMLGregorianCalendarTime(24, 0, 0, 0); 68 } catch (IllegalArgumentException e) { 69 Assert.fail(e.getMessage()); 70 } 71 } 72 73 @Test 74 public void test3() { 75 try { 76 df = DatatypeFactory.newInstance(); 77 } catch (DatatypeConfigurationException e) { 78 Assert.fail(e.getMessage()); 79 } 80 try { 81 XMLGregorianCalendar calendar = df.newXMLGregorianCalendar(); 82 // Must fail as other params are not 0 but undefined 83 calendar.setHour(24); 84 Assert.fail("test3() - Expected IllegalArgumentException not thrown"); 85 } catch (IllegalArgumentException e) { 86 // falls through 87 } 88 } 89 90 @Test 91 public void test4() { 92 try { 93 df = DatatypeFactory.newInstance(); 94 } catch (DatatypeConfigurationException e) { 95 Assert.fail(e.getMessage()); 96 } 97 98 try { 99 XMLGregorianCalendar calendar = df.newXMLGregorianCalendar(); 100 calendar.setTime(24, 0, 0, 0); 101 } catch (IllegalArgumentException e) { 102 Assert.fail(e.getMessage()); 103 } 104 } 105 106 }