I have to make changes to a web application that has zero unit tests.
So the first task is to provide unit tests that can be used to
regression test the changes.
I am using Maven and TestNG but have an problem.
The code required to lookup the data source via JNDI from within a
webapp running in Tomcat but I dont want to run the whole app just to
unit test a part of it - that would be integration testing which comes
later :)
I have been trying all kinds of methods to get the JNDI lookup to
work. Using for example
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.rmi.registry.RegistryContextFactory");
System.setProperty(Context.PROVIDER_URL, "rmi://localhost:1098");
java.rmi.registry.LocateRegistry.createRegistry(1098);
InitialContext ic = new InitialContext();
Reference ref = new Reference("javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory", null);
ref.add(new StringRefAddr("driverClassName",
"com.mysql.jdbc.Driver"));
ref.add(new StringRefAddr("url", "jdbc:mysql://
127.0.0.1:3306/
xxxxxx"));
ref.add(new StringRefAddr("username", "xxxxxxxx"));
ref.add(new StringRefAddr("password", "xxxxxxxx"));
ic.bind("xxxxxxx", ref);
Here is get a timeout exception on the IP address of the DNS server
doing any lookup !
The code will run in Tomcat (its live) so I am thinking that may be
the way to go is runt he tests within tomcat so the question is how do
I start Tomcat on the Maven test phase and stop it when that phase
ends.
Any suggestions much appreciated, been beating my head against this
for some time.
Many thanks.