junction: switch from SortedSet to List for blocking states

Let the database order the states for us - the comparator was buggy
anyways.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
payment: fix error logging

* Make PaymentProcessor log errors at the WARN level
* Don't make InvoiceHandler log the full stack trace. The useful
  information will be in BillingExceptionBase#toString()

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: remove unused MergeEvent

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: fix ordering of DefaultBillingEvent

* Use custom transition type for entering/leaving an overdue period to
  differentiate these events with real (un)cancellations
* Fix ordering of billing events
* Enable tests (add missing group). Some are currently failing

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: fix two bugs in BlockingCalculator

* fix date comparison
* fix typo when looking for the bundleId in the backing map
* add a regression test for both bugs

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: fix typo in sql statements

Order events in asc order, not desc.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: fix test failure in TestBillingApi

Rename blocking states.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: fix testInsertBlockingEvents

The mock object wasn't setup properly.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: fix test issue with global total order

globaltotalOrder is static, causing tests to be flaky (ordering issue).
Applied a band-aid for now, but we probably want to get rid of it.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: fix ordering in getBlockingStateFor SQL

The history needs to be ordered, hence the asc. But to get the current
(latest) state, we need to order desc limit 1.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: fix BillingEvent for invoice

Make invoice ignore the START_BILLING_DISABLED event, by setting the
fixed price to null and setting the billing period to NO_BILLING_PERIOD.

Add an overdue test in TestInvoiceDispatcher to verify this works. The
(hardcoded) test scenario is similar to the one in beatrix
(TestOverdueIntegration#testBasicOverdueState).

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
beatrix: fix TestOverdueIntegration

The test now passes. Add extra checks for invoice items (it's a bit
convoluted because of the extra credit generated).

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: remove unused MockPrice in TestBillingApi

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
invoice: optimize imports in DefaultInvoiceGenerator

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
junction: cleanup TestBillingApi

* Refactor tests to avoid duplicated setup code
* Make disabled tests pass

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
beatrix: fix indentation in TestIntegration

No functional change.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
payment: post an event on the bus if there is no default payment method

If a payment cannot be processed because there is no default payment
method, we need to post an event on the bus for overdue to refresh the
overdue state.

Note that an event will be posted even if the invoice balance is zero.

Added a Beatrix test for this scenario.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
beatrix: test the overdue notification queue

The test was previously checking the overdue states by explicitly
calling refresh on the bundle (the configuration parameter
autoReevaluationInterval was so high, that the notification queue never
kicked in).

This wasn't fully testing overdue though. For instance, the test
testOverdueStateIfNoPaymentMethod() would pass even if we don't send
the payment errors on the bus when there is no default payment method
(because we were asking overdue to refresh its state manually).
Since there is no payment retry if the account doesn't have a default
payment method, overdue has to rely on the notification queue to refresh
its state (and make the bundle go through the various overdue stages
when we move the clock).

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
beatrix: fix comments in TestOverdueIntegration

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
analytics: fix potential NPE in AuditedPaymentDao

AuditedPaymentDao.getPayment(paymentId) throws NPE if paymentId is null.
We want to ignore these events in analytics anyways as they are not real
attempts.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>