killbill-memoizeit

Details

diff --git a/api/src/main/java/com/ning/billing/config/PaymentConfig.java b/api/src/main/java/com/ning/billing/config/PaymentConfig.java
index efd012e..edabb71 100644
--- a/api/src/main/java/com/ning/billing/config/PaymentConfig.java
+++ b/api/src/main/java/com/ning/billing/config/PaymentConfig.java
@@ -53,4 +53,7 @@ public interface PaymentConfig extends NotificationConfig, KillbillConfig {
     @Default("false")
     public boolean isNotificationProcessingOff();
 
+    @Config("killbill.payment.off")
+    @Default("false")
+    public boolean isPaymentOff();
 }
diff --git a/api/src/main/java/com/ning/billing/payment/api/PaymentStatus.java b/api/src/main/java/com/ning/billing/payment/api/PaymentStatus.java
index cb27428..91a33f7 100644
--- a/api/src/main/java/com/ning/billing/payment/api/PaymentStatus.java
+++ b/api/src/main/java/com/ning/billing/payment/api/PaymentStatus.java
@@ -30,5 +30,7 @@ public enum PaymentStatus {
     /* Exception from plugin, state is unknown and needs to be retried */
     PLUGIN_FAILURE,
     /* Exception from plugin, we already retried a maximum of time */
-    PLUGIN_FAILURE_ABORTED
+    PLUGIN_FAILURE_ABORTED,
+    /* Payment Subsystem is off */
+    PAYMENT_SYSTEM_OFF
 }
diff --git a/entitlement/src/test/resources/localtest.xml b/entitlement/src/test/resources/localtest.xml
new file mode 100644
index 0000000..61b4a0e
--- /dev/null
+++ b/entitlement/src/test/resources/localtest.xml
@@ -0,0 +1,39 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+  
+<suite name="Suite1" verbose="1" >
+  <test name="Changes">
+    <groups>
+      <run>
+        <exclude name="slow"/>
+        <include name="fast"/>
+      </run>
+    </groups>
+    <classes>
+      <class name="com.ning.billing.entitlement.api.user.TestUserApiChangePlanMemory"/>
+    </classes>
+  </test>
+  <test name="Cancel">
+    <groups>
+      <run>
+        <exclude name="slow"/>
+        <include name="fast"/>
+      </run>
+    </groups>
+    <classes>
+      <class name="com.ning.billing.entitlement.api.user.TestUserApiCancelMemory"/>
+    </classes>
+  </test>
+  <test name="Create">
+    <groups>
+      <run>
+        <exclude name="slow"/>
+        <include name="fast"/>
+      </run>
+    </groups>
+    <classes>
+      <class name="com.ning.billing.entitlement.api.user.TestUserApiCreateMemory"/>
+    </classes>
+  </test>
+</suite>
+
+
diff --git a/entitlement/src/test/resources/testng-default.xml b/entitlement/src/test/resources/testng-default.xml
new file mode 100644
index 0000000..ccc953f
--- /dev/null
+++ b/entitlement/src/test/resources/testng-default.xml
@@ -0,0 +1,28 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+  
+<suite name="Suite1" verbose="1" >
+  <test name="Cancel">
+    <groups>
+      <run>
+        <exclude name="slow"/>
+        <include name="fast"/>
+      </run>
+    </groups>
+    <classes>
+      <class name="com.ning.billing.entitlement.api.user.TestUserApiCancelMemory"/>
+    </classes>
+  </test>
+  <test name="Create">
+    <groups>
+      <run>
+        <exclude name="slow"/>
+        <include name="fast"/>
+      </run>
+    </groups>
+    <classes>
+      <class name="com.ning.billing.entitlement.api.user.TestUserApiCreateMemory"/>
+    </classes>
+  </test>
+</suite>
+
+
diff --git a/entitlement/src/test/resources/testng-localtest.xml b/entitlement/src/test/resources/testng-localtest.xml
new file mode 100644
index 0000000..b3a46cd
--- /dev/null
+++ b/entitlement/src/test/resources/testng-localtest.xml
@@ -0,0 +1,17 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+  
+<suite name="Suite1" verbose="1" >
+  <test name="Changes">
+    <groups>
+      <run>
+        <exclude name="slow"/>
+        <include name="fast"/>
+      </run>
+    </groups>
+    <classes>
+      <class name="com.ning.billing.entitlement.api.user.TestUserApiChangePlanMemory"/>
+    </classes>
+  </test>
+</suite>
+
+
diff --git a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
index 3a861c1..71d5554 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
@@ -40,6 +40,7 @@ import com.ning.billing.ErrorCode;
 import com.ning.billing.account.api.Account;
 import com.ning.billing.account.api.AccountApiException;
 import com.ning.billing.account.api.AccountUserApi;
