Merge pull request #11 from apache/FINCN-114

Merge progress from FINCN-114 into develop
diff --git a/.gitignore b/.gitignore
index 300fb08..3642fde 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 .idea
 build/
 target/
+out
 
 # Ignore Gradle GUI config
 gradle-app.setting
diff --git a/NOTICE.txt b/NOTICE.txt
index 15413c9..df63679 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
 Apache Fineract CN Test
-Copyright [2017-2018] The Apache Software Foundation
+Copyright [2017-2019] The Apache Software Foundation
 
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
diff --git a/README.md b/README.md
index dfd7ff5..1dad2f7 100644
--- a/README.md
+++ b/README.md
@@ -7,13 +7,14 @@
 ### Runtime
 Install Java 8 as described at https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html.
 
-### MariaDB
-Install MariaDB as described at https://mariadb.com/kb/en/mariadb/binary-packages/.
+### PostgreSQL
+Install PostgreSQL as described at
+https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04.
 
 After installation you need to create the meta database:
 
-    mysql -u root -pmysql
-    CREATE DATABASE IF NOT EXISTS system_console;
+    sudo -i -u postgres psql
+    CREATE DATABASE system_console;
     
 ### Cassandra
 Install Apache Cassandra as described at https://wiki.apache.org/cassandra/GettingStarted.
@@ -46,4 +47,4 @@
 1.3.5-RELEASE
 
 ## License
-See [LICENSE](LICENSE) file.
+See [LICENSE](LICENSE) file.
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 6365ff6..e3795fb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -36,7 +36,6 @@
         gson                      : '2.5',
         findbugs                  : '3.0.1',
         frameworklang             : '0.1.0-BUILD-SNAPSHOT',
-        frameworkmariadb          : '0.1.0-BUILD-SNAPSHOT',
         frameworkcassandra        : '0.1.0-BUILD-SNAPSHOT'
 ]
 
@@ -65,11 +64,11 @@
             [group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.springboot],
             [group: 'com.google.code.gson', name: 'gson', version: versions.gson],
             [group: 'org.apache.fineract.cn', name: 'cassandra', version: versions.frameworkcassandra],
-            [group: 'org.apache.fineract.cn', name: 'mariadb', version: versions.frameworkmariadb],
+            [group: 'org.apache.fineract.cn', name: 'postgresql', version: '0.1.0-BUILD-SNAPSHOT'],
             [group: 'org.apache.fineract.cn', name: 'lang', version: versions.frameworklang],
             [group: 'io.jsonwebtoken', name: 'jjwt', version: '0.6.0'],
             [group: 'org.cassandraunit', name: 'cassandra-unit', version: '3.0.0.1'],
-            [group: 'ch.vorburger.mariaDB4j', name: 'mariaDB4j', version: '2.1.3'],
+            [group: 'com.opentable.components', name: 'otj-pg-embedded', version: '0.7.1']
     )
 }
 
@@ -125,4 +124,4 @@
             "gradlew.bat",
             "README.md"
     ]
-}
+}
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index ba3a06f..fe81d05 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Mar 14 11:47:51 CET 2017
+#Fri Jan 04 23:49:37 WAT 2019
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip
diff --git a/src/main/java/org/apache/fineract/cn/test/env/TestEnvironment.java b/src/main/java/org/apache/fineract/cn/test/env/TestEnvironment.java
index 8b4b7ac..ed4500c 100644
--- a/src/main/java/org/apache/fineract/cn/test/env/TestEnvironment.java
+++ b/src/main/java/org/apache/fineract/cn/test/env/TestEnvironment.java
@@ -59,23 +59,24 @@
   public static final String CASSANDRA_CONSISTENCY_LEVEL_DELETE_PROPERTY = "cassandra.cl.delete";
   public static final String CASSANDRA_CONSISTENCY_LEVEL_DEFAULT = "ONE";
 
