< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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.

@@ -25,63 +25,58 @@
 import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_LANGUAGE;
 import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_SOURCE;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
-
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigInteger;
 import java.nio.file.Paths;
 import java.util.GregorianCalendar;
 import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
-
-import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeConstants;
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.Duration;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 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.JAXPFileReadOnlyBaseTest;
 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;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.TypeInfo;
 import org.w3c.dom.bootstrap.DOMImplementationRegistry;
 import org.w3c.dom.ls.DOMImplementationLS;
 import org.w3c.dom.ls.LSSerializer;
-import org.xml.sax.SAXException;
 import static test.auctionportal.HiBidConstants.PORTAL_ACCOUNT_NS;
 import static test.auctionportal.HiBidConstants.XML_DIR;
 
 /**
  * This is the user controller  class for the Auction portal HiBid.com.
  */
-public class AuctionController {
+public class AuctionController extends JAXPFileReadOnlyBaseTest {
     /**
      * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927
      * DOMConfiguration.setParameter("well-formed",true) throws an exception.
+     * 
+     * @throws Exception If any errors occur.
      */
-    @Test
-    public void testCreateNewItem2Sell() {
+    @Test(groups = {"readLocalFiles"})
+    public void testCreateNewItem2Sell() throws Exception {
         String xmlFile = XML_DIR + "novelsInvalid.xml";
 
-        try {
             Document document = DocumentBuilderFactory.newInstance()
                     .newDocumentBuilder().parse(xmlFile);
 
             document.getDomConfig().setParameter("well-formed", true);
 

@@ -89,26 +84,22 @@
             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.
+     * 
+     * @throws Exception If any errors occur.
      */
-    @Test
-    public void testCreateNewItem2SellRetry() {
+    @Test(groups = {"readLocalFiles"})
+    public void testCreateNewItem2SellRetry() throws Exception  {
         String xmlFile = XML_DIR + "accountInfo.xml";
 
-        try {
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             dbf.setNamespaceAware(true);
             Document document = dbf.newDocumentBuilder().parse(xmlFile);
 
             DOMConfiguration domConfig = document.getDomConfig();

@@ -125,49 +116,43 @@
             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.
+     * 
+     * @throws Exception If any errors occur.
      */
-    @Test
-    public void testCreateID() {
+    @Test(groups = {"readLocalFiles"})
+    public void testCreateID() throws Exception {
         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.
+     * 
+     * @throws Exception If any errors occur.
      */
-    @Test
-    public void testCheckingUserData() {
+    @Test(groups = {"readLocalFiles"})
+    public void testCheckingUserData() throws Exception {
         String xmlFile = XML_DIR + "accountInfo.xml";
 
-        try {
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             dbf.setNamespaceAware(true);
 
             DocumentBuilder docBuilder = dbf.newDocumentBuilder();
             Document document = docBuilder.parse(xmlFile);

@@ -188,50 +173,47 @@
             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.
+     * 
+     * @throws Exception If any errors occur.
      * @see <a href="content/movies.xml">movies.xml</a>
      */
-    @Test
-    public void testCheckingEncoding() {
+    @Test(groups = {"readLocalFiles"})
+    public void testCheckingEncoding() throws Exception {
         // 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 {
+        try (InputStream source = bomStream("UTF-16", xmlFile)) {
             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.
+     * 
+     * @throws Exception If any errors occur.
      * @see <a href="content/userDetails.xsd">userDetails.xsd</a>
      */
-    @Test
-    public void testGetOwnerInfo() {
+    @Test(groups = {"readLocalFiles"})
+    public void testGetOwnerInfo() throws Exception {
         String schemaFile = XML_DIR + "userDetails.xsd";
         String xmlFile = XML_DIR + "userDetails.xml";
 
-        try {
+        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,31 +224,31 @@
             validator.setErrorHandler(eh);
 
             DocumentBuilder docBuilder = dbf.newDocumentBuilder();
             docBuilder.setErrorHandler(eh);
 
-            Document document = docBuilder.parse(new FileInputStream(xmlFile));
+            Document document = docBuilder.parse(fis);
             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.
+     * 
+     * @throws Exception If any errors occur.
      * @see <a href="content/coins.xsd">coins.xsd</a>
      * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a>
      */
-    @Test
-    public void testGetOwnerItemList() {
+    @Test(groups = {"readLocalFiles"})
+    public void testGetOwnerItemList() throws Exception {
         String xsdFile = XML_DIR + "coins.xsd";
         String xmlFile = XML_DIR + "coins.xml";
 
-        try {
+        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,33 +258,31 @@
             MyErrorHandler eh = new MyErrorHandler();
             Validator validator = schema.newValidator();
             validator.setErrorHandler(eh);
 
             DocumentBuilder docBuilder = dbf.newDocumentBuilder();
-            Document document = docBuilder.parse(new FileInputStream(xmlFile));
+            Document document = docBuilder.parse(fis);
             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.
+     * 
+     * @throws Exception If any errors occur.
      * @see <a href="content/coins.xsd">coins.xsd</a>
      * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a>
      */
 
-    @Test
-    public void testGetOwnerItemList1() {
+    @Test(groups = {"readLocalFiles"})
+    public void testGetOwnerItemList1() throws Exception {
         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();

@@ -310,23 +290,21 @@
             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.
+     * 
+     * @throws Exception If any errors occur.
      */
-    @Test
-    public void testGetItemDuration() {
+    @Test(groups = {"readLocalFiles"})
+    public void testGetItemDuration() throws Exception {
         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);

@@ -345,24 +323,21 @@
             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.
+     * 
+     * @throws Exception If any errors occur.
      */
-    @Test
-    public void testGetTypeInfo() {
+    @Test(groups = {"readLocalFiles"})
+    public void testGetTypeInfo() throws Exception {
         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);
 

@@ -377,10 +352,7 @@
 
             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);
-        }
     }
 }
< prev index next >