< prev index next >

test/javax/xml/jaxp/functional/test/auctionportal/AuctionController.java

Print this page

        

*** 28,37 **** --- 28,38 ---- import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import java.io.File; import java.io.FileInputStream; + import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; import java.nio.file.Paths; import java.util.GregorianCalendar;
*** 49,60 **** import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import static jaxp.library.JAXPTestUtilities.bomStream; ! import static jaxp.library.JAXPTestUtilities.failUnexpected; import org.testng.annotations.Test; import org.w3c.dom.Attr; import org.w3c.dom.DOMConfiguration; import org.w3c.dom.Document; import org.w3c.dom.Element; --- 50,63 ---- import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; + import jaxp.library.JAXPBaseTest; import static jaxp.library.JAXPTestUtilities.bomStream; ! import org.testng.annotations.AfterGroups; ! import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import org.w3c.dom.Attr; import org.w3c.dom.DOMConfiguration; import org.w3c.dom.Document; import org.w3c.dom.Element;
*** 68,87 **** import static test.auctionportal.HiBidConstants.XML_DIR; /** * This is the user controller class for the Auction portal HiBid.com. */ ! public class AuctionController { /** * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927 * DOMConfiguration.setParameter("well-formed",true) throws an exception. ! */ ! @Test ! public void testCreateNewItem2Sell() { String xmlFile = XML_DIR + "novelsInvalid.xml"; - try { Document document = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(xmlFile); document.getDomConfig().setParameter("well-formed", true); --- 71,119 ---- import static test.auctionportal.HiBidConstants.XML_DIR; /** * This is the user controller class for the Auction portal HiBid.com. */ ! public class AuctionController extends JAXPBaseTest { ! /** ! * Save system property for restoring. ! */ ! @BeforeGroups (groups = {"readLocalFiles"}) ! public void setFilePermissions() { ! setPermissions(new FilePermission(XML_DIR + "/-", "read")); ! } ! ! /** ! * Restore the system property. ! */ ! @AfterGroups (groups = {"readLocalFiles"}) ! public void restoreFilePermissions() { ! setPermissions(); ! } ! /** * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927 * DOMConfiguration.setParameter("well-formed",true) throws an exception. ! * ! * @throws ClassNotFoundException If any specified class does not implement. ! * @throws ParserConfigurationException if a DocumentBuilder cannot be ! * created which satisfies the configuration requested. ! * @throws InstantiationException If any specified class is an interface or ! * abstract class. ! * @throws IllegalAccessException If the default constructor of a specified ! * class is not accessible. ! * @throws SAXException If any parse errors occur. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCreateNewItem2Sell() throws ClassNotFoundException, ! ParserConfigurationException, InstantiationException, ! IllegalAccessException, SAXException, IOException { String xmlFile = XML_DIR + "novelsInvalid.xml"; Document document = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(xmlFile); document.getDomConfig().setParameter("well-formed", true);
*** 89,114 **** DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); MyDOMOutput domOutput = new MyDOMOutput(); domOutput.setByteStream(System.out); LSSerializer writer = impl.createLSSerializer(); writer.write(document, domOutput); - } catch (ParserConfigurationException | SAXException | IOException - | ClassNotFoundException | InstantiationException - | IllegalAccessException | ClassCastException e) { - failUnexpected(e); - } } /** * Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132 * test throws DOM Level 1 node error. ! */ ! @Test ! public void testCreateNewItem2SellRetry() { String xmlFile = XML_DIR + "accountInfo.xml"; - try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(xmlFile); DOMConfiguration domConfig = document.getDomConfig(); --- 121,154 ---- DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); MyDOMOutput domOutput = new MyDOMOutput(); domOutput.setByteStream(System.out); LSSerializer writer = impl.createLSSerializer(); writer.write(document, domOutput); } /** * Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132 * test throws DOM Level 1 node error. ! * ! * @throws ClassNotFoundException If any specified class does not implement. ! * @throws ParserConfigurationException if a DocumentBuilder cannot be ! * created which satisfies the configuration requested. ! * @throws InstantiationException If any specified class is an interface or ! * abstract class. ! * @throws IllegalAccessException If the default constructor of a specified ! * class is not accessible. ! * @throws SAXException If any parse errors occur. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCreateNewItem2SellRetry() throws ClassNotFoundException, ! ParserConfigurationException, InstantiationException, ! IllegalAccessException, SAXException, IOException { String xmlFile = XML_DIR + "accountInfo.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(xmlFile); DOMConfiguration domConfig = document.getDomConfig();
*** 125,173 **** writer.write(document, domoutput); document.normalizeDocument(); writer.write(document, domoutput); assertFalse(errHandler.isError()); - } catch (ParserConfigurationException | SAXException | IOException - | ClassNotFoundException | InstantiationException - | IllegalAccessException | ClassCastException e) { - failUnexpected(e); - } } /** * Check if setting the attribute to be of type ID works. This will affect * the Attr.isID method according to the spec. ! */ ! @Test ! public void testCreateID() { String xmlFile = XML_DIR + "accountInfo.xml"; - try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(xmlFile); Element account = (Element)document .getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Account").item(0); account.setIdAttributeNS(PORTAL_ACCOUNT_NS, "accountID", true); Attr aID = account.getAttributeNodeNS(PORTAL_ACCOUNT_NS, "accountID"); assertTrue(aID.isId()); - } catch (ParserConfigurationException | SAXException | IOException e) { - failUnexpected(e); - } } /** * Check the user data on the node. ! */ ! @Test ! public void testCheckingUserData() { String xmlFile = XML_DIR + "accountInfo.xml"; - try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); Document document = docBuilder.parse(xmlFile); --- 165,219 ---- writer.write(document, domoutput); document.normalizeDocument(); writer.write(document, domoutput); assertFalse(errHandler.isError()); } /** * Check if setting the attribute to be of type ID works. This will affect * the Attr.isID method according to the spec. ! * ! * @throws ParserConfigurationException if a DocumentBuilder cannot be ! * created which satisfies the configuration requested. ! * @throws SAXException If any parse errors occur. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCreateID() throws ParserConfigurationException, ! SAXException, IOException { String xmlFile = XML_DIR + "accountInfo.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(xmlFile); Element account = (Element)document .getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Account").item(0); account.setIdAttributeNS(PORTAL_ACCOUNT_NS, "accountID", true); Attr aID = account.getAttributeNodeNS(PORTAL_ACCOUNT_NS, "accountID"); assertTrue(aID.isId()); } /** * Check the user data on the node. ! * ! * @throws ParserConfigurationException if a DocumentBuilder cannot be ! * created which satisfies the configuration requested. ! * @throws SAXException If any parse errors occur. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCheckingUserData() throws ParserConfigurationException, ! SAXException, IOException { String xmlFile = XML_DIR + "accountInfo.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); Document document = docBuilder.parse(xmlFile);
*** 188,237 **** Element impAccount = (Element)document.importNode(someName, true); assertEquals(impAccount.getNodeName(), "newelem"); document.normalizeDocument(); String data = (someName.getUserData("mykey")).toString(); assertEquals(data, "dd"); - } catch (ParserConfigurationException | SAXException | IOException e) { - failUnexpected(e); - } } /** * Check the UTF-16 XMLEncoding xml file. * @see <a href="content/movies.xml">movies.xml</a> */ ! @Test ! public void testCheckingEncoding() { // Note since movies.xml is UTF-16 encoding. We're not using stanard XML // file suffix. String xmlFile = XML_DIR + "movies.xml.data"; ! //try (FileInputStream is = new FileInputStream(xmlFile)) { ! try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); - InputStream source = bomStream("UTF-16", xmlFile); Document document = dbf.newDocumentBuilder().parse(source); assertEquals(document.getXmlEncoding(), "UTF-16"); assertEquals(document.getXmlStandalone(), true); - } catch (ParserConfigurationException | SAXException | IOException e) { - failUnexpected(e); } } /** * Check validation API features. A schema which is including in Bug 4909119 * used to be testing for the functionalities. * @see <a href="content/userDetails.xsd">userDetails.xsd</a> */ ! @Test ! public void testGetOwnerInfo() { String schemaFile = XML_DIR + "userDetails.xsd"; String xmlFile = XML_DIR + "userDetails.xml"; ! try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); --- 234,292 ---- Element impAccount = (Element)document.importNode(someName, true); assertEquals(impAccount.getNodeName(), "newelem"); document.normalizeDocument(); String data = (someName.getUserData("mykey")).toString(); assertEquals(data, "dd"); } /** * Check the UTF-16 XMLEncoding xml file. + * + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. + * @throws SAXException If any parse errors occur. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. * @see <a href="content/movies.xml">movies.xml</a> */ ! @Test(groups = {"readLocalFiles"}) ! public void testCheckingEncoding() throws ParserConfigurationException, ! IOException, SAXException { // Note since movies.xml is UTF-16 encoding. We're not using stanard XML // file suffix. String xmlFile = XML_DIR + "movies.xml.data"; ! try (InputStream source = bomStream("UTF-16", xmlFile)) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(source); assertEquals(document.getXmlEncoding(), "UTF-16"); assertEquals(document.getXmlStandalone(), true); } } /** * Check validation API features. A schema which is including in Bug 4909119 * used to be testing for the functionalities. + * + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. + * @throws SAXException If any parse errors occur. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. * @see <a href="content/userDetails.xsd">userDetails.xsd</a> */ ! @Test(groups = {"readLocalFiles"}) ! public void testGetOwnerInfo() throws ParserConfigurationException, ! SAXException, IOException { String schemaFile = XML_DIR + "userDetails.xsd"; String xmlFile = XML_DIR + "userDetails.xml"; ! try(FileInputStream fis = new FileInputStream(xmlFile)) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
*** 242,272 **** validator.setErrorHandler(eh); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); docBuilder.setErrorHandler(eh); ! Document document = docBuilder.parse(new FileInputStream(xmlFile)); DOMResult dResult = new DOMResult(); DOMSource domSource = new DOMSource(document); validator.validate(domSource, dResult); assertFalse(eh.isAnyError()); - } catch (SAXException | ParserConfigurationException | IOException e) { - failUnexpected(e); } } /** * Check grammar caching with imported schemas. * @see <a href="content/coins.xsd">coins.xsd</a> * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a> */ ! @Test ! public void testGetOwnerItemList() { String xsdFile = XML_DIR + "coins.xsd"; String xmlFile = XML_DIR + "coins.xml"; ! try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); dbf.setValidating(false); --- 297,333 ---- validator.setErrorHandler(eh); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); docBuilder.setErrorHandler(eh); ! Document document = docBuilder.parse(fis); DOMResult dResult = new DOMResult(); DOMSource domSource = new DOMSource(document); validator.validate(domSource, dResult); assertFalse(eh.isAnyError()); } } /** * Check grammar caching with imported schemas. + * + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. + * @throws SAXException If any parse errors occur. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. * @see <a href="content/coins.xsd">coins.xsd</a> * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a> */ ! @Test(groups = {"readLocalFiles"}) ! public void testGetOwnerItemList() throws ParserConfigurationException, ! IOException, SAXException { String xsdFile = XML_DIR + "coins.xsd"; String xmlFile = XML_DIR + "coins.xml"; ! try(FileInputStream fis = new FileInputStream(xmlFile)) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); dbf.setValidating(false);
*** 276,308 **** MyErrorHandler eh = new MyErrorHandler(); Validator validator = schema.newValidator(); validator.setErrorHandler(eh); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); ! Document document = docBuilder.parse(new FileInputStream(xmlFile)); validator.validate(new DOMSource(document), new DOMResult()); assertFalse(eh.isAnyError()); - } catch (SAXException | ParserConfigurationException | IOException e) { - failUnexpected(e); } } /** * Check for the same imported schemas but will use SAXParserFactory and try * parsing using the SAXParser. SCHEMA_SOURCE attribute is using for this * test. * @see <a href="content/coins.xsd">coins.xsd</a> * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a> */ ! @Test ! public void testGetOwnerItemList1() { String xsdFile = XML_DIR + "coins.xsd"; String xmlFile = XML_DIR + "coins.xml"; - - try { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setValidating(true); SAXParser sp = spf.newSAXParser(); --- 337,373 ---- MyErrorHandler eh = new MyErrorHandler(); Validator validator = schema.newValidator(); validator.setErrorHandler(eh); DocumentBuilder docBuilder = dbf.newDocumentBuilder(); ! Document document = docBuilder.parse(fis); validator.validate(new DOMSource(document), new DOMResult()); assertFalse(eh.isAnyError()); } } /** * Check for the same imported schemas but will use SAXParserFactory and try * parsing using the SAXParser. SCHEMA_SOURCE attribute is using for this * test. + * + * @throws SAXException If any parse errors occur. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. * @see <a href="content/coins.xsd">coins.xsd</a> * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a> */ ! @Test(groups = {"readLocalFiles"}) ! public void testGetOwnerItemList1() throws SAXException, IOException, ! ParserConfigurationException { String xsdFile = XML_DIR + "coins.xsd"; String xmlFile = XML_DIR + "coins.xml"; SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setValidating(true); SAXParser sp = spf.newSAXParser();
*** 310,332 **** sp.setProperty(JAXP_SCHEMA_SOURCE, xsdFile); MyErrorHandler eh = new MyErrorHandler(); sp.parse(new File(xmlFile), eh); assertFalse(eh.isAnyError()); - } catch (ParserConfigurationException | SAXException | IOException e) { - failUnexpected(e); - } } /** * Check usage of javax.xml.datatype.Duration class. ! */ ! @Test ! public void testGetItemDuration() { String xmlFile = XML_DIR + "itemsDuration.xml"; - try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(xmlFile); Element durationElement = (Element) document.getElementsByTagName("sellDuration").item(0); --- 375,403 ---- sp.setProperty(JAXP_SCHEMA_SOURCE, xsdFile); MyErrorHandler eh = new MyErrorHandler(); sp.parse(new File(xmlFile), eh); assertFalse(eh.isAnyError()); } /** * Check usage of javax.xml.datatype.Duration class. ! * ! * @throws SAXException If any parse errors occur. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! * @throws ParserConfigurationException if a DocumentBuilder cannot be ! * created which satisfies the configuration requested. ! * @throws DatatypeConfigurationException If the implementation is not ! * available or cannot be instantiated. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testGetItemDuration() throws ParserConfigurationException, ! SAXException, DatatypeConfigurationException, IOException { String xmlFile = XML_DIR + "itemsDuration.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(xmlFile); Element durationElement = (Element) document.getElementsByTagName("sellDuration").item(0);
*** 345,368 **** assertEquals(sellDuration.normalizeWith(new GregorianCalendar(1999, 2, 22)), duration); Duration myDuration = sellDuration.add(duration); assertEquals(myDuration.normalizeWith(new GregorianCalendar(2003, 2, 22)), DatatypeFactory.newInstance().newDuration("P730D")); - } catch (ParserConfigurationException | DatatypeConfigurationException - | SAXException | IOException e) { - failUnexpected(e); - } } /** * Check usage of TypeInfo interface introduced in DOM L3. ! */ ! @Test ! public void testGetTypeInfo() { String xmlFile = XML_DIR + "accountInfo.xml"; - try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); --- 416,442 ---- assertEquals(sellDuration.normalizeWith(new GregorianCalendar(1999, 2, 22)), duration); Duration myDuration = sellDuration.add(duration); assertEquals(myDuration.normalizeWith(new GregorianCalendar(2003, 2, 22)), DatatypeFactory.newInstance().newDuration("P730D")); } /** * Check usage of TypeInfo interface introduced in DOM L3. ! * ! * @throws ParserConfigurationException if a DocumentBuilder cannot be ! * created which satisfies the configuration requested. ! * @throws SAXException If any parse errors occur. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testGetTypeInfo() throws ParserConfigurationException, ! SAXException, IOException { String xmlFile = XML_DIR + "accountInfo.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
*** 377,386 **** Element role = (Element)document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Role").item(0); TypeInfo roletypeInfo = role.getSchemaTypeInfo(); assertTrue(roletypeInfo.getTypeName().equals("BuyOrSell")); assertTrue(roletypeInfo.getTypeNamespace().equals(PORTAL_ACCOUNT_NS)); - } catch (ParserConfigurationException | SAXException | IOException e) { - failUnexpected(e); - } } } --- 451,457 ----
< prev index next >