当前位置: 首页>>代码示例>>Java>>正文


Java Duration.getXMLSchemaType方法代码示例

本文整理汇总了Java中javax.xml.datatype.Duration.getXMLSchemaType方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.getXMLSchemaType方法的具体用法?Java Duration.getXMLSchemaType怎么用?Java Duration.getXMLSchemaType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.datatype.Duration的用法示例。


在下文中一共展示了Duration.getXMLSchemaType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkDurationGetXMLSchemaType

import javax.xml.datatype.Duration; //导入方法依赖的package包/类
@Test
public void checkDurationGetXMLSchemaType() {
    // DURATION
    Duration duration = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
    QName duration_xmlSchemaType = duration.getXMLSchemaType();
    assertEquals(duration_xmlSchemaType, DatatypeConstants.DURATION, "Expected DatatypeConstants.DURATION, returned " + duration_xmlSchemaType.toString());

    // DURATION_DAYTIME
    Duration duration_dayTime = datatypeFactory.newDuration("P1DT1H1M1S");
    QName duration_dayTime_xmlSchemaType = duration_dayTime.getXMLSchemaType();
    assertEquals(duration_dayTime_xmlSchemaType, DatatypeConstants.DURATION_DAYTIME, "Expected DatatypeConstants.DURATION_DAYTIME, returned "
            + duration_dayTime_xmlSchemaType.toString());

    // DURATION_YEARMONTH
    Duration duration_yearMonth = datatypeFactory.newDuration("P1Y1M");
    QName duration_yearMonth_xmlSchemaType = duration_yearMonth.getXMLSchemaType();
    assertEquals(duration_yearMonth_xmlSchemaType, DatatypeConstants.DURATION_YEARMONTH, "Expected DatatypeConstants.DURATION_YEARMONTH, returned "
            + duration_yearMonth_xmlSchemaType.toString());

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:DurationTest.java

示例2: testNewDurationYearMonthLexicalRepresentation

import javax.xml.datatype.Duration; //导入方法依赖的package包/类
/**
 * Test {@link DatatypeFactory.newDurationYearMonth(String
 * lexicalRepresentation)}.
 */
@Test
public final void testNewDurationYearMonthLexicalRepresentation() {

    /**
     * Lexical test values to test.
     */
    final String[] TEST_VALUES_LEXICAL = { null, TEST_VALUE_FAIL, "", TEST_VALUE_FAIL, "-", TEST_VALUE_FAIL, "P", TEST_VALUE_FAIL, "-P", TEST_VALUE_FAIL,
            "P1D", TEST_VALUE_FAIL, "P1Y1M1D", TEST_VALUE_FAIL, "P1M", "P1M", "-P1M", "-P1M", "P1Y", "P1Y", "-P1Y", "-P1Y", "P1Y1M", "P1Y1M", "-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_LEXICAL.length; onTestValue = onTestValue + 2) {

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

        try {
            Duration duration = datatypeFactory.newDurationYearMonth(TEST_VALUES_LEXICAL[onTestValue]);

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

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

            // right XMLSchemaType?
            // TODO: enable test, it should pass, it fails with Exception(s)
            // for now due to a bug
            try {
                QName xmlSchemaType = duration.getXMLSchemaType();
                if (!xmlSchemaType.equals(DatatypeConstants.DURATION_YEARMONTH)) {
                    Assert.fail("Duration created with XMLSchemaType of\"" + xmlSchemaType + "\" was expected to be \""
                            + DatatypeConstants.DURATION_YEARMONTH + "\" and has the value \"" + duration.toString() + "\"");
                }
            } catch (IllegalStateException illegalStateException) {
                // TODO; this test really should pass
                System.err.println("Please fix this bug that is being ignored, for now: " + illegalStateException.getMessage());
            }

            // does it have the right value?
            if (!TEST_VALUES_LEXICAL[onTestValue + 1].equals(duration.toString())) {
                Assert.fail("Duration created with \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" was expected to be \""
                        + TEST_VALUES_LEXICAL[onTestValue + 1] + "\" and has the value \"" + duration.toString() + "\"");
            }

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

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

            // was this expected to succed?
            if (!TEST_VALUES_LEXICAL[onTestValue + 1].equals(TEST_VALUE_FAIL)) {
                Assert.fail("the value \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" is valid yet it failed with \"" + exception.toString() + "\"");
            }
            // expected failure
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:80,代码来源:DatatypeFactoryTest.java

示例3: testNewDurationYearMonthLexicalRepresentation1

import javax.xml.datatype.Duration; //导入方法依赖的package包/类
@Test
public final void testNewDurationYearMonthLexicalRepresentation1() {

    /**
     * Lexical test values to test.
     */
    final String[] TEST_VALUES_LEXICAL = { "P13M", "P1Y1M", "-P13M", "-P1Y1M", "P1Y", "P1Y", "-P1Y", "-P1Y", "P1Y25M", "P3Y1M", "-P1Y25M", "-P3Y1M" };

    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_LEXICAL.length; onTestValue = onTestValue + 2) {

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

        try {
            Duration duration = datatypeFactory.newDurationYearMonth(TEST_VALUES_LEXICAL[onTestValue]);

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

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

            // right XMLSchemaType?
            // TODO: enable test, it should pass, it fails with Exception(s)
            // for now due to a bug
            try {
                QName xmlSchemaType = duration.getXMLSchemaType();
                if (!xmlSchemaType.equals(DatatypeConstants.DURATION_YEARMONTH)) {
                    Assert.fail("Duration created with XMLSchemaType of\"" + xmlSchemaType + "\" was expected to be \""
                            + DatatypeConstants.DURATION_YEARMONTH + "\" and has the value \"" + duration.toString() + "\"");
                }
            } catch (IllegalStateException illegalStateException) {
                // TODO; this test really should pass
                System.err.println("Please fix this bug that is being ignored, for now: " + illegalStateException.getMessage());
            }

            // does it have the right value?
            if (!TEST_VALUES_LEXICAL[onTestValue + 1].equals(duration.toString())) {
                Assert.fail("Duration created with \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" was expected to be \""
                        + TEST_VALUES_LEXICAL[onTestValue + 1] + "\" and has the value \"" + duration.toString() + "\"");
            }

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

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

            // was this expected to succed?
            if (!TEST_VALUES_LEXICAL[onTestValue + 1].equals(TEST_VALUE_FAIL)) {
                Assert.fail("the value \"" + TEST_VALUES_LEXICAL[onTestValue] + "\" is valid yet it failed with \"" + exception.toString() + "\"");
            }
            // expected failure
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:74,代码来源:Bug6937964Test.java


注:本文中的javax.xml.datatype.Duration.getXMLSchemaType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。