@Test(groups = "fast")
  public void testFromSubscription() throws Exception {
    BusinessSubscriptionEvent event;

    final DateTime now = new DateTime();

    event =
        BusinessSubscriptionEvent.subscriptionCreated(
            subscription.getCurrentPlan().getName(), catalog, now, now);
    Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.ADD);
    Assert.assertEquals(event.getCategory(), product.getCategory());
    Assert.assertEquals(event.toString(), "ADD_BASE");

    event =
        BusinessSubscriptionEvent.subscriptionCancelled(
            subscription.getCurrentPlan().getName(), catalog, now, now);
    Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.CANCEL);
    Assert.assertEquals(event.getCategory(), product.getCategory());
    Assert.assertEquals(event.toString(), "CANCEL_BASE");

    event =
        BusinessSubscriptionEvent.subscriptionChanged(
            subscription.getCurrentPlan().getName(), catalog, now, now);
    Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.CHANGE);
    Assert.assertEquals(event.getCategory(), product.getCategory());
    Assert.assertEquals(event.toString(), "CHANGE_BASE");

    event =
        BusinessSubscriptionEvent.subscriptionPhaseChanged(
            subscription.getCurrentPlan().getName(), subscription.getState(), catalog, now, now);
    // The subscription is still active, it's a system change
    Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.SYSTEM_CHANGE);
    Assert.assertEquals(event.getCategory(), product.getCategory());
    Assert.assertEquals(event.toString(), "SYSTEM_CHANGE_BASE");

    subscription = new MockSubscription(Subscription.SubscriptionState.CANCELLED, plan, phase);
    event =
        BusinessSubscriptionEvent.subscriptionPhaseChanged(
            subscription.getCurrentPlan().getName(), subscription.getState(), catalog, now, now);
    // The subscription is cancelled, it's a system cancellation
    Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.SYSTEM_CANCEL);
    Assert.assertEquals(event.getCategory(), product.getCategory());
    Assert.assertEquals(event.toString(), "SYSTEM_CANCEL_BASE");
  }
  private SubscriptionBaseTransition createTransition(
      final UUID entitlementId,
      final EventType eventType,
      final ApiEventType apiEventType,
      final DateTime requestedDate,
      final DateTime effectiveDate,
      final DateTime createdDate,
      final String prevPhaseName,
      final String nextPhaseName)
      throws CatalogApiException {

    final PlanPhase prevPhase = prevPhaseName != null ? Mockito.mock(PlanPhase.class) : null;
    if (prevPhase != null) {
      Mockito.when(prevPhase.getName()).thenReturn(prevPhaseName);
    }

    final PlanPhase nextPhase = nextPhaseName != null ? Mockito.mock(PlanPhase.class) : null;
    if (nextPhase != null) {
      Mockito.when(nextPhase.getName()).thenReturn(nextPhaseName);
    }

    // catalogService.getCurrentCatalog().findCurrentPhase("pistol-monthly-trial");
    final Plan plan = Mockito.mock(Plan.class);
    Mockito.when(plan.getName()).thenReturn("plan");

    // catalogService.getCurrentCatalog().findCurrentPlan("pistol-monthly");
    final Product product = Mockito.mock(Product.class);
    Mockito.when(product.getName()).thenReturn("product");

    // catalogService.getCurrentCatalog().findCurrentProduct("Pistol");

    final PriceList priceList = Mockito.mock(PriceList.class);
    Mockito.when(priceList.getName()).thenReturn("pricelist");

    // catalogService.getCurrentCatalog().findCurrentPricelist(PriceListSet.DEFAULT_PRICELIST_NAME);
    final BillingPeriod billingPeriod = BillingPeriod.MONTHLY;

    final SubscriptionBaseTransition transition =
        new SubscriptionBaseTransitionData(
            UUID.randomUUID(),
            entitlementId,
            bundleId,
            eventType,
            apiEventType,
            requestedDate,
            effectiveDate,
            null,
            null,
            null,
            plan,
            prevPhase,
            priceList,
            null,
            null,
            null,
            plan,
            nextPhase,
            priceList,
            1L,
            createdDate,
            UUID.randomUUID(),
            true);
    return transition;
  }