Java Code Examples for javax.xml.datatype.DatatypeFactory#newDurationDayTime()

The following examples show how to use javax.xml.datatype.DatatypeFactory#newDurationDayTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug6937964Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNewDurationDayTimeLexicalRepresentation() throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    Duration d = dtf.newDurationDayTime("P1DT23H59M65S");
    int days = d.getDays();
    Assert.assertTrue(days == 2, "Return value should be normalized");
}
 
Example 2
Source File: Bug6937964Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNewDurationDayTimeMilliseconds() throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    Duration d = dtf.newDurationDayTime(172805000L);
    int days = d.getDays();
    Assert.assertTrue(days == 2, "Return value should be normalized");
}
 
Example 3
Source File: Bug6937964Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNewDurationDayTimeBigInteger() throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    BigInteger day = new BigInteger("1");
    BigInteger hour = new BigInteger("23");
    BigInteger min = new BigInteger("59");
    BigInteger sec = new BigInteger("65");
    Duration d = dtf.newDurationDayTime(true, day, hour, min, sec);
    int days = d.getDays();
    System.out.println("Days: " + days);
    Assert.assertTrue(days == 2, "Return value should be normalized");
}
 
Example 4
Source File: Bug6937964Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNewDurationDayTimeInt() throws DatatypeConfigurationException {
    DatatypeFactory dtf = DatatypeFactory.newInstance();
    Duration d = dtf.newDurationDayTime(true, 1, 23, 59, 65);
    int days = d.getDays();
    System.out.println("Days: " + days);
    Assert.assertTrue(days == 2, "Return value should be normalized");
}
 
Example 5
Source File: DurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void newDurationDayTimeTester(boolean isPositive, boolean normalizedIsPositive, BigInteger years, BigInteger normalizedYears, BigInteger months,
        BigInteger normalizedMonths, BigInteger days, BigInteger normalizedDays, BigInteger hours, BigInteger normalizedHours, BigInteger minutes,
        BigInteger normalizedMinutes, BigDecimal seconds, BigDecimal normalizedSeconds, long durationInMilliSeconds, long normalizedDurationInMilliSeconds,
        String lexicalRepresentation, String normalizedLexicalRepresentation) {

    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {
        ex.printStackTrace();
        Assert.fail(ex.toString());
    }

    // create 4 dayTime Durations using the 4 different constructors

    Duration durationDayTimeBigInteger = datatypeFactory.newDurationDayTime(isPositive, days, hours, minutes, seconds.toBigInteger());
    durationAssertEquals(durationDayTimeBigInteger, DatatypeConstants.DURATION_DAYTIME, normalizedIsPositive, normalizedYears.intValue(),
            normalizedMonths.intValue(), normalizedDays.intValue(), normalizedHours.intValue(), normalizedMinutes.intValue(), normalizedSeconds.intValue(),
            normalizedDurationInMilliSeconds, normalizedLexicalRepresentation);

    /*
     * Duration durationDayTimeInt = datatypeFactory.newDurationDayTime(
     * isPositive, days.intValue(), hours.intValue(), minutes.intValue(),
     * seconds.intValue()); Duration durationDayTimeMilliseconds =
     * datatypeFactory.newDurationDayTime( durationInMilliSeconds); Duration
     * durationDayTimeLexical = datatypeFactory.newDurationDayTime(
     * lexicalRepresentation);
     * Duration durationYearMonthBigInteger =
     * datatypeFactory.newDurationYearMonth( isPositive, years, months);
     * Duration durationYearMonthInt = datatypeFactory.newDurationYearMonth(
     * isPositive, years.intValue(), months.intValue()); Duration
     * durationYearMonthMilliseconds = datatypeFactory.newDurationYearMonth(
     * durationInMilliSeconds); Duration durationYearMonthLexical =
     * datatypeFactory.newDurationYearMonth( lexicalRepresentation) ;
     */

}
 
Example 6
Source File: ValueConverterTest.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertFromJavaDuration() throws DatatypeConfigurationException {
  DatatypeFactory f = DatatypeFactory.newInstance();
  Duration d = f.newDuration(true, 1, 2, 3, 4, 5, 6);
  ValueConverter.convertFromJava(d, processor);
  checkProcessor("duration", "xs:duration", d);

  d = f.newDurationYearMonth(true, 1, 2);
  ValueConverter.convertFromJava(d, processor);
  checkProcessor("year month duration", "xs:yearMonthDuration", d);

  d = f.newDurationDayTime(true, 3, 4, 5, 6);
  ValueConverter.convertFromJava(d, processor);
  checkProcessor("day time duration", "xs:dayTimeDuration", d);
}
 
