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.timeline;
 
 import java.util.List;
 
 
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 
 
     @Test(groups = "slow")
     public void testRepairChangeBPWithAddonIncluded() throws Exception {
         final String baseProduct = "Shotgun";
         final BillingPeriod baseTerm = .;
         final String basePriceList = .;
 
         // CREATE BP
         final DefaultSubscriptionBase baseSubscription = .createSubscription(baseProductbaseTermbasePriceList);
 
         // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
         Interval it = new Interval(.getUTCNow(), .getUTCNow().plusDays(4));
 
         final DefaultSubscriptionBase aoSubscription = .createSubscription("Telescopic-Scope"..);
 
         final DefaultSubscriptionBase aoSubscription2 = .createSubscription("Laser-Scope"..);
 
         // MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
         it = new Interval(.getUTCNow(), .getUTCNow().plusDays(3));
 
         BundleBaseTimeline bundleRepair = .getBundleTimeline(.getId(), );
         .sortEventsOnBundle(bundleRepair);
 
         // Quick check
         SubscriptionBaseTimeline bpRepair = .getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
         assertEquals(bpRepair.getExistingEvents().size(), 2);
 
         SubscriptionBaseTimeline aoRepair = .getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
         assertEquals(aoRepair.getExistingEvents().size(), 2);
 
         SubscriptionBaseTimeline aoRepair2 = .getSubscriptionRepair(aoSubscription2.getId(), bundleRepair);
         assertEquals(aoRepair2.getExistingEvents().size(), 2);
 
         final DateTime bpChangeDate = .getUTCNow().minusDays(1);
 
         final List<DeletedEventdes = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>();
         des.add(.createDeletedEvent(bpRepair.getExistingEvents().get(1).getEventId()));
 
         final NewEvent ne = .createNewEvent(.bpChangeDatespec);
 
         bpRepair = .createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne));
 
         bundleRepair = .createBundleRepair(.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
 
         boolean dryRun = true;
         final BundleBaseTimeline dryRunBundleRepair = .repairBundle(bundleRepairdryRun);
 
         aoRepair = .getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
         assertEquals(aoRepair.getExistingEvents().size(), 2);
        aoRepair2 = .getSubscriptionRepair(aoSubscription2.getId(), dryRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        bpRepair = .getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 3);
        // Check expected for AO
        final List<ExistingEventexpectedAO = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                                ...aoSubscription.getStartDate()));
                                                                ...bpChangeDate));
        int index = 0;
        for (final ExistingEvent e : expectedAO) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        final List<ExistingEventexpectedAO2 = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                                 ...aoSubscription2.getStartDate()));
                                                                 ...aoSubscription2.getStartDate().plusMonths(1)));
        index = 0;
        for (final ExistingEvent e : expectedAO2) {
            .validateExistingEventForAssertion(eaoRepair2.getExistingEvents().get(index++));
        }
        // Check expected for BP
        final List<ExistingEventexpectedBP = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                                ...baseSubscription.getStartDate()));
                                                                ...bpChangeDate));
                                                                ...baseSubscription.getStartDate().plusDays(30)));
        index = 0;
        for (final ExistingEvent e : expectedBP) {
            .validateExistingEventForAssertion(ebpRepair.getExistingEvents().get(index++));
        }
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription.getActiveVersion(), .);
        assertEquals(newAoSubscription2.getState(), .);
        assertEquals(newAoSubscription2.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription2.getActiveVersion(), .);
        assertEquals(newBaseSubscription.getState(), .);
        assertEquals(newBaseSubscription.getAllTransitions().size(), 2);
        assertEquals(newBaseSubscription.getActiveVersion(), .);
        dryRun = false;
        final BundleBaseTimeline realRunBundleRepair = .repairBundle(bundleRepairdryRun);
        assertListenerStatus();
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        bpRepair = .getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 3);
        index = 0;
        for (final ExistingEvent e : expectedAO) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        index = 0;
        for (final ExistingEvent e : expectedAO2) {
            .validateExistingEventForAssertion(eaoRepair2.getExistingEvents().get(index++));
        }
        index = 0;
        for (final ExistingEvent e : expectedBP) {
            .validateExistingEventForAssertion(ebpRepair.getExistingEvents().get(index++));
        }
        newAoSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(aoSubscription.getId(), );
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription.getActiveVersion(), . + 1);
        newAoSubscription2 = (DefaultSubscriptionBase.getSubscriptionFromId(aoSubscription2.getId(), );
        assertEquals(newAoSubscription2.getState(), .);
        assertEquals(newAoSubscription2.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription2.getActiveVersion(), . + 1);
        newBaseSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(baseSubscription.getId(), );
        assertEquals(newBaseSubscription.getState(), .);
        assertEquals(newBaseSubscription.getAllTransitions().size(), 3);
        assertEquals(newBaseSubscription.getActiveVersion(), . + 1);
    }
    @Test(groups = "slow")
    public void testRepairChangeBPWithAddonNonAvailable() throws Exception {
        final String baseProduct = "Shotgun";
        final BillingPeriod baseTerm = .;
        final String basePriceList = .;
        // CREATE BP
        final DefaultSubscriptionBase baseSubscription = .createSubscription(baseProductbaseTermbasePriceList);
        // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
        Interval it = new Interval(.getUTCNow(), .getUTCNow().plusDays(3));
        final DefaultSubscriptionBase aoSubscription = .createSubscription("Telescopic-Scope"..);
        // MOVE CLOCK A LITTLE BIT MORE -- AFTER TRIAL
        it = new Interval(.getUTCNow(), .getUTCNow().plusDays(32));
        assertListenerStatus();
        .sortEventsOnBundle(bundleRepair);
        // Quick check
        SubscriptionBaseTimeline bpRepair = .getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 2);
        SubscriptionBaseTimeline aoRepair = .getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        final DateTime bpChangeDate = .getUTCNow().minusDays(1);
        final NewEvent ne = .createNewEvent(.bpChangeDatespec);
        bpRepair = .createSubscriptionRepair(baseSubscription.getId(), Collections.<SubscriptionBaseTimeline.DeletedEvent>emptyList(), Collections.singletonList(ne));
        bundleRepair = .createBundleRepair(.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
        boolean dryRun = true;
        final BundleBaseTimeline dryRunBundleRepair = .repairBundle(bundleRepairdryRun);
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 3);
        bpRepair = .getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 3);
        // Check expected for AO
        final List<ExistingEventexpectedAO = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                                ...aoSubscription.getStartDate()));
                                                                ...baseSubscription.getStartDate().plusMonths(1)));
                                                                ...bpChangeDate));
        int index = 0;
        for (final ExistingEvent e : expectedAO) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        // Check expected for BP
        final List<ExistingEventexpectedBP = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                                ...baseSubscription.getStartDate()));
                                                                ...baseSubscription.getStartDate().plusDays(30)));
                                                                ...bpChangeDate));
        index = 0;
        for (final ExistingEvent e : expectedBP) {
            .validateExistingEventForAssertion(ebpRepair.getExistingEvents().get(index++));
        }
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription.getActiveVersion(), .);
        assertEquals(newBaseSubscription.getState(), .);
        assertEquals(newBaseSubscription.getAllTransitions().size(), 2);
        assertEquals(newBaseSubscription.getActiveVersion(), .);
        dryRun = false;
        final BundleBaseTimeline realRunBundleRepair = .repairBundle(bundleRepairdryRun);
        assertListenerStatus();
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 3);
        bpRepair = .getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 3);
        index = 0;
        for (final ExistingEvent e : expectedAO) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        index = 0;
        for (final ExistingEvent e : expectedBP) {
            .validateExistingEventForAssertion(ebpRepair.getExistingEvents().get(index++));
        }
        newAoSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(aoSubscription.getId(), );
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 3);
        assertEquals(newAoSubscription.getActiveVersion(), . + 1);
        newBaseSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(baseSubscription.getId(), );
        assertEquals(newBaseSubscription.getState(), .);
        assertEquals(newBaseSubscription.getAllTransitions().size(), 3);
        assertEquals(newBaseSubscription.getActiveVersion(), . + 1);
    }
    @Test(groups = "slow")
    public void testRepairCancelBP_EOT_WithAddons() throws Exception {
        final String baseProduct = "Shotgun";
        final BillingPeriod baseTerm = .;
        final String basePriceList = .;
        // CREATE BP
        DefaultSubscriptionBase baseSubscription = .createSubscription(baseProductbaseTermbasePriceList);
        // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
        Interval it = new Interval(.getUTCNow(), .getUTCNow().plusDays(4));
        final DefaultSubscriptionBase aoSubscription = .createSubscription("Telescopic-Scope"..);
        // MOVE CLOCK A LITTLE BIT MORE -- AFTER TRIAL
        it = new Interval(.getUTCNow(), .getUTCNow().plusDays(40));
        assertListenerStatus();
        // SET CTD to BASE SUBSCRIPTION SP CANCEL OCCURS EOT
        final DateTime newChargedThroughDate = baseSubscription.getStartDate().plusDays(30).plusMonths(1);
        .setChargedThroughDate(baseSubscription.getId(), newChargedThroughDate);
        baseSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(baseSubscription.getId(), );
        .sortEventsOnBundle(bundleRepair);
        // Quick check
        SubscriptionBaseTimeline bpRepair = .getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 2);
        SubscriptionBaseTimeline aoRepair = .getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        final DateTime bpCancelDate = .getUTCNow().minusDays(1);
        final NewEvent ne = .createNewEvent(.bpCancelDatenull);
        bpRepair = .createSubscriptionRepair(baseSubscription.getId(), Collections.<SubscriptionBaseTimeline.DeletedEvent>emptyList(), Collections.singletonList(ne));
        bundleRepair = .createBundleRepair(.getId(), bundleRepair.getViewId(), Collections.singletonList(bpRepair));
        boolean dryRun = true;
        final BundleBaseTimeline dryRunBundleRepair = .repairBundle(bundleRepairdryRun);
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 3);
        bpRepair = .getSubscriptionRepair(baseSubscription.getId(), dryRunBundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 3);
        // Check expected for AO
        final List<ExistingEventexpectedAO = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                                ...aoSubscription.getStartDate()));
                                                                ...baseSubscription.getStartDate().plusMonths(1)));
                                                                ...bpCancelDate));
        int index = 0;
        for (final ExistingEvent e : expectedAO) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        // Check expected for BP
        final List<ExistingEventexpectedBP = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                                ...baseSubscription.getStartDate()));
                                                                ...baseSubscription.getStartDate().plusDays(30)));
                                                                ...bpCancelDate));
        index = 0;
        for (final ExistingEvent e : expectedBP) {
            .validateExistingEventForAssertion(ebpRepair.getExistingEvents().get(index++));
        }
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription.getActiveVersion(), .);
        assertEquals(newBaseSubscription.getState(), .);
        assertEquals(newBaseSubscription.getAllTransitions().size(), 2);
        assertEquals(newBaseSubscription.getActiveVersion(), .);
        dryRun = false;
        final BundleBaseTimeline realRunBundleRepair = .repairBundle(bundleRepairdryRun);
        assertListenerStatus();
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 3);
        bpRepair = .getSubscriptionRepair(baseSubscription.getId(), realRunBundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 3);
        index = 0;
        for (final ExistingEvent e : expectedAO) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        index = 0;
        for (final ExistingEvent e : expectedBP) {
            .validateExistingEventForAssertion(ebpRepair.getExistingEvents().get(index++));
        }
        newAoSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(aoSubscription.getId(), );
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 3);
        assertEquals(newAoSubscription.getActiveVersion(), . + 1);
        newBaseSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(baseSubscription.getId(), );
        assertEquals(newBaseSubscription.getState(), .);
        assertEquals(newBaseSubscription.getAllTransitions().size(), 3);
        assertEquals(newBaseSubscription.getActiveVersion(), . + 1);
    }
    @Test(groups = "slow")
    public void testRepairCancelAO() throws Exception {
        final String baseProduct = "Shotgun";
        final BillingPeriod baseTerm = .;
        final String basePriceList = .;
        // CREATE BP
        final DefaultSubscriptionBase baseSubscription = .createSubscription(baseProductbaseTermbasePriceList);
        // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
        Interval it = new Interval(.getUTCNow(), .getUTCNow().plusDays(4));
        final DefaultSubscriptionBase aoSubscription = .createSubscription("Telescopic-Scope"..);
        // MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
        it = new Interval(.getUTCNow(), .getUTCNow().plusDays(3));
        final BundleBaseTimeline bundleRepair = .getBundleTimeline(.getId(), );
        .sortEventsOnBundle(bundleRepair);
        // Quick check
        SubscriptionBaseTimeline bpRepair = .getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 2);
        SubscriptionBaseTimeline aoRepair = .getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        final List<DeletedEventdes = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>();
        des.add(.createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
        final DateTime aoCancelDate = aoSubscription.getStartDate().plusDays(1);
        final NewEvent ne = .createNewEvent(.aoCancelDatenull);
        final SubscriptionBaseTimeline saoRepair = .createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
        final BundleBaseTimeline bRepair = .createBundleRepair(.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
        boolean dryRun = true;
        final BundleBaseTimeline dryRunBundleRepair = .repairBundle(bRepairdryRun);
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        bpRepair = .getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 2);
        final List<ExistingEventexpected = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                              ...aoSubscription.getStartDate()));
                                                              ...aoCancelDate));
        int index = 0;
        for (final ExistingEvent e : expected) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription.getActiveVersion(), .);
        assertEquals(newBaseSubscription.getState(), .);
        assertEquals(newBaseSubscription.getAllTransitions().size(), 2);
        assertEquals(newBaseSubscription.getActiveVersion(), .);
        dryRun = false;
        final BundleBaseTimeline realRunBundleRepair = .repairBundle(bRepairdryRun);
        assertListenerStatus();
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        index = 0;
        for (final ExistingEvent e : expected) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        newAoSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(aoSubscription.getId(), );
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription.getActiveVersion(), . + 1);
        newBaseSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(baseSubscription.getId(), );
        assertEquals(newBaseSubscription.getState(), .);
        assertEquals(newBaseSubscription.getAllTransitions().size(), 2);
        assertEquals(newBaseSubscription.getActiveVersion(), .);
    }
    @Test(groups = "slow")
    public void testRepairRecreateAO() throws Exception {
        final String baseProduct = "Shotgun";
        final BillingPeriod baseTerm = .;
        final String basePriceList = .;
        // CREATE BP
        final DefaultSubscriptionBase baseSubscription = .createSubscription(baseProductbaseTermbasePriceList);
        // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
        Interval it = new Interval(.getUTCNow(), .getUTCNow().plusDays(4));
        final DefaultSubscriptionBase aoSubscription = .createSubscription("Telescopic-Scope"..);
        // MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
        it = new Interval(.getUTCNow(), .getUTCNow().plusDays(3));
        final BundleBaseTimeline bundleRepair = .getBundleTimeline(.getId(), );
        .sortEventsOnBundle(bundleRepair);
        // Quick check
        final SubscriptionBaseTimeline bpRepair = .getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 2);
        SubscriptionBaseTimeline aoRepair = .getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        final List<DeletedEventdes = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>();
        des.add(.createDeletedEvent(aoRepair.getExistingEvents().get(0).getEventId()));
        des.add(.createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
        final DateTime aoRecreateDate = aoSubscription.getStartDate().plusDays(1);
        final NewEvent ne = .createNewEvent(.aoRecreateDatespec);
        final SubscriptionBaseTimeline saoRepair = .createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
        final BundleBaseTimeline bRepair = .createBundleRepair(.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
        boolean dryRun = true;
        final BundleBaseTimeline dryRunBundleRepair = .repairBundle(bRepairdryRun);
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        final List<ExistingEventexpected = new LinkedList<SubscriptionBaseTimeline.ExistingEvent>();
                                                              ...aoRecreateDate));
                                                              ...baseSubscription.getStartDate().plusMonths(1) /* Bundle align */));
        int index = 0;
        for (final ExistingEvent e : expected) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription.getStartDate(), aoSubscription.getStartDate());
        assertEquals(newAoSubscription.getActiveVersion(), .);
        // NOW COMMIT
        dryRun = false;
        final BundleBaseTimeline realRunBundleRepair = .repairBundle(bRepairdryRun);
        assertListenerStatus();
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), realRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        index = 0;
        for (final ExistingEvent e : expected) {
            .validateExistingEventForAssertion(eaoRepair.getExistingEvents().get(index++));
        }
        newAoSubscription = (DefaultSubscriptionBase.getSubscriptionFromId(aoSubscription.getId(), );
        assertEquals(newAoSubscription.getState(), .);
        assertEquals(newAoSubscription.getAllTransitions().size(), 2);
        assertEquals(newAoSubscription.getStartDate(), aoRecreateDate);
        assertEquals(newAoSubscription.getActiveVersion(), . + 1);
    }
    // Fasten your seatbelt here:
    //
    // We are doing repair for multi-phase tiered-addon with different alignment:
    // Telescopic-Scope -> Laser-Scope
    // Tiered ADON logic
    // . Both multi phase
    // . Telescopic-Scope (bundle align) and Laser-Scope is SubscriptionBase align
    //
    @Test(groups = "slow")
    public void testRepairChangeAOOK() throws Exception {
        final String baseProduct = "Shotgun";
        final BillingPeriod baseTerm = .;
        final String basePriceList = .;
        // CREATE BP
        final DefaultSubscriptionBase baseSubscription = .createSubscription(baseProductbaseTermbasePriceList);
        // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL
        Interval it = new Interval(.getUTCNow(), .getUTCNow().plusDays(4));
        final DefaultSubscriptionBase aoSubscription = .createSubscription("Telescopic-Scope"..);
        // MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL
        it = new Interval(.getUTCNow(), .getUTCNow().plusDays(3));
        final BundleBaseTimeline bundleRepair = .getBundleTimeline(.getId(), );
        .sortEventsOnBundle(bundleRepair);
        // Quick check
        final SubscriptionBaseTimeline bpRepair = .getSubscriptionRepair(baseSubscription.getId(), bundleRepair);
        assertEquals(bpRepair.getExistingEvents().size(), 2);
        SubscriptionBaseTimeline aoRepair = .getSubscriptionRepair(aoSubscription.getId(), bundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 2);
        final List<DeletedEventdes = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>();
        des.add(.createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId()));
        final DateTime aoChangeDate = aoSubscription.getStartDate().plusDays(1);
        final NewEvent ne = .createNewEvent(.aoChangeDatespec);
        final SubscriptionBaseTimeline saoRepair = .createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne));
        final BundleBaseTimeline bRepair = .createBundleRepair(.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair));
        boolean dryRun = true;
        final BundleBaseTimeline dryRunBundleRepair = .repairBundle(bRepairdryRun);
        aoRepair = .getSubscriptionRepair(aoSubscription.getId(), dryRunBundleRepair);
        assertEquals(aoRepair.getExistingEvents().size(), 3);
        final List<ExistingEventexpected = new LinkedList<