Search in sources :

Example 21 with Usage

use of org.killbill.billing.catalog.api.Usage in project killbill by killbill.

the class TestInvoiceHelper method createMockBillingEvent.

public BillingEvent createMockBillingEvent(@Nullable final Account account, final SubscriptionBase subscription, final DateTime effectiveDate, final Plan plan, final PlanPhase planPhase, @Nullable final BigDecimal fixedPrice, @Nullable final BigDecimal recurringPrice, final Currency currency, final BillingPeriod billingPeriod, final int billCycleDayLocal, final BillingMode billingMode, final String description, final long totalOrdering, final SubscriptionBaseTransitionType type) {
    final Account mockAccount = Mockito.mock(Account.class);
    Mockito.when(mockAccount.getTimeZone()).thenReturn(DateTimeZone.UTC);
    return new BillingEvent() {

        @Override
        public int getBillCycleDayLocal() {
            return billCycleDayLocal;
        }

        @Override
        public SubscriptionBase getSubscription() {
            return subscription;
        }

        @Override
        public DateTime getEffectiveDate() {
            return effectiveDate;
        }

        @Override
        public PlanPhase getPlanPhase() {
            return planPhase;
        }

        @Override
        public Plan getPlan() {
            return plan;
        }

        @Override
        public BillingPeriod getBillingPeriod() {
            return billingPeriod;
        }

        @Override
        public String getDescription() {
            return description;
        }

        @Override
        public BigDecimal getFixedPrice() {
            return fixedPrice;
        }

        @Override
        public BigDecimal getRecurringPrice(DateTime effectiveDate) {
            return recurringPrice;
        }

        @Override
        public Currency getCurrency() {
            return currency;
        }

        @Override
        public SubscriptionBaseTransitionType getTransitionType() {
            return type;
        }

        @Override
        public Long getTotalOrdering() {
            return totalOrdering;
        }

        @Override
        public DateTimeZone getTimeZone() {
            return DateTimeZone.UTC;
        }

        @Override
        public List<Usage> getUsages() {
            return Collections.emptyList();
        }

        @Override
        public int compareTo(final BillingEvent e1) {
            if (!getSubscription().getId().equals(e1.getSubscription().getId())) {
                // First order by subscription
                return getSubscription().getId().compareTo(e1.getSubscription().getId());
            } else {
                // subscriptions are the same
                if (!getEffectiveDate().equals(e1.getEffectiveDate())) {
                    // Secondly order by date
                    return getEffectiveDate().compareTo(e1.getEffectiveDate());
                } else {
                    // dates and subscriptions are the same
                    return getTotalOrdering().compareTo(e1.getTotalOrdering());
                }
            }
        }
    };
}
Also used : Account(org.killbill.billing.account.api.Account) Usage(org.killbill.billing.catalog.api.Usage) BillingEvent(org.killbill.billing.junction.BillingEvent) DateTime(org.joda.time.DateTime)

Aggregations

Usage (org.killbill.billing.catalog.api.Usage)21 Test (org.testng.annotations.Test)14 LocalDate (org.joda.time.LocalDate)11 BigDecimal (java.math.BigDecimal)9 DefaultTier (org.killbill.billing.catalog.DefaultTier)9 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)9 DefaultUsage (org.killbill.billing.catalog.DefaultUsage)8 HashMap (java.util.HashMap)7 DefaultTieredBlock (org.killbill.billing.catalog.DefaultTieredBlock)7 UsageInvoiceItem (org.killbill.billing.invoice.model.UsageInvoiceItem)7 RawUsage (org.killbill.billing.usage.RawUsage)7 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)6 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)5 BillingEvent (org.killbill.billing.junction.BillingEvent)5 Function (com.google.common.base.Function)4 ArrayList (java.util.ArrayList)4 RolledUpUsage (org.killbill.billing.usage.api.RolledUpUsage)4 DefaultRawUsage (org.killbill.billing.usage.api.svcs.DefaultRawUsage)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2