+import com.ning.billing.config.PaymentConfig;
 import com.ning.billing.invoice.api.Invoice;
 import com.ning.billing.invoice.api.InvoicePaymentApi;
 import com.ning.billing.payment.api.DefaultPayment;
@@ -88,6 +89,8 @@ public class PaymentProcessor extends ProcessorBase {
     private final CallContextFactory factory;
     private final Clock clock;
 
+    private final PaymentConfig paymentConfig;
+
     private final PluginDispatcher<Payment> paymentPluginDispatcher;
     private final PluginDispatcher<Void> voidPluginDispatcher;
 
@@ -106,6 +109,7 @@ public class PaymentProcessor extends ProcessorBase {
                             final Bus eventBus,
                             final Clock clock,
                             final GlobalLocker locker,
+                            final PaymentConfig paymentConfig,
                             @Named(PLUGIN_EXECUTOR_NAMED) final ExecutorService executor,
                             final CallContextFactory factory) {
         super(pluginRegistry, accountUserApi, eventBus, paymentDao, tagUserApi, locker, executor);
@@ -116,6 +120,7 @@ public class PaymentProcessor extends ProcessorBase {
         this.autoPayoffRetryService = autoPayoffRetryService;
         this.clock = clock;
         this.factory = factory;
+        this.paymentConfig = paymentConfig;
         this.paymentPluginDispatcher = new PluginDispatcher<Payment>(executor);
         this.voidPluginDispatcher = new PluginDispatcher<Void>(executor);
     }
@@ -401,9 +406,15 @@ public class PaymentProcessor extends ProcessorBase {
     private Payment processPaymentWithAccountLocked(final PaymentPluginApi plugin, final Account account, final Invoice invoice,
             final PaymentModelDao paymentInput, final PaymentAttemptModelDao attemptInput, final boolean isInstantPayment, final CallContext context) throws PaymentApiException {
 
-        BusEvent event = null;
-        List<PaymentAttemptModelDao> allAttempts = null;
         PaymentModelDao payment = null;
+        List<PaymentAttemptModelDao> allAttempts = null;
+        if (paymentConfig.isPaymentOff()) {
+            paymentDao.updateStatusForPaymentWithAttempt(paymentInput.getId(), PaymentStatus.PAYMENT_SYSTEM_OFF, null, null, null, null, attemptInput.getId(), context);
+            allAttempts = paymentDao.getAttemptsForPayment(paymentInput.getId());
+            return new DefaultPayment(payment, allAttempts, Collections.<RefundModelDao>emptyList());
+        }
+
+        BusEvent event = null;
         PaymentStatus paymentStatus;
         try {
 

tmp/db-helper 157(+157 -0)

diff --git a/tmp/db-helper b/tmp/db-helper
new file mode 100755
index 0000000..1d4a5b9
--- /dev/null
+++ b/tmp/db-helper
@@ -0,0 +1,157 @@
+#! /usr/bin/env bash
+
+
+###################################################################################
+#                                                                                 #
+#                   Copyright 2010-2011 Ning, Inc.                                #
+#                                                                                 #
+#      Ning 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.                                                         #
+#                                                                                 #
+###################################################################################
+
+#set -x 
+
+HERE=`cd \`dirname $0\`; pwd`
+TOP=$HERE/..
+
+POM="$TOP/pom.xml"
+
+ACTION=
+DATABASE="killbill"
+USER="root"
+PWD="root"
+TEST_ALSO=
+
+DDL_FILE=
+CLEAN_FILE=
+
+function usage() {
+    echo -n "./db_helper "
+    echo -n " -a <create|clean>"
+    echo -n " -d database_name (default = killbill)"    
+    echo -n " -u user_name (default = root)"
+    echo -n " -p password (default = root)"
+    echo -n " -t (also include test ddl)"
+    echo -n "-h this message"
+    echo
+    exit 1
+}
+
+function get_modules() {
+    local modules=`grep module $POM  | grep -v modules | cut -d '>' -f 2 | cut -d '<' -f 1`
+    echo $modules
+}
+
+function find_test_ddl() {
+
+    local modules=`get_modules`
+    local ddl_test=
+    
+    local cur_ddl=
+    for m in $modules; do
+        cur_ddl=`find $m/src/test/resources/ -name ddl_test.sql 2>/dev/null`
+        ddl_test="$ddl_test $cur_ddl"
+    done
+    echo "$ddl_test"
+    
+}
+function find_src_ddl() {
+    
+    local modules=`get_modules`
+    local ddl_src=
+    
+    local cur_ddl=
+    for m in $modules; do
+        cur_ddl=`find $m/src/main/resources/ -name ddl.sql 2>/dev/null`
+        ddl_src="$ddl_src $cur_ddl"
+    done
+    echo "$ddl_src"
+}
+
+
+function create_clean_file() {
+    local ddl_file=$1
+    local tables=`cat $ddl_file | grep -i "create table" | awk ' { print $3 } '` 
+
+    local tmp="/tmp/clean-$DATABASE.$$" 
+    echo "use $DATABASE;" >> $tmp
+    echo "" >> $tmp
+    for t in $tables; do
+        echo "truncate $t;" >> $tmp
+    done
+    echo $tmp
+}
+
+function create_ddl_file() {
+    local ddls=`find_src_ddl`
+    local test_ddls=
+    if [ ! -z $TEST_ALSO ]; then
+        test_ddls=`find_test_ddl`
+        ddls="$ddls $test_ddls"
+    fi
+
+    local tmp="/tmp/ddl-$DATABASE.$$"
+    touch $tmp
+    echo "use $DATABASE;" >> $tmp
+    echo "" >> $tmp
+    for d in $ddls; do
+        cat $d >> $tmp
+        echo "" >> $tmp
+    done
+    echo $tmp
+}
+
+function cleanup() {
+    rm -f "/tmp/*.$$"
+}
+
+
+while getopts ":a:d:u:pt" options; do
+  case $options in
+    a ) ACTION=$OPTARG;;
+	d ) DATABASE=$OPTARG;;
+	u ) USER=$OPTARG;;
+	p ) PWD=$OPTARG;;
+	t ) TEST_ALSO=1;;
+    h ) usage;;
+    * ) usage;;
+  esac
+done
+
+
+
+if [ -z $ACTION ]; then
+    echo "Need to specify an action <CREATE|CLEAN>"
+    usage
+fi
+
+
+if [ $ACTION == "dump" ]; then
+    DDL_FILE=`create_ddl_file`
+    cat $DDL_FILE
+fi
+
+if [ $ACTION == "create" ]; then
+    DDL_FILE=`create_ddl_file`
+    echo "Applying new schema $tmp to database $DATABASE"    
+    mysql -u $USER --password=$PWD < $DDL_FILE
+fi
+
+if [ $ACTION == "clean" ]; then
+    DDL_FILE=`create_ddl_file` 
+    CLEAN_FILE=`create_clean_file $DDL_FILE`   
+    echo "Cleaning db tables on database $DATABASE"
+    mysql -u $USER --password=$PWD < $DDL_FILE
+fi
+
+cleanup