Example 7
Source File: DatatypeFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test {@link DatatypeFactory.newDurationDayTime(long milliseconds)}.
 */
@Test
public final void testNewDurationDayTime() {

    /**
     * Millisecond test values to test.
     */
    final long[] TEST_VALUES_MILLISECONDS = { 0L, 1L, -1L, 2678400000L, // 31
                                                                        // days,
                                                                        // e.g.
                                                                        // 1
                                                                        // month
            -2678400000L, 5270400000L, // 61 days, e.g. 2 months
            -5270400000L, 31622400000L, // 366 days, e.g. 1 year
            -31622400000L, 34300800000L, // 397 days, e.g. 1 year, 1 month
            -34300800000L };

    /**
     * Millisecond test value results of test.
     */
    final String[] TEST_VALUES_MILLISECONDS_RESULTS = { "P0Y0M0DT0H0M0.000S", "P0Y0M0DT0H0M0.001S", "-P0Y0M0DT0H0M0.001S", "P0Y1M", "-P0Y1M", "P0Y2M",
            "-P0Y2M", "P1Y0M", "-P1Y0M", "P1Y1M", "-P1Y1M" };

    DatatypeFactory datatypeFactory = null;
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException datatypeConfigurationException) {
        Assert.fail(datatypeConfigurationException.toString());
    }

    if (DEBUG) {
        System.err.println("DatatypeFactory created: " + datatypeFactory.toString());
    }

    // test each value
    for (int onTestValue = 0; onTestValue < TEST_VALUES_MILLISECONDS.length; onTestValue++) {

        if (DEBUG) {
            System.err.println("testing value: \"" + TEST_VALUES_MILLISECONDS[onTestValue] + "\", expecting: \""
                    + TEST_VALUES_MILLISECONDS_RESULTS[onTestValue] + "\"");
        }

        try {
            Duration duration = datatypeFactory.newDurationDayTime(TEST_VALUES_MILLISECONDS[onTestValue]);

            if (DEBUG) {
                System.err.println("Duration created: \"" + duration.toString() + "\"");
            }

            // was this expected to fail?
            if (TEST_VALUES_MILLISECONDS_RESULTS[onTestValue].equals(TEST_VALUE_FAIL)) {
                Assert.fail("the value \"" + TEST_VALUES_MILLISECONDS[onTestValue] + "\" is invalid yet it created the Duration \"" + duration.toString()
                        + "\"");
            }

            // does it have the right value?
            if (!TEST_VALUES_MILLISECONDS_RESULTS[onTestValue].equals(duration.toString())) {
                // TODO: this is bug that should be fixed
                if (false) {
                    Assert.fail("Duration created with \"" + TEST_VALUES_MILLISECONDS[onTestValue] + "\" was expected to be \""
                            + TEST_VALUES_MILLISECONDS_RESULTS[onTestValue] + "\" and has the value \"" + duration.toString() + "\"");
                } else {
                    System.err.println("Please fix this bug: " + "Duration created with \"" + TEST_VALUES_MILLISECONDS[onTestValue]
                            + "\" was expected to be \"" + TEST_VALUES_MILLISECONDS_RESULTS[onTestValue] + "\" and has the value \"" + duration.toString()
                            + "\"");
                }
            }

            // only day, hour, minute, and second should have values
            QName xmlSchemaType = duration.getXMLSchemaType();
            int years = duration.getYears();
            int months = duration.getMonths();

            if (!xmlSchemaType.equals(DatatypeConstants.DURATION_DAYTIME) || years != 0 || months != 0) {
                // TODO: this is bug that should be fixed
                if (false) {
                    Assert.fail("xdt:dayTimeDuration created without discarding remaining milliseconds: " + " XMLSchemaType = " + xmlSchemaType
                            + ", years = " + years + ", months = " + months);
                } else {
                    System.err.println("Please fix this bug: " + "xdt:dayTimeDuration created without discarding remaining milliseconds: "
                            + " XMLSchemaType = " + xmlSchemaType + ", years = " + years + ", months = " + months);
                }
            }

            // Duration created with correct values
        } catch (Exception exception) {

            if (DEBUG) {
                System.err.println("Exception in creating duration: \"" + exception.toString() + "\"");
            }

            // was this expected to succed?
            if (!TEST_VALUES_MILLISECONDS_RESULTS[onTestValue].equals(TEST_VALUE_FAIL)) {
                Assert.fail("the value \"" + TEST_VALUES_MILLISECONDS[onTestValue] + "\" is valid yet it failed with \"" + exception.toString() + "\"");
            }
            // expected failure
        }
    }
}