test/jaxp/javax/xml/jaxp/unittest/validation/ValidationTest.java
changeset 55688 0e1bc587472c
parent 54672 a43d6467317d
child 57545 550a1a6ca596
equal deleted inserted replaced
55687:065142ace8e9 55688:0e1bc587472c
    34 import javax.xml.validation.Validator;
    34 import javax.xml.validation.Validator;
    35 import org.testng.annotations.DataProvider;
    35 import org.testng.annotations.DataProvider;
    36 
    36 
    37 import org.testng.annotations.Listeners;
    37 import org.testng.annotations.Listeners;
    38 import org.testng.annotations.Test;
    38 import org.testng.annotations.Test;
       
    39 import org.xml.sax.SAXException;
    39 import org.xml.sax.SAXParseException;
    40 import org.xml.sax.SAXParseException;
    40 
    41 
    41 /*
    42 /*
    42  * @test
    43  * @test
    43  * @bug 8220818
    44  * @bug 8220818 8176447
    44  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
    45  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
    45  * @run testng/othervm validation.ValidationTest
    46  * @run testng/othervm validation.ValidationTest
    46  * @summary Runs validations with schemas and sources
    47  * @summary Runs validations with schemas and sources
    47  */
    48  */
    48 @Listeners({jaxp.library.FilePolicy.class})
    49 @Listeners({jaxp.library.FilePolicy.class})
    69             {"JDK8220818a.xsd", "JDK8220818a_Invalid.xml"},
    70             {"JDK8220818a.xsd", "JDK8220818a_Invalid.xml"},
    70             {"JDK8220818b.xsd", "JDK8220818b_Invalid.xml"},
    71             {"JDK8220818b.xsd", "JDK8220818b_Invalid.xml"},
    71         };
    72         };
    72     }
    73     }
    73 
    74 
       
    75     /*
       
    76      DataProvider: uniqueness
       
    77      */
       
    78     @DataProvider(name = "uniqueness")
       
    79     Object[][] getUniqueData() {
       
    80         return new Object[][]{
       
    81             {"JDK8176447a.xsd", "JDK8176447a.xml"},
       
    82             {"JDK8176447b.xsd", "JDK8176447b.xml"},
       
    83         };
       
    84     }
       
    85 
    74     @Test(dataProvider = "invalid", expectedExceptions = SAXParseException.class)
    86     @Test(dataProvider = "invalid", expectedExceptions = SAXParseException.class)
    75     public void testValidateRefType(String xsd, String xml) throws Exception {
    87     public void testValidateRefType(String xsd, String xml) throws Exception {
    76         validate(xsd, xml);
    88         validate(xsd, xml);
    77     }
    89     }
    78 
    90 
    79     @Test(dataProvider = "valid")
    91     @Test(dataProvider = "valid")
    80     public void testValidateRefType1(String xsd, String xml) throws Exception {
    92     public void testValidateRefType1(String xsd, String xml) throws Exception {
       
    93         validate(xsd, xml);
       
    94     }
       
    95 
       
    96     /**
       
    97      * @bug 8176447
       
    98      * Verifies that the uniqueness constraint is checked.
       
    99      * @param xsd the XSD
       
   100      * @param xml the XML
       
   101      * @throws Exception expected when the uniqueness constraint is validated
       
   102      * correctly.
       
   103      */
       
   104     @Test(dataProvider = "uniqueness", expectedExceptions = SAXException.class)
       
   105     public void testUnique(String xsd, String xml) throws Exception {
    81         validate(xsd, xml);
   106         validate(xsd, xml);
    82     }
   107     }
    83 
   108 
    84     private void validate(String xsd, String xml) throws Exception {
   109     private void validate(String xsd, String xml) throws Exception {
    85         final SchemaFactory schemaFactory = SchemaFactory.newInstance(
   110         final SchemaFactory schemaFactory = SchemaFactory.newInstance(
    88                 new File(getClass().getResource(FILE_PATH + xsd).getFile()));
   113                 new File(getClass().getResource(FILE_PATH + xsd).getFile()));
    89         final Validator validator = schema.newValidator();
   114         final Validator validator = schema.newValidator();
    90         validator.validate(new StreamSource(
   115         validator.validate(new StreamSource(
    91                 new File(getClass().getResource(FILE_PATH + xml).getFile())));
   116                 new File(getClass().getResource(FILE_PATH + xml).getFile())));
    92     }
   117     }
       
   118 
    93 }
   119 }