killbill-memoizeit
Changes
payment/pom.xml 1(+1 -0)
Details
payment/pom.xml 1(+1 -0)
diff --git a/payment/pom.xml b/payment/pom.xml
index 6debb70..ee99669 100644
--- a/payment/pom.xml
+++ b/payment/pom.xml
@@ -170,6 +170,7 @@
<dependency>
<groupId>org.kill-bill.commons</groupId>
<artifactId>killbill-xmlloader</artifactId>
+ <version>0.2.29-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
diff --git a/payment/src/main/java/org/killbill/billing/payment/glue/PaymentModule.java b/payment/src/main/java/org/killbill/billing/payment/glue/PaymentModule.java
index 72741f9..7bcf32e 100644
--- a/payment/src/main/java/org/killbill/billing/payment/glue/PaymentModule.java
+++ b/payment/src/main/java/org/killbill/billing/payment/glue/PaymentModule.java
@@ -60,6 +60,7 @@ import org.killbill.commons.concurrent.WithProfilingThreadPoolExecutor;
import org.killbill.xmlloader.XMLLoader;
import org.skife.config.ConfigurationObjectFactory;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.io.Resources;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
@@ -76,6 +77,11 @@ public class PaymentModule extends KillBillModule {
public static final String STATE_MACHINE_RETRY = "RetryStateMachine";
public static final String STATE_MACHINE_PAYMENT = "PaymentStateMachine";
+ @VisibleForTesting
+ static final String DEFAULT_STATE_MACHINE_RETRY_XML = "org/killbill/billing/payment/retry/RetryStates.xml";
+ @VisibleForTesting
+ static final String DEFAULT_STATE_MACHINE_PAYMENT_XML = "org/killbill/billing/payment/PaymentStates.xml";
+
public PaymentModule(final KillbillConfigSource configSource) {
super(configSource);
}
@@ -106,11 +112,11 @@ public class PaymentModule extends KillBillModule {
protected void installStateMachines() {
- bind(StateMachineProvider.class).annotatedWith(Names.named(STATE_MACHINE_RETRY)).toInstance(new StateMachineProvider("org/killbill/billing/payment/retry/RetryStates.xml"));
+ bind(StateMachineProvider.class).annotatedWith(Names.named(STATE_MACHINE_RETRY)).toInstance(new StateMachineProvider(DEFAULT_STATE_MACHINE_RETRY_XML));
bind(StateMachineConfig.class).annotatedWith(Names.named(STATE_MACHINE_RETRY)).toProvider(Key.get(StateMachineProvider.class, Names.named(STATE_MACHINE_RETRY)));
bind(RetryStateMachineHelper.class).asEagerSingleton();
- bind(StateMachineProvider.class).annotatedWith(Names.named(STATE_MACHINE_PAYMENT)).toInstance(new StateMachineProvider("org/killbill/billing/payment/PaymentStates.xml"));
+ bind(StateMachineProvider.class).annotatedWith(Names.named(STATE_MACHINE_PAYMENT)).toInstance(new StateMachineProvider(DEFAULT_STATE_MACHINE_PAYMENT_XML));
bind(StateMachineConfig.class).annotatedWith(Names.named(STATE_MACHINE_PAYMENT)).toProvider(Key.get(StateMachineProvider.class, Names.named(STATE_MACHINE_PAYMENT)));
bind(PaymentStateMachineHelper.class).asEagerSingleton();
}
diff --git a/payment/src/test/java/org/killbill/billing/payment/glue/TestStateMachineProvider.java b/payment/src/test/java/org/killbill/billing/payment/glue/TestStateMachineProvider.java
new file mode 100644
index 0000000..7ab6922
--- /dev/null
+++ b/payment/src/test/java/org/killbill/billing/payment/glue/TestStateMachineProvider.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2014 Groupon, Inc
+ * Copyright 2014 The Billing Project, LLC
+ *
+ * The Billing Project 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.killbill.billing.payment.glue;
+
+import org.killbill.automaton.StateMachineConfig;
+import org.killbill.billing.payment.PaymentTestSuiteNoDB;
+import org.killbill.billing.payment.glue.PaymentModule.StateMachineProvider;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestStateMachineProvider extends PaymentTestSuiteNoDB {
+
+ @Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/226")
+ public void testStateMachineProvider() throws Exception {
+ final StateMachineProvider retryStateMachineProvider = new StateMachineProvider(PaymentModule.DEFAULT_STATE_MACHINE_RETRY_XML);
+ final StateMachineConfig retryStateMachineConfig = retryStateMachineProvider.get();
+ Assert.assertEquals(retryStateMachineConfig.getStateMachines().length, 1);
+
+ final StateMachineProvider paymentStateMachineProvider = new StateMachineProvider(PaymentModule.DEFAULT_STATE_MACHINE_PAYMENT_XML);
+ final StateMachineConfig paymentStateMachineConfig = paymentStateMachineProvider.get();
+ Assert.assertEquals(paymentStateMachineConfig.getStateMachines().length, 8);
+ }
+}
diff --git a/util/src/test/java/org/killbill/billing/util/dao/TestStringTemplateInheritance.java b/util/src/test/java/org/killbill/billing/util/dao/TestStringTemplateInheritance.java
index 55ca1d9..149d852 100644
--- a/util/src/test/java/org/killbill/billing/util/dao/TestStringTemplateInheritance.java
+++ b/util/src/test/java/org/killbill/billing/util/dao/TestStringTemplateInheritance.java
@@ -18,15 +18,15 @@ package org.killbill.billing.util.dao;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.regex.Pattern;
import org.antlr.stringtemplate.StringTemplateGroup;
+import org.killbill.billing.util.UtilTestSuiteNoDB;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.killbill.billing.util.UtilTestSuiteNoDB;
-
import com.google.common.collect.ImmutableMap;
public class TestStringTemplateInheritance extends UtilTestSuiteNoDB {
@@ -66,127 +66,131 @@ public class TestStringTemplateInheritance extends UtilTestSuiteNoDB {
Assert.assertEquals(kombucha.getInstanceOf("isIsTimeForKombucha").toString(), "select hour(current_timestamp()) = 17 as is_time;");
// Verify inherited templates
- Assert.assertEquals(kombucha.getInstanceOf("getById").toString(), "select\n" +
- " t.record_id\n" +
- ", t.id\n" +
- ", t.tea\n" +
- ", t.mushroom\n" +
- ", t.sugar\n" +
- ", t.account_record_id\n" +
- ", t.tenant_record_id\n" +
- "from kombucha t\n" +
- "where t.id = :id\n" +
- "and t.tenant_record_id = :tenantRecordId\n" +
+ assertPattern(kombucha.getInstanceOf("getById").toString(), "select\r?\n" +
+ " t.record_id\r?\n" +
+ ", t.id\r?\n" +
+ ", t.tea\r?\n" +
+ ", t.mushroom\r?\n" +
+ ", t.sugar\r?\n" +
+ ", t.account_record_id\r?\n" +
+ ", t.tenant_record_id\r?\n" +
+ "from kombucha t\r?\n" +
+ "where t.id = :id\r?\n" +
+ "and t.tenant_record_id = :tenantRecordId\r?\n" +
+ ";");
+ assertPattern(kombucha.getInstanceOf("getByRecordId").toString(), "select\r?\n" +
+ " t.record_id\r?\n" +
+ ", t.id\r?\n" +
+ ", t.tea\r?\n" +
+ ", t.mushroom\r?\n" +
+ ", t.sugar\r?\n" +
+ ", t.account_record_id\r?\n" +
+ ", t.tenant_record_id\r?\n" +
+ "from kombucha t\r?\n" +
+ "where t.record_id = :recordId\r?\n" +
+ "and t.tenant_record_id = :tenantRecordId\r?\n" +
";");
- Assert.assertEquals(kombucha.getInstanceOf("getByRecordId").toString(), "select\n" +
- " t.record_id\n" +
- ", t.id\n" +
- ", t.tea\n" +
- ", t.mushroom\n" +
- ", t.sugar\n" +
- ", t.account_record_id\n" +
- ", t.tenant_record_id\n" +
- "from kombucha t\n" +
- "where t.record_id = :recordId\n" +
- "and t.tenant_record_id = :tenantRecordId\n" +
- ";");
- Assert.assertEquals(kombucha.getInstanceOf("getRecordId").toString(), "select\n" +
- " t.record_id\n" +
- "from kombucha t\n" +
- "where t.id = :id\n" +
- "and t.tenant_record_id = :tenantRecordId\n" +
- ";");
- Assert.assertEquals(kombucha.getInstanceOf("getHistoryRecordId").toString(), "select\n" +
- " max(t.record_id)\n" +
- "from kombucha_history t\n" +
- "where t.target_record_id = :targetRecordId\n" +
- "and t.tenant_record_id = :tenantRecordId\n" +
- ";");
- Assert.assertEquals(kombucha.getInstanceOf("getAll").toString(), "select\n" +
- " t.record_id\n" +
- ", t.id\n" +
- ", t.tea\n" +
- ", t.mushroom\n" +
- ", t.sugar\n" +
- ", t.account_record_id\n" +
- ", t.tenant_record_id\n" +
- "from kombucha t\n" +
- "where t.tenant_record_id = :tenantRecordId\n" +
- "order by t.record_id ASC\n" +
- ";");
- Assert.assertEquals(kombucha.getInstanceOf("get", ImmutableMap.<String, String>of("orderBy", "record_id", "offset", "3", "rowCount", "12")).toString(), "select\n" +
- " t.record_id\n" +
- ", t.id\n" +
- ", t.tea\n" +
- ", t.mushroom\n" +
- ", t.sugar\n" +
- ", t.account_record_id\n" +
- ", t.tenant_record_id\n" +
- "from kombucha t\n" +
- "where t.tenant_record_id = :tenantRecordId\n" +
- "order by t.record_id\n" +
- "limit :offset, :rowCount\n" +
- ";");
- Assert.assertEquals(kombucha.getInstanceOf("test").toString(), "select\n" +
- " t.record_id\n" +
- ", t.id\n" +
- ", t.tea\n" +
- ", t.mushroom\n" +
- ", t.sugar\n" +
- ", t.account_record_id\n" +
- ", t.tenant_record_id\n" +
- "from kombucha t\n" +
- "where t.tenant_record_id = :tenantRecordId\n" +
- "limit 1\n" +
- ";");
- Assert.assertEquals(kombucha.getInstanceOf("addHistoryFromTransaction").toString(), "insert into kombucha_history (\n" +
- " id\n" +
- ", target_record_id\n" +
- ", change_type\n" +
- ", tea\n" +
- ", mushroom\n" +
- ", sugar\n" +
- ", account_record_id\n" +
- ", tenant_record_id\n" +
- ")\n" +
- "values (\n" +
- " :id\n" +
- ", :targetRecordId\n" +
- ", :changeType\n" +
- ", :tea\n" +
- ", :mushroom\n" +
- ", :sugar\n" +
- ", :accountRecordId\n" +
- ", :tenantRecordId\n" +
- ")\n" +
- ";");
+ assertPattern(kombucha.getInstanceOf("getRecordId").toString(), "select\r?\n" +
+ " t.record_id\r?\n" +
+ "from kombucha t\r?\n" +
+ "where t.id = :id\r?\n" +
+ "and t.tenant_record_id = :tenantRecordId\r?\n" +
+ ";");
+ assertPattern(kombucha.getInstanceOf("getHistoryRecordId").toString(), "select\r?\n" +
+ " max\\(t.record_id\\)\r?\n" +
+ "from kombucha_history t\r?\n" +
+ "where t.target_record_id = :targetRecordId\r?\n" +
+ "and t.tenant_record_id = :tenantRecordId\r?\n" +
+ ";");
+ assertPattern(kombucha.getInstanceOf("getAll").toString(), "select\r?\n" +
+ " t.record_id\r?\n" +
+ ", t.id\r?\n" +
+ ", t.tea\r?\n" +
+ ", t.mushroom\r?\n" +
+ ", t.sugar\r?\n" +
+ ", t.account_record_id\r?\n" +
+ ", t.tenant_record_id\r?\n" +
+ "from kombucha t\r?\n" +
+ "where t.tenant_record_id = :tenantRecordId\r?\n" +
+ "order by t.record_id ASC\r?\n" +
+ ";");
+ assertPattern(kombucha.getInstanceOf("get", ImmutableMap.<String, String>of("orderBy", "record_id", "offset", "3", "rowCount", "12")).toString(), "select\r?\n" +
+ " t.record_id\r?\n" +
+ ", t.id\r?\n" +
+ ", t.tea\r?\n" +
+ ", t.mushroom\r?\n" +
+ ", t.sugar\r?\n" +
+ ", t.account_record_id\r?\n" +
+ ", t.tenant_record_id\r?\n" +
+ "from kombucha t\r?\n" +
+ "where t.tenant_record_id = :tenantRecordId\r?\n" +
+ "order by t.record_id\r?\n" +
+ "limit :offset, :rowCount\r?\n" +
+ ";");
+ assertPattern(kombucha.getInstanceOf("test").toString(), "select\r?\n" +
+ " t.record_id\r?\n" +
+ ", t.id\r?\n" +
+ ", t.tea\r?\n" +
+ ", t.mushroom\r?\n" +
+ ", t.sugar\r?\n" +
+ ", t.account_record_id\r?\n" +
+ ", t.tenant_record_id\r?\n" +
+ "from kombucha t\r?\n" +
+ "where t.tenant_record_id = :tenantRecordId\r?\n" +
+ "limit 1\r?\n" +
+ ";");
+ assertPattern(kombucha.getInstanceOf("addHistoryFromTransaction").toString(), "insert into kombucha_history \\(\r?\n" +
+ " id\r?\n" +
+ ", target_record_id\r?\n" +
+ ", change_type\r?\n" +
+ ", tea\r?\n" +
+ ", mushroom\r?\n" +
+ ", sugar\r?\n" +
+ ", account_record_id\r?\n" +
+ ", tenant_record_id\r?\n" +
+ "\\)\r?\n" +
+ "values \\(\r?\n" +
+ " :id\r?\n" +
+ ", :targetRecordId\r?\n" +
+ ", :changeType\r?\n" +
+ ", :tea\r?\n" +
+ ", :mushroom\r?\n" +
+ ", :sugar\r?\n" +
+ ", :accountRecordId\r?\n" +
+ ", :tenantRecordId\r?\n" +
+ "\\)\r?\n" +
+ ";");
+
+ assertPattern(kombucha.getInstanceOf("insertAuditFromTransaction").toString(), "insert into audit_log \\(\r?\n" +
+ "id\r?\n" +
+ ", table_name\r?\n" +
+ ", target_record_id\r?\n" +
+ ", change_type\r?\n" +
+ ", created_by\r?\n" +
+ ", reason_code\r?\n" +
+ ", comments\r?\n" +
+ ", user_token\r?\n" +
+ ", created_date\r?\n" +
+ ", account_record_id\r?\n" +
+ ", tenant_record_id\r?\n" +
+ "\\)\r?\n" +
+ "values \\(\r?\n" +
+ " :id\r?\n" +
+ ", :tableName\r?\n" +
+ ", :targetRecordId\r?\n" +
+ ", :changeType\r?\n" +
+ ", :createdBy\r?\n" +
+ ", :reasonCode\r?\n" +
+ ", :comments\r?\n" +
+ ", :userToken\r?\n" +
+ ", :createdDate\r?\n" +
+ ", :accountRecordId\r?\n" +
+ ", :tenantRecordId\r?\n" +
+ "\\)\r?\n" +
+ ";");
+ }
- Assert.assertEquals(kombucha.getInstanceOf("insertAuditFromTransaction").toString(), "insert into audit_log (\n" +
- "id\n" +
- ", table_name\n" +
- ", target_record_id\n" +
- ", change_type\n" +
- ", created_by\n" +
- ", reason_code\n" +
- ", comments\n" +
- ", user_token\n" +
- ", created_date\n" +
- ", account_record_id\n" +
- ", tenant_record_id\n" +
- ")\n" +
- "values (\n" +
- " :id\n" +
- ", :tableName\n" +
- ", :targetRecordId\n" +
- ", :changeType\n" +
- ", :createdBy\n" +
- ", :reasonCode\n" +
- ", :comments\n" +
- ", :userToken\n" +
- ", :createdDate\n" +
- ", :accountRecordId\n" +
- ", :tenantRecordId\n" +
- ")\n" +
- ";");
+ private void assertPattern(final String actual, final String expected) {
+ Assert.assertTrue(Pattern.compile(expected).matcher(actual).find(), String.format("Expected to see:\n%s\nin:\n%s", expected, actual));
}
}