Home | History | Annotate | Download | only in xml
      1 package org.testng.xml;
      2 
      3 import org.testng.Assert;
      4 import org.testng.annotations.DataProvider;
      5 import org.testng.annotations.Test;
      6 
      7 import java.io.File;
      8 import java.io.FileInputStream;
      9 
     10 import static test.SimpleBaseTest.getPathToResource;
     11 
     12 public class SuiteXmlParserTest {
     13 
     14     private static final File PARENT = new File(getPathToResource("xml"));
     15 
     16     @DataProvider
     17     private static Object[][] dp() {
     18         return new Object[][] {
     19                 { "goodWithDoctype.xml", true },
     20                 { "goodWithoutDoctype.xml", true },
     21                 { "badWithDoctype.xml", false }, // TestNGException -> SAXParseException
     22                 { "badWithoutDoctype.xml", false } // NullPointerException
     23         };
     24     }
     25 
     26     @Test(dataProvider = "dp")
     27     public void testParse(String fileName, boolean shouldWork) {
     28         SuiteXmlParser parser = new SuiteXmlParser();
     29 
     30         try (FileInputStream stream = new FileInputStream(new File(PARENT, fileName))) {
     31             parser.parse(fileName, stream, false);
     32             if (!shouldWork) {
     33                 Assert.fail("Parsing of " + fileName + " is supposed to fail");
     34             }
     35         } catch (Exception e) {
     36             if (shouldWork) {
     37                 Assert.fail("Parsing of " + fileName + " is supposed to work");
     38             }
     39         }
     40     }
     41 }