killbill 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Jarfile +4 -2
- data/VERSION +1 -1
- data/lib/killbill.rb +69 -13
- data/lib/killbill/creator.rb +16 -2
- data/lib/killbill/enum.rb +72 -0
- data/lib/killbill/gen/account.rb +43 -0
- data/lib/killbill/gen/account_data.rb +39 -0
- data/lib/killbill/gen/account_email.rb +25 -0
- data/lib/killbill/gen/audit_log.rb +28 -0
- data/lib/killbill/gen/blocking_state.rb +32 -0
- data/lib/killbill/gen/call_context.rb +29 -0
- data/lib/killbill/gen/call_origin.rb +34 -0
- data/lib/killbill/gen/currency.rb +34 -0
- data/lib/killbill/gen/custom_field.rb +27 -0
- data/lib/killbill/gen/date_time_zone.rb +35 -0
- data/lib/killbill/gen/ext_bus_event.rb +25 -0
- data/lib/killbill/gen/ext_bus_event_type.rb +34 -0
- data/lib/killbill/gen/invoice.rb +39 -0
- data/lib/killbill/gen/invoice_item.rb +37 -0
- data/lib/killbill/gen/invoice_payment.rb +31 -0
- data/lib/killbill/gen/invoice_payment_type.rb +34 -0
- data/lib/killbill/gen/object_type.rb +34 -0
- data/lib/killbill/gen/payment.rb +36 -0
- data/lib/killbill/gen/payment_attempt.rb +27 -0
- data/lib/killbill/gen/payment_info_plugin.rb +28 -0
- data/lib/killbill/gen/payment_method_info_plugin.rb +24 -0
- data/lib/killbill/gen/payment_method_kv_info.rb +21 -0
- data/lib/killbill/gen/payment_method_plugin.rb +36 -0
- data/lib/killbill/gen/payment_plugin_status.rb +34 -0
- data/lib/killbill/gen/refund.rb +29 -0
- data/lib/killbill/gen/refund_info_plugin.rb +27 -0
- data/lib/killbill/gen/refund_plugin_status.rb +34 -0
- data/lib/killbill/gen/require_gen.rb +38 -0
- data/lib/killbill/gen/subscription.rb +44 -0
- data/lib/killbill/gen/subscription_bundle.rb +27 -0
- data/lib/killbill/gen/subscription_source_type.rb +34 -0
- data/lib/killbill/gen/subscription_state.rb +34 -0
- data/lib/killbill/gen/tag.rb +26 -0
- data/lib/killbill/gen/tag_definition.rb +27 -0
- data/lib/killbill/gen/tenant_context.rb +21 -0
- data/lib/killbill/gen/user_type.rb +34 -0
- data/lib/killbill/gen/uuid.rb +22 -0
- data/lib/killbill/http_servlet.rb +10 -3
- data/lib/killbill/jconverter.rb +540 -0
- data/lib/killbill/jkillbill_api.rb +137 -0
- data/lib/killbill/jnotification.rb +0 -1
- data/lib/killbill/jpayment.rb +7 -19
- data/lib/killbill/jplugin.rb +27 -16
- data/lib/killbill/killbill_api.rb +28 -0
- data/lib/killbill/killbill_logger.rb +31 -8
- data/lib/killbill/notification.rb +0 -1
- data/lib/killbill/payment.rb +0 -5
- data/lib/killbill/plugin.rb +4 -46
- data/spec/killbill/base_plugin_spec.rb +2 -1
- data/spec/killbill/{jresponse/jconverter_spec.rb → jconverter_spec.rb} +46 -90
- data/spec/killbill/jnotification_spec.rb +2 -1
- data/spec/killbill/jpayment_spec.rb +17 -16
- data/spec/killbill/killbill_integration_spec.rb +1 -1
- data/spec/killbill/killbillapi_spec.rb +49 -0
- data/spec/killbill/payment_test.rb +5 -5
- data/spec/killbill/rack_handler_spec.rb +1 -2
- data/spec/spec_helper.rb +3 -0
- data/tools/java2ruby.rb +440 -0
- metadata +48 -26
- data/lib/killbill/jresponse/jconverter.rb +0 -126
- data/lib/killbill/jresponse/jevent.rb +0 -58
- data/lib/killbill/jresponse/jpayment_method_response.rb +0 -148
- data/lib/killbill/jresponse/jpayment_method_response_internal.rb +0 -54
- data/lib/killbill/jresponse/jpayment_response.rb +0 -74
- data/lib/killbill/jresponse/jrefund_response.rb +0 -68
- data/lib/killbill/response/event.rb +0 -18
- data/lib/killbill/response/payment_method_response.rb +0 -50
- data/lib/killbill/response/payment_method_response_internal.rb +0 -20
- data/lib/killbill/response/payment_response.rb +0 -26
- data/lib/killbill/response/payment_status.rb +0 -10
- data/lib/killbill/response/refund_response.rb +0 -25
- data/spec/killbill/jresponse/jevent_spec.rb +0 -18
- data/spec/killbill/jresponse/jpayment_method_response_internal_spec.rb +0 -34
- data/spec/killbill/jresponse/jpayment_method_response_spec.rb +0 -53
- data/spec/killbill/jresponse/jpayment_response_spec.rb +0 -41
- data/spec/killbill/jresponse/jrefund_response_spec.rb +0 -41
@@ -15,6 +15,7 @@ class LifecycleNotificationPlugin < Killbill::Plugin::PluginBase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe Killbill::Plugin::PluginBase do
|
18
|
+
=begin
|
18
19
|
it 'should be able to register Killbill API instances' do
|
19
20
|
plugin = Killbill::Plugin::PluginBase.new(:account_user_api => MockAccountUserApi.new)
|
20
21
|
|
@@ -28,7 +29,7 @@ describe Killbill::Plugin::PluginBase do
|
|
28
29
|
# Default method missing behavior
|
29
30
|
lambda { plugin.blablabla }.should raise_error NoMethodError
|
30
31
|
end
|
31
|
-
|
32
|
+
=end
|
32
33
|
it 'should be able to default to the ruby logger for tests' do
|
33
34
|
logger = Logger.new(STDOUT)
|
34
35
|
logger.level = Logger::DEBUG
|
@@ -1,17 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'date'
|
3
|
-
|
4
|
-
require 'killbill/response/payment_method_response'
|
5
|
-
require 'killbill/response/payment_method_response_internal'
|
6
|
-
require 'killbill/response/payment_status'
|
7
|
-
require 'killbill/response/payment_response'
|
8
|
-
require 'killbill/response/refund_response'
|
9
|
-
require 'killbill/response/event'
|
10
|
-
|
11
|
-
require 'killbill/jresponse/jconverter'
|
12
|
-
require 'killbill/jresponse/jpayment_method_response'
|
13
|
-
require 'killbill/jresponse/jpayment_method_response_internal'
|
14
|
-
require 'killbill/jresponse/jevent'
|
3
|
+
require 'killbill/jconverter'
|
15
4
|
|
16
5
|
describe Killbill::Plugin::JConverter do
|
17
6
|
|
@@ -38,25 +27,32 @@ describe Killbill::Plugin::JConverter do
|
|
38
27
|
output.should == input
|
39
28
|
end
|
40
29
|
|
30
|
+
it "should_test_to_string_converter_from_non_string" do
|
31
|
+
input = 12
|
32
|
+
output = Killbill::Plugin::JConverter.to_string(input)
|
33
|
+
output.should be_an_instance_of java.lang.String
|
34
|
+
output.should == input.to_s
|
35
|
+
end
|
36
|
+
|
41
37
|
it "should_test_payment_plugin_status_success_converter" do
|
42
|
-
input = Killbill::Plugin::
|
38
|
+
input = Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
|
43
39
|
output = Killbill::Plugin::JConverter.to_payment_plugin_status(input)
|
44
|
-
output.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.
|
45
|
-
output.should == Java::com.ning.billing.payment.plugin.api.
|
40
|
+
output.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus
|
41
|
+
output.should == Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::PROCESSED
|
46
42
|
end
|
47
43
|
|
48
44
|
it "should_test_payment_plugin_status_failed_converter" do
|
49
|
-
input = Killbill::Plugin::
|
45
|
+
input = Killbill::Plugin::Model::PaymentPluginStatus.new(:ERROR)
|
50
46
|
output = Killbill::Plugin::JConverter.to_payment_plugin_status(input)
|
51
|
-
output.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.
|
52
|
-
output.should == Java::com.ning.billing.payment.plugin.api.
|
47
|
+
output.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus
|
48
|
+
output.should == Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::ERROR
|
53
49
|
end
|
54
50
|
|
55
51
|
it "should_test_payment_plugin_status_undefined_converter" do
|
56
|
-
input = Killbill::Plugin::
|
52
|
+
input = Killbill::Plugin::Model::PaymentPluginStatus.new(:UNDEFINED)
|
57
53
|
output = Killbill::Plugin::JConverter.to_payment_plugin_status(input)
|
58
|
-
output.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.
|
59
|
-
output.should == Java::com.ning.billing.payment.plugin.api.
|
54
|
+
output.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus
|
55
|
+
output.should == Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::UNDEFINED
|
60
56
|
end
|
61
57
|
|
62
58
|
it "should_test_big_decimal_converter" do
|
@@ -68,7 +64,7 @@ describe Killbill::Plugin::JConverter do
|
|
68
64
|
12376 => '12.376',
|
69
65
|
-532 => '-5.32'
|
70
66
|
}.each do |input,output|
|
71
|
-
output = Killbill::Plugin::JConverter.
|
67
|
+
output = Killbill::Plugin::JConverter.to_big_decimal_with_cents_conversion(input)
|
72
68
|
output.should be_an_instance_of java.math.BigDecimal
|
73
69
|
output.to_s.should == output.to_s
|
74
70
|
end
|
@@ -91,7 +87,7 @@ describe Killbill::Plugin::JConverter do
|
|
91
87
|
it "should_test_uuid_from_converter" do
|
92
88
|
input = java.util.UUID.random_uuid
|
93
89
|
output = Killbill::Plugin::JConverter.from_uuid(input)
|
94
|
-
output.should be_an_instance_of
|
90
|
+
output.should be_an_instance_of Killbill::Plugin::Model::UUID
|
95
91
|
output.to_s.should == input.to_s
|
96
92
|
end
|
97
93
|
|
@@ -117,7 +113,6 @@ describe Killbill::Plugin::JConverter do
|
|
117
113
|
output.to_s == "false"
|
118
114
|
end
|
119
115
|
|
120
|
-
|
121
116
|
it "should_test_boolean_from_true_converter" do
|
122
117
|
input = java.lang.Boolean.new("true")
|
123
118
|
output = Killbill::Plugin::JConverter.from_boolean(input)
|
@@ -144,94 +139,55 @@ describe Killbill::Plugin::JConverter do
|
|
144
139
|
end
|
145
140
|
|
146
141
|
it "should_test_payment_status_from_converter" do
|
147
|
-
input = Java::com.ning.billing.payment.plugin.api.
|
142
|
+
input = Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::PROCESSED
|
148
143
|
output = Killbill::Plugin::JConverter.from_payment_plugin_status(input)
|
149
|
-
output.should == Killbill::Plugin::
|
144
|
+
output.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
|
150
145
|
end
|
151
146
|
|
152
147
|
it "should_test_big_decimal_from_converter" do
|
153
148
|
input = java.math.BigDecimal::TEN
|
154
|
-
output = Killbill::Plugin::JConverter.
|
149
|
+
output = Killbill::Plugin::JConverter.from_big_decimal_with_cents_conversion(input)
|
155
150
|
output.should be_an_instance_of Fixnum
|
156
151
|
output.to_s.should == "1000"
|
157
152
|
end
|
158
153
|
|
159
|
-
it "should_test_payment_method_plugin_from_converter" do
|
160
|
-
prop = Killbill::Plugin::PaymentMethodProperty.new("key", "value", true)
|
161
|
-
payment_method_response = Killbill::Plugin::PaymentMethodResponse.new("external_payment_method_id", true, [prop])
|
162
|
-
input = Killbill::Plugin::JPaymentMethodResponse.new(payment_method_response)
|
163
|
-
output = Killbill::Plugin::JConverter.from_payment_method_plugin(input)
|
164
|
-
|
165
|
-
output.should be_an_instance_of Killbill::Plugin::PaymentMethodResponse
|
166
|
-
|
167
|
-
output.external_payment_method_id.should be_an_instance_of String
|
168
|
-
output.external_payment_method_id.should == payment_method_response.external_payment_method_id
|
169
|
-
|
170
|
-
output.is_default.should be_an_instance_of TrueClass
|
171
|
-
output.is_default.should == payment_method_response.is_default
|
172
|
-
|
173
|
-
output.properties.should be_an_instance_of Array
|
174
|
-
output.properties.size.should == 1
|
175
|
-
|
176
|
-
output_prop = output.properties[0]
|
177
|
-
output_prop.should be_an_instance_of Killbill::Plugin::PaymentMethodProperty
|
178
|
-
|
179
|
-
output_prop.key.should be_an_instance_of String
|
180
|
-
output_prop.key.should == prop.key
|
181
|
-
|
182
|
-
output_prop.value.should be_an_instance_of String
|
183
|
-
output_prop.value.should == prop.value
|
184
|
-
|
185
|
-
output_prop.is_updatable.should be_an_instance_of TrueClass
|
186
|
-
output_prop.is_updatable.should == prop.is_updatable
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should_test_payment_method_info_plugin__from_converter" do
|
190
|
-
|
191
|
-
payment_method_info = Killbill::Plugin::PaymentMethodResponseInternal.new("bf5c926e-3d9c-470e-b34b-0719d7b58323", "ca5c926e-3d9c-470e-b34b-0719d7b58312", false, "external_payment_method_id")
|
192
|
-
input = Killbill::Plugin::JPaymentMethodResponseInternal.new(payment_method_info)
|
193
|
-
output = Killbill::Plugin::JConverter.from_payment_method_info_plugin(input)
|
194
|
-
|
195
|
-
output.should be_an_instance_of Killbill::Plugin::PaymentMethodResponseInternal
|
196
|
-
|
197
|
-
output.kb_account_id.should be_an_instance_of String
|
198
|
-
output.kb_account_id.should == payment_method_info.kb_account_id
|
199
|
-
|
200
|
-
output.kb_payment_method_id.should be_an_instance_of String
|
201
|
-
output.kb_payment_method_id.should == payment_method_info.kb_payment_method_id
|
202
|
-
|
203
|
-
output.is_default.should be_an_instance_of FalseClass
|
204
|
-
output.is_default.should == payment_method_info.is_default
|
205
|
-
|
206
|
-
output.external_payment_method_id.should be_an_instance_of String
|
207
|
-
output.external_payment_method_id.should == payment_method_info.external_payment_method_id
|
208
|
-
end
|
209
|
-
|
210
154
|
it "should_test_ext_bus_event__from_converter" do
|
211
155
|
|
212
156
|
object_type = Java::com.ning.billing.ObjectType::INVOICE
|
213
157
|
event_type = Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::INVOICE_CREATION
|
214
158
|
uuid = java.util.UUID.random_uuid
|
215
159
|
|
216
|
-
input = Killbill::Plugin::
|
160
|
+
input = Killbill::Plugin::Model::ExtBusEvent.new(event_type, object_type, uuid, uuid, uuid)
|
217
161
|
output = Killbill::Plugin::JConverter.from_ext_bus_event(input)
|
218
162
|
|
219
|
-
output.should be_an_instance_of Killbill::Plugin::
|
163
|
+
output.should be_an_instance_of Killbill::Plugin::Model::ExtBusEvent
|
164
|
+
|
165
|
+
output.event_type.should == Killbill::Plugin::Model::ExtBusEventType.new(:INVOICE_CREATION)
|
166
|
+
|
167
|
+
output.object_type.should == Killbill::Plugin::Model::ObjectType.new(:INVOICE)
|
220
168
|
|
221
|
-
output.
|
222
|
-
output.
|
169
|
+
output.object_id.should be_an_instance_of Killbill::Plugin::Model::UUID
|
170
|
+
output.object_id.to_s.should == Killbill::Plugin::JConverter.from_uuid(uuid).to_s
|
223
171
|
|
224
|
-
output.
|
225
|
-
output.
|
172
|
+
output.account_id.should be_an_instance_of Killbill::Plugin::Model::UUID
|
173
|
+
output.account_id.to_s.should == Killbill::Plugin::JConverter.from_uuid(uuid).to_s
|
174
|
+
|
175
|
+
output.tenant_id.should be_an_instance_of Killbill::Plugin::Model::UUID
|
176
|
+
output.tenant_id.to_s.should == Killbill::Plugin::JConverter.from_uuid(uuid).to_s
|
177
|
+
|
178
|
+
end
|
179
|
+
it "should_test_enum_object_type_from_converter" do
|
226
180
|
|
227
|
-
|
228
|
-
output.object_id.should == Killbill::Plugin::JConverter.from_uuid(uuid)
|
181
|
+
java_object_type = Java::com.ning.billing.ObjectType::ACCOUNT
|
229
182
|
|
230
|
-
|
231
|
-
|
183
|
+
ruby_object_type = Killbill::Plugin::JConverter.from_object_type(java_object_type)
|
184
|
+
ruby_object_type.should be_an_instance_of Killbill::Plugin::Model::ObjectType
|
185
|
+
ruby_object_type.enum.to_s.should == java_object_type.to_s
|
232
186
|
|
233
|
-
|
234
|
-
|
187
|
+
java_object_type_back = Killbill::Plugin::JConverter.to_object_type(ruby_object_type)
|
188
|
+
java_object_type_back.should be_an_instance_of Java::com.ning.billing.ObjectType
|
189
|
+
java_object_type_back.to_s.should == java_object_type.to_s
|
190
|
+
java_object_type_back.to_s.should == "ACCOUNT"
|
235
191
|
|
236
192
|
end
|
237
193
|
end
|
@@ -5,7 +5,8 @@ require 'killbill/jnotification'
|
|
5
5
|
describe Killbill::Plugin::JNotification do
|
6
6
|
|
7
7
|
before(:all) do
|
8
|
-
|
8
|
+
logger = ::Logger.new(STDOUT)
|
9
|
+
@jnotification = Killbill::Plugin::JNotification.new("Killbill::Plugin::NotificationTest", { "logger" => logger })
|
9
10
|
end
|
10
11
|
|
11
12
|
|
@@ -5,7 +5,8 @@ require 'killbill/jpayment'
|
|
5
5
|
describe Killbill::Plugin::JPayment do
|
6
6
|
|
7
7
|
before(:all) do
|
8
|
-
|
8
|
+
logger = ::Logger.new(STDOUT)
|
9
|
+
@jpayment = Killbill::Plugin::JPayment.new("Killbill::Plugin::PaymentTest", { "logger" => logger })
|
9
10
|
@kb_account_id = java.util.UUID.fromString("aa5c926e-3d9d-4435-b44b-719d7b583256")
|
10
11
|
@kb_payment_id = java.util.UUID.fromString("bf5c926e-3d9c-470e-b34b-719d7b58323a")
|
11
12
|
@kb_payment_method_id = java.util.UUID.fromString("bf5c926e-3d9c-470e-b34b-719d7b58323a")
|
@@ -20,10 +21,10 @@ describe Killbill::Plugin::JPayment do
|
|
20
21
|
|
21
22
|
it "should_test_charge_ok" do
|
22
23
|
output = @jpayment.process_payment(@kb_account_id, @kb_payment_id, @kb_payment_method_id, @amount, @currency)
|
23
|
-
output.
|
24
|
-
output.
|
25
|
-
output.
|
26
|
-
output.
|
24
|
+
output.amount.should be_an_instance_of java.math.BigDecimal
|
25
|
+
output.amount.to_s.should == "50.00";
|
26
|
+
output.status.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus
|
27
|
+
output.status.to_s.should == "PROCESSED"
|
27
28
|
end
|
28
29
|
|
29
30
|
it "should_test_charge_exception" do
|
@@ -33,10 +34,10 @@ describe Killbill::Plugin::JPayment do
|
|
33
34
|
|
34
35
|
it "should_test_get_payment_info_ok" do
|
35
36
|
output = @jpayment.get_payment_info(@kb_account_id, @kb_payment_method_id)
|
36
|
-
output.
|
37
|
-
output.
|
38
|
-
output.
|
39
|
-
output.
|
37
|
+
output.amount.should be_an_instance_of java.math.BigDecimal
|
38
|
+
output.amount.to_s.should == "0.00";
|
39
|
+
output.status.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus
|
40
|
+
output.status.to_s.should == "PROCESSED"
|
40
41
|
end
|
41
42
|
|
42
43
|
it "should_test_get_payment_info_exception" do
|
@@ -46,10 +47,10 @@ describe Killbill::Plugin::JPayment do
|
|
46
47
|
|
47
48
|
it "should_test_refund_ok" do
|
48
49
|
output = @jpayment.process_refund(@kb_account_id, @kb_payment_method_id, @amount, @currency)
|
49
|
-
output.
|
50
|
-
output.
|
51
|
-
output.
|
52
|
-
output.
|
50
|
+
output.amount.should be_an_instance_of java.math.BigDecimal
|
51
|
+
output.amount.to_s.should == "50.00";
|
52
|
+
output.status.should be_an_instance_of Java::com.ning.billing.payment.plugin.api.RefundPluginStatus
|
53
|
+
output.status.to_s.should == "PROCESSED"
|
53
54
|
end
|
54
55
|
|
55
56
|
it "should_test_refund_exception" do
|
@@ -77,8 +78,8 @@ describe Killbill::Plugin::JPayment do
|
|
77
78
|
|
78
79
|
it "should_test_get_payment_method_detail_ok" do
|
79
80
|
output = @jpayment.get_payment_method_detail(@kb_account_id, @kb_payment_method_id)
|
80
|
-
output.
|
81
|
-
output.
|
81
|
+
output.external_payment_method_id.should be_an_instance_of java.lang.String
|
82
|
+
output.external_payment_method_id.should == "foo"
|
82
83
|
end
|
83
84
|
|
84
85
|
it "should_test_get_payment_method_detail_exception" do
|
@@ -102,7 +103,7 @@ describe Killbill::Plugin::JPayment do
|
|
102
103
|
output.size.should == 1
|
103
104
|
|
104
105
|
current_payment_method = output.get(0)
|
105
|
-
current_payment_method.
|
106
|
+
current_payment_method.account_id.to_s.should == @kb_account_id.to_s
|
106
107
|
end
|
107
108
|
|
108
109
|
it "should_get_payment_methods_exception" do
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'killbill/jkillbill_api'
|
4
|
+
require 'killbill/killbill_api'
|
5
|
+
|
6
|
+
require 'killbill/gen/account_data'
|
7
|
+
require 'killbill/gen/currency'
|
8
|
+
require 'killbill/gen/date_time_zone'
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
describe Killbill::Plugin do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@account_user_api_mock = MockAccountUserApi.new
|
16
|
+
@japi_proxy = Killbill::Plugin::JKillbillApi.new("foo", {:account_user_api => @account_user_api_mock})
|
17
|
+
@kb_apis = Killbill::Plugin::KillbillApi.new(@japi_proxy)
|
18
|
+
@account = Killbill::Plugin::Model::AccountData.new("external_key", "name", 3, "email", 1, Killbill::Plugin::Model::Currency.new(:USD), nil, Killbill::Plugin::Model::DateTimeZone.new(:UTC), "locale", "address1", nil,
|
19
|
+
"company_name", "city", "state_or_province", "postal_code", "country", "phone", true, false)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should test create/get_account_by_id' do
|
23
|
+
|
24
|
+
account_created = @kb_apis.create_account(@account)
|
25
|
+
account_created.should be_an_instance_of Killbill::Plugin::Model::Account
|
26
|
+
|
27
|
+
account_fetched = @kb_apis.get_account_by_id(account_created.id)
|
28
|
+
account_fetched.should be_an_instance_of Killbill::Plugin::Model::Account
|
29
|
+
account_fetched.id.should be_an_instance_of Killbill::Plugin::Model::UUID
|
30
|
+
account_fetched.id.to_s.should == account_created.id.to_s
|
31
|
+
account_fetched.external_key.should == "external_key"
|
32
|
+
account_fetched.name.should == "name"
|
33
|
+
account_fetched.first_name_length.should == 3
|
34
|
+
account_fetched.email.should == "email"
|
35
|
+
account_fetched.bill_cycle_day_local.should == 1
|
36
|
+
account_fetched.currency.should == Killbill::Plugin::Model::Currency.new(:USD)
|
37
|
+
account_fetched.locale.should == "locale"
|
38
|
+
account_fetched.address1.should == "address1"
|
39
|
+
account_fetched.address2.should == nil
|
40
|
+
account_fetched.time_zone.should == Killbill::Plugin::Model::DateTimeZone.new(:UTC)
|
41
|
+
account_fetched.company_name.should == "company_name"
|
42
|
+
account_fetched.city.should == "city"
|
43
|
+
account_fetched.state_or_province.should == "state_or_province"
|
44
|
+
account_fetched.postal_code.should == "postal_code"
|
45
|
+
account_fetched.country.should == "country"
|
46
|
+
account_fetched.phone.should == "phone"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -12,7 +12,7 @@ module Killbill
|
|
12
12
|
if @raise_exception
|
13
13
|
raise StandardError.new("Test exception")
|
14
14
|
else
|
15
|
-
|
15
|
+
Killbill::Plugin::Model::PaymentInfoPlugin.new(amount_in_cents, DateTime.now, DateTime.now, Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED), "gateway_error", "gateway_error_code", nil, nil)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ module Killbill
|
|
20
20
|
if @raise_exception
|
21
21
|
raise StandardError.new("Test exception")
|
22
22
|
else
|
23
|
-
|
23
|
+
Killbill::Plugin::Model::PaymentInfoPlugin.new(0, DateTime.now, DateTime.now, Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED), "gateway_error", "gateway_error_code", nil, nil)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -28,7 +28,7 @@ module Killbill
|
|
28
28
|
if @raise_exception
|
29
29
|
raise StandardError.new("Test exception")
|
30
30
|
else
|
31
|
-
|
31
|
+
Killbill::Plugin::Model::RefundInfoPlugin.new(5000, DateTime.now, DateTime.now, Killbill::Plugin::Model::RefundPluginStatus.new(:PROCESSED), "gateway_error", "gateway_error_code", nil)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -48,7 +48,7 @@ module Killbill
|
|
48
48
|
if @raise_exception
|
49
49
|
raise StandardError.new("Test exception")
|
50
50
|
else
|
51
|
-
|
51
|
+
Killbill::Plugin::Model::PaymentMethodPlugin.new("foo", true, [], nil, "type", "cc_name", "cc_type", "cc_expiration_month", "cc_expiration_year", "cc_last4", "address1", "address2", "city", "state", "zip", "country")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -62,7 +62,7 @@ module Killbill
|
|
62
62
|
if @raise_exception
|
63
63
|
raise StandardError.new("Test exception")
|
64
64
|
else
|
65
|
-
[
|
65
|
+
[Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, kb_account_id, true, "external_payment_method_id")]
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'logger'
|
3
2
|
|
4
3
|
describe Killbill::Plugin::RackHandler do
|
5
4
|
it 'should be able to register Sinatra apps' do
|
6
5
|
rack = Killbill::Plugin::RackHandler.instance
|
7
6
|
rack.configured?.should be_false
|
8
7
|
|
9
|
-
rack.configure(Logger.new(STDOUT), File.expand_path('../config_test.ru', __FILE__))
|
8
|
+
rack.configure(Killbill::Plugin::KillbillLogger.new(::Logger.new(STDOUT)), File.expand_path('../config_test.ru', __FILE__))
|
10
9
|
rack.configured?.should be_true
|
11
10
|
|
12
11
|
status, headers, body = rack.rack_service('/ping')
|
data/spec/spec_helper.rb
CHANGED
data/tools/java2ruby.rb
ADDED
@@ -0,0 +1,440 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
|
5
|
+
# Relative path from Killbill repo
|
6
|
+
API_DIR_SRC="api/src/main/java"
|
7
|
+
|
8
|
+
# Interfaces to consider
|
9
|
+
INTERFACES = ["Account",
|
10
|
+
"AccountData",
|
11
|
+
"AccountEmail",
|
12
|
+
"BlockingState",
|
13
|
+
"ExtBusEvent",
|
14
|
+
"ExtBusEventType",
|
15
|
+
"ObjectType",
|
16
|
+
"Subscription",
|
17
|
+
"SubscriptionState",
|
18
|
+
"SubscriptionSourceType",
|
19
|
+
"SubscriptionBundle",
|
20
|
+
"Invoice",
|
21
|
+
"InvoiceItem",
|
22
|
+
"InvoicePayment",
|
23
|
+
"InvoicePaymentType",
|
24
|
+
"Payment",
|
25
|
+
"PaymentAttempt",
|
26
|
+
"Refund",
|
27
|
+
"AuditLog",
|
28
|
+
"CallContext",
|
29
|
+
"CallOrigin",
|
30
|
+
"UserType",
|
31
|
+
"TenantContext",
|
32
|
+
"CustomField",
|
33
|
+
"Tag",
|
34
|
+
"TagDefinition",
|
35
|
+
"Currency",
|
36
|
+
"PaymentInfoPlugin",
|
37
|
+
"PaymentPluginStatus",
|
38
|
+
"RefundInfoPlugin",
|
39
|
+
"RefundPluginStatus",
|
40
|
+
"PaymentMethodKVInfo",
|
41
|
+
"PaymentMethodPlugin",
|
42
|
+
"PaymentMethodInfoPlugin"]
|
43
|
+
|
44
|
+
|
45
|
+
class String
|
46
|
+
def snake_case
|
47
|
+
return downcase if match(/\A[A-Z]+\z/)
|
48
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
49
|
+
gsub(/([a-z])([A-Z])/, '\1_\2').
|
50
|
+
downcase
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Pojo
|
55
|
+
|
56
|
+
attr_accessor :name, :package, :fields
|
57
|
+
|
58
|
+
def initialize(dummy=nil)
|
59
|
+
@name = nil
|
60
|
+
@package = nil
|
61
|
+
@fields = []
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
=begin
|
66
|
+
class ObjectType
|
67
|
+
|
68
|
+
@@admissible_values = [:ACCOUNT, :ACCOUNT_EMAIL]
|
69
|
+
attr_reader :enum
|
70
|
+
|
71
|
+
def initialize(value)
|
72
|
+
@enum = value
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.is_admissible_value(value)
|
76
|
+
@@admissible_values.include?(value)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.admissible_values
|
80
|
+
@@admissible_values
|
81
|
+
end
|
82
|
+
=end
|
83
|
+
|
84
|
+
class PojoEnum < Pojo
|
85
|
+
|
86
|
+
def initialize
|
87
|
+
super
|
88
|
+
end
|
89
|
+
|
90
|
+
def generate(out)
|
91
|
+
out.write("\n")
|
92
|
+
out.write("\#\n")
|
93
|
+
out.write("\# Ruby classes automatically generated from java classes-- don't edit\n")
|
94
|
+
out.write("\#\n")
|
95
|
+
out.write("module Killbill\n")
|
96
|
+
out.write(" module Plugin\n")
|
97
|
+
out.write(" module Model\n")
|
98
|
+
out.write("\n")
|
99
|
+
out.write(" class #{name}\n")
|
100
|
+
out.write("\n")
|
101
|
+
out.write(" @@admissible_values = #{@fields.collect {|e| e.to_sym }}\n")
|
102
|
+
out.write(" attr_reader :enum\n")
|
103
|
+
out.write("\n")
|
104
|
+
out.write(" def initialize(value)\n")
|
105
|
+
out.write(" raise ArgumentError.new(\"Enum #{name} does not have such value : \#{value}\") if ! #{name}.is_admissible_value?(value)\n")
|
106
|
+
out.write(" @enum = value\n")
|
107
|
+
out.write(" end\n")
|
108
|
+
out.write("\n")
|
109
|
+
out.write(" def ==(other)\n")
|
110
|
+
out.write(" return false if other.nil?\n")
|
111
|
+
out.write(" self.enum == other.enum\n")
|
112
|
+
out.write(" end\n")
|
113
|
+
out.write("\n")
|
114
|
+
out.write(" def self.is_admissible_value?(value)\n")
|
115
|
+
out.write(" @@admissible_values.include?(value)\n")
|
116
|
+
out.write(" end\n")
|
117
|
+
out.write("\n")
|
118
|
+
out.write(" def self.admissible_values \n")
|
119
|
+
out.write(" @@admissible_values\n")
|
120
|
+
out.write(" end\n")
|
121
|
+
out.write(" end\n")
|
122
|
+
out.write(" end\n")
|
123
|
+
out.write(" end\n")
|
124
|
+
out.write("end\n")
|
125
|
+
out.flush
|
126
|
+
end
|
127
|
+
|
128
|
+
def export(output_dir, parents_pojo)
|
129
|
+
@fields.uniq!
|
130
|
+
File.open("#{output_dir}/#{name.snake_case}.rb", "w+") do |f|
|
131
|
+
generate(f)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
class PojoIfceOrClass < Pojo
|
140
|
+
|
141
|
+
attr_accessor :interface, :parents
|
142
|
+
|
143
|
+
def initialize(is_interface)
|
144
|
+
super
|
145
|
+
@interface = is_interface
|
146
|
+
@parents = []
|
147
|
+
end
|
148
|
+
|
149
|
+
def generate(out)
|
150
|
+
out.write("\n")
|
151
|
+
out.write("\#\n")
|
152
|
+
out.write("\# Ruby classes automatically generated from java classes-- don't edit\n")
|
153
|
+
out.write("\#\n")
|
154
|
+
out.write("module Killbill\n")
|
155
|
+
out.write(" module Plugin\n")
|
156
|
+
out.write(" module Model\n")
|
157
|
+
out.write("\n")
|
158
|
+
out.write(" class #{name}\n")
|
159
|
+
out.write("\n")
|
160
|
+
if @interface
|
161
|
+
out.write(" include #{@package}.#{@name}\n")
|
162
|
+
out.write("\n")
|
163
|
+
end
|
164
|
+
out.write(" attr_reader #{fields.collect { |i| ":#{i}"}.join(", ")}\n")
|
165
|
+
out.write("\n")
|
166
|
+
out.write(" def initialize(#{@fields.join(", ")})\n")
|
167
|
+
fields.each do |f|
|
168
|
+
out.write(" @#{f} = #{f}\n")
|
169
|
+
end
|
170
|
+
out.write(" end\n")
|
171
|
+
out.write(" end\n")
|
172
|
+
out.write(" end\n")
|
173
|
+
out.write(" end\n")
|
174
|
+
out.write("end\n")
|
175
|
+
out.flush
|
176
|
+
end
|
177
|
+
|
178
|
+
def export(output_dir, parents_pojo)
|
179
|
+
parents.each do |p|
|
180
|
+
if ! parents_pojo[p].nil?
|
181
|
+
(@fields.unshift(parents_pojo[p].fields)).flatten!
|
182
|
+
end
|
183
|
+
end
|
184
|
+
@fields.uniq!
|
185
|
+
File.open("#{output_dir}/#{name.snake_case}.rb", "w+") do |f|
|
186
|
+
generate(f)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def to_s
|
191
|
+
"#{@name} : #{@fields.join(",")}"
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
class Visitor
|
199
|
+
|
200
|
+
attr_reader :pojo
|
201
|
+
|
202
|
+
def initialize
|
203
|
+
@pojo = nil
|
204
|
+
end
|
205
|
+
|
206
|
+
def create_interface(name, package)
|
207
|
+
@pojo = PojoIfceOrClass.new(true)
|
208
|
+
@pojo.name = name
|
209
|
+
@pojo.package = package
|
210
|
+
end
|
211
|
+
|
212
|
+
def create_class(name, package)
|
213
|
+
@pojo = PojoIfceOrClass.new(false)
|
214
|
+
@pojo.name = name
|
215
|
+
@pojo.package = package
|
216
|
+
end
|
217
|
+
|
218
|
+
def create_enum(name, package)
|
219
|
+
@pojo = PojoEnum.new
|
220
|
+
@pojo.name = name
|
221
|
+
@pojo.package = package
|
222
|
+
end
|
223
|
+
|
224
|
+
def add_parents(parents)
|
225
|
+
(@pojo.parents << parents).flatten!
|
226
|
+
end
|
227
|
+
|
228
|
+
def add_getter(getter)
|
229
|
+
@pojo.fields << getter.snake_case
|
230
|
+
end
|
231
|
+
|
232
|
+
def add_enum_field(enum_field)
|
233
|
+
@pojo.fields << enum_field
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class Generator
|
238
|
+
|
239
|
+
attr_reader :output_dir, :finder, :files
|
240
|
+
|
241
|
+
def initialize(output_dir, interfaces, finder)
|
242
|
+
@output_dir = output_dir
|
243
|
+
@finder = finder
|
244
|
+
@files = finder.search(interfaces)
|
245
|
+
end
|
246
|
+
|
247
|
+
def generate_all
|
248
|
+
|
249
|
+
pojos = []
|
250
|
+
@files.each do |i|
|
251
|
+
generate_file(i) do |pojo|
|
252
|
+
pojos << pojo
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
parent_pojos = {}
|
257
|
+
|
258
|
+
parent_ifces = []
|
259
|
+
pojos.each do |pojo|
|
260
|
+
if pojo.is_a? PojoIfceOrClass
|
261
|
+
(parent_ifces << pojo.parents).flatten!
|
262
|
+
end
|
263
|
+
end
|
264
|
+
parent_ifces.uniq!
|
265
|
+
|
266
|
+
puts "UNIQ PARENTS = #{parent_ifces.to_s}"
|
267
|
+
|
268
|
+
parent_files = finder.search(parent_ifces)
|
269
|
+
puts "PARENT FILES = #{parent_files}"
|
270
|
+
parent_files.each do |i|
|
271
|
+
puts "Starting processing parent file #{i}"
|
272
|
+
generate_file(i) do |pojo|
|
273
|
+
parent_pojos[pojo.name] = pojo
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
pojos.each do |pojo|
|
278
|
+
puts "Starting processing file #{pojo.name}"
|
279
|
+
|
280
|
+
pojo.export(@output_dir, parent_pojos)
|
281
|
+
|
282
|
+
File.open("#{output_dir}/require_gen.rb", "w+") do |f|
|
283
|
+
pojos.each do |pojo|
|
284
|
+
f.write("require \'killbill/gen/#{pojo.name.snake_case}\'\n")
|
285
|
+
end
|
286
|
+
end
|
287
|
+
puts "Completing processing file #{pojo.name}"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
private
|
292
|
+
|
293
|
+
|
294
|
+
def generate_file(file)
|
295
|
+
visitor = Visitor.new
|
296
|
+
File.open(file, "r") do |f|
|
297
|
+
|
298
|
+
is_enum = false
|
299
|
+
is_interface = false
|
300
|
+
is_class = false
|
301
|
+
package = nil
|
302
|
+
while (line = f.gets)
|
303
|
+
|
304
|
+
# Package
|
305
|
+
re = /\s*package\s+((?:\w|\.)+)\s*;/
|
306
|
+
if re.match(line)
|
307
|
+
package = $1
|
308
|
+
end
|
309
|
+
|
310
|
+
# Interface
|
311
|
+
re = /public\s+(interface|class)\s+(\w+)\s+(extends(?:\w|,|\s|<|>)+){0,1}\s*{\s*/
|
312
|
+
if re.match(line)
|
313
|
+
is_interface = ($1 == "interface")
|
314
|
+
is_class = ($1 == "class")
|
315
|
+
name = $2
|
316
|
+
visitor.create_interface(name, package) if is_interface
|
317
|
+
visitor.create_class(name, package) if is_class
|
318
|
+
if ! $3.nil?
|
319
|
+
re = /\s*extends\s+(.*)/
|
320
|
+
extends_ifces = $3
|
321
|
+
if re.match(extends_ifces)
|
322
|
+
# extract each parent and remove trailing, leading space
|
323
|
+
parents = $1.split(",").collect { |e| e.strip}
|
324
|
+
# remove generics
|
325
|
+
re = /(\w+)(?:<\w+>){0,1}/
|
326
|
+
parents.collect! { |e| re.match(e); $1 }
|
327
|
+
visitor.add_parents(parents)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
# Enum
|
333
|
+
re = /public\s+enum\s+(\w+)\s+/
|
334
|
+
if re.match(line)
|
335
|
+
enum_name = $1
|
336
|
+
visitor.create_enum(enum_name, package)
|
337
|
+
is_enum = true
|
338
|
+
is_enum_complete = false
|
339
|
+
end
|
340
|
+
|
341
|
+
# Non static getters for interfaces
|
342
|
+
re = /(?:public){0,1}\s+(?:static\s+(?:\w|<|>)+)\s+(?:get|is).*/
|
343
|
+
if (is_interface || is_class) && !re.match(line)
|
344
|
+
re = /(?:public){0,1}\s+(?:(?:\w|<|>)+)\s+get(\w+)()\s*/
|
345
|
+
if re.match(line)
|
346
|
+
visitor.add_getter($1)
|
347
|
+
end
|
348
|
+
re = /(?:public){0,1}\s+(?:(?:\w|<|>)+)\s+(is\w+)()\s*/
|
349
|
+
if re.match(line)
|
350
|
+
visitor.add_getter($1)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
# Enum fields
|
355
|
+
re = /\s+((?:\w|_)+)(?:\((?:\w|\s|\")+\)){0,1}\s*(,|;){1}/
|
356
|
+
if !is_enum_complete && is_enum && re.match(line)
|
357
|
+
visitor.add_enum_field($1.strip)
|
358
|
+
if $2 == ';'
|
359
|
+
is_enum_complete = true
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
yield(visitor.pojo)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
|
369
|
+
class Finder
|
370
|
+
|
371
|
+
attr_reader :interfaces, :src_dir
|
372
|
+
|
373
|
+
def initialize(src_dir)
|
374
|
+
@interfaces = interfaces
|
375
|
+
@src_dir = src_dir
|
376
|
+
end
|
377
|
+
|
378
|
+
def search(interfaces)
|
379
|
+
res = []
|
380
|
+
if !interfaces.nil? && interfaces.size > 0
|
381
|
+
Dir.chdir(@src_dir)
|
382
|
+
Dir.glob("**/*") do |e|
|
383
|
+
if File.file?(e)
|
384
|
+
basename = File.basename(e, ".java")
|
385
|
+
if interfaces.include? basename
|
386
|
+
res << e
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
res
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
|
396
|
+
class CommandParser
|
397
|
+
|
398
|
+
attr_reader :options, :args, :interfaces, :src_relative_path
|
399
|
+
|
400
|
+
def initialize(args, interfaces, src_relative_path)
|
401
|
+
@options = {}
|
402
|
+
@args = args
|
403
|
+
@interfaces = interfaces
|
404
|
+
@src_relative_path = src_relative_path
|
405
|
+
end
|
406
|
+
|
407
|
+
|
408
|
+
def run
|
409
|
+
parse
|
410
|
+
puts "Generating ruby classes under: #{@options[:output]}"
|
411
|
+
finder = Finder.new("#{@options[:src]}/#{@src_relative_path}")
|
412
|
+
gen = Generator.new(@options[:output], @interfaces, finder)
|
413
|
+
gen.generate_all
|
414
|
+
end
|
415
|
+
|
416
|
+
private
|
417
|
+
|
418
|
+
def parse()
|
419
|
+
optparse = OptionParser.new do |opts|
|
420
|
+
opts.banner = "Usage: java2ruby.rb [options]"
|
421
|
+
|
422
|
+
opts.separator ""
|
423
|
+
|
424
|
+
opts.on("-o", "--output OUTPUT",
|
425
|
+
"Output directory") do |o|
|
426
|
+
@options[:output] = o
|
427
|
+
end
|
428
|
+
|
429
|
+
opts.on("-s", "--src SRC",
|
430
|
+
"Killbill source directory") do |s|
|
431
|
+
@options[:src] = s
|
432
|
+
end
|
433
|
+
end
|
434
|
+
optparse.parse!(@args)
|
435
|
+
end
|
436
|
+
|
437
|
+
end
|
438
|
+
|
439
|
+
parser = CommandParser.new(ARGV, INTERFACES, API_DIR_SRC)
|
440
|
+
parser.run
|