We need to be able to set an alternate location for the entity resolver
(i.e.,
include the dtd in the lib) or be able to set the proxy settings for
the
plugin. I have verified that if instead I go to the "Run..." button and
define
a TestNG suite to run but I add the JVM args "-Dhttp.proxySet=true -
Dhttp.proxyHost=proxy.companyName.com -Dhttp.proxyPort=8080" it works
fine.
With the following xml file:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="My suite">
<test name="Simple example">
<parameter name="first-name" value="Doug"/>
<classes>
<class name="com.comapany.zed.integration.SimpleTest"/>
</classes>
</test>
<test name="Simple example">
<parameter name="first-name" value="Fred"/>
<classes>
<class name="com.quest.zed.integration.SimpleTest"/>
</classes>
</test>
</suite>
If I right click on the file in Eclipse, in the "Run As" menu it is
correctly
recognized as a TestNG Suite, however it runs with an error because we
are
behind a firewall & the SAX parser is apparently attempting to validate
the
file using the dtd:
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress
(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient
(HttpURLConnection.java:784)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect
(HttpURLConnection.java:736)
at sun.net.www.protocol.http.HttpURLConnection.connect
(HttpURLConnection.java:661)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream
(HttpURLConnection.java:905)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity
(XMLEntityManager.java:973)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity
(XMLEntityManager.java:905)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity
(XMLEntityManager.java:872)
at
com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource
(XMLDTDScannerImpl.java:282)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDispatcher.dis
patch(XMLDocumentScannerImpl.java:1021)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocum
ent(XMLDocumentFragmentScannerImpl.java:368)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
(XML11Configuration.java:834)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse
(XMLParser.java:148)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse
(AbstractSAXParser.java:1242)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:176)
at org.testng.xml.Parser.parse(Parser.java:58)
at org.testng.TestNG.setTestSuites(TestNG.java:160)
at org.testng.eclipse.runner.RemoteTestNG.main
(RemoteTestNG.java:128)
WARNING: No test suite found. Nothing to run
Exception in thread "ReaderThread" java.lang.NullPointerException
at
org.testng.eclipse.runner.StringMessageSenderHelper$ReaderThread.run
(StringMessageSenderHelper.java:189)
Also, as a workaround, I found that if I put the .dtd in the same
directory as the testng.xml file and change the Doc Type to "<!DOCTYPE
suite SYSTEM "testng-1.0.dtd">" it works too. Better to put it in the
jar though.
On the XML reader object specify the entity resolver:
xmlReader.setEntityResolver(new TestNGEntityResolver());
public class TestNGEntityResolver implements EntityResolver
{
public InputSource resolveEntity(String publicId, String
systemId)
{
byte[] file bytes = loadDTDfromJarAndReturnTheBytes();
return new InputSource(new ByteArrayInputStream(bytes));
}
}
The testng.org site had an example that I copy & pasted:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
The problem is that the or.testng.xml.Parser 's TESTNG_DTD_URL was
referencing the "beust.com/testng" URI. Changing my DOCTYPE to:
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd">
fixed the problem. If you decide to change this you may want to test
for both the old and the new URLs before deciding to load from the jar.