Path: blob/master/test/jaxp/javax/xml/jaxp/unittest/datatype/Bug6320118.java
41893 views
/*1* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package datatype;2425import javax.xml.datatype.DatatypeConfigurationException;26import javax.xml.datatype.DatatypeFactory;27import javax.xml.datatype.XMLGregorianCalendar;2829import org.testng.Assert;30import org.testng.annotations.BeforeClass;31import org.testng.annotations.Listeners;32import org.testng.annotations.Test;3334/*35* @test36* @bug 632011837* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest38* @run testng/othervm -DrunSecMngr=true -Djava.security.manager=allow datatype.Bug632011839* @run testng/othervm datatype.Bug632011840* @summary Test xml datatype XMLGregorianCalendar.41*/42@Listeners({jaxp.library.BasePolicy.class})43public class Bug6320118 {4445DatatypeFactory df;4647@BeforeClass48public void createDataTypeFactory() throws DatatypeConfigurationException {49df = DatatypeFactory.newInstance();50}5152@Test53public void test1() {54XMLGregorianCalendar calendar = df.newXMLGregorianCalendar(1970, 1, 1, 24, 0, 0, 0, 0);55Assert.assertEquals(calendar.getYear(), 1970);56Assert.assertEquals(calendar.getMonth(), 1);57Assert.assertEquals(calendar.getDay(), 2);58Assert.assertEquals(calendar.getHour(), 0, "hour 24 needs to be treated as hour 0 of next day");59}6061@Test62public void test2() {63XMLGregorianCalendar calendar = df.newXMLGregorianCalendarTime(24, 0, 0, 0);64Assert.assertEquals(calendar.getHour(), 0, "hour 24 needs to be treated as hour 0 of next day");65}6667@Test(expectedExceptions = IllegalArgumentException.class)68public void test3() {69XMLGregorianCalendar calendar = df.newXMLGregorianCalendar();70// Must fail as other params are not 0 but undefined71calendar.setHour(24);72}7374@Test75public void test4() {76XMLGregorianCalendar calendar = df.newXMLGregorianCalendar();77calendar.setTime(24, 0, 0, 0);78Assert.assertEquals(calendar.getHour(), 0, "hour 24 needs to be treated as hour 0 of next day");79}8081}828384