Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2013 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.
  */
 
 package com.ning.billing.subscription.api.transfer;
 
 import java.util.List;
 import java.util.UUID;
 
 
 
 
 // Simple unit tests for DefaultSubscriptionBaseTransferApi, see TestTransfer for more advanced tests with dao
 
 
     @Override
     @BeforeMethod(groups = "fast")
     public void beforeMethod() throws Exception {
         super.beforeMethod();
         final NonEntityDao nonEntityDao = Mockito.mock(NonEntityDao.class);
         final SubscriptionDao dao = Mockito.mock(SubscriptionDao.class);
         final CatalogService catalogService = new MockCatalogService(new MockCatalog());
         final SubscriptionBaseApiService apiService = Mockito.mock(SubscriptionBaseApiService.class);
         final SubscriptionBaseTimelineApi timelineApi = Mockito.mock(SubscriptionBaseTimelineApi.class);
         final InternalCallContextFactory internalCallContextFactory = new InternalCallContextFactory(nonEntityDaonew CacheControllerDispatcher());
          = new DefaultSubscriptionBaseTransferApi(daotimelineApicatalogServiceapiServiceinternalCallContextFactory);
     }
 
     @Test(groups = "fast")
         final DateTime subscriptionStartTime = .getUTCNow();
         final DateTime subscriptionCancelTime = subscriptionStartTime.plusDays(1);
         final ImmutableList<ExistingEventexistingEvents = ImmutableList.<ExistingEvent>of(createEvent(subscriptionStartTime.),
                                                                                             createEvent(subscriptionCancelTime.));
         final SubscriptionBuilder subscriptionBuilder = new SubscriptionBuilder();
         final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(subscriptionBuilder);
 
         final DateTime transferDate = subscriptionStartTime.plusDays(10);
         final List<SubscriptionBaseEventevents = .toEvents(existingEventssubscriptiontransferDate);
 
         Assert.assertEquals(events.size(), 0);
     }
 
     @Test(groups = "fast")
     public void testEventsForCancelledSubscriptionAfterTransfer() throws Exception {
         final DateTime subscriptionStartTime = .getUTCNow();
         final DateTime subscriptionCancelTime = subscriptionStartTime.plusDays(1);
         final ImmutableList<ExistingEventexistingEvents = ImmutableList.<ExistingEvent>of(createEvent(subscriptionStartTime.),
                                                                                             createEvent(subscriptionCancelTime.));
         final SubscriptionBuilder subscriptionBuilder = new SubscriptionBuilder();
         final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(subscriptionBuilder);
 
         final DateTime transferDate = subscriptionStartTime.plusHours(1);
         final List<SubscriptionBaseEventevents = .toEvents(existingEventssubscriptiontransferDate);
 
         Assert.assertEquals(events.size(), 1);
        Assert.assertEquals(events.get(0).getType(), .);
        Assert.assertEquals(events.get(0).getEffectiveDate(), transferDate);
        Assert.assertEquals(((ApiEventTransferevents.get(0)).getEventType(), .);
    }
    @Test(groups = "fast")
    public void testEventsAfterTransferForMigratedBundle1() throws Exception {
        // MIGRATE_ENTITLEMENT then MIGRATE_BILLING (both in the past)
        final DateTime transferDate = .getUTCNow();
        final DateTime migrateSubscriptionEventEffectiveDate = transferDate.minusDays(10);
        final DateTime migrateBillingEventEffectiveDate = migrateSubscriptionEventEffectiveDate.plusDays(1);
        final List<SubscriptionBaseEventevents = transferBundle(migrateSubscriptionEventEffectiveDatemigrateBillingEventEffectiveDatetransferDate);
        Assert.assertEquals(events.size(), 1);
        Assert.assertEquals(events.get(0).getType(), .);
        Assert.assertEquals(events.get(0).getEffectiveDate(), transferDate);
        Assert.assertEquals(((ApiEventTransferevents.get(0)).getEventType(), .);
    }
    @Test(groups = "fast")
    public void testEventsAfterTransferForMigratedBundle2() throws Exception {
        // MIGRATE_ENTITLEMENT and MIGRATE_BILLING at the same time (both in the past)
        final DateTime transferDate = .getUTCNow();
        final DateTime migrateSubscriptionEventEffectiveDate = transferDate.minusDays(10);
        final DateTime migrateBillingEventEffectiveDate = migrateSubscriptionEventEffectiveDate;
        final List<SubscriptionBaseEventevents = transferBundle(migrateSubscriptionEventEffectiveDatemigrateBillingEventEffectiveDatetransferDate);
        Assert.assertEquals(events.size(), 1);
        Assert.assertEquals(events.get(0).getType(), .);
        Assert.assertEquals(events.get(0).getEffectiveDate(), transferDate);
        Assert.assertEquals(((ApiEventTransferevents.get(0)).getEventType(), .);
    }
    @Test(groups = "fast")
    public void testEventsAfterTransferForMigratedBundle3() throws Exception {
        // MIGRATE_ENTITLEMENT then MIGRATE_BILLING (the latter in the future)
        final DateTime transferDate = .getUTCNow();
        final DateTime migrateSubscriptionEventEffectiveDate = transferDate.minusDays(10);
        final DateTime migrateBillingEventEffectiveDate = migrateSubscriptionEventEffectiveDate.plusDays(20);
        final List<SubscriptionBaseEventevents = transferBundle(migrateSubscriptionEventEffectiveDatemigrateBillingEventEffectiveDatetransferDate);
        Assert.assertEquals(events.size(), 1);
        Assert.assertEquals(events.get(0).getType(), .);
        Assert.assertEquals(events.get(0).getEffectiveDate(), transferDate);
        Assert.assertEquals(((ApiEventTransferevents.get(0)).getEventType(), .);
    }
    @Test(groups = "fast")
    public void testEventsAfterTransferForMigratedBundle4() throws Exception {
        // MIGRATE_ENTITLEMENT then MIGRATE_BILLING (both in the future)
        final DateTime transferDate = .getUTCNow();
        final DateTime migrateSubscriptionEventEffectiveDate = transferDate.plusDays(10);
        final DateTime migrateBillingEventEffectiveDate = migrateSubscriptionEventEffectiveDate.plusDays(20);
        final List<SubscriptionBaseEventevents = transferBundle(migrateSubscriptionEventEffectiveDatemigrateBillingEventEffectiveDatetransferDate);
        Assert.assertEquals(events.size(), 1);
        Assert.assertEquals(events.get(0).getType(), .);
        Assert.assertEquals(events.get(0).getEffectiveDate(), migrateSubscriptionEventEffectiveDate);
        Assert.assertEquals(((ApiEventTransferevents.get(0)).getEventType(), .);
    }
    private List<SubscriptionBaseEventtransferBundle(final DateTime migrateSubscriptionEventEffectiveDatefinal DateTime migrateBillingEventEffectiveDate,
                                                       final DateTime transferDatethrows SubscriptionBaseTransferApiException {
        final ImmutableList<ExistingEventexistingEvents = createMigrateEvents(migrateSubscriptionEventEffectiveDatemigrateBillingEventEffectiveDate);
        final SubscriptionBuilder subscriptionBuilder = new SubscriptionBuilder();
        final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(subscriptionBuilder);
        return .toEvents(existingEventssubscriptiontransferDate);
    }
    private ExistingEvent createEvent(final DateTime eventEffectiveDatefinal SubscriptionBaseTransitionType subscriptionTransitionType) {
        return new ExistingEvent() {
            @Override
            public DateTime getEffectiveDate() {
                return eventEffectiveDate;
            }
            @Override
            public String getPlanPhaseName() {
                return ..equals(subscriptionTransitionType) ? null : "BicycleTrialEvergreen1USD-trial";
            }
            @Override
            public UUID getEventId() {
                return UUID.randomUUID();
            }
            @Override
            public PlanPhaseSpecifier getPlanPhaseSpecifier() {
                return ..equals(subscriptionTransitionType) ? null :
                       new PlanPhaseSpecifier("BicycleTrialEvergreen1USD"..,
                                              ..);
            }
            @Override
            public DateTime getRequestedDate() {
                return getEffectiveDate();
            }
            @Override
                return subscriptionTransitionType;
            }
        };
    }
    private ImmutableList<ExistingEventcreateMigrateEvents(final DateTime migrateSubscriptionEventEffectiveDatefinal DateTime migrateBillingEventEffectiveDate) {
        final ExistingEvent migrateEntitlementEvent = new ExistingEvent() {
            @Override
            public DateTime getEffectiveDate() {
                return migrateSubscriptionEventEffectiveDate;
            }
            @Override
            public String getPlanPhaseName() {
                return "BicycleTrialEvergreen1USD-trial";
            }
            @Override
            public UUID getEventId() {
                return UUID.randomUUID();
            }
            @Override
            public PlanPhaseSpecifier getPlanPhaseSpecifier() {
                return new PlanPhaseSpecifier("BicycleTrialEvergreen1USD"..,
                                              ..);
            }
            @Override
            public DateTime getRequestedDate() {
                return getEffectiveDate();
            }
            @Override
                return .;
            }
        };
        final ExistingEvent migrateBillingEvent = new ExistingEvent() {
            @Override
            public DateTime getEffectiveDate() {
                return migrateBillingEventEffectiveDate;
            }
            @Override
            public String getPlanPhaseName() {
                return migrateEntitlementEvent.getPlanPhaseName();
            }
            @Override
            public UUID getEventId() {
                return UUID.randomUUID();
            }
            @Override
            public PlanPhaseSpecifier getPlanPhaseSpecifier() {
                return migrateEntitlementEvent.getPlanPhaseSpecifier();
            }
            @Override
            public DateTime getRequestedDate() {
                return migrateEntitlementEvent.getRequestedDate();
            }
            @Override
                return .;
            }
        };
        return ImmutableList.<ExistingEvent>of(migrateEntitlementEventmigrateBillingEvent);
    }
New to GrepCode? Check out our FAQ X