< prev index next >

test/javax/xml/jaxp/unittest/datatype/Bug6937964Test.java

Print this page


   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 java.math.BigDecimal;
  27 import java.math.BigInteger;
  28 
  29 import javax.xml.datatype.DatatypeConfigurationException;
  30 import javax.xml.datatype.DatatypeConstants;
  31 import javax.xml.datatype.DatatypeFactory;
  32 import javax.xml.datatype.Duration;
  33 import javax.xml.namespace.QName;
  34 
  35 import org.testng.Assert;

  36 import org.testng.annotations.Test;
  37 
  38 /*
  39  * @bug 6937964
  40  * @summary Test Duration is normalized.
  41  */

  42 public class Bug6937964Test {
  43     /**
  44      * Print debugging to System.err.
  45      */
  46     private static final boolean DEBUG = false;
  47     /**
  48      * Constant to indicate expected lexical test failure.
  49      */
  50     private static final String TEST_VALUE_FAIL = "*FAIL*";
  51 
  52     private static final String FIELD_UNDEFINED = "FIELD_UNDEFINED";
  53     static final DatatypeConstants.Field[] fields = { DatatypeConstants.YEARS, DatatypeConstants.MONTHS, DatatypeConstants.DAYS, DatatypeConstants.HOURS,
  54             DatatypeConstants.MINUTES, DatatypeConstants.SECONDS };
  55 
  56     @Test
  57     public void test() throws DatatypeConfigurationException {
  58         DatatypeFactory dtf = DatatypeFactory.newInstance();
  59         Duration d = dtf.newDurationYearMonth("P20Y15M");
  60         int years = d.getYears();
  61         System.out.println(d.getYears() == 21 ? "pass" : "fail");


   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 java.math.BigDecimal;
  27 import java.math.BigInteger;
  28 
  29 import javax.xml.datatype.DatatypeConfigurationException;
  30 import javax.xml.datatype.DatatypeConstants;
  31 import javax.xml.datatype.DatatypeFactory;
  32 import javax.xml.datatype.Duration;
  33 import javax.xml.namespace.QName;
  34 
  35 import org.testng.Assert;
  36 import org.testng.annotations.Listeners;
  37 import org.testng.annotations.Test;
  38 
  39 /*
  40  * @bug 6937964
  41  * @summary Test Duration is normalized.
  42  */
  43 @Listeners({jaxp.library.BasePolicy.class})
  44 public class Bug6937964Test {
  45     /**
  46      * Print debugging to System.err.
  47      */
  48     private static final boolean DEBUG = false;
  49     /**
  50      * Constant to indicate expected lexical test failure.
  51      */
  52     private static final String TEST_VALUE_FAIL = "*FAIL*";
  53 
  54     private static final String FIELD_UNDEFINED = "FIELD_UNDEFINED";
  55     static final DatatypeConstants.Field[] fields = { DatatypeConstants.YEARS, DatatypeConstants.MONTHS, DatatypeConstants.DAYS, DatatypeConstants.HOURS,
  56             DatatypeConstants.MINUTES, DatatypeConstants.SECONDS };
  57 
  58     @Test
  59     public void test() throws DatatypeConfigurationException {
  60         DatatypeFactory dtf = DatatypeFactory.newInstance();
  61         Duration d = dtf.newDurationYearMonth("P20Y15M");
  62         int years = d.getYears();
  63         System.out.println(d.getYears() == 21 ? "pass" : "fail");


< prev index next >