setting up a test-environment

Every once in a while you need to test something for OpenClinica and you don't want to clutter your production database, so you decide you need a test-environment. Here is how to do that, plus instructions how to clean up after your testing.

It takes four steps to create your test-environment:

  1. make a backup of the production database
  2. create a new database and restore the production database
  3. make a copy of the application and the data directory
  4. edit datainfo.properties

make a backup of the production database

Let's say our production instance is called OpenClinica and we want to create an instance called octest. First we make a directory to store the postgres-dump.

cd $HOME
mkdir octest
cd $HOME/octest
pg_dump -U postgres openclinica > pgd_openclinica_20131109

create a new database and restore the production database

We create the new database with psql:

psql -U postgres
CREATE DATABASE octest WITH ENCODING='UTF8' OWNER=clinica;

Check if the database was created correctly with "\list" (or just "\l" will do) and quit psql with "\q". Now restore the production database to this new one:

psql -U postgres octest < pgd_openclinica_20131109

make a copy of the application and the data directory

Now we stop both tomcat:

/etc/init.d/tomcat stop

And we make a copy of the war and of the data-directory:

cd /opt/tomcat/webapps/
cp OpenClinica.war ./octest.war
cd ..
cp -R /opt/tomcat/openclinica.data ./octest.data
chown -R tomcat:tomcat octest.data

edit datainfo.properties

Now we will start tomcat, so the new octest.war can be deployed. But we do not start postgresql yet, because we want to edit datainfo.properties.

/etc/init.d/tomcat start

Then after a few minutes we see the directory structure of octest and then we copy the datainfo.properties of OpenClincia and edit it.

For OpenClinica before 3.4 the location of the file is /opt/tomcat/webapps/octest/WEB-INF/classes, but since 3.4 it is:

cd /opt/tomcat/octest.config
cp /opt/tomcat/openclinica.config/datainfo.properties ./
vi datainfo.properties

The editing only concerns the database name and if your original datainfo.properties refers to db=${WEBAPP.lower} you're good to go. If not, change this line to db=octest.

Now we can start tomcat again and start both applications with the tomcat-manager.

cleaning up

After testing you should clean up the database and the app and you do this by:

  1. undeploying in tomcat-manager the application octest
  2. stopping tomcat: "/etc/init.d/tomcat stop"
  3. removing the data-directory: "rm -rf /opt/tomcat/octest.data"
  4. removing the config-directory: "rm -rf /opt/tomcat/octest.config"
  5. starting psql and removing the database: "drop database octest;"

Other how-to-pages can be found here.

this page was last reviewed August 2015