mercredi 2 décembre 2015

Running Spring unit tests on local machine pointed to remote server (jdbc host)

Background

I am working with a CXF servlet that hosts a server that facilitate my REST APIs, and the database I am working with is postgres. The postgres instance runs on my remote VM and WAR files are hosted via Tomcat 7 container.

I have a remote VM running a postgres instance with localhost (ip of 127.0.0.1) and I have a number of TestNG unit tests I have written I want to run against that remote postgres instance.

The problem

The tests work just fine when I run them against my localhost on my local machine that has postgres running as well, but I want to switch the postgres instance being tested to be my remote's, and have the tests run FROM my local machine. When I compile my WAR file on my local machine, I upload it to the remote machine and it operates on the remote machines database so that is where it gets tricky, and why I have to run the tests from my local machine (or can I run the tests via the remote??)

The reason I want to do this is to not force all users of my tests to have to have a postgres setup on their local machine, and instead use my remote host the jdbc url.

Here is the java bean that sets up the JDBC driver:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbc:http://postgresql${db.host}:${db.port}/${db.name}" />
    <property name="username" value="${db.user}" />
</bean>

I want to change the url to work with the remote's local host. Now, I know you cannot access the remote's local host outside of the remote machine, but there must be something I can do to point the jdbc driver to the right location.

Any ideas?

Aucun commentaire:

Enregistrer un commentaire