-  public static final String MARIADB_DRIVER_CLASS_PROPERTY = "mariadb.driverClass";
-  public static final String MARIADB_DRIVER_CLASS_DEFAULT = "org.mariadb.jdbc.Driver";
+  public static final String POSTGRESQL_DRIVER_CLASS_PROPERTY = "postgresql.driverClass";
+  public static final String POSTGRESQL_DRIVER_CLASS_DEFAULT = "org.postgresql.Driver";
 
-  public static final String MARIADB_DATABASE_NAME_PROPERTY = "mariadb.database";
-  public static final String MARIADB_DATABASE_NAME_DEFAULT = "seshat";
+  public static final String POSTGRESQL_DATABASE_NAME_PROPERTY = "postgresql.database";
+  public static final String POSTGRESQL_DATABASE_NAME_DEFAULT = "seshat";
+  public static final String POSTGRESQL_DATABASE_NAME = "postgres";
 
-  public static final String MARIADB_HOST_PROPERTY = "mariadb.host";
-  public static final String MARIADB_HOST_DEFAULT = "localhost";
+  public static final String POSTGRESQL_HOST_PROPERTY = "postgresql.host";
+  public static final String POSTGRESQL_HOST_DEFAULT = "localhost";
 
-  public static final String MARIADB_PORT_PROPERTY = "mariadb.port";
-  public static final String MARIADB_PORT_DEFAULT = "3306";
+  public static final String POSTGRESQL_PORT_PROPERTY = "postgresql.port";
+  public static final String POSTGRESQL_PORT_DEFAULT = "5432";
 
-  public static final String MARIADB_USER_PROPERTY = "mariadb.user";
-  public static final String MARIADB_USER_DEFAULT = "root";
+  public static final String POSTGRESQL_USER_PROPERTY = "postgresql.user";
+  public static final String POSTGRESQL_USER_DEFAULT = "postgres";
 
-  public static final String MARIADB_PASSWORD_PROPERTY = "mariadb.password";
-  public static final String MARIADB_PASSWORD_DEFAULT = "mysql";
+  public static final String POSTGRESQL_PASSWORD_PROPERTY = "postgresql.password";
+  public static final String POSTGRESQL_PASSWORD_DEFAULT = "postgres";
 
   public static final String SPRING_CLOUD_DISCOVERY_ENABLED_PROPERTY = "spring.cloud.discovery.enabled";
   public static final String SPRING_CLOUD_DISCOVERY_ENABLED_DEFAULT = "false";
@@ -211,12 +212,12 @@
     this.properties.setProperty(CASSANDRA_CONSISTENCY_LEVEL_READ_PROPERTY, CASSANDRA_CONSISTENCY_LEVEL_DEFAULT);
     this.properties.setProperty(CASSANDRA_CONSISTENCY_LEVEL_WRITE_PROPERTY, CASSANDRA_CONSISTENCY_LEVEL_DEFAULT);
     this.properties.setProperty(CASSANDRA_CONSISTENCY_LEVEL_DELETE_PROPERTY, CASSANDRA_CONSISTENCY_LEVEL_DEFAULT);
-    this.properties.setProperty(MARIADB_DRIVER_CLASS_PROPERTY, MARIADB_DRIVER_CLASS_DEFAULT);
-    this.properties.setProperty(MARIADB_DATABASE_NAME_PROPERTY, MARIADB_DATABASE_NAME_DEFAULT);
-    this.properties.setProperty(MARIADB_HOST_PROPERTY, MARIADB_HOST_DEFAULT);
-    this.properties.setProperty(MARIADB_PORT_PROPERTY, MARIADB_PORT_DEFAULT);
-    this.properties.setProperty(MARIADB_USER_PROPERTY, MARIADB_USER_DEFAULT);
-    this.properties.setProperty(MARIADB_PASSWORD_PROPERTY, MARIADB_PASSWORD_DEFAULT);
+    this.properties.setProperty(POSTGRESQL_DRIVER_CLASS_PROPERTY, POSTGRESQL_DRIVER_CLASS_DEFAULT);
+    this.properties.setProperty(POSTGRESQL_DATABASE_NAME_PROPERTY, POSTGRESQL_DATABASE_NAME_DEFAULT);
+    this.properties.setProperty(POSTGRESQL_HOST_PROPERTY, POSTGRESQL_HOST_DEFAULT);
+    this.properties.setProperty(POSTGRESQL_PORT_PROPERTY, POSTGRESQL_PORT_DEFAULT);
+    this.properties.setProperty(POSTGRESQL_USER_PROPERTY, POSTGRESQL_USER_DEFAULT);
+    this.properties.setProperty(POSTGRESQL_PASSWORD_PROPERTY, POSTGRESQL_PASSWORD_DEFAULT);
     this.properties.setProperty(SPRING_CLOUD_DISCOVERY_ENABLED_PROPERTY, SPRING_CLOUD_DISCOVERY_ENABLED_DEFAULT);
     this.properties.setProperty(SPRING_CLOUD_CONFIG_ENABLED_PROPERTY, SPRING_CLOUD_CONFIG_ENABLED_DEFAULT);
     this.properties.setProperty(FLYWAY_ENABLED_PROPERTY, FLYWAY_ENABLED_DEFAULT);
diff --git a/src/main/java/org/apache/fineract/cn/test/fixture/mariadb/MariaDBInitializer.java b/src/main/java/org/apache/fineract/cn/test/fixture/mariadb/MariaDBInitializer.java
deleted file mode 100644
index 9b5de8d..0000000
--- a/src/main/java/org/apache/fineract/cn/test/fixture/mariadb/MariaDBInitializer.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.fineract.cn.test.fixture.mariadb;
-
-import ch.vorburger.mariadb4j.DB;
-import org.apache.fineract.cn.test.env.TestEnvironment;
-import org.apache.fineract.cn.test.fixture.DataStoreTenantInitializer;
-
-import java.sql.*;
-import org.apache.fineract.cn.mariadb.util.JdbcUrlBuilder;
-
-@SuppressWarnings({"WeakerAccess", "unused", "SqlNoDataSourceInspection", "SqlDialectInspection"})
-public final class MariaDBInitializer extends DataStoreTenantInitializer {
-
-  private final boolean useExistingDB;
-  private static DB db;
-
-  public MariaDBInitializer() {
-    this(false);
-  }
-
-  public MariaDBInitializer(final boolean useExistingDB) {
-    super();
-    this.useExistingDB = useExistingDB;
-  }
-
-  @Override
-  public void initialize() throws Exception  {
-    MariaDBInitializer.setup(useExistingDB);
-  }
-
-  @Override
-  public void initializeTenant(final String tenantName) {
-    MariaDBInitializer.createDatabaseTenant(tenantName);
-
-  }
-
-  @Override
-  public void finish() {
-    if (!useExistingDB) {
-      try {
-        MariaDBInitializer.tearDown();
-      } catch (final Exception e) {
-        throw new RuntimeException(e);
-      }
-    }
-  }
-
-  public static void setup() throws Exception {
-    setup(false);
-  }
-  public static void setup(final boolean useExistingDB) throws Exception {
-    if (!useExistingDB) {
-      MariaDBInitializer.startEmbeddedMariaDB();
-      MariaDBInitializer.createDatabaseSeshat();
-    }
-  }
-
-  public static void tearDown() throws Exception {
-    if (MariaDBInitializer.db != null) {
-      MariaDBInitializer.db.stop();
-      MariaDBInitializer.db = null;
-    }
-  }
-
-  private static void startEmbeddedMariaDB() throws Exception {
-    if (MariaDBInitializer.db == null) {
-      MariaDBInitializer.db = DB.newEmbeddedDB(3306);
-      MariaDBInitializer.db.start();
-    }
-  }
-
-  private static void createDatabaseSeshat() {
-    try {
-      Class.forName(System.getProperty(TestEnvironment.MARIADB_DRIVER_CLASS_PROPERTY));
-    } catch (ClassNotFoundException ex) {
-      throw new IllegalArgumentException(ex.getMessage(), ex);
-    }
-    final String jdbcUrl = JdbcUrlBuilder
-        .create(JdbcUrlBuilder.DatabaseType.MARIADB)
-        .host(System.getProperty(TestEnvironment.MARIADB_HOST_PROPERTY))
-        .port(System.getProperty(TestEnvironment.MARIADB_PORT_PROPERTY))
-        .build();
-    try (final Connection connection = DriverManager.getConnection(jdbcUrl,
-        System.getProperty(TestEnvironment.MARIADB_USER_PROPERTY),
-        System.getProperty(TestEnvironment.MARIADB_PASSWORD_PROPERTY))) {
-      try (final Statement statement = connection.createStatement()) {
-        // create meta database seshat
-        statement.execute("CREATE DATABASE IF NOT EXISTS " + System.getProperty(TestEnvironment.MARIADB_DATABASE_NAME_PROPERTY));
-        statement.execute("USE " + System.getProperty(TestEnvironment.MARIADB_DATABASE_NAME_PROPERTY));
-        // create needed tenant management table
-        statement.execute("CREATE TABLE IF NOT EXISTS tenants (" +
-            "  identifier    VARCHAR(32) NOT NULL," +
-            "  driver_class  VARCHAR(255) NOT NULL," +
-            "  database_name VARCHAR(32) NOT NULL," +
-            "  host          VARCHAR(32) NOT NULL," +
-            "  port          VARCHAR(5)  NOT NULL," +
-            "  a_user        VARCHAR(32) NOT NULL," +
-            "  pwd           VARCHAR(32) NOT NULL," +
-            "  PRIMARY KEY (identifier)" +
-            ")");
-      }
-      connection.commit();
-    } catch (final SQLException ex) {
-      ex.printStackTrace();
-    }
-  }
-
-  public static void createDatabaseTenant(final String identifier) {
-    try {
-      Class.forName(System.getProperty(TestEnvironment.MARIADB_DRIVER_CLASS_PROPERTY));
-    } catch (ClassNotFoundException ex) {
-      throw new IllegalArgumentException(ex.getMessage(), ex);
-    }
-    final String jdbcUrl = JdbcUrlBuilder
-        .create(JdbcUrlBuilder.DatabaseType.MARIADB)
-        .host(System.getProperty(TestEnvironment.MARIADB_HOST_PROPERTY))
-        .port(System.getProperty(TestEnvironment.MARIADB_PORT_PROPERTY))
-        .build();
-    try (final Connection connection = DriverManager.getConnection(jdbcUrl,
-        System.getProperty(TestEnvironment.MARIADB_USER_PROPERTY),
-        System.getProperty(TestEnvironment.MARIADB_PASSWORD_PROPERTY))) {
-      try (final Statement statement = connection.createStatement()) {
-        // create tenant database
-        statement.execute("CREATE DATABASE IF NOT EXISTS " + identifier);
-        // insert tenant connection info in management table
-        try (final ResultSet resultSet = statement.executeQuery(
-            "SELECT EXISTS (SELECT * FROM " +
-                System.getProperty(TestEnvironment.MARIADB_DATABASE_NAME_PROPERTY) +
-                ".tenants WHERE identifier = '" + identifier + "')")) {
-          if (resultSet.next()
-              && resultSet.getInt(1) == 0) {
-            final MariaDBTenant mariaDBTenant = new MariaDBTenant();
-            mariaDBTenant.setIdentifier(identifier);
-            mariaDBTenant.setDriverClass(System.getProperty(TestEnvironment.MARIADB_DRIVER_CLASS_PROPERTY));
-            mariaDBTenant.setDatabaseName(identifier);
-            mariaDBTenant.setHost(System.getProperty(TestEnvironment.MARIADB_HOST_PROPERTY));
-            mariaDBTenant.setPort(System.getProperty(TestEnvironment.MARIADB_PORT_PROPERTY));
-            mariaDBTenant.setUser(System.getProperty(TestEnvironment.MARIADB_USER_PROPERTY));
-            mariaDBTenant.setPassword(System.getProperty(TestEnvironment.MARIADB_PASSWORD_PROPERTY));
-            mariaDBTenant.insert(connection);
-          }
-        }
-      }
-      connection.commit();
-    } catch (final SQLException ex) {
-      ex.printStackTrace();
-    }
-  }
-}
diff --git a/src/main/java/org/apache/fineract/cn/test/fixture/postgresql/PostgreSQLInitializer.java b/src/main/java/org/apache/fineract/cn/test/fixture/postgresql/PostgreSQLInitializer.java
new file mode 100644
index 0000000..678abc1
--- /dev/null
+++ b/src/main/java/org/apache/fineract/cn/test/fixture/postgresql/PostgreSQLInitializer.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cn.test.fixture.postgresql;
+
+import com.opentable.db.postgres.embedded.EmbeddedPostgres;
+import org.apache.fineract.cn.test.env.TestEnvironment;
+import org.apache.fineract.cn.test.fixture.DataStoreTenantInitializer;
+
+import java.sql.*;
+import org.apache.fineract.cn.postgresql.util.JdbcUrlBuilder;
+
+@SuppressWarnings({"WeakerAccess", "unused", "SqlNoDataSourceInspection", "SqlDialectInspection"})
+public final class PostgreSQLInitializer extends DataStoreTenantInitializer {
+
+  private final boolean useExistingDB;
+  private static EmbeddedPostgres pg;
+
+  public PostgreSQLInitializer() {
+    this(false);
+  }
+
+  public PostgreSQLInitializer(final boolean useExistingDB) {
+    super();
+    this.useExistingDB = useExistingDB;
+  }
+
+  @Override
+  public void initialize() throws Exception  {
+    PostgreSQLInitializer.setup(useExistingDB);
+  }
+
+  @Override
+  public void initializeTenant(final String tenantName) {
+    PostgreSQLInitializer.createDatabaseTenant(tenantName);
+
+  }
+
+  @Override
+  public void finish() {
+    if (!useExistingDB) {
+      try {
+        PostgreSQLInitializer.tearDown();
+      } catch (final Exception e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  public static void setup() throws Exception {
+    setup(false);
+  }
+  public static void setup(final boolean useExistingDB) throws Exception {
+    if (!useExistingDB) {
+      PostgreSQLInitializer.startEmbeddedPostgreSQL();
+      PostgreSQLInitializer.createDatabaseSeshat();
+    }
+  }
+
+  public static void tearDown() throws Exception {
+    if (PostgreSQLInitializer.pg != null) {
+      PostgreSQLInitializer.pg.close();
+      PostgreSQLInitializer.pg = null;
+    }
+  }
+
+  private static void startEmbeddedPostgreSQL() throws Exception {
+    PostgreSQLInitializer.pg = EmbeddedPostgres.builder().setPort(Integer.valueOf(TestEnvironment.POSTGRESQL_PORT_DEFAULT)).start();
+    System.setProperty(TestEnvironment.POSTGRESQL_HOST_PROPERTY, TestEnvironment.POSTGRESQL_HOST_DEFAULT);
+    System.setProperty(TestEnvironment.POSTGRESQL_PORT_PROPERTY, TestEnvironment.POSTGRESQL_PORT_DEFAULT);
+  }
+
+  private static void createDatabaseSeshat() {
+    try {
+      Class.forName(System.getProperty(TestEnvironment.POSTGRESQL_DRIVER_CLASS_PROPERTY));
+    } catch (ClassNotFoundException ex) {
+      throw new IllegalArgumentException(ex.getMessage(), ex);
+    }
+
+    final String jdbcUrl = JdbcUrlBuilder
+            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+            .host(System.getProperty(TestEnvironment.POSTGRESQL_HOST_PROPERTY))
+            .port(System.getProperty(TestEnvironment.POSTGRESQL_PORT_PROPERTY))
+            .instanceName(TestEnvironment.POSTGRESQL_DATABASE_NAME)
+            .build();
+    try (final Connection pgConnection = DriverManager.getConnection(jdbcUrl,
+            System.getProperty(TestEnvironment.POSTGRESQL_USER_PROPERTY),
+            System.getProperty(TestEnvironment.POSTGRESQL_PASSWORD_PROPERTY));
+         final Statement createDbStatement = pgConnection.createStatement()) {
+      pgConnection.setAutoCommit(true);
+      // create meta database seshat
+      createDbStatement.execute("CREATE DATABASE " + System.getProperty(TestEnvironment.POSTGRESQL_DATABASE_NAME_PROPERTY));
+      createDbStatement.execute("CREATE DATABASE playground");
+    } catch (final SQLException ex) {
+      ex.printStackTrace();
+    }
+
+    final String tenantJdbcUrl = JdbcUrlBuilder
+            .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+            .host(System.getProperty(TestEnvironment.POSTGRESQL_HOST_PROPERTY))
+            .port(System.getProperty(TestEnvironment.POSTGRESQL_PORT_PROPERTY))
+            .instanceName(System.getProperty(TestEnvironment.POSTGRESQL_DATABASE_NAME_PROPERTY))
+            .build();
+
+    try (
+            final Connection metaDbConnection = DriverManager.getConnection(tenantJdbcUrl,
+                    System.getProperty(TestEnvironment.POSTGRESQL_USER_PROPERTY),
+                    System.getProperty(TestEnvironment.POSTGRESQL_PASSWORD_PROPERTY));
+            final Statement metaStatement = metaDbConnection.createStatement()
+    ) {
+      metaDbConnection.setAutoCommit(true);
+      // create needed tenant management table
+      metaStatement.execute("CREATE TABLE IF NOT EXISTS tenants (" +
+              "  identifier    VARCHAR(32) NOT NULL," +
+              "  driver_class  VARCHAR(255) NOT NULL," +
+              "  database_name VARCHAR(32) NOT NULL," +
+              "  host          VARCHAR(32) NOT NULL," +
+              "  port          VARCHAR(5)  NOT NULL," +
+              "  a_user        VARCHAR(32) NOT NULL," +
+              "  pwd           VARCHAR(32) NOT NULL," +
+              "  PRIMARY KEY (identifier)" +
+              ")");
+    } catch (SQLException e) {
+      e.printStackTrace();
+    }
+  }
+
+  public static void createDatabaseTenant(final String identifier) {
+    try {
+      Class.forName(System.getProperty(TestEnvironment.POSTGRESQL_DRIVER_CLASS_PROPERTY));
+    } catch (ClassNotFoundException ex) {
+      throw new IllegalArgumentException(ex.getMessage(), ex);
+    }
+    final String jdbcUrl = JdbcUrlBuilder
+        .create(JdbcUrlBuilder.DatabaseType.POSTGRESQL)
+        .host(System.getProperty(TestEnvironment.POSTGRESQL_HOST_PROPERTY))
+        .port(System.getProperty(TestEnvironment.POSTGRESQL_PORT_PROPERTY))
+        .instanceName(TestEnvironment.POSTGRESQL_DATABASE_NAME_DEFAULT)
+        .build();
+    try (final Connection connection = DriverManager.getConnection(jdbcUrl,
+        System.getProperty(TestEnvironment.POSTGRESQL_USER_PROPERTY),
+        System.getProperty(TestEnvironment.POSTGRESQL_PASSWORD_PROPERTY))) {
+      try (final Statement statement = connection.createStatement()) {
+        connection.setAutoCommit(true);
+        // create tenant database
+        statement.execute("CREATE DATABASE " + identifier);
+        // insert tenant connection info in management table
+        try (final ResultSet resultSet = statement.executeQuery("SELECT * FROM tenants WHERE identifier = '" + identifier + "'")) {
+          if (resultSet.next()
+              && resultSet.getInt(1) == 0) {
+            final PostgreSQLTenant postgreSQLTenant = new PostgreSQLTenant();
+            postgreSQLTenant.setIdentifier(identifier);
+            postgreSQLTenant.setDriverClass(System.getProperty(TestEnvironment.POSTGRESQL_DRIVER_CLASS_PROPERTY));
+            postgreSQLTenant.setDatabaseName(identifier);
+            postgreSQLTenant.setHost(System.getProperty(TestEnvironment.POSTGRESQL_HOST_PROPERTY));
+            postgreSQLTenant.setPort(System.getProperty(TestEnvironment.POSTGRESQL_PORT_PROPERTY));
+            postgreSQLTenant.setUser(System.getProperty(TestEnvironment.POSTGRESQL_USER_PROPERTY));
+            postgreSQLTenant.setPassword(System.getProperty(TestEnvironment.POSTGRESQL_PASSWORD_PROPERTY));
+            postgreSQLTenant.insert(connection);
+          }
+        }
+      }
+    } catch (final SQLException ex) {
+      ex.printStackTrace();
+    }
+  }
+}
diff --git a/src/main/java/org/apache/fineract/cn/test/fixture/mariadb/MariaDBTenant.java b/src/main/java/org/apache/fineract/cn/test/fixture/postgresql/PostgreSQLTenant.java
similarity index 87%
rename from src/main/java/org/apache/fineract/cn/test/fixture/mariadb/MariaDBTenant.java
rename to src/main/java/org/apache/fineract/cn/test/fixture/postgresql/PostgreSQLTenant.java
index 6cf8b16..779ea8a 100644
--- a/src/main/java/org/apache/fineract/cn/test/fixture/mariadb/MariaDBTenant.java
+++ b/src/main/java/org/apache/fineract/cn/test/fixture/postgresql/PostgreSQLTenant.java
@@ -16,16 +16,14 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.fineract.cn.test.fixture.mariadb;
-
-import org.apache.fineract.cn.test.env.TestEnvironment;
+package org.apache.fineract.cn.test.fixture.postgresql;
 
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 @SuppressWarnings({"SqlNoDataSourceInspection", "SqlDialectInspection", "WeakerAccess"})
-class MariaDBTenant {
+class PostgreSQLTenant {
 
   private static final int INDEX_IDENTIFIER = 1;
   private static final int INDEX_DRIVER_CLASS = 2;
@@ -35,9 +33,7 @@
   private static final int INDEX_USER = 6;
   private static final int INDEX_PASSWORD = 7;
 
-  private static final String TABLE_NAME = System.getProperty(TestEnvironment.MARIADB_DATABASE_NAME_PROPERTY) + ".tenants";
-  private static final String INSERT_STMT = " INSERT INTO " +
-      MariaDBTenant.TABLE_NAME +
+  private static final String INSERT_STMT = " INSERT INTO " + "tenants" +
       " (identifier, driver_class, database_name, host, port, a_user, pwd) " +
       " values " +
       " (?, ?, ?, ?, ?, ?, ?) ";
@@ -50,12 +46,12 @@
   private String user;
   private String password;
 
-  MariaDBTenant() {
+  PostgreSQLTenant() {
     super();
   }
 
   void insert(final Connection connection) throws SQLException {
-    try (final PreparedStatement insertTenantStatement = connection.prepareStatement(MariaDBTenant.INSERT_STMT)) {
+    try (final PreparedStatement insertTenantStatement = connection.prepareStatement(PostgreSQLTenant.INSERT_STMT)) {
       insertTenantStatement.setString(INDEX_IDENTIFIER, this.getIdentifier());
       insertTenantStatement.setString(INDEX_DRIVER_CLASS, this.getDriverClass());
       insertTenantStatement.setString(INDEX_DATABASE_NAME, this.getDatabaseName());