You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ma...@apache.org on 2016/01/28 06:47:02 UTC
[17/51] [partial] incubator-fineract git commit: initial code push
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/dependencies.gradle
----------------------------------------------------------------------
diff --git a/fineract-provider/dependencies.gradle b/fineract-provider/dependencies.gradle
new file mode 100644
index 0000000..e40a330
--- /dev/null
+++ b/fineract-provider/dependencies.gradle
@@ -0,0 +1,80 @@
+dependencies {
+ def tomcatVersion = '7.0.54'
+ tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
+ "org.apache.tomcat.embed:tomcat-embed-logging-log4j:${tomcatVersion}" // NOT tomcat-embed-logging-juli (http://stackoverflow.com/questions/23963049/classcircularityerror-java-util-logging-logrecord-running-gradle-webapp-with-ja)
+ tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
+ exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
+ }
+ tomcat "org.apache.tomcat:tomcat-dbcp:${tomcatVersion}"
+
+ providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
+
+ providedCompile(
+// [group: 'javax.servlet', name: 'servlet-api', version: '2.5'],
+ )
+
+ compile(
+ // [group: 'ch.vorburger.mariaDB4j', name: 'mariaDB4j', version: '2.1.3'],
+
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion],
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion],
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: springBootVersion],
+
+ [group: 'org.springframework', name: 'spring-context-support', version: springVersion],
+
+ [group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: springOauthVersion],
+
+ [group: 'javax.ws.rs', name: 'jsr311-api', version: '1.1.1'],
+ [group: 'com.sun.jersey', name: 'jersey-core', version: jerseyVersion],
+ [group: 'com.sun.jersey', name: 'jersey-servlet', version: jerseyVersion],
+ [group: 'com.sun.jersey', name: 'jersey-server', version: jerseyVersion],
+ [group: 'com.sun.jersey', name: 'jersey-json', version: jerseyVersion],
+ [group: 'com.sun.jersey.contribs', name: 'jersey-spring', version: jerseyVersion],
+ [group: 'com.sun.jersey.contribs', name: 'jersey-multipart', version: jerseyVersion],
+
+ [group: 'com.squareup.retrofit', name: 'retrofit', version: '1.6.1'],
+ [group: 'com.squareup.okhttp', name: 'okhttp', version: '2.0.0'],
+ [group: 'com.squareup.okhttp', name: 'okhttp-urlconnection', version: '2.0.0'],
+
+
+ [group: 'com.google.code.gson', name: 'gson', version: '2.2.4'],
+ [group: 'com.google.guava', name: 'guava', version: '15.0'],
+
+ [group: 'joda-time', name: 'joda-time', version: '2.4'],
+ [group: 'net.sourceforge.javacsv', name: 'javacsv', version: '2.0'],
+ [group: 'org.apache.commons', name: 'commons-email', version: '1.3.3'],
+ [group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'],
+
+ // no slf4j & logback here (anymore), as spring-boot-starter-logging already brings this now, better assembled (log4j-over-slf4j was originally forgotten here)
+
+ [group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'],
+ // [group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: tomcatVersion],
+
+
+ [group: 'org.apache.poi',name: 'poi', version: '3.9'],
+ [group: 'org.apache.poi',name: 'poi-ooxml', version: '3.9'],
+ [group: 'org.apache.poi',name: 'poi-ooxml-schemas', version: '3.9'],
+
+ [group: 'com.lowagie', name: 'itext', version: '2.1.7'],
+ [group: 'com.lowagie', name: 'itext-rtf', version: '2.1.7'],
+ [group: 'org.mnode.ical4j', name: 'ical4j', version: '1.0.4'],
+ [group: 'com.googlecode.flyway', name: 'flyway-core', version: '2.1.1'],
+ [group: 'org.quartz-scheduler', name: 'quartz', version: '2.1.7'],
+ [group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.2.1'],
+ [group: 'net.sf.ehcache', name: 'ehcache', version: '2.7.2'],
+ [group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.12'],
+ [group: 'com.jayway.jsonpath', name: 'json-path', version: '0.9.1'],
+
+ // Although fineract (at the time of writing) doesn't have any compile time dep. on this,
+ // it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility
+ [group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'],
+ // Once we've switched to Java 8 this dep can be removed.
+ [group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0']
+ )
+ testCompile 'junit:junit:4.11',
+ 'junit:junit-dep:4.11',
+ 'org.mockito:mockito-core:1.9.5',
+ 'com.jayway.restassured:rest-assured:2.3.3',
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion]
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/dev-dependencies.gradle
----------------------------------------------------------------------
diff --git a/fineract-provider/dev-dependencies.gradle b/fineract-provider/dev-dependencies.gradle
new file mode 100644
index 0000000..83039f7
--- /dev/null
+++ b/fineract-provider/dev-dependencies.gradle
@@ -0,0 +1,79 @@
+dependencies {
+ def tomcatVersion = '7.0.54'
+ tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
+ "org.apache.tomcat.embed:tomcat-embed-logging-log4j:${tomcatVersion}" // NOT tomcat-embed-logging-juli (http://stackoverflow.com/questions/23963049/classcircularityerror-java-util-logging-logrecord-running-gradle-webapp-with-ja)
+ tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
+ exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
+ }
+ tomcat "org.apache.tomcat:tomcat-dbcp:${tomcatVersion}"
+
+ providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
+
+ providedCompile(
+// [group: 'javax.servlet', name: 'servlet-api', version: '2.5'],
+ )
+
+ compile(
+ [group: 'ch.vorburger.mariaDB4j', name: 'mariaDB4j', version: '2.1.3'],
+
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion],
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion],
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: springBootVersion],
+
+ [group: 'org.springframework', name: 'spring-context-support', version: springVersion],
+ [group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: springOauthVersion],
+
+ [group: 'javax.ws.rs', name: 'jsr311-api', version: '1.1.1'],
+ [group: 'com.sun.jersey', name: 'jersey-core', version: jerseyVersion],
+ [group: 'com.sun.jersey', name: 'jersey-servlet', version: jerseyVersion],
+ [group: 'com.sun.jersey', name: 'jersey-server', version: jerseyVersion],
+ [group: 'com.sun.jersey', name: 'jersey-json', version: jerseyVersion],
+ [group: 'com.sun.jersey.contribs', name: 'jersey-spring', version: jerseyVersion],
+ [group: 'com.sun.jersey.contribs', name: 'jersey-multipart', version: jerseyVersion],
+
+ [group: 'com.squareup.retrofit', name: 'retrofit', version: '1.6.1'],
+ [group: 'com.squareup.okhttp', name: 'okhttp', version: '2.0.0'],
+ [group: 'com.squareup.okhttp', name: 'okhttp-urlconnection', version: '2.0.0'],
+
+
+ [group: 'com.google.code.gson', name: 'gson', version: '2.2.4'],
+ [group: 'com.google.guava', name: 'guava', version: '15.0'],
+
+ [group: 'joda-time', name: 'joda-time', version: '2.4'],
+ [group: 'net.sourceforge.javacsv', name: 'javacsv', version: '2.0'],
+ [group: 'org.apache.commons', name: 'commons-email', version: '1.3.3'],
+ [group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'],
+
+ // no slf4j & logback here (anymore), as spring-boot-starter-logging already brings this now, better assembled (log4j-over-slf4j was originally forgotten here)
+
+ [group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'],
+ [group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: tomcatVersion],
+
+
+ [group: 'org.apache.poi',name: 'poi', version: '3.9'],
+ [group: 'org.apache.poi',name: 'poi-ooxml', version: '3.9'],
+ [group: 'org.apache.poi',name: 'poi-ooxml-schemas', version: '3.9'],
+
+ [group: 'com.lowagie', name: 'itext', version: '2.1.7'],
+ [group: 'com.lowagie', name: 'itext-rtf', version: '2.1.7'],
+ [group: 'org.mnode.ical4j', name: 'ical4j', version: '1.0.4'],
+ [group: 'com.googlecode.flyway', name: 'flyway-core', version: '2.1.1'],
+ [group: 'org.quartz-scheduler', name: 'quartz', version: '2.1.7'],
+ [group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.2.1'],
+ [group: 'net.sf.ehcache', name: 'ehcache', version: '2.7.2'],
+ [group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.12'],
+ [group: 'com.jayway.jsonpath', name: 'json-path', version: '0.9.1'],
+
+ // Although fineract (at the time of writing) doesn't have any compile time dep. on this,
+ // it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility
+ [group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'],
+ // Once we've switched to Java 8 this dep can be removed.
+ [group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.0']
+ )
+ testCompile 'junit:junit:4.11',
+ 'junit:junit-dep:4.11',
+ 'org.mockito:mockito-core:1.9.5',
+ 'com.jayway.restassured:rest-assured:2.3.3',
+ [group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion]
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/gradle.properties
----------------------------------------------------------------------
diff --git a/fineract-provider/gradle.properties b/fineract-provider/gradle.properties
new file mode 100644
index 0000000..706f6ee
--- /dev/null
+++ b/fineract-provider/gradle.properties
@@ -0,0 +1,3 @@
+releaseVersion=16.01.2.RELEASE
+
+
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/gradlew
----------------------------------------------------------------------
diff --git a/fineract-provider/gradlew b/fineract-provider/gradlew
new file mode 100755
index 0000000..210ae59
--- /dev/null
+++ b/fineract-provider/gradlew
@@ -0,0 +1,167 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8005,server=y,suspend=n"
+
+CATALINA_OPTS="-Xms512m -Xmx2048m"
+JAVA_OPTS="-Xms512m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=512m"
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/gradlew.bat
----------------------------------------------------------------------
diff --git a/fineract-provider/gradlew.bat b/fineract-provider/gradlew.bat
new file mode 100644
index 0000000..51aaeab
--- /dev/null
+++ b/fineract-provider/gradlew.bat
@@ -0,0 +1,93 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8005,server=y,suspend=n
+
+set CATALINA_OPTS=-Xms512m -Xmx512m
+set JAVA_OPTS=-Xms512m -Xmx512m -XX:PermSize=256m -XX:MaxPermSize=512m
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/properties/basicauth/application.properties
----------------------------------------------------------------------
diff --git a/fineract-provider/properties/basicauth/application.properties b/fineract-provider/properties/basicauth/application.properties
new file mode 100644
index 0000000..adbef74
--- /dev/null
+++ b/fineract-provider/properties/basicauth/application.properties
@@ -0,0 +1,2 @@
+
+spring.profiles.default=basicauth
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/properties/oauth/application.properties
----------------------------------------------------------------------
diff --git a/fineract-provider/properties/oauth/application.properties b/fineract-provider/properties/oauth/application.properties
new file mode 100644
index 0000000..05ef979
--- /dev/null
+++ b/fineract-provider/properties/oauth/application.properties
@@ -0,0 +1,3 @@
+
+spring.profiles.default=basicauth
+spring.profiles.active=oauth
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/AccountNumberPreferencesTest.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/AccountNumberPreferencesTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/AccountNumberPreferencesTest.java
new file mode 100644
index 0000000..97c3fac
--- /dev/null
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/AccountNumberPreferencesTest.java
@@ -0,0 +1,486 @@
+/**
+ * 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.integrationtests;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.fineract.integrationtests.common.CenterDomain;
+import org.apache.fineract.integrationtests.common.CenterHelper;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.CommonConstants;
+import org.apache.fineract.integrationtests.common.GroupHelper;
+import org.apache.fineract.integrationtests.common.OfficeHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
+import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
+import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
+import org.apache.fineract.integrationtests.common.system.AccountNumberPreferencesHelper;
+import org.apache.fineract.integrationtests.common.system.CodeHelper;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.builder.ResponseSpecBuilder;
+import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.specification.RequestSpecification;
+import com.jayway.restassured.specification.ResponseSpecification;
+
+public class AccountNumberPreferencesTest {
+
+ private RequestSpecification requestSpec;
+ private ResponseSpecification responseSpec;
+ private ResponseSpecification responseValidationError;
+ private ResponseSpecification responseNotFoundError;
+ private ResponseSpecification responseForbiddenError;
+ private Integer clientId;
+ private Integer loanProductId;
+ private Integer loanId;
+ private Integer savingsProductId;
+ private Integer savingsId;
+ private final String loanPrincipalAmount = "100000.00";
+ private final String numberOfRepayments = "12";
+ private final String interestRatePerPeriod = "18";
+ private final String dateString = "4 September 2014";
+ private final String minBalanceForInterestCalculation = null;
+ private final String minRequiredBalance = null;
+ private final String enforceMinRequiredBalance = "false";
+ private LoanTransactionHelper loanTransactionHelper;
+ private SavingsAccountHelper savingsAccountHelper;
+ private AccountNumberPreferencesHelper accountNumberPreferencesHelper;
+ private Integer clientAccountNumberPreferenceId;
+ private Integer loanAccountNumberPreferenceId;
+ private Integer savingsAccountNumberPreferenceId;
+ private Integer groupsAccountNumberPreferenceId;
+ private Integer centerAccountNumberPreferenceId;
+ private final String MINIMUM_OPENING_BALANCE = "1000.0";
+ private final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
+ private Boolean isAccountPreferenceSetUp = false;
+ private Integer clientTypeCodeId;
+ private String clientCodeValueName;
+ private Integer clientCodeValueId;
+ private final String clientTypeName = "CLIENT_TYPE";
+ private final String officeName = "OFFICE_NAME";
+ private final String loanShortName = "LOAN_PRODUCT_SHORT_NAME";
+ private final String savingsShortName = "SAVINGS_PRODUCT_SHORT_NAME";
+ private Integer groupID;
+ private Integer centerId;
+ private String groupAccountNo;
+
+ @Before
+ public void setup() {
+ Utils.initializeRESTAssured();
+ this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+ this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.responseValidationError = new ResponseSpecBuilder().expectStatusCode(400).build();
+ this.responseNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build();
+ this.responseForbiddenError = new ResponseSpecBuilder().expectStatusCode(403).build();
+ this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
+ this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper(this.requestSpec, this.responseSpec);
+
+ }
+
+ @Test
+ public void testAccountNumberPreferences() {
+
+ /* Create Loan and Savings Product */
+ this.createLoanAndSavingsProduct();
+
+ /* Ensure no account number preferences are present in the system */
+ this.deleteAllAccountNumberPreferences();
+
+ /*
+ * Validate the default account number generation rules for clients,
+ * loans and savings accounts.
+ */
+ this.validateDefaultAccountNumberGeneration();
+
+ /* Create and Validate account number preferences */
+ this.createAccountNumberPreference();
+
+ /*
+ * Validate account number preference rules apply to Clients,Loans and
+ * Saving Accounts
+ */
+ this.validateAccountNumberGenerationWithPreferences();
+
+ /* Validate account number preferences Updation */
+ this.updateAccountNumberPreference();
+
+ /*
+ * Validate account number preference rules apply to Clients,Loans and
+ * Saving Accounts after Updation
+ */
+ this.validateAccountNumberGenerationWithPreferences();
+
+ /* Delete all account number preferences */
+ this.deleteAllAccountNumberPreferences();
+
+ }
+
+ private void createLoanAndSavingsProduct() {
+ this.createLoanProduct();
+ this.createSavingsProduct();
+ }
+
+ private void deleteAllAccountNumberPreferences() {
+ ArrayList<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper.getAllAccountNumberPreferences();
+ /* Deletion of valid account preference ID */
+ for (HashMap<String, Object> preferenceId : preferenceIds) {
+ Integer id = (Integer) preferenceId.get("id");
+ HashMap<String, Object> delResponse = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(id, this.responseSpec,
+ "");
+ System.out.println("Successfully deleted account number preference (ID: " + delResponse.get("resourceId") + ")");
+ }
+ /* Deletion of invalid account preference ID should fail */
+ System.out
+ .println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------");
+
+ HashMap<String, Object> deletionError = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(10,
+ this.responseNotFoundError, "");
+ Assert.assertEquals("error.msg.resource.not.found", deletionError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
+ }
+
+ private void validateDefaultAccountNumberGeneration() {
+ this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
+ this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
+ this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
+ this.createAndValidateGroup(this.isAccountPreferenceSetUp);
+ this.createAndValidateCenter(this.isAccountPreferenceSetUp);
+ }
+
+ private void validateAccountNumberGenerationWithPreferences() {
+ this.isAccountPreferenceSetUp = true;
+ this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
+ this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
+ this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
+ this.createAndValidateGroup(this.isAccountPreferenceSetUp);
+ this.createAndValidateCenter(this.isAccountPreferenceSetUp);
+ }
+
+ private void createAccountNumberPreference() {
+ this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createClientAccountNumberPreference(
+ this.responseSpec, "resourceId");
+ System.out.println("Successfully created account number preferences for Client (ID: " + this.clientAccountNumberPreferenceId);
+
+ this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createLoanAccountNumberPreference(
+ this.responseSpec, "resourceId");
+ System.out.println("Successfully created account number preferences for Loan (ID: " + this.loanAccountNumberPreferenceId);
+
+ this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createSavingsAccountNumberPreference(
+ this.responseSpec, "resourceId");
+ System.out.println("Successfully created account number preferences for Savings (ID: " + this.savingsAccountNumberPreferenceId);
+
+ this.groupsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createGroupsAccountNumberPreference(
+ this.responseSpec, "resourceId");
+ System.out.println("Successfully created account number preferences for Groups (ID: " + this.groupsAccountNumberPreferenceId);
+
+ this.centerAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createCenterAccountNumberPreference(
+ this.responseSpec, "resourceId");
+ System.out.println("Successfully created account number preferences for Center (ID: " + this.centerAccountNumberPreferenceId);
+
+ this.accountNumberPreferencesHelper.verifyCreationOfAccountNumberPreferences(this.clientAccountNumberPreferenceId,
+ this.loanAccountNumberPreferenceId, this.savingsAccountNumberPreferenceId, this.groupsAccountNumberPreferenceId,
+ this.centerAccountNumberPreferenceId, this.responseSpec, this.requestSpec);
+
+ this.createAccountNumberPreferenceInvalidData("1000", "1001");
+ this.createAccountNumberPreferenceDuplicateData("1", "101");
+
+ }
+
+ private void createAccountNumberPreferenceDuplicateData(final String accountType, final String prefixType) {
+ /* Creating account Preference with duplicate data should fail */
+ System.out
+ .println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------");
+
+ HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData(
+ this.responseForbiddenError, accountType, prefixType, "");
+
+ Assert.assertEquals("error.msg.account.number.format.duplicate.account.type",
+ creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
+
+ }
+
+ private void createAccountNumberPreferenceInvalidData(final String accountType, final String prefixType) {
+
+ /* Creating account Preference with invalid data should fail */
+ System.out
+ .println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
+
+ HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData(
+ this.responseValidationError, accountType, prefixType, "");
+
+ if (creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals(
+ "validation.msg.accountNumberFormat.accountType.is.not.within.expected.range")) {
+ Assert.assertEquals("validation.msg.accountNumberFormat.accountType.is.not.within.expected.range",
+ creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
+ } else if (creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals(
+ "validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations")) {
+ Assert.assertEquals("validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations",
+ creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
+ }
+ }
+
+ private void updateAccountNumberPreference() {
+ HashMap<String, Object> accountNumberPreferences = this.accountNumberPreferencesHelper.updateAccountNumberPreference(
+ this.clientAccountNumberPreferenceId, "101", this.responseSpec, "");
+
+ System.out.println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID "
+ + accountNumberPreferences.get("resourceId"));
+
+ this.accountNumberPreferencesHelper.verifyUpdationOfAccountNumberPreferences((Integer) accountNumberPreferences.get("resourceId"),
+ this.responseSpec, this.requestSpec);
+
+ /* Update invalid account preference id should fail */
+ System.out
+ .println("---------------------------------UPDATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
+
+ /* Invalid Account Type */
+ HashMap<String, Object> updationError = this.accountNumberPreferencesHelper.updateAccountNumberPreference(9999, "101",
+ this.responseNotFoundError, "");
+ if (updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals("error.msg.resource.not.found")) {
+ Assert.assertEquals("error.msg.resource.not.found", updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
+ }
+ /* Invalid Prefix Type */
+ HashMap<String, Object> updationError1 = this.accountNumberPreferencesHelper.updateAccountNumberPreference(
+ this.clientAccountNumberPreferenceId, "103", this.responseValidationError, "");
+
+ Assert.assertEquals("validation.msg.validation.errors.exist", updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
+
+ }
+
+ private void createAndValidateClientEntity(Boolean isAccountPreferenceSetUp) {
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ if (isAccountPreferenceSetUp) {
+ this.createAndValidateClientBasedOnAccountPreference();
+ } else {
+ this.createAndValidateClientWithoutAccountPreference();
+ }
+ }
+
+ private void createAndValidateGroup(Boolean isAccountPreferenceSetUp) {
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec);
+ GroupHelper.verifyGroupCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
+
+ this.groupID = GroupHelper.activateGroup(this.requestSpec, this.responseSpec, groupID.toString());
+ GroupHelper.verifyGroupActivatedOnServer(this.requestSpec, this.responseSpec, groupID, true);
+
+ final String GROUP_URL = "/fineract-provider/api/v1/groups/" + this.groupID + "?" + Utils.TENANT_IDENTIFIER;
+ this.groupAccountNo = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "accountNo");
+
+ if (isAccountPreferenceSetUp) {
+ String groupsPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
+ this.groupsAccountNumberPreferenceId, "prefixType.value");
+
+ if (groupsPrefixName.equals(this.officeName)) {
+
+ final String groupOfficeName = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "officeName");
+
+ this.validateAccountNumberLengthAndStartsWithPrefix(this.groupAccountNo, groupOfficeName);
+ }
+ } else {
+ validateAccountNumberLengthAndStartsWithPrefix(this.groupAccountNo, null);
+ }
+ }
+
+ private void createAndValidateCenter(Boolean isAccountPreferenceSetUp) {
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ Integer officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007");
+
+ String name = "CenterCreation" + new Timestamp(new java.util.Date().getTime());
+ this.centerId = CenterHelper.createCenter(name, officeId, requestSpec, responseSpec);
+ CenterDomain center = CenterHelper.retrieveByID(centerId, requestSpec, responseSpec);
+ Assert.assertNotNull(center);
+ Assert.assertTrue(center.getName().equals(name));
+
+ if (isAccountPreferenceSetUp) {
+ String centerPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
+ this.centerAccountNumberPreferenceId, "prefixType.value");
+ final String CENTER_URL = "/fineract-provider/api/v1/centers/" + this.centerId + "?" + Utils.TENANT_IDENTIFIER;
+
+ if (centerPrefixName.equals(this.officeName)) {
+ final String centerOfficeName = Utils.performServerGet(requestSpec, responseSpec, CENTER_URL, "officeName");
+ this.validateAccountNumberLengthAndStartsWithPrefix(center.getAccountNo(), centerOfficeName);
+ }
+ } else {
+ validateAccountNumberLengthAndStartsWithPrefix(center.getAccountNo(), null);
+ }
+ }
+
+
+ private void createAndValidateClientWithoutAccountPreference() {
+ this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
+ Assert.assertNotNull(this.clientId);
+ String clientAccountNo = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "accountNo");
+ validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, null);
+ }
+
+ private void createAndValidateClientBasedOnAccountPreference() {
+ final String codeName = "ClientType";
+ String clientAccountNo = null;
+ String clientPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
+ this.clientAccountNumberPreferenceId, "prefixType.value");
+ if (clientPrefixName.equals(this.clientTypeName)) {
+
+ /* Retrieve Code id for the Code "ClientType" */
+ HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
+ this.clientTypeCodeId = (Integer) code.get("id");
+
+ /* Retrieve/Create Code Values for the Code "ClientType" */
+ HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(this.clientTypeCodeId, this.requestSpec,
+ this.responseSpec);
+
+ this.clientCodeValueName = (String) codeValue.get("name");
+ this.clientCodeValueId = (Integer) codeValue.get("id");
+
+ /* Create Client with Client Type */
+ this.clientId = ClientHelper.createClientForAccountPreference(this.requestSpec, this.responseSpec, this.clientCodeValueId,
+ "clientId");
+
+ Assert.assertNotNull(clientId);
+
+ clientAccountNo = (String) ClientHelper.getClient(this.requestSpec, this.responseSpec, this.clientId.toString(), "accountNo");
+ this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, this.clientCodeValueName);
+
+ } else if (clientPrefixName.equals(this.officeName)) {
+ this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
+ Assert.assertNotNull(clientId);
+ clientAccountNo = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "accountNo");
+ String officeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
+ this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, officeName);
+ }
+ }
+
+ private void validateAccountNumberLengthAndStartsWithPrefix(final String accountNumber, final String prefix) {
+ if (prefix != null) {
+ Assert.assertEquals(accountNumber.length(), prefix.length() + 9);
+ Assert.assertTrue(accountNumber.startsWith(prefix));
+ } else {
+ Assert.assertEquals(accountNumber.length(), 9);
+ }
+ }
+
+ private void createLoanProduct() {
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+
+ System.out.println("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
+
+ final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
+ .withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
+ .withInterestRateFrequencyTypeAsYear().build(null);
+
+ this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
+ System.out.println("Successfully created loan product (ID: " + this.loanProductId + ")");
+ }
+
+ private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) {
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+
+ System.out.println("---------------------------------NEW LOAN APPLICATION------------------------------------------");
+
+ final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount)
+ .withLoanTermFrequency(numberOfRepayments).withLoanTermFrequencyAsMonths().withNumberOfRepayments(numberOfRepayments)
+ .withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments()
+ .withInterestCalculationPeriodTypeAsDays().withInterestRatePerPeriod(interestRatePerPeriod).withLoanTermFrequencyAsMonths()
+ .withSubmittedOnDate(dateString).withExpectedDisbursementDate(dateString).withPrincipalGrace("2").withInterestGrace("2")
+ .build(this.clientId.toString(), this.loanProductId.toString(), null);
+
+ System.out.println("Loan Application :" + loanApplicationJSON);
+
+ this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
+ String loanAccountNo = (String) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec, this.loanId,
+ "accountNo");
+
+ if (isAccountPreferenceSetUp) {
+ String loanPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
+ this.loanAccountNumberPreferenceId, "prefixType.value");
+ if (loanPrefixName.equals(this.officeName)) {
+ String loanOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
+ this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanOfficeName);
+ } else if (loanPrefixName.equals(this.loanShortName)) {
+ String loanShortName = (String) this.loanTransactionHelper.getLoanProductDetail(this.requestSpec, this.responseSpec,
+ this.loanProductId, "shortName");
+ this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanShortName);
+ }
+ System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION BASED ON ACCOUNT PREFERENCES (ID: " + this.loanId + ")");
+ } else {
+ this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, null);
+ System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION (ID: " + loanId + ")");
+ }
+ }
+
+ private void createSavingsProduct() {
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+
+ System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
+
+ SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
+
+ final String savingsProductJSON = savingsProductHelper
+ //
+ .withInterestCompoundingPeriodTypeAsDaily()
+ //
+ .withInterestPostingPeriodTypeAsMonthly()
+ //
+ .withInterestCalculationPeriodTypeAsDailyBalance()
+ //
+ .withMinBalanceForInterestCalculation(minBalanceForInterestCalculation)
+ //
+ .withMinRequiredBalance(minRequiredBalance).withEnforceMinRequiredBalance(enforceMinRequiredBalance)
+ .withMinimumOpenningBalance(this.MINIMUM_OPENING_BALANCE).build();
+ this.savingsProductId = SavingsProductHelper.createSavingsProduct(savingsProductJSON, this.requestSpec, this.responseSpec);
+ System.out.println("Sucessfully created savings product (ID: " + this.savingsProductId + ")");
+
+ }
+
+ private void createAndValidateSavingsEntity(Boolean isAccountPreferenceSetUp) {
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+
+ this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
+
+ this.savingsId = this.savingsAccountHelper
+ .applyForSavingsApplication(this.clientId, this.savingsProductId, ACCOUNT_TYPE_INDIVIDUAL);
+
+ String savingsAccountNo = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "accountNo");
+
+ if (isAccountPreferenceSetUp) {
+ String savingsPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
+ this.savingsAccountNumberPreferenceId, "prefixType.value");
+
+ if (savingsPrefixName.equals(this.officeName)) {
+ String savingsOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(),
+ "officeName");
+ this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, savingsOfficeName);
+ } else if (savingsPrefixName.equals(this.savingsShortName)) {
+ String loanShortName = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "shortName");
+ this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, loanShortName);
+ }
+ System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION BASED ON ACCOUNT PREFERENCES (ID: " + this.loanId + ")");
+ } else {
+ this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, null);
+ System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID: " + this.savingsId + ")");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/AccountTransferTest.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/AccountTransferTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/AccountTransferTest.java
new file mode 100644
index 0000000..01399c2
--- /dev/null
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/AccountTransferTest.java
@@ -0,0 +1,492 @@
+/**
+ * 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.integrationtests;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.CommonConstants;
+import org.apache.fineract.integrationtests.common.OfficeHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.integrationtests.common.accounting.Account;
+import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
+import org.apache.fineract.integrationtests.common.accounting.FinancialActivityAccountHelper;
+import org.apache.fineract.integrationtests.common.accounting.JournalEntry;
+import org.apache.fineract.integrationtests.common.accounting.JournalEntryHelper;
+import org.apache.fineract.integrationtests.common.accounting.Account.AccountType;
+import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
+import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
+import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
+import org.apache.fineract.integrationtests.common.savings.AccountTransferHelper;
+import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
+import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
+import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.builder.ResponseSpecBuilder;
+import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.specification.RequestSpecification;
+import com.jayway.restassured.specification.ResponseSpecification;
+
+/**
+ * JUnit Test Cases for Account Transfer for.
+ */
+@SuppressWarnings({ "rawtypes", "unused" })
+public class AccountTransferTest {
+
+ public static final String MINIMUM_OPENING_BALANCE = "30000.0";
+ public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
+ public static final String ACCOUNT_TRANSFER_AMOUNT = "15000.0";
+ public static final String ACCOUNT_TRANSFER_AMOUNT_ADJUST = "3000.0";
+ public static final String FROM_LOAN_ACCOUNT_TYPE = "1";
+ public static final String FROM_SAVINGS_ACCOUNT_TYPE = "2";
+ public static final String TO_LOAN_ACCOUNT_TYPE = "1";
+ public static final String TO_SAVINGS_ACCOUNT_TYPE = "2";
+
+ public static final String LOAN_APPROVAL_DATE = "01 March 2013";
+ public static final String LOAN_APPROVAL_DATE_PLUS_ONE = "02 March 2013";
+ public static final String LOAN_DISBURSAL_DATE = "01 March 2013";
+
+ private ResponseSpecification responseSpec;
+ private RequestSpecification requestSpec;
+ private SavingsAccountHelper savingsAccountHelper;
+ private AccountTransferHelper accountTransferHelper;
+ private LoanTransactionHelper loanTransactionHelper;
+ private AccountHelper accountHelper;
+ private JournalEntryHelper journalEntryHelper;
+
+ Float TRANSFER_AMOUNT = new Float(ACCOUNT_TRANSFER_AMOUNT);
+ Float TRANSFER_AMOUNT_ADJUST = new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST);
+
+ private FinancialActivityAccountHelper financialActivityAccountHelper;
+ private Integer financialActivityAccountId;
+ private Account liabilityTransferAccount;
+
+ @Before
+ public void setup() {
+ Utils.initializeRESTAssured();
+ this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
+ this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+ this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+ this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
+ this.journalEntryHelper = new JournalEntryHelper(this.requestSpec, this.responseSpec);
+ this.financialActivityAccountHelper = new FinancialActivityAccountHelper(this.requestSpec);
+
+ List<HashMap> financialActivities = this.financialActivityAccountHelper.getAllFinancialActivityAccounts(this.responseSpec);
+ if (financialActivities.isEmpty()) {
+ /** Setup liability transfer account **/
+ /** Create a Liability and an Asset Transfer Account **/
+ liabilityTransferAccount = accountHelper.createLiabilityAccount();
+ Assert.assertNotNull(liabilityTransferAccount);
+
+ /*** Create A Financial Activity to Account Mapping **/
+ financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount(
+ FinancialActivityAccountsTest.liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(),
+ responseSpec, CommonConstants.RESPONSE_RESOURCE_ID);
+ Assert.assertNotNull(financialActivityAccountId);
+ } else {
+ for (HashMap financialActivity : financialActivities) {
+ HashMap financialActivityData = (HashMap) financialActivity.get("financialActivityData");
+ if (financialActivityData.get("id").equals(FinancialActivityAccountsTest.liabilityTransferFinancialActivityId)) {
+ HashMap glAccountData = (HashMap) financialActivity.get("glAccountData");
+ liabilityTransferAccount = new Account((Integer) glAccountData.get("id"), AccountType.LIABILITY);
+ financialActivityAccountId = (Integer) financialActivity.get("id");
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Delete the Liability transfer account
+ */
+ @After
+ public void tearDown() {
+ Integer deletedFinancialActivityAccountId = financialActivityAccountHelper.deleteFinancialActivityAccount(
+ financialActivityAccountId, responseSpec, CommonConstants.RESPONSE_RESOURCE_ID);
+ Assert.assertNotNull(deletedFinancialActivityAccountId);
+ Assert.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId);
+ }
+
+ @Test
+ public void testFromSavingsToSavingsAccountTransfer() {
+ this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
+ this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec);
+
+ final Account assetAccount = this.accountHelper.createAssetAccount();
+ final Account incomeAccount = this.accountHelper.createIncomeAccount();
+ final Account expenseAccount = this.accountHelper.createExpenseAccount();
+ final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
+
+ OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec);
+ Integer toOfficeId = officeHelper.createOffice("01 January 2011");
+ Assert.assertNotNull(toOfficeId);
+
+ // Creating Savings Account to which fund to be Transferred
+ final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
+ String.valueOf(toOfficeId));
+ Assert.assertNotNull(toClientID);
+
+ final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount,
+ incomeAccount, expenseAccount, liabilityAccount);
+ Assert.assertNotNull(toSavingsProductID);
+
+ final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID,
+ ACCOUNT_TYPE_INDIVIDUAL);
+ Assert.assertNotNull(toSavingsProductID);
+
+ HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID);
+ SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap);
+
+ toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID);
+ SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap);
+
+ toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID);
+ SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap);
+
+ final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
+
+ Integer fromOfficeId = officeHelper.createOffice("01 January 2011");
+ Assert.assertNotNull(fromOfficeId);
+
+ // Creating Savings Account from which the Fund has to be Transferred
+ final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
+ String.valueOf(fromOfficeId));
+ Assert.assertNotNull(fromClientID);
+
+ final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
+ assetAccount, incomeAccount, expenseAccount, liabilityAccount);
+ Assert.assertNotNull(fromSavingsProductID);
+
+ final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
+ ACCOUNT_TYPE_INDIVIDUAL);
+ Assert.assertNotNull(fromSavingsID);
+
+ HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap);
+
+ fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap);
+
+ fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap);
+
+ final HashMap fromSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
+
+ Float fromSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
+ Float toSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
+
+ this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, fromClientID, toSavingsID, FROM_SAVINGS_ACCOUNT_TYPE,
+ TO_SAVINGS_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT);
+
+ fromSavingsBalance -= new Float(ACCOUNT_TRANSFER_AMOUNT);
+ toSavingsBalance += new Float(ACCOUNT_TRANSFER_AMOUNT);
+
+ HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
+ assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance,
+ fromSavingsSummaryAfter.get("accountBalance"));
+
+ HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
+ assertEquals("Verifying To Savings Account Balance after Account Transfer", toSavingsBalance,
+ toSavingsSummaryAfter.get("accountBalance"));
+ final JournalEntry[] office1LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT),
+ JournalEntry.TransactionType.CREDIT) };
+ final JournalEntry[] office2LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT),
+ JournalEntry.TransactionType.DEBIT) };
+
+ this.journalEntryHelper.checkJournalEntryForLiabilityAccount(fromOfficeId, liabilityTransferAccount,
+ AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office1LiabilityEntries);
+ this.journalEntryHelper.checkJournalEntryForLiabilityAccount(toOfficeId, liabilityTransferAccount,
+ AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office2LiabilityEntries);
+
+ }
+
+ @Test
+ public void testFromSavingsToLoanAccountTransfer() {
+ final Account assetAccount = this.accountHelper.createAssetAccount();
+ final Account incomeAccount = this.accountHelper.createIncomeAccount();
+ final Account expenseAccount = this.accountHelper.createExpenseAccount();
+ final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
+
+ final Account loanAssetAccount = this.accountHelper.createAssetAccount();
+ final Account loanIncomeAccount = this.accountHelper.createIncomeAccount();
+ final Account loanExpenseAccount = this.accountHelper.createExpenseAccount();
+ final Account overpaymentAccount = this.accountHelper.createLiabilityAccount();
+
+ this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
+ this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
+ this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec);
+
+ OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec);
+ Integer toOfficeId = officeHelper.createOffice("01 January 2011");
+ Assert.assertNotNull(toOfficeId);
+
+ // Creating Loan Account to which fund to be Transferred
+ final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
+ String.valueOf(toOfficeId));
+ Assert.assertNotNull(toClientID);
+
+ Account toTransferAccount = accountHelper.createLiabilityAccount();
+ Assert.assertNotNull(toTransferAccount);
+
+ final Integer toLoanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount);
+ Assert.assertNotNull(toLoanProductID);
+
+ final Integer toLoanID = applyForLoanApplication(toClientID, toLoanProductID);
+ Assert.assertNotNull(toLoanID);
+
+ HashMap toLoanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, toLoanID);
+ LoanStatusChecker.verifyLoanIsPending(toLoanStatusHashMap);
+
+ toLoanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, toLoanID);
+ LoanStatusChecker.verifyLoanIsApproved(toLoanStatusHashMap);
+
+ toLoanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSAL_DATE, toLoanID);
+ LoanStatusChecker.verifyLoanIsActive(toLoanStatusHashMap);
+
+ Integer fromOfficeId = officeHelper.createOffice("01 January 2011");
+ Assert.assertNotNull(fromOfficeId);
+
+ // Creating Savings Account from which the Fund has to be Transferred
+ final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
+ String.valueOf(fromOfficeId));
+ Assert.assertNotNull(fromClientID);
+
+ final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
+ assetAccount, incomeAccount, expenseAccount, liabilityAccount);
+ Assert.assertNotNull(fromSavingsProductID);
+
+ final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
+ ACCOUNT_TYPE_INDIVIDUAL);
+ Assert.assertNotNull(fromSavingsID);
+
+ HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap);
+
+ fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap);
+
+ fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap);
+
+ final HashMap fromSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
+
+ Float fromSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
+
+ this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, toClientID, toLoanID, FROM_SAVINGS_ACCOUNT_TYPE,
+ TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT_ADJUST);
+
+ fromSavingsBalance -= TRANSFER_AMOUNT_ADJUST;
+
+ HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
+ assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance,
+ fromSavingsSummaryAfter.get("accountBalance"));
+
+ HashMap toLoanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, toLoanID);
+ assertEquals("Verifying To Loan Repayment Amount after Account Transfer", TRANSFER_AMOUNT_ADJUST,
+ toLoanSummaryAfter.get("totalRepayment"));
+
+ final JournalEntry[] office1LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST),
+ JournalEntry.TransactionType.CREDIT) };
+ final JournalEntry[] office2LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST),
+ JournalEntry.TransactionType.DEBIT) };
+
+ this.journalEntryHelper.checkJournalEntryForLiabilityAccount(fromOfficeId, liabilityTransferAccount,
+ AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office1LiabilityEntries);
+ this.journalEntryHelper.checkJournalEntryForLiabilityAccount(toOfficeId, liabilityTransferAccount,
+ AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office2LiabilityEntries);
+ }
+
+ @Test
+ public void testFromLoanToSavingsAccountTransfer() {
+ final Account assetAccount = this.accountHelper.createAssetAccount();
+ final Account incomeAccount = this.accountHelper.createIncomeAccount();
+ final Account expenseAccount = this.accountHelper.createExpenseAccount();
+ final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
+
+ final Account loanAssetAccount = this.accountHelper.createAssetAccount();
+ final Account loanIncomeAccount = this.accountHelper.createIncomeAccount();
+ final Account loanExpenseAccount = this.accountHelper.createExpenseAccount();
+ final Account overpaymentAccount = this.accountHelper.createLiabilityAccount();
+
+ this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
+ this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
+ this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec);
+
+ OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec);
+ Integer toOfficeId = officeHelper.createOffice("01 January 2011");
+ Assert.assertNotNull(toOfficeId);
+
+ // Creating Loan Account to which fund to be Transferred
+ final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
+ String.valueOf(toOfficeId));
+ Assert.assertNotNull(toClientID);
+
+ final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount,
+ incomeAccount, expenseAccount, liabilityAccount);
+ Assert.assertNotNull(toSavingsProductID);
+
+ final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID,
+ ACCOUNT_TYPE_INDIVIDUAL);
+ Assert.assertNotNull(toSavingsID);
+
+ HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID);
+ SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap);
+
+ toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID);
+ SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap);
+
+ toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID);
+ SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap);
+
+ Integer fromOfficeId = officeHelper.createOffice("01 January 2011");
+ Assert.assertNotNull(fromOfficeId);
+
+ // Creating Savings Account from which the Fund has to be Transferred
+ final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
+ String.valueOf(fromOfficeId));
+ Assert.assertNotNull(fromClientID);
+
+ final Integer loanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount);
+ Assert.assertNotNull(loanProductID);
+
+ final Integer loanID = applyForLoanApplication(fromClientID, loanProductID);
+ Assert.assertNotNull(loanID);
+
+ HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
+ LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
+
+ loanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, loanID);
+ LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
+
+ loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSAL_DATE, loanID);
+ LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
+
+ final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
+ assetAccount, incomeAccount, expenseAccount, liabilityAccount);
+ Assert.assertNotNull(fromSavingsProductID);
+
+ final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
+ ACCOUNT_TYPE_INDIVIDUAL);
+ Assert.assertNotNull(fromSavingsID);
+
+ HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap);
+
+ fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap);
+
+ fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID);
+ SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap);
+
+ final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
+
+ Float fromSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
+
+ this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, fromClientID, loanID, FROM_SAVINGS_ACCOUNT_TYPE,
+ TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT);
+
+ fromSavingsBalance -= TRANSFER_AMOUNT;
+
+ HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
+
+ // Verifying fromSavings Account Balance after Account Transfer
+ assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance,
+ fromSavingsSummaryAfter.get("accountBalance"));
+
+ Float toSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
+
+ this.accountTransferHelper.accountTransfer(fromClientID, loanID, toClientID, toSavingsID, FROM_LOAN_ACCOUNT_TYPE,
+ TO_SAVINGS_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT_ADJUST);
+
+ toSavingsBalance += TRANSFER_AMOUNT_ADJUST;
+
+ HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
+
+ // Verifying toSavings Account Balance after Account Transfer
+ assertEquals("Verifying From Savings Account Balance after Account Transfer", toSavingsBalance,
+ toSavingsSummaryAfter.get("accountBalance"));
+
+ final JournalEntry[] office1LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST),
+ JournalEntry.TransactionType.CREDIT) };
+ final JournalEntry[] office2LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST),
+ JournalEntry.TransactionType.DEBIT) };
+
+ this.journalEntryHelper.checkJournalEntryForLiabilityAccount(fromOfficeId, liabilityTransferAccount,
+ AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office1LiabilityEntries);
+ this.journalEntryHelper.checkJournalEntryForLiabilityAccount(toOfficeId, liabilityTransferAccount,
+ AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office2LiabilityEntries);
+
+ }
+
+ private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
+ final String minOpenningBalance, final Account... accounts) {
+ System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
+ SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
+ final String savingsProductJSON = savingsProductHelper //
+ .withInterestCompoundingPeriodTypeAsDaily() //
+ .withInterestPostingPeriodTypeAsMonthly() //
+ .withInterestCalculationPeriodTypeAsDailyBalance() //
+ .withMinimumOpenningBalance(minOpenningBalance).withAccountingRuleAsCashBased(accounts).build();
+ return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
+ }
+
+ private Integer createLoanProduct(final Account... accounts) {
+ System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
+ final String loanProductJSON = new LoanProductTestBuilder() //
+ .withPrincipal("8,000.00") //
+ .withNumberOfRepayments("4") //
+ .withRepaymentAfterEvery("1") //
+ .withRepaymentTypeAsMonth() //
+ .withinterestRatePerPeriod("1") //
+ .withInterestRateFrequencyTypeAsMonths() //
+ .withAmortizationTypeAsEqualInstallments() //
+ .withInterestTypeAsDecliningBalance() //
+ .withAccountingRuleAsCashBased(accounts)//
+ .build(null);
+ return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
+ }
+
+ private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
+ System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
+ final String loanApplicationJSON = new LoanApplicationTestBuilder() //
+ .withPrincipal("8,000.00") //
+ .withLoanTermFrequency("4") //
+ .withLoanTermFrequencyAsMonths() //
+ .withNumberOfRepayments("4") //
+ .withRepaymentEveryAfter("1") //
+ .withRepaymentFrequencyTypeAsMonths() //
+ .withInterestRatePerPeriod("2") //
+ .withAmortizationTypeAsEqualInstallments() //
+ .withInterestTypeAsDecliningBalance() //
+ .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
+ .withExpectedDisbursementDate("10 January 2013") //
+ .withSubmittedOnDate("10 January 2013") //
+ .build(clientID.toString(), loanProductID.toString(), null);
+ return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
+ }
+}
\ No newline at end of file