private static Parser newParser(String path, IPostProcessor processor) { Parser result = new Parser(path); result.setPostProcessor(processor); return result; }
/** * * @param uri - The uri to be verified. * @return - <code>true</code> if the uri has "file:" as its scheme. */ public static boolean hasFileScheme(String uri) { URI constructedURI = constructURI(uri); if (constructedURI == null) { //There were difficulties in constructing the URI. Falling back to considering the URI as a file. return true; } String scheme = constructedURI.getScheme(); //A URI is regarded as having a file scheme if it either has its scheme as "file" //(or) if the scheme is null (which is true when uri's represent local file system path.) return scheme == null || "file".equalsIgnoreCase(scheme); }
Parser parser = new Parser(file); parser.setLoadClasses(false); // we might not have these classes on the classpath findAllSuites(parser.parse(), allSuites);
@Test(dataProvider = "dp") public void compareFiles(String name) throws IOException { Collection<XmlSuite> s1 = new Parser(getPathToResource("yaml" + File.separator + name + ".yaml")).parse(); Collection<XmlSuite> s2 = new Parser(getPathToResource("yaml" + File.separator + name + ".xml")).parse(); Assert.assertEquals(s1, s2); }
@Test(dataProvider = "dp") public void testParsing(String file) throws Exception { Parser parser = new Parser(file); List<XmlSuite> suites = parser.parseToList(); assertEquals(suites.size(), 1); }
public List<XmlSuite> parseToList() throws IOException { return Lists.newArrayList(parse()); }
JarEntry je = entries.nextElement(); String jeName = je.getName(); if (Parser.canParse(jeName.toLowerCase())){ InputStream inputStream = jf.getInputStream(je); File copyFile = new File(file, jeName); return foundTestngXml; Collection<XmlSuite> parsedSuites = Parser.parse(suitePath, processor); for (XmlSuite suite : parsedSuites) {
URI uri = constructURI(m_fileName); if (uri == null || uri.getScheme() == null) { uri = new File(m_fileName).toURI(); InputStream inputStream = null; if (hasFileScheme(currentFile)) { File currFile = new File(currentFile); parentFile = currFile.getParentFile(); IFileParser<XmlSuite> fileParser = getParser(currentFile); XmlSuite currentXmlSuite = fileParser.parse(currentFile, inputStream, m_loadClasses); currentXmlSuite.setParsed(true); for (String path : suiteFiles) { String canonicalPath = path; if (hasFileScheme(path)) { if (parentFile != null && new File(parentFile, path).exists()) { canonicalPath = new File(parentFile, path).getCanonicalPath();
/** * Constructs a <code>Parser</code> to use the inputStream as the source of * the xml test suite to parse. * @param fileName the filename corresponding to the inputStream or null if * unknown. */ public Parser(String fileName) { init(fileName, null); }
@Override public boolean accept(String fileName) { return Parser.hasFileScheme(fileName) && fileName.endsWith(".xml"); }
Parser parser = new Parser(file); parser.setLoadClasses(false); // we might not have these classes on the classpath findAllSuites(parser.parse(), allSuites);
@Test public void annotationTransformerInXmlShouldBeRun() throws Exception { String xml = "<suite name=\"SingleSuite\" >" + " <listeners>" + " <listener class-name=\"test.annotationtransformer.AnnotationTransformerInTestngXml\" />" + " </listeners>" + " <test enabled=\"true\" name=\"SingleTest\">" + " <classes>" + " <class name=\"test.annotationtransformer.AnnotationTransformerInTestngXml\" />" + " </classes>" + " </test>" + "</suite>"; ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes()); Collection<XmlSuite> suites = new Parser(is).parse(); TestNG tng = create(); tng.setXmlSuites(Arrays.asList(suites.toArray(new XmlSuite[0]))); TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener(tla); tng.run(); Assert.assertEquals(tla.getPassedTests().size(), 1); }
protected static List<XmlSuite> getSuites(String... suiteFiles){ List<XmlSuite> suites = new ArrayList<>(); for (String suiteFile : suiteFiles) { try { suites.addAll(new Parser(suiteFile).parseToList()); } catch (IOException e) { throw new TestNGException(e); } } return suites; }
public List<XmlSuite> parseToList() throws IOException { return Lists.newArrayList(parse()); }
JarEntry je = entries.nextElement(); String jeName = je.getName(); if (Parser.canParse(jeName.toLowerCase())) { InputStream inputStream = jf.getInputStream(je); File copyFile = new File(file, jeName); return false; Collection<XmlSuite> parsedSuites = Parser.parse(suitePath, processor); delete(file); for (XmlSuite suite : parsedSuites) {
URI uri = constructURI(m_fileName); if (uri == null || uri.getScheme() == null) { uri = new File(m_fileName).toURI(); InputStream inputStream = null; if (hasFileScheme(currentFile)) { File currFile = new File(currentFile); parentFile = currFile.getParentFile(); IFileParser<XmlSuite> fileParser = getParser(currentFile); XmlSuite currentXmlSuite = fileParser.parse(currentFile, inputStream, m_loadClasses); currentXmlSuite.setParsed(true); for (String path : suiteFiles) { String canonicalPath = path; if (hasFileScheme(path)) { if (parentFile != null && new File(parentFile, path).exists()) { canonicalPath = new File(parentFile, path).getCanonicalPath();
/** * Creates a parser that will try to find the DEFAULT_FILENAME from the jar. * @throws FileNotFoundException if the DEFAULT_FILENAME resource is not * found in the classpath. */ public Parser() throws FileNotFoundException { init(null, null); }
@Override public boolean accept(String fileName) { return Parser.hasFileScheme(fileName) && fileName.endsWith(".yaml"); }
if (file != null) { IPath location = file.getLocation(); Parser p = new Parser(location.toOSString()); p.setLoadClasses(false); Collection<XmlSuite> suites = p.parse(); StringBuilder yamlSb = Yaml.toYaml(suites.iterator().next());