Highlight of suite .xml file and Context Run As "TestNG Suite" requires proxy

50 views
Skip to first unread message

freddio

unread,
Jul 14, 2005, 1:52:29 PM7/14/05
to testng...@googlegroups.com
I think this has been posted before, but I thought I'd add my vote to
the list:

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)

Alexandru Popescu

unread,
Jul 14, 2005, 5:07:30 PM7/14/05
to testng...@googlegroups.com
#: by freddio's words the mind was *winged* :#
We will probably need to include the dtd in the jar and validate against it?

:alex |.::the_mindstorm::.|

freddio

unread,
Jul 14, 2005, 6:11:10 PM7/14/05
to testng...@googlegroups.com
That would be good.

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.

Alexandru Popescu

unread,
Jul 14, 2005, 7:47:40 PM7/14/05
to testng...@googlegroups.com
#: by freddio's words the mind was *winged* :#
This can definitely be done ;-).

:alex |.::the_mindstorm::.|

Alexandru Popescu

unread,
Jul 15, 2005, 6:26:24 PM7/15/05
to testng...@googlegroups.com
#: by freddio's words the mind was *winged* :#
freddio can you pls check if the testng jars in the plugin dir/lib are containing the dtd?

i think we are including them, so the exception should not occur. waiting for your confirmation
before doing more investigations.

:alex |.::the_mindstorm::.|

freddio

unread,
Jul 15, 2005, 8:00:11 PM7/15/05
to testng...@googlegroups.com
It is indeed in the .jar file but you need to have an XML Entity
Resolver which tells the XML engine to create an InputSource object
using the one from the jar.

freddio

unread,
Jul 15, 2005, 8:06:09 PM7/15/05
to testng...@googlegroups.com
code snippet:

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));
}
}

Alexandru Popescu

unread,
Jul 16, 2005, 5:14:29 AM7/16/05
to testng...@googlegroups.com
#: by freddio's words the mind was *winged* :#
But we already do the same:

[code]
if(Parser.TESTNG_DTD_URL.equals(publicId)) {
InputStream is = getClass().getClassLoader().getResourceAsStream(Parser.TESTNG_DTD);
if(null == is) {
is = Thread.currentThread()
.getContextClassLoader().getResourceAsStream(Parser.TESTNG_DTD);
if(null == is) {
System.out.println(
"WARNING: couldn't find in classpath "
+ Parser.TESTNG_DTD_URL
+ "\n"
+ "Fetching it from the Web site.");
result = super.resolveEntity(systemId, publicId);
}
else {
result = new InputSource(is);
}
}
else {
result = new InputSource(is);
}
}
[/code]


:alex |.::the_mindstorm::.|

freddio

unread,
Jul 18, 2005, 1:25:50 AM7/18/05
to testng...@googlegroups.com
<confused> Should do it?!? Hmmmmm....?!?! What are the values of
Parser.TESTN­G_DTD && Parser.TESTNG_DTD_URL? Seems like if this code
was being executed I'd see some message in the logs. I'll double check
them. If not, the ge­tResourceAsStream() methods may be unable to
locate the file?!?
</confused>

freddio

unread,
Jul 20, 2005, 7:19:26 PM7/20/05
to testng...@googlegroups.com
I figured it out. It turns out that I was using an incorrect SYSTEM id.

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.

Alexandru Popescu

unread,
Jul 20, 2005, 8:23:52 PM7/20/05
to testng...@googlegroups.com
#: by freddio's words the mind was *winged* :#
Excellent catch! I am going to fix this right now.

:alex |.::the_mindstorm::.|

Cedric Beust

unread,
Jul 20, 2005, 7:26:01 PM7/20/05
to testng...@googlegroups.com
Yup, thanks a lot Fred!

--
Cedric

Alexandru Popescu

unread,
Jul 20, 2005, 8:32:14 PM7/20/05
to testng...@googlegroups.com
#: by freddio's words the mind was *winged* :#
fixed in cvs head. thanks

:alex |.::the_mindstorm::.|
Reply all
Reply to author
Forward
0 new messages