--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/datatype/ptests/DurationTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,585 @@
+/*
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.datatype.ptests;
+
+import static javax.xml.datatype.DatatypeConstants.DAYS;
+import static javax.xml.datatype.DatatypeConstants.HOURS;
+import static javax.xml.datatype.DatatypeConstants.MINUTES;
+import static javax.xml.datatype.DatatypeConstants.MONTHS;
+import static javax.xml.datatype.DatatypeConstants.SECONDS;
+import static javax.xml.datatype.DatatypeConstants.YEARS;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Calendar;
+import java.util.function.Function;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+import javax.xml.namespace.QName;
+
+import jaxp.library.JAXPBaseTest;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/*
+ * @summary Class containing the test cases for Duration.
+ */
+public class DurationTest extends JAXPBaseTest {
+
+ private DatatypeFactory datatypeFactory;
+
+ /*
+ * Setup.
+ */
+ @BeforeClass
+ public void setup() throws DatatypeConfigurationException {
+ datatypeFactory = DatatypeFactory.newInstance();
+ }
+
+ @DataProvider(name = "legal-number-duration")
+ public Object[][] getLegalNumberDuration() {
+ return new Object[][] {
+ // is positive, year, month, day, hour, minute, second
+ { true, 1, 1, 1, 1, 1, 1 },
+ { false, 1, 1, 1, 1, 1, 1 },
+ { true, 1, 0, 0, 0, 0, 0 },
+ { false, 1, 0, 0, 0, 0, 0 }
+ };
+ }
+
+ /*
+ * Test for constructor Duration(boolean isPositive,int years,int months,
+ * int days,int hours,int minutes,int seconds).
+ */
+ @Test(dataProvider = "legal-number-duration")
+ public void checkNumberDurationPos(boolean isPositive, int years, int months, int days, int hours, int minutes, int seconds) {
+ datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
+ }
+
+ @DataProvider(name = "illegal-number-duration")
+ public Object[][] getIllegalNumberDuration() {
+ return new Object[][] {
+ // is positive, year, month, day, hour, minute, second
+ { true, 1, 1, -1, 1, 1, 1 },
+ { false, 1, 1, -1, 1, 1, 1 },
+ { true, undef, undef, undef, undef, undef, undef },
+ { false, undef, undef, undef, undef, undef, undef }
+ };
+ }
+
+ /*
+ * Test for constructor Duration(boolean isPositive,int years,int months,
+ * int days,int hours,int minutes,int seconds), if any of the fields is
+ * negative should throw IllegalArgumentException.
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "illegal-number-duration")
+ public void checkDurationNumberNeg(boolean isPositive, int years, int months, int days, int hours, int minutes, int seconds) {
+ datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
+ }
+
+ @DataProvider(name = "legal-bigint-duration")
+ public Object[][] getLegalBigIntegerDuration() {
+ return new Object[][] {
+ // is positive, year, month, day, hour, minute, second
+ { true, zero, zero, zero, zero, zero, new BigDecimal(zero) },
+ { false, zero, zero, zero, zero, zero, new BigDecimal(zero) },
+ { true, one, one, one, one, one, new BigDecimal(one) },
+ { false, one, one, one, one, one, new BigDecimal(one) },
+ { true, null, null, null, null, null, new BigDecimal(one) },
+ { false, null, null, null, null, null, new BigDecimal(one) } };
+ }
+
+ /*
+ * Test for constructor Duration(boolean isPositive,BigInteger
+ * years,BigInteger months, BigInteger days,BigInteger hours,BigInteger
+ * minutes,BigDecimal seconds).
+ */
+ @Test(dataProvider = "legal-bigint-duration")
+ public void checkBigIntegerDurationPos(boolean isPositive, BigInteger years, BigInteger months, BigInteger days, BigInteger hours, BigInteger minutes,
+ BigDecimal seconds) {
+ datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
+ }
+
+ @DataProvider(name = "illegal-bigint-duration")
+ public Object[][] getIllegalBigIntegerDuration() {
+ return new Object[][] {
+ // is positive, year, month, day, hour, minute, second
+ { true, null, null, null, null, null, null },
+ { false, null, null, null, null, null, null }
+ };
+ }
+
+ /*
+ * Test for constructor Duration(boolean isPositive,BigInteger
+ * years,BigInteger months, BigInteger days,BigInteger hours,BigInteger
+ * minutes,BigDecimal seconds), if all the fields are null should throw
+ * IllegalArgumentException.
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "illegal-bigint-duration")
+ public void checkBigIntegerDurationNeg(boolean isPositive, BigInteger years, BigInteger months, BigInteger days, BigInteger hours, BigInteger minutes,
+ BigDecimal seconds) {
+ datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
+ }
+
+ @DataProvider(name = "legal-millisec-duration")
+ public Object[][] getLegalMilliSecondDuration() {
+ return new Object[][] { { 1000000 }, { 0 }, { Long.MAX_VALUE }, { Long.MIN_VALUE }
+
+ };
+ }
+
+ /*
+ * Test for constructor Duration(long durationInMilliSeconds)
+ */
+ @Test(dataProvider = "legal-millisec-duration")
+ public void checkMilliSecondDuration(long millisec) {
+ datatypeFactory.newDuration(millisec);
+ }
+
+ @DataProvider(name = "legal-lexical-duration")
+ public Object[][] getLegalLexicalDuration() {
+ return new Object[][] { { "P1Y1M1DT1H1M1S" }, { "-P1Y1M1DT1H1M1S" } };
+ }
+
+ /*
+ * Test for constructor Duration(java.lang.String lexicalRepresentation)
+ */
+ @Test(dataProvider = "legal-lexical-duration")
+ public void checkLexicalDurationPos(String lexRepresentation) {
+ datatypeFactory.newDuration(lexRepresentation);
+ }
+
+ @DataProvider(name = "illegal-lexical-duration")
+ public Object[][] getIllegalLexicalDuration() {
+ return new Object[][] {
+ { null },
+ { "P1Y1M1DT1H1M1S " },
+ { " P1Y1M1DT1H1M1S" },
+ { "X1Y1M1DT1H1M1S" },
+ { "" },
+ { "P1Y2MT" } // The designator 'T' shall be absent if all of the time items are absent in "PnYnMnDTnHnMnS"
+ };
+ }
+
+ /*
+ * Test for constructor Duration(java.lang.String lexicalRepresentation),
+ * null should throw NullPointerException, invalid lex should throw
+ * IllegalArgumentException
+ */
+ @Test(expectedExceptions = { NullPointerException.class, IllegalArgumentException.class }, dataProvider = "illegal-lexical-duration")
+ public void checkLexicalDurationNeg(String lexRepresentation) {
+ datatypeFactory.newDuration(lexRepresentation);
+ }
+
+ @DataProvider(name = "equal-duration")
+ public Object[][] getEqualDurations() {
+ return new Object[][] { { "P1Y1M1DT1H1M1S", "P1Y1M1DT1H1M1S" } };
+ }
+
+ /*
+ * Test for compare() both durations valid and equal.
+ */
+ @Test(dataProvider = "equal-duration")
+ public void checkDurationEqual(String lexRepresentation1, String lexRepresentation2) {
+ Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
+ Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
+ assertTrue(duration1.equals(duration2));
+ }
+
+ @DataProvider(name = "greater-duration")
+ public Object[][] getGreaterDuration() {
+ return new Object[][] {
+ { "P1Y1M1DT1H1M2S", "P1Y1M1DT1H1M1S" },
+ { "P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M2S" },
+ { "P1Y1M1DT1H1M2S", "-P1Y1M1DT1H1M1S" },
+ { "-P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M2S" }, };
+ }
+
+ /*
+ * Test for compare() both durations valid and lhs > rhs.
+ */
+ @Test(dataProvider = "greater-duration")
+ public void checkDurationCompare(String lexRepresentation1, String lexRepresentation2) {
+ Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
+ Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
+ assertTrue(duration1.compare(duration2) == DatatypeConstants.GREATER);
+ }
+
+ @DataProvider(name = "not-equal-duration")
+ public Object[][] getNotEqualDurations() {
+ return new Object[][] {
+ { "P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M1S" },
+ { "P2Y1M1DT1H1M1S", "P1Y1M1DT1H1M1S" } };
+ }
+
+ /*
+ * Test for equals() both durations valid and lhs not equals rhs.
+ */
+ @Test(dataProvider = "not-equal-duration")
+ public void checkDurationNotEqual(String lexRepresentation1, String lexRepresentation2) {
+ Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
+ Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
+ Assert.assertNotEquals(duration1, duration2);
+ }
+
+ @DataProvider(name = "duration-sign")
+ public Object[][] getDurationAndSign() {
+ return new Object[][] {
+ { "P0Y0M0DT0H0M0S", 0 },
+ { "P1Y0M0DT0H0M0S", 1 },
+ { "-P1Y0M0DT0H0M0S", -1 } };
+ }
+
+ /*
+ * Test for Duration.getSign().
+ */
+ @Test(dataProvider = "duration-sign")
+ public void checkDurationSign(String lexRepresentation, int sign) {
+ Duration duration = datatypeFactory.newDuration(lexRepresentation);
+ assertEquals(duration.getSign(), sign);
+ }
+
+ /*
+ * Test for Duration.negate().
+ */
+ @Test
+ public void checkDurationNegate() {
+ Duration durationPos = datatypeFactory.newDuration("P1Y0M0DT0H0M0S");
+ Duration durationNeg = datatypeFactory.newDuration("-P1Y0M0DT0H0M0S");
+
+ assertEquals(durationPos.negate(), durationNeg);
+ assertEquals(durationNeg.negate(), durationPos);
+ assertEquals(durationPos.negate().negate(), durationPos);
+
+ }
+
+ /*
+ * Test for Duration.isShorterThan(Duration) and
+ * Duration.isLongerThan(Duration).
+ */
+ @Test
+ public void checkDurationShorterLonger() {
+ Duration shorter = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
+ Duration longer = datatypeFactory.newDuration("P2Y1M1DT1H1M1S");
+
+ assertTrue(shorter.isShorterThan(longer));
+ assertFalse(longer.isShorterThan(shorter));
+ assertFalse(shorter.isShorterThan(shorter));
+
+ assertTrue(longer.isLongerThan(shorter));
+ assertFalse(shorter.isLongerThan(longer));
+ assertFalse(shorter.isLongerThan(shorter));
+ }
+
+ /*
+ * Test for Duration.isSet().
+ */
+ @Test
+ public void checkDurationIsSet() {
+ Duration duration1 = datatypeFactory.newDuration(true, 1, 1, 1, 1, 1, 1);
+ Duration duration2 = datatypeFactory.newDuration(true, 0, 0, 0, 0, 0, 0);
+
+ assertTrue(duration1.isSet(YEARS));
+ assertTrue(duration1.isSet(MONTHS));
+ assertTrue(duration1.isSet(DAYS));
+ assertTrue(duration1.isSet(HOURS));
+ assertTrue(duration1.isSet(MINUTES));
+ assertTrue(duration1.isSet(SECONDS));
+
+ assertTrue(duration2.isSet(YEARS));
+ assertTrue(duration2.isSet(MONTHS));
+ assertTrue(duration2.isSet(DAYS));
+ assertTrue(duration2.isSet(HOURS));
+ assertTrue(duration2.isSet(MINUTES));
+ assertTrue(duration2.isSet(SECONDS));
+
+ Duration duration66 = datatypeFactory.newDuration(true, null, null, zero, null, null, null);
+ assertFalse(duration66.isSet(YEARS));
+ assertFalse(duration66.isSet(MONTHS));
+ assertFalse(duration66.isSet(HOURS));
+ assertFalse(duration66.isSet(MINUTES));
+ assertFalse(duration66.isSet(SECONDS));
+
+ Duration duration3 = datatypeFactory.newDuration("P1D");
+ assertFalse(duration3.isSet(YEARS));
+ assertFalse(duration3.isSet(MONTHS));
+ assertFalse(duration3.isSet(HOURS));
+ assertFalse(duration3.isSet(MINUTES));
+ assertFalse(duration3.isSet(SECONDS));
+ }
+
+ /*
+ * Test Duration.isSet(Field) throws NPE if the field parameter is null.
+ */
+ @Test(expectedExceptions = NullPointerException.class)
+ public void checkDurationIsSetNeg() {
+ Duration duration = datatypeFactory.newDuration(true, 0, 0, 0, 0, 0, 0);
+ duration.isSet(null);
+ }
+
+ /*
+ * Test for -getField(DatatypeConstants.Field) DatatypeConstants.Field is
+ * null - throws NPE.
+ */
+ @Test(expectedExceptions = NullPointerException.class)
+ public void checkDurationGetFieldNeg() {
+ Duration duration67 = datatypeFactory.newDuration("P1Y1M1DT1H1M1S");
+ duration67.getField(null);
+ }
+
+ @DataProvider(name = "duration-fields")
+ public Object[][] getDurationAndFields() {
+ return new Object[][] {
+ { "P1Y1M1DT1H1M1S", one, one, one, one, one, new BigDecimal(one) },
+ { "PT1M", null, null, null, null, one, null },
+ { "P1M", null, one, null, null, null, null } };
+ }
+
+ /*
+ * Test for Duration.getField(DatatypeConstants.Field).
+ */
+ @Test(dataProvider = "duration-fields")
+ public void checkDurationGetField(String lexRepresentation, BigInteger years, BigInteger months, BigInteger days, BigInteger hours, BigInteger minutes,
+ BigDecimal seconds) {
+ Duration duration = datatypeFactory.newDuration(lexRepresentation);
+
+ assertEquals(duration.getField(YEARS), years);
+ assertEquals(duration.getField(MONTHS), months);
+ assertEquals(duration.getField(DAYS), days);
+ assertEquals(duration.getField(HOURS), hours);
+ assertEquals(duration.getField(MINUTES), minutes);
+ assertEquals(duration.getField(SECONDS), seconds);
+ }
+
+ @DataProvider(name = "number-string")
+ public Object[][] getNumberAndString() {
+ return new Object[][] {
+ // is positive, year, month, day, hour, minute, second, lexical
+ { true, 1, 1, 1, 1, 1, 1, "P1Y1M1DT1H1M1S" },
+ { false, 1, 1, 1, 1, 1, 1, "-P1Y1M1DT1H1M1S" },
+ { true, 0, 0, 0, 0, 0, 0, "P0Y0M0DT0H0M0S" },
+ { false, 0, 0, 0, 0, 0, 0, "P0Y0M0DT0H0M0S" }
+ };
+ }
+
+ /*
+ * Test for - toString().
+ */
+ @Test(dataProvider = "number-string")
+ public void checkDurationToString(boolean isPositive, int years, int months, int days, int hours, int minutes, int seconds, String lexical) {
+ Duration duration = datatypeFactory.newDuration(isPositive, years, months, days, hours, minutes, seconds);
+ assertEquals(duration.toString(), lexical);
+
+ assertEquals(datatypeFactory.newDuration(duration.toString()), duration);
+ }
+
+ @DataProvider(name = "duration-field")
+ public Object[][] getDurationAndField() {
+ Function<Duration, Integer> getyears = duration -> duration.getYears();
+ Function<Duration, Integer> getmonths = duration -> duration.getMonths();
+ Function<Duration, Integer> getdays = duration -> duration.getDays();
+ Function<Duration, Integer> gethours = duration -> duration.getHours();
+ Function<Duration, Integer> getminutes = duration -> duration.getMinutes();
+ Function<Duration, Integer> getseconds = duration -> duration.getSeconds();
+ return new Object[][] {
+ { "P1Y1M1DT1H1M1S", getyears, 1 },
+ { "P1M1DT1H1M1S", getyears, 0 },
+ { "P1Y1M1DT1H1M1S", getmonths, 1 },
+ { "P1Y1DT1H1M1S", getmonths, 0 },
+ { "P1Y1M1DT1H1M1S", getdays, 1 },
+ { "P1Y1MT1H1M1S", getdays, 0 },
+ { "P1Y1M1DT1H1M1S", gethours, 1 },
+ { "P1Y1M1DT1M1S", gethours, 0 },
+ { "P1Y1M1DT1H1M1S", getminutes, 1 },
+ { "P1Y1M1DT1H1S", getminutes, 0 },
+ { "P1Y1M1DT1H1M1S", getseconds, 1 },
+ { "P1Y1M1DT1H1M", getseconds, 0 },
+ { "P1Y1M1DT1H1M100000000S", getseconds, 100000000 }, };
+ }
+
+ /*
+ * Test for Duration.getYears(), getMonths(), etc.
+ */
+ @Test(dataProvider = "duration-field")
+ public void checkDurationGetOneField(String lexRepresentation, Function<Duration, Integer> getter, int value) {
+ Duration duration = datatypeFactory.newDuration(lexRepresentation);
+ assertEquals(getter.apply(duration).intValue(), value);
+ }
+
+ /*
+ * Test for - getField(SECONDS)
+ */
+ @Test
+ public void checkDurationGetSecondsField() {
+ Duration duration85 = datatypeFactory.newDuration("P1Y1M1DT1H1M100000000S");
+ assertEquals((duration85.getField(SECONDS)).intValue(), 100000000);
+ }
+
+ /*
+ * getTimeInMillis(java.util.Calendar startInstant) returns milliseconds
+ * between startInstant and startInstant plus this Duration.
+ */
+ @Test
+ public void checkDurationGetTimeInMillis() {
+ Duration duration86 = datatypeFactory.newDuration("PT1M1S");
+ Calendar calendar86 = Calendar.getInstance();
+ assertEquals(duration86.getTimeInMillis(calendar86), 61000);
+ }
+
+ /*
+ * getTimeInMillis(java.util.Calendar startInstant) returns milliseconds
+ * between startInstant and startInstant plus this Duration throws NPE if
+ * startInstant parameter is null.
+ */
+ @Test(expectedExceptions = NullPointerException.class)
+ public void checkDurationGetTimeInMillisNeg() {
+ Duration duration87 = datatypeFactory.newDuration("PT1M1S");
+ Calendar calendar87 = null;
+ duration87.getTimeInMillis(calendar87);
+ }
+
+ @DataProvider(name = "duration-for-hash")
+ public Object[][] getDurationsForHash() {
+ return new Object[][] {
+ { "P1Y1M1DT1H1M1S", "P1Y1M1DT1H1M1S" },
+ { "P1D", "PT24H" },
+ { "PT1H", "PT60M" },
+ { "PT1M", "PT60S" },
+ { "P1Y", "P12M" } };
+ }
+
+ /*
+ * Test for Duration.hashcode(). hashcode() should return same value for
+ * some equal durations.
+ */
+ @Test(dataProvider = "duration-for-hash")
+ public void checkDurationHashCode(String lexRepresentation1, String lexRepresentation2) {
+ Duration duration1 = datatypeFactory.newDuration(lexRepresentation1);
+ Duration duration2 = datatypeFactory.newDuration(lexRepresentation2);
+ int hash1 = duration1.hashCode();
+ int hash2 = duration2.hashCode();
+ assertTrue(hash1 == hash2, " generated hash1 : " + hash1 + " generated hash2 : " + hash2);
+ }
+
+ @DataProvider(name = "duration-for-add")
+ public Object[][] getDurationsForAdd() {
+ return new Object[][] {
+ // initVal, addVal, resultVal
+ { "P1Y1M1DT1H1M1S", "P1Y1M1DT1H1M1S", "P2Y2M2DT2H2M2S" },
+ { "P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M1S", "P0Y0M0DT0H0M0S" },
+ { "-P1Y1M1DT1H1M1S", "-P1Y1M1DT1H1M1S", "-P2Y2M2DT2H2M2S" }, };
+ }
+
+ /*
+ * Test for add(Duration rhs).
+ */
+ @Test(dataProvider = "duration-for-add")
+ public void checkDurationAdd(String initVal, String addVal, String result) {
+ Duration durationInit = datatypeFactory.newDuration(initVal);
+ Duration durationAdd = datatypeFactory.newDuration(addVal);
+ Duration durationResult = datatypeFactory.newDuration(result);
+
+ assertEquals(durationInit.add(durationAdd), durationResult);
+ }
+
+ @DataProvider(name = "duration-for-addneg")
+ public Object[][] getDurationsForAddNeg() {
+ return new Object[][] {
+ // initVal, addVal
+ { "P1Y1M1DT1H1M1S", null },
+ { "P1Y", "-P1D" },
+ { "-P1Y", "P1D" }, };
+ }
+
+ /*
+ * Test for add(Duration rhs) 'rhs' is null , should throw NPE. "1 year" +
+ * "-1 day" or "-1 year" + "1 day" should throw IllegalStateException
+ */
+ @Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }, dataProvider = "duration-for-addneg")
+ public void checkDurationAddNeg(String initVal, String addVal) {
+ Duration durationInit = datatypeFactory.newDuration(initVal);
+ Duration durationAdd = addVal == null ? null : datatypeFactory.newDuration(addVal);
+
+ durationInit.add(durationAdd);
+ }
+
+ /*
+ * Test Duration#compare(Duration duration) with large durations.
+ *
+ * Bug # 4972785 UnsupportedOperationException is expected
+ *
+ */
+ @Test(expectedExceptions = UnsupportedOperationException.class)
+ public void checkDurationCompareLarge() {
+ String duration1Lex = "P100000000000000000000D";
+ String duration2Lex = "PT2400000000000000000000H";
+
+ Duration duration1 = datatypeFactory.newDuration(duration1Lex);
+ Duration duration2 = datatypeFactory.newDuration(duration2Lex);
+ duration1.compare(duration2);
+
+ }
+
+ /*
+ * Test Duration#getXMLSchemaType().
+ *
+ * Bug # 5049544 Duration.getXMLSchemaType shall return the correct result
+ *
+ */
+ @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());
+
+ }
+
+
+ private final int undef = DatatypeConstants.FIELD_UNDEFINED;
+ private final BigInteger zero = BigInteger.ZERO;
+ private final BigInteger one = BigInteger.ONE;
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/datatype/ptests/FactoryNewInstanceTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.datatype.ptests;
+
+import static org.testng.Assert.assertNotNull;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+
+import jaxp.library.JAXPDataProvider;
+import jaxp.library.JAXPBaseTest;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/*
+ * @summary Tests for DatatypeFactory.newInstance(factoryClassName , classLoader)
+ */
+public class FactoryNewInstanceTest extends JAXPBaseTest {
+
+ private static final String DATATYPE_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl";
+
+ @DataProvider(name = "parameters")
+ public Object[][] getValidateParameters() {
+ return new Object[][] { { DATATYPE_FACTORY_CLASSNAME, null }, { DATATYPE_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
+ }
+
+ /*
+ * test for DatatypeFactory.newInstance(java.lang.String factoryClassName,
+ * java.lang.ClassLoader classLoader) factoryClassName points to correct
+ * implementation of javax.xml.datatype.DatatypeFactory , should return
+ * newInstance of DatatypeFactory
+ */
+ @Test(dataProvider = "parameters")
+ public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
+ DatatypeFactory dtf = DatatypeFactory.newInstance(DATATYPE_FACTORY_CLASSNAME, null);
+ Duration duration = dtf.newDuration(true, 1, 1, 1, 1, 1, 1);
+ assertNotNull(duration);
+ }
+
+
+ /*
+ * test for DatatypeFactory.newInstance(java.lang.String factoryClassName,
+ * java.lang.ClassLoader classLoader) factoryClassName is null , should
+ * throw DatatypeConfigurationException
+ */
+ @Test(expectedExceptions = DatatypeConfigurationException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+ public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
+ DatatypeFactory.newInstance(factoryClassName, classLoader);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/datatype/ptests/XMLGregorianCalendarTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,356 @@
+/*
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.datatype.ptests;
+
+import static java.util.Calendar.HOUR;
+import static java.util.Calendar.MINUTE;
+import static java.util.Calendar.YEAR;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import jaxp.library.JAXPBaseTest;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/*
+ * @bug 5049592 5041845 5048932 5064587 5040542 5049531 5049528
+ * @summary Class containing the test cases for XMLGregorianCalendar
+ */
+public class XMLGregorianCalendarTest extends JAXPBaseTest {
+
+ private DatatypeFactory datatypeFactory;
+
+ @BeforeClass
+ public void setup() throws DatatypeConfigurationException {
+ datatypeFactory = DatatypeFactory.newInstance();
+ }
+
+ @DataProvider(name = "valid-milliseconds")
+ public Object[][] getValidMilliSeconds() {
+ return new Object[][] { { 0 }, { 1 }, { 2 }, { 16 }, { 1000 } };
+ }
+
+ /*
+ * Test DatatypeFactory.newXMLGregorianCalendar(..) with milliseconds > 1.
+ *
+ * Bug # 5049592
+ *
+ */
+ @Test(dataProvider = "valid-milliseconds")
+ public void checkNewCalendar(int ms) {
+ // valid milliseconds
+ XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar(2004, // year
+ 6, // month
+ 2, // day
+ 19, // hour
+ 20, // minute
+ 59, // second
+ ms, // milliseconds
+ 840 // timezone
+ );
+ // expected success
+
+ assertEquals(calendar.getMillisecond(), ms);
+ }
+
+ /*
+ * Test DatatypeFactory.newXMLGregorianCalendarTime(..).
+ *
+ * Bug # 5049592
+ */
+ @Test(dataProvider = "valid-milliseconds")
+ public void checkNewTime(int ms) {
+ // valid milliseconds
+ XMLGregorianCalendar calendar2 = datatypeFactory.newXMLGregorianCalendarTime(19, // hour
+ 20, // minute
+ 59, // second
+ ms, // milliseconds
+ 840 // timezone
+ );
+ // expected success
+
+ assertEquals(calendar2.getMillisecond(), ms);
+ }
+
+ @DataProvider(name = "invalid-milliseconds")
+ public Object[][] getInvalidMilliSeconds() {
+ return new Object[][] { { -1 }, { 1001 } };
+ }
+
+ /*
+ * Test DatatypeFactory.newXMLGregorianCalendar(..).
+ *
+ * Bug # 5049592 IllegalArgumentException is thrown if milliseconds < 0 or >
+ * 1001.
+ *
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "invalid-milliseconds")
+ public void checkNewCalendarNeg(int milliseconds) {
+ // invalid milliseconds
+ datatypeFactory.newXMLGregorianCalendar(2004, // year
+ 6, // month
+ 2, // day
+ 19, // hour
+ 20, // minute
+ 59, // second
+ milliseconds, // milliseconds
+ 840 // timezone
+ );
+ }
+
+ /*
+ * Test DatatypeFactory.newXMLGregorianCalendarTime(..).
+ *
+ * Bug # 5049592 IllegalArgumentException is thrown if milliseconds < 0 or >
+ * 1001.
+ *
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "invalid-milliseconds")
+ public void checkNewTimeNeg(int milliseconds) {
+ // invalid milliseconds
+ datatypeFactory.newXMLGregorianCalendarTime(19, // hour
+ 20, // minute
+ 59, // second
+ milliseconds, // milliseconds
+ 840 // timezone
+ );
+ }
+
+ @DataProvider(name = "data-for-add")
+ public Object[][] getDataForAdd() {
+ return new Object[][] {
+ //calendar1, calendar2, duration
+ { "1999-12-31T00:00:00Z", "2000-01-01T00:00:00Z", "P1D" },
+ { "2000-12-31T00:00:00Z", "2001-01-01T00:00:00Z", "P1D" },
+ { "1998-12-31T00:00:00Z", "1999-01-01T00:00:00Z", "P1D" },
+ { "2001-12-31T00:00:00Z", "2002-01-01T00:00:00Z", "P1D" },
+ { "2003-04-11T00:00:00Z", "2003-04-12T00:00:00Z", "P1D" },
+ { "2003-04-11T00:00:00Z", "2003-04-14T00:00:00Z", "P3D" },
+ { "2003-04-30T00:00:00Z", "2003-05-01T00:00:00Z", "P1D" },
+ { "2003-02-28T00:00:00Z", "2003-03-01T00:00:00Z", "P1D" },
+ { "2000-02-29T00:00:00Z", "2000-03-01T00:00:00Z", "P1D" },
+ { "2000-02-28T00:00:00Z", "2000-02-29T00:00:00Z", "P1D" },
+ { "1998-01-11T00:00:00Z", "1998-04-11T00:00:00Z", "P90D" },
+ { "1999-05-11T00:00:00Z", "2002-05-11T00:00:00Z", "P1096D" }};
+ }
+
+ /*
+ * Test XMLGregorianCalendar.add(Duration).
+ *
+ */
+ @Test(dataProvider = "data-for-add")
+ public void checkAddDays(String cal1, String cal2, String dur) {
+
+ XMLGregorianCalendar calendar1 = datatypeFactory.newXMLGregorianCalendar(cal1);
+ XMLGregorianCalendar calendar2 = datatypeFactory.newXMLGregorianCalendar(cal2);
+
+ Duration duration = datatypeFactory.newDuration(dur);
+
+ XMLGregorianCalendar calendar1Clone = (XMLGregorianCalendar)calendar1.clone();
+
+ calendar1Clone.add(duration);
+ assertEquals(calendar1Clone, calendar2);
+
+ calendar2.add(duration.negate());
+ assertEquals(calendar2, calendar1);
+
+ }
+
+ @DataProvider(name = "gMonth")
+ public Object[][] getGMonth() {
+ return new Object[][] {
+ { "2000-02" },
+ { "2000-03" },
+ { "2018-02" }};
+ }
+ /*
+ * Test XMLGregorianCalendar#isValid(). for gMonth
+ *
+ * Bug # 5041845
+ *
+ */
+ @Test(dataProvider = "gMonth")
+ public void checkIsValid(String month) {
+
+ XMLGregorianCalendar gMonth = datatypeFactory.newXMLGregorianCalendar(month);
+ gMonth.setYear(null);
+ Assert.assertTrue(gMonth.isValid(), gMonth.toString() + " should isValid");
+
+ }
+
+ @DataProvider(name = "lexical01")
+ public Object[][] getLexicalRepresentForNormalize01() {
+ return new Object[][] { { "2000-01-16T12:00:00Z" }, { "2000-01-16T12:00:00" } };
+ }
+
+ /*
+ * Test XMLGregorianCalendar#normalize(...).
+ *
+ * Bug # 5048932 XMLGregorianCalendar.normalize works
+ *
+ */
+ @Test(dataProvider = "lexical01")
+ public void checkNormalize01(String lexical) {
+ XMLGregorianCalendar lhs = datatypeFactory.newXMLGregorianCalendar(lexical);
+ lhs.normalize();
+ }
+
+ @DataProvider(name = "lexical02")
+ public Object[][] getLexicalRepresentForNormalize02() {
+ return new Object[][] { { "2000-01-16T00:00:00.01Z" }, { "2000-01-16T00:00:00.01" }, { "13:20:00" } };
+ }
+
+ /*
+ * Test XMLGregorianCalendar#normalize(...).
+ *
+ * Bug # 5064587 XMLGregorianCalendar.normalize shall not change timezone
+ *
+ */
+ @Test(dataProvider = "lexical02")
+ public void checkNormalize02(String lexical) {
+ XMLGregorianCalendar orig = datatypeFactory.newXMLGregorianCalendar(lexical);
+ XMLGregorianCalendar normalized = datatypeFactory.newXMLGregorianCalendar(lexical).normalize();
+
+ assertEquals(normalized.getTimezone(), orig.getTimezone());
+ assertEquals(normalized.getMillisecond(), orig.getMillisecond());
+ }
+
+ /*
+ * Test XMLGregorianCalendar#toGregorianCalendar( TimeZone timezone, Locale
+ * aLocale, XMLGregorianCalendar defaults)
+ *
+ * Bug # 5040542 the defaults XMLGregorianCalendar parameter shall take
+ * effect
+ *
+ */
+ @Test
+ public void checkToGregorianCalendar01() {
+
+ XMLGregorianCalendar time_16_17_18 = datatypeFactory.newXMLGregorianCalendar("16:17:18");
+ XMLGregorianCalendar date_2001_02_03 = datatypeFactory.newXMLGregorianCalendar("2001-02-03");
+ GregorianCalendar calendar = date_2001_02_03.toGregorianCalendar(null, null, time_16_17_18);
+
+ int year = calendar.get(YEAR);
+ int minute = calendar.get(MINUTE);
+
+ assertTrue((year == 2001 && minute == 17), " expecting year == 2001, minute == 17" + ", result is year == " + year + ", minute == " + minute);
+
+
+ calendar = time_16_17_18.toGregorianCalendar(null, null, date_2001_02_03);
+
+ year = calendar.get(YEAR);
+ minute = calendar.get(MINUTE);
+
+ assertTrue((year == 2001 && minute == 17), " expecting year == 2001, minute == 17" + ", result is year == " + year + ", minute == " + minute);
+
+
+ date_2001_02_03.setMinute(3);
+ date_2001_02_03.setYear(null);
+
+ XMLGregorianCalendar date_time = datatypeFactory.newXMLGregorianCalendar("2003-04-11T02:13:01Z");
+
+ calendar = date_2001_02_03.toGregorianCalendar(null, null, date_time);
+
+ year = calendar.get(YEAR);
+ minute = calendar.get(MINUTE);
+ int hour = calendar.get(HOUR);
+
+ assertTrue((year == 2003 && hour == 2 && minute == 3), " expecting year == 2003, hour == 2, minute == 3" + ", result is year == " + year + ", hour == " + hour + ", minute == " + minute);
+
+
+ }
+
+ /*
+ * Test XMLGregorianCalendar#toGregorianCalendar( TimeZone timezone, Locale
+ * aLocale, XMLGregorianCalendar defaults) with the 'defaults' parameter
+ * being null.
+ *
+ * Bug # 5049531 XMLGregorianCalendar.toGregorianCalendar(..) can accept
+ * 'defaults' is null
+ *
+ */
+ @Test
+ public void checkToGregorianCalendar02() {
+
+ XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar("2004-05-19T12:00:00+06:00");
+ calendar.toGregorianCalendar(TimeZone.getDefault(), Locale.getDefault(), null);
+ }
+
+ @DataProvider(name = "calendar")
+ public Object[][] getXMLGregorianCalendarData() {
+ return new Object[][] {
+ // year, month, day, hour, minute, second
+ { 1970, 1, 1, 0, 0, 0 }, // DATETIME
+ { 1970, 1, 1, undef, undef, undef }, // DATE
+ { undef, undef, undef, 1, 0, 0 }, // TIME
+ { 1970, 1, undef, undef, undef, undef }, // GYEARMONTH
+ { undef, 1, 1, undef, undef, undef }, // GMONTHDAY
+ { 1970, undef, undef, undef, undef, undef }, // GYEAR
+ { undef, 1, undef, undef, undef, undef }, // GMONTH
+ { undef, undef, 1, undef, undef, undef } // GDAY
+ };
+ }
+
+ /*
+ * Test XMLGregorianCalendar#toString()
+ *
+ * Bug # 5049528
+ *
+ */
+ @Test(dataProvider = "calendar")
+ public void checkToStringPos(final int year, final int month, final int day, final int hour, final int minute, final int second) {
+ XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar(year, month, day, hour, minute, second, undef, undef);
+ calendar.toString();
+ }
+
+ /*
+ * Negative Test XMLGregorianCalendar#toString()
+ *
+ * Bug # 5049528 XMLGregorianCalendar.toString throws IllegalStateException
+ * if all parameters are undef
+ *
+ */
+ @Test(expectedExceptions = IllegalStateException.class)
+ public void checkToStringNeg() {
+ XMLGregorianCalendar calendar = datatypeFactory.newXMLGregorianCalendar(undef, undef, undef, undef, undef, undef, undef, undef);
+ // expected to fail
+ calendar.toString();
+ }
+
+ private final int undef = DatatypeConstants.FIELD_UNDEFINED;
+
+}
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/DocumentBuilderFactoryTest.java Thu Feb 05 11:43:32 2015 -0800
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/DocumentBuilderFactoryTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -26,27 +26,38 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilePermission;
import java.io.FileReader;
+
import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
+
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+
import static javax.xml.parsers.ptests.ParserTestConst.GOLDEN_DIR;
import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
+
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
+
+import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPFileBaseTest;
import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.compareWithGold;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -60,6 +71,52 @@
*/
public class DocumentBuilderFactoryTest extends JAXPFileBaseTest {
/**
+ * DocumentBuilderFactory implementation class name.
+ */
+ private static final String DOCUMENT_BUILDER_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
+
+ /**
+ * Provide valid DocumentBuilderFactory instantiation parameters.
+ *
+ * @return a data provider contains DocumentBuilderFactory instantiation parameters.
+ */
+ @DataProvider(name = "parameters")
+ public Object[][] getValidateParameters() {
+ return new Object[][] { { DOCUMENT_BUILDER_FACTORY_CLASSNAME, null }, { DOCUMENT_BUILDER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
+ }
+
+ /**
+ * Test for DocumentBuilderFactory.newInstance(java.lang.String
+ * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
+ * points to correct implementation of
+ * javax.xml.parsers.DocumentBuilderFactory , should return newInstance of
+ * DocumentBuilderFactory
+ *
+ * @param factoryClassName
+ * @param classLoader
+ * @throws ParserConfigurationException
+ */
+ @Test(dataProvider = "parameters")
+ public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws ParserConfigurationException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(factoryClassName, classLoader);
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ assertNotNull(builder);
+ }
+
+ /**
+ * test for DocumentBuilderFactory.newInstance(java.lang.String
+ * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is
+ * null , should throw FactoryConfigurationError
+ *
+ * @param factoryClassName
+ * @param classLoader
+ */
+ @Test(expectedExceptions = FactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+ public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
+ DocumentBuilderFactory.newInstance(factoryClassName, classLoader);
+ }
+
+ /**
* Test the default functionality of schema support method.
* @throws Exception If any errors occur.
*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXFactoryNewInstanceTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.parsers.ptests;
+
+import static org.testng.Assert.assertNotNull;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import jaxp.library.JAXPDataProvider;
+import jaxp.library.JAXPBaseTest;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import org.xml.sax.SAXException;
+
+/*
+ * @summary Tests for SAXParserFactory.newInstance(factoryClassName , classLoader)
+ */
+public class SAXFactoryNewInstanceTest extends JAXPBaseTest {
+
+ private static final String SAXPARSER_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl";
+
+ @DataProvider(name = "parameters")
+ public Object[][] getValidateParameters() {
+ return new Object[][] { { SAXPARSER_FACTORY_CLASSNAME, null }, { SAXPARSER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
+ }
+
+ /*
+ * test for SAXParserFactory.newInstance(java.lang.String factoryClassName,
+ * java.lang.ClassLoader classLoader) factoryClassName points to correct
+ * implementation of javax.xml.parsers.SAXParserFactory , should return
+ * newInstance of SAXParserFactory
+ */
+ @Test(dataProvider = "parameters")
+ public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws ParserConfigurationException, SAXException {
+ SAXParserFactory spf = SAXParserFactory.newInstance(factoryClassName, classLoader);
+ SAXParser sp = spf.newSAXParser();
+ assertNotNull(sp);
+ }
+
+ /*
+ * test for SAXParserFactory.newInstance(java.lang.String factoryClassName,
+ * java.lang.ClassLoader classLoader) factoryClassName is null , should
+ * throw FactoryConfigurationError
+ */
+ @Test(expectedExceptions = FactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+ public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
+ SAXParserFactory.newInstance(factoryClassName, classLoader);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLEventFactoryNewInstanceTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.stream.ptests;
+
+import static org.testng.Assert.assertNotNull;
+
+import javax.xml.stream.XMLEventFactory;
+
+import jaxp.library.JAXPDataProvider;
+import jaxp.library.JAXPBaseTest;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/*
+ * @summary Tests for XMLEventFactory.newFactory(factoryId , classLoader)
+ */
+public class XMLEventFactoryNewInstanceTest extends JAXPBaseTest {
+
+ private static final String XMLEVENT_FACTORY_CLASSNAME = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
+ private static final String XMLEVENT_FACRORY_ID = "javax.xml.stream.XMLEventFactory";
+
+ @DataProvider(name = "parameters")
+ public Object[][] getValidateParameters() {
+ return new Object[][] { { XMLEVENT_FACRORY_ID, null }, { XMLEVENT_FACRORY_ID, this.getClass().getClassLoader() } };
+ }
+
+ /*
+ * test for XMLEventFactory.newFactory(java.lang.String factoryClassName,
+ * java.lang.ClassLoader classLoader) factoryClassName points to correct
+ * implementation of javax.xml.stream.XMLEventFactory , should return
+ * newInstance of XMLEventFactory
+ */
+ @Test(dataProvider = "parameters")
+ public void testNewFactory(String factoryId, ClassLoader classLoader) {
+ setSystemProperty(XMLEVENT_FACRORY_ID, XMLEVENT_FACTORY_CLASSNAME);
+ try {
+ XMLEventFactory xef = XMLEventFactory.newFactory(factoryId, classLoader);
+ assertNotNull(xef);
+ } finally {
+ setSystemProperty(XMLEVENT_FACRORY_ID, null);
+ }
+ }
+
+ /*
+ * test for XMLEventFactory.newFactory(java.lang.String factoryClassName,
+ * java.lang.ClassLoader classLoader) factoryClassName is null , should
+ * throw NullPointerException
+ */
+ @Test(expectedExceptions = NullPointerException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+ public void testNewFactoryNeg(String factoryId, ClassLoader classLoader) {
+ XMLEventFactory.newFactory(null, null);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/stream/ptests/XMLInputFactoryNewInstanceTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.stream.ptests;
+
+import static org.testng.Assert.assertNotNull;
+
+import javax.xml.stream.XMLInputFactory;
+
+import jaxp.library.JAXPDataProvider;
+import jaxp.library.JAXPBaseTest;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/*
+ * @summary Tests for XMLInputFactory.newFactory(factoryId , classLoader)
+ */
+public class XMLInputFactoryNewInstanceTest extends JAXPBaseTest {
+
+ private static final String XMLINPUT_FACTORY_CLASSNAME = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
+ private static final String XMLINPUT_FACRORY_ID = "javax.xml.stream.XMLInputFactory";
+
+ @DataProvider(name = "parameters")
+ public Object[][] getValidateParameters() {
+ return new Object[][] { { XMLINPUT_FACRORY_ID, null }, { XMLINPUT_FACRORY_ID, this.getClass().getClassLoader() } };
+ }
+
+ /*
+ * test for XMLInputFactory.newFactory(java.lang.String factoryId,
+ * java.lang.ClassLoader classLoader) factoryClassName points to correct
+ * implementation of javax.xml.stream.XMLInputFactory , should return
+ * newInstance of XMLInputFactory
+ */
+ @Test(dataProvider = "parameters")
+ public void testNewFactory(String factoryId, ClassLoader classLoader) {
+ setSystemProperty(XMLINPUT_FACRORY_ID, XMLINPUT_FACTORY_CLASSNAME);
+ try {
+ XMLInputFactory xif = XMLInputFactory.newFactory(factoryId, classLoader);
+ assertNotNull(xif);
+ } finally {
+ setSystemProperty(XMLINPUT_FACRORY_ID, null);
+ }
+ }
+
+ /*
+ * test for XMLInputFactory.newFactory(java.lang.String factoryClassName,
+ * java.lang.ClassLoader classLoader) factoryClassName is null , should
+ * throw NullPointerException
+ */
+ @Test(expectedExceptions = NullPointerException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+ public void testNewFactoryNeg(String factoryId, ClassLoader classLoader) {
+ XMLInputFactory.newFactory(factoryId, classLoader);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/Bug6384418Test.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.transform.ptests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import jaxp.library.JAXPFileBaseTest;
+import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
+
+import org.testng.annotations.Test;
+import org.w3c.dom.Document;
+
+/*
+ * @bug 6384418
+ * @summary verify the transforming won't throw any exception
+ */
+public class Bug6384418Test extends JAXPFileBaseTest {
+
+ @Test
+ public void test() throws Exception {
+ TransformerFactory tfactory = TransformerFactory.newInstance();
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document document = db.parse(new File(XML_DIR + "dataentry.xsl"));
+ DOMSource domSource = new DOMSource(document);
+
+ Transformer transformer = tfactory.newTransformer(domSource);
+ StreamSource streamSource = new StreamSource(new File(XML_DIR + "test.xml"));
+ StreamResult streamResult = new StreamResult(new ByteArrayOutputStream());
+ transformer.transform(streamSource, streamResult);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,383 @@
+/*
+ * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.xml.transform.ptests;
+
+import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.function.Supplier;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stax.StAXResult;
+import javax.xml.transform.stax.StAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import jaxp.library.JAXPFileBaseTest;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+import org.w3c.dom.Document;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+/*
+ * @summary Tests for variable combination of Transformer.transform(Source, Result)
+ */
+@Test(singleThreaded = true)
+public class TransformTest extends JAXPFileBaseTest {
+
+ /*
+ * Initialize the share objects.
+ */
+ @BeforeClass
+ public void setup() throws Exception {
+ ifac = XMLInputFactory.newInstance();
+ ofac = XMLOutputFactory.newInstance();
+ tfac = TransformerFactory.newInstance();
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ db = dbf.newDocumentBuilder();
+
+ xml = Files.readAllBytes(Paths.get(XML_DIR + "cities.xml"));
+ template = Files.readAllBytes(Paths.get(XML_DIR + "cities.xsl"));
+
+ xmlDoc = db.parse(xmlInputStream());
+ }
+
+ @DataProvider(name = "input-provider")
+ public Object[][] prepareTestCombination() throws Exception {
+
+ Supplier<Source> staxStreamSource = () -> new StAXSource(getXMLStreamReader());
+ Supplier<Source> staxEventSource = this::getStAXEventSource;
+ Supplier<Source> domSource = () -> new DOMSource(xmlDoc);
+ Supplier<Source> saxSource = () -> new SAXSource(new InputSource(xmlInputStream()));
+ Supplier<Source> streamSource = () -> new StreamSource(xmlInputStream());
+
+ Supplier<Result> staxStreamResult = () -> new StAXResult(getXMLStreamWriter());
+ Supplier<Result> staxEventResult = () -> new StAXResult(getXMLEventWriter());
+ Supplier<Result> saxResult = this::getHandlerSAXResult;
+ Supplier<Result> streamResult = () -> new StreamResult(transOutputStream());
+
+ Transformer domTemplateTransformer = createTransformer(getDomTemplate());
+ Transformer saxTemplateTransformer = createTransformer(getSAXTemplate());
+ Transformer streamTemplateTransformer = createTransformer(getStreamTemplate());
+ Transformer noTemplateTransformer = createTransformer(null);
+ Transformer staxStreamTemplateTransformer = createTransformer(getStAXStreamTemplate());
+ Transformer staxEventTemplateTransformer = createTransformer(getStAXEventTemplate());
+
+ return new Object[][] {
+ // StAX Stream
+ { staxStreamSource, staxStreamResult, domTemplateTransformer },
+ { staxStreamSource, staxStreamResult, saxTemplateTransformer },
+ { staxStreamSource, staxStreamResult, streamTemplateTransformer },
+ { staxStreamSource, staxStreamResult, noTemplateTransformer },
+ { staxStreamSource, staxStreamResult, staxStreamTemplateTransformer },
+ { staxStreamSource, saxResult, domTemplateTransformer },
+ { staxStreamSource, streamResult, domTemplateTransformer },
+ { domSource, staxStreamResult, domTemplateTransformer },
+ { saxSource, staxStreamResult, domTemplateTransformer },
+ { streamSource, staxStreamResult, domTemplateTransformer },
+ { staxStreamSource, streamResult, saxTemplateTransformer },
+ { domSource, staxStreamResult, saxTemplateTransformer },
+ { saxSource, staxStreamResult, saxTemplateTransformer },
+ { streamSource, staxStreamResult, saxTemplateTransformer },
+ { staxStreamSource, streamResult, streamTemplateTransformer },
+ { domSource, staxStreamResult, streamTemplateTransformer },
+ { saxSource, staxStreamResult, streamTemplateTransformer },
+ { streamSource, staxStreamResult, streamTemplateTransformer },
+ // StAX Event
+ { staxEventSource, staxEventResult, domTemplateTransformer },
+ { staxEventSource, staxEventResult, saxTemplateTransformer },
+ { staxEventSource, staxEventResult, streamTemplateTransformer },
+ { staxEventSource, staxEventResult, noTemplateTransformer },
+ { staxEventSource, staxEventResult, staxEventTemplateTransformer },
+ { staxEventSource, saxResult, domTemplateTransformer },
+ { staxEventSource, streamResult, domTemplateTransformer },
+ { domSource, staxEventResult, domTemplateTransformer },
+ { saxSource, staxEventResult, domTemplateTransformer },
+ { streamSource, staxEventResult, domTemplateTransformer },
+ { staxEventSource, streamResult, saxTemplateTransformer },
+ { domSource, staxEventResult, saxTemplateTransformer },
+ { saxSource, staxEventResult, saxTemplateTransformer },
+ { streamSource, staxEventResult, saxTemplateTransformer },
+ { staxEventSource, streamResult, streamTemplateTransformer },
+ { domSource, staxEventResult, streamTemplateTransformer },
+ { saxSource, staxEventResult, streamTemplateTransformer },
+ { streamSource, staxEventResult, streamTemplateTransformer } };
+ }
+
+ /*
+ * run Transformer.transform(Source, Result)
+ */
+ @Test(dataProvider = "input-provider")
+ public void testTransform(Supplier<Source> src, Supplier<Result> res, Transformer transformer) throws Throwable {
+ try {
+ transformer.transform(src.get(), res.get());
+ } catch (WrapperException e) {
+ throw e.getCause();
+ }
+ }
+
+ private InputStream xmlInputStream() {
+ return new ByteArrayInputStream(xml);
+ }
+
+ private InputStream templateInputStream() {
+ return new ByteArrayInputStream(template);
+ }
+
+ private OutputStream transOutputStream() {
+ return new ByteArrayOutputStream(xml.length);
+ }
+
+ private XMLStreamReader getXMLStreamReader() {
+ try {
+ return ifac.createXMLStreamReader(xmlInputStream());
+ } catch (XMLStreamException e) {
+ throw new WrapperException(e);
+ }
+ }
+
+ private XMLStreamWriter getXMLStreamWriter() {
+ try {
+ return ofac.createXMLStreamWriter(transOutputStream());
+ } catch (XMLStreamException e) {
+ throw new WrapperException(e);
+ }
+ }
+
+ private StAXSource getStAXEventSource() {
+ try {
+ return new StAXSource(ifac.createXMLEventReader(xmlInputStream()));
+ } catch (XMLStreamException e) {
+ throw new WrapperException(e);
+ }
+ }
+
+ private XMLEventWriter getXMLEventWriter() {
+ try {
+ return ofac.createXMLEventWriter(transOutputStream());
+ } catch (XMLStreamException e) {
+ throw new WrapperException(e);
+ }
+ }
+
+ private SAXResult getHandlerSAXResult() {
+ SAXResult res = new SAXResult();
+ MyContentHandler myContentHandler = new MyContentHandler(transOutputStream());
+ res.setHandler(myContentHandler);
+ return res;
+ }
+
+ private Source getDomTemplate() throws SAXException, IOException {
+ return new DOMSource(db.parse(templateInputStream()));
+ }
+
+ private Source getSAXTemplate() {
+ return new SAXSource(new InputSource(templateInputStream()));
+ }
+
+ private Source getStreamTemplate() {
+ return new StreamSource(templateInputStream());
+ }
+
+ private Source getStAXStreamTemplate() throws XMLStreamException {
+ return new StAXSource(ifac.createXMLStreamReader(templateInputStream()));
+ }
+
+ private Source getStAXEventTemplate() throws XMLStreamException {
+ return new StAXSource(ifac.createXMLEventReader(templateInputStream()));
+ }
+
+ private Transformer createTransformer(Source templateSource) throws TransformerConfigurationException {
+ Transformer transformer = (templateSource == null) ? tfac.newTransformer() : tfac.newTransformer(templateSource);
+ transformer.setOutputProperty("indent", "yes");
+ return transformer;
+
+ }
+
+ private static class MyContentHandler implements ContentHandler {
+ private BufferedWriter bWriter;
+
+ public MyContentHandler(OutputStream os) {
+ bWriter = new BufferedWriter(new OutputStreamWriter(os));
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ }
+
+ public void startDocument() throws SAXException {
+ String str = "startDocument";
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+
+ public void endDocument() throws SAXException {
+ String str = "endDocument";
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ bWriter.flush();
+ bWriter.close();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ String str = "startPrefixMapping: " + prefix + ", " + uri;
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ String str = "endPrefixMapping: " + prefix;
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+
+ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
+ StringBuilder str = new StringBuilder("startElement: ").append(namespaceURI).append(", ").append(namespaceURI).append(", ").append(qName).append(" : ");
+ int n = atts.getLength();
+ for (int i = 0; i < n; i++) {
+ str.append(", ").append(atts.getQName(i)).append(" : ").append(atts.getValue(i));
+ }
+
+ try {
+ bWriter.write(str.toString(), 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+
+ public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
+ String str = "endElement: " + namespaceURI + ", " + namespaceURI + ", " + qName;
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+
+ }
+
+ public void characters(char ch[], int start, int length) throws SAXException {
+ String str = new String(ch, start, length);
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+
+ public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
+ String str = "ignorableWhitespace";
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+
+ public void processingInstruction(String target, String data) throws SAXException {
+ String str = "processingInstruction: " + target + ", " + target;
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+
+ public void skippedEntity(String name) throws SAXException {
+ String str = "skippedEntity: " + name;
+ try {
+ bWriter.write(str, 0, str.length());
+ bWriter.newLine();
+ } catch (IOException e) {
+ System.out.println("bWriter error");
+ }
+ }
+ }
+
+ private static class WrapperException extends RuntimeException {
+ public WrapperException(Throwable cause) {
+ super(cause);
+ }
+ }
+
+ private XMLInputFactory ifac;
+ private XMLOutputFactory ofac;
+ private TransformerFactory tfac;
+ private DocumentBuilder db;
+ private byte[] xml;
+ private byte[] template;
+ private Document xmlDoc;
+
+}
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java Thu Feb 05 11:43:32 2015 -0800
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerFactoryTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -23,26 +23,79 @@
package javax.xml.transform.ptests;
import java.io.*;
-import java.io.FileOutputStream;
+
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
+
import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR;
import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
+
import javax.xml.transform.stream.*;
+
+import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPFileBaseTest;
import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.compareWithGold;
+import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.*;
/**
* Class containing the test cases for TransformerFactory API's
- * getAssociatedStyleSheet method.
+ * getAssociatedStyleSheet method and TransformerFactory.newInstance(factoryClassName , classLoader).
*/
public class TransformerFactoryTest extends JAXPFileBaseTest {
/**
+ * TransformerFactory implementation class name.
+ */
+ private static final String TRANSFORMER_FACTORY_CLASSNAME = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
+
+ /**
+ * Provide valid TransformerFactory instantiation parameters.
+ *
+ * @return a data provider contains TransformerFactory instantiation parameters.
+ */
+ @DataProvider(name = "parameters")
+ public Object[][] getValidateParameters() {
+ return new Object[][] { { TRANSFORMER_FACTORY_CLASSNAME, null }, { TRANSFORMER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
+ }
+
+ /**
+ * Test for TransformerFactory.newInstance(java.lang.String
+ * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
+ * points to correct implementation of
+ * javax.xml.transform.TransformerFactory , should return newInstance of
+ * TransformerFactory
+ *
+ * @param factoryClassName
+ * @param classLoader
+ * @throws TransformerConfigurationException
+ */
+ @Test(dataProvider = "parameters")
+ public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws TransformerConfigurationException {
+ TransformerFactory tf = TransformerFactory.newInstance(factoryClassName, classLoader);
+ Transformer transformer = tf.newTransformer();
+ assertNotNull(transformer);
+ }
+
+ /**
+ * Test for TransformerFactory.newInstance(java.lang.String
+ * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is
+ * null , should throw TransformerFactoryConfigurationError
+ *
+ * @param factoryClassName
+ * @param classLoader
+ */
+ @Test(expectedExceptions = TransformerFactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+ public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
+ TransformerFactory.newInstance(factoryClassName, classLoader);
+ }
+
+ /**
* This test case checks for the getAssociatedStylesheet method
* of TransformerFactory.
* The style sheet returned is then copied to an tfactory01.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/dataentry.xsl Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:template match="dataentry">
+ <table cellspacing="0" cellpadding="0" width="85%" align="center"
+class="color1" border="0">
+ <xsl:apply-templates/>
+ </table>
+
+ </xsl:template>
+ <xsl:template match="list">
+ <xsl:value-of select="self::node()[@multi='false']"/>
+
+ <!--
+ <xsl:if test="self::node()[@multi='false']">
+ <xsl:if test="self::node()">
+ FALSE<br/>
+ </xsl:if>
+ -->
+ </xsl:template>
+</xsl:stylesheet>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/transform/xmlfiles/test.xml Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,8 @@
+<appcapp>
+<dataentry>
+<list multi="false">
+ <name>TypeOfLifeApp</name>
+</list>
+</dataentry>
+</appcapp>
+
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/validation/ptests/SchemaFactoryTest.java Thu Feb 05 11:43:32 2015 -0800
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/validation/ptests/SchemaFactoryTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -46,6 +46,8 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
+import jaxp.library.JAXPDataProvider;
+
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -81,6 +83,59 @@
xml = Files.readAllBytes(Paths.get(XML_DIR + "test.xml"));
}
+
+ @DataProvider(name = "parameters")
+ public Object[][] getValidateParameters() {
+ return new Object[][] { { W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, null },
+ { W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
+ }
+
+ /*
+ * test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
+ * java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
+ * factoryClassName points to correct implementation of
+ * javax.xml.validation.SchemaFactory , should return newInstance of
+ * SchemaFactory
+ */
+ @Test(dataProvider = "parameters")
+ public void testNewInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader) throws SAXException {
+ SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, null);
+ Schema schema = sf.newSchema();
+ assertNotNull(schema);
+ }
+
+ /*
+ * test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
+ * java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
+ * factoryClassName is null , should throw IllegalArgumentException
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+ public void testNewInstanceWithNullFactoryClassName(String factoryClassName, ClassLoader classLoader) {
+
+ SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI, factoryClassName, classLoader);
+ }
+
+ /*
+ * test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
+ * java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
+ * schemaLanguage is null , should throw NPE
+ */
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testNewInstanceWithNullSchemaLanguage() {
+ SchemaFactory.newInstance(null, SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader());
+ }
+
+ /*
+ * test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
+ * java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
+ * schemaLanguage is empty , should throw IllegalArgumentException
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNewInstanceWithEmptySchemaLanguage() {
+ SchemaFactory.newInstance("", SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader());
+ }
+
+
@Test(expectedExceptions = SAXParseException.class)
public void testNewSchemaDefault() throws SAXException, IOException {
validate(sf.newSchema());
@@ -288,6 +343,8 @@
private static final String UNRECOGNIZED_NAME = "http://xml.org/sax/features/namespace-prefixes";
+ private static final String SCHEMA_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory";
+
private SchemaFactory sf;
private byte[] xsd1;
private byte[] xsd2;
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathFactoryTest.java Thu Feb 05 11:43:32 2015 -0800
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathFactoryTest.java Thu Feb 05 15:45:17 2015 -0800
@@ -24,10 +24,16 @@
package javax.xml.xpath.ptests;
import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL;
+
+import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
+
+import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPBaseTest;
-import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.Assert.assertNotNull;
+
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
@@ -45,6 +51,78 @@
private static final String INVALID_URL = "http://java.sun.com/jaxp/xpath/dom1";
/**
+ * XPathFactory implementation class name.
+ */
+ private static final String XPATH_FACTORY_CLASSNAME = "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl";
+
+
+ /**
+ * Provide valid XPathFactory instantiation parameters.
+ *
+ * @return a data provider contains XPathFactory instantiation parameters.
+ */
+ @DataProvider(name = "parameters")
+ public Object[][] getValidateParameters() {
+ return new Object[][] { { VALID_URL, XPATH_FACTORY_CLASSNAME, null }, { VALID_URL, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
+ }
+
+ /**
+ * Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
+ * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
+ * points to correct implementation of javax.xml.xpath.XPathFactory , should
+ * return newInstance of XPathFactory
+ *
+ * @param uri
+ * @param factoryClassName
+ * @param classLoader
+ * @throws XPathFactoryConfigurationException
+ */
+ @Test(dataProvider = "parameters")
+ public void testNewInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
+ XPathFactory xpf = XPathFactory.newInstance(uri, factoryClassName, classLoader);
+ XPath xpath = xpf.newXPath();
+ assertNotNull(xpath);
+ }
+
+ /**
+ * Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
+ * factoryClassName, java.lang.ClassLoader classLoader)
+ *
+ * @param factoryClassName
+ * @param classLoader
+ * @throws XPathFactoryConfigurationException
+ * is expected when factoryClassName is null
+ */
+ @Test(expectedExceptions = XPathFactoryConfigurationException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
+ public void testNewInstanceWithNullFactoryClassName(String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
+ XPathFactory.newInstance(VALID_URL, factoryClassName, classLoader);
+ }
+
+ /**
+ * Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
+ * factoryClassName, java.lang.ClassLoader classLoader) uri is null , should
+ * throw NPE
+ *
+ * @throws XPathFactoryConfigurationException
+ */
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testNewInstanceWithNullUri() throws XPathFactoryConfigurationException {
+ XPathFactory.newInstance(null, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader());
+ }
+
+ /**
+ * Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
+ * factoryClassName, java.lang.ClassLoader classLoader)
+ *
+ * @throws IllegalArgumentException
+ * is expected when uri is empty
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNewInstanceWithEmptyUri() throws XPathFactoryConfigurationException {
+ XPathFactory.newInstance("", XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader());
+ }
+
+ /**
* Test for constructor - XPathFactory.newInstance().
*/
@Test
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/libs/jaxp/library/JAXPDataProvider.java Thu Feb 05 15:45:17 2015 -0800
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jaxp.library;
+
+import org.testng.annotations.DataProvider;
+
+/**
+ * Provide invalid parameters for negative testing Factory.newInstance.
+ */
+public class JAXPDataProvider {
+
+ @DataProvider(name = "new-instance-neg")
+ public static Object[][] getNewInstanceNeg() {
+ return new Object[][] { { null, null }, { null, JAXPDataProvider.class.getClassLoader() } };
+ }
+
+}