@Test(groups = "fast") public void testENT_REPAIR_AO_CREATE_BEFORE_BP_START() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException {
@Test(groups = "fast", enabled = false) public void testENT_REPAIR_MISSING_AO_DELETE_EVENT() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException {
@Test(groups = "fast") public void testENT_REPAIR_NEW_EVENT_BEFORE_LAST_AO_REMAINING() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { // MOVE CLOCK A LITTLE BIT-- STILL IN TRIAL Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4)); clock.addDeltaFromReality(it.toDurationMillis()); final DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); // MOVE CLOCK A LITTLE BIT MORE -- STILL IN TRIAL it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4)); clock.addDeltaFromReality(it.toDurationMillis()); BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); // Quick check final SubscriptionBaseTimeline bpRepair = testUtil.getSubscriptionRepair(baseSubscription.getId(), bundleRepair); assertEquals(bpRepair.getExistingEvents().size(), 2); final SubscriptionBaseTimeline aoRepair = testUtil.getSubscriptionRepair(aoSubscription.getId(), bundleRepair); assertEquals(aoRepair.getExistingEvents().size(), 2); final List<DeletedEvent> des = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>(); //des.add(createDeletedEvent(aoRepair.getExistingEvents().get(1).getEventId())); final DateTime aoCancelDate = aoSubscription.getStartDate().plusDays(10); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CANCEL, aoCancelDate, null); final SubscriptionBaseTimeline saoRepair = testUtil.createSubscriptionRepair(aoSubscription.getId(), des, Collections.singletonList(ne)); bundleRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(saoRepair)); final boolean dryRun = true; repairApi.repairBundle(bundleRepair, dryRun, callContext); } }, ErrorCode.SUB_REPAIR_NEW_EVENT_BEFORE_LAST_AO_REMAINING); }
@Test(groups = "slow") public void testENT_REPAIR_VIEW_CHANGED_ctd() throws Exception { final TestWithException test = new TestWithException(); final DateTime startDate = clock.getUTCNow(); test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException {
@Test(groups = "fast") public void testENT_REPAIR_INVALID_DELETE_SET() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3)); clock.addDeltaFromReality(it.toDurationMillis()); testListener.pushExpectedEvent(NextEvent.CHANGE); final DateTime changeTime = clock.getUTCNow(); baseSubscription.changePlanWithDate("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, changeTime, callContext); assertListenerStatus(); // MOVE AFTER TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(40)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final DeletedEvent de = testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId()); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_INVALID_DELETE_SET); }
@Test(groups = "fast", enabled = false) public void testENT_REPAIR_BP_RECREATE_MISSING_AO_CREATE() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException {
@Test(groups = "fast") public void testENT_REPAIR_SUB_EMPTY() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException { // MOVE AFTER TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(40)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final List<DeletedEvent> des = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>(); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId())); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId())); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_SUB_EMPTY); }
@Test(groups = "fast", enabled = false) // TODO - fails on jdk7 on Travis public void testENT_REPAIR_BP_RECREATE_MISSING_AO() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { //testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(4)); clock.addDeltaFromReality(it.toDurationMillis()); //assertListenerStatus(); final DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, "Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final DateTime newCreateTime = baseSubscription.getStartDate().plusDays(3); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.TRIAL); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CREATE, newCreateTime, spec); final List<DeletedEvent> des = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>(); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId())); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId())); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne)); // FIRST ISSUE DRY RUN final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); final boolean dryRun = true; repairApi.repairBundle(bRepair, dryRun, callContext); } }, ErrorCode.SUB_REPAIR_BP_RECREATE_MISSING_AO); }
@Test(groups = "slow") public void testENT_REPAIR_VIEW_CHANGED_newEvent() throws Exception { final TestWithException test = new TestWithException(); final DateTime startDate = clock.getUTCNow(); final SubscriptionBase baseSubscription = testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate); test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException, SubscriptionBaseApiException { final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final List<DeletedEvent> des = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>(); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(0).getEventId())); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId())); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); testListener.pushExpectedEvent(NextEvent.CHANGE); final DateTime changeTime = clock.getUTCNow(); baseSubscription.changePlanWithDate("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, changeTime, callContext); assertListenerStatus(); repairApi.repairBundle(bRepair, true, callContext); assertListenerStatus(); } }, ErrorCode.SUB_REPAIR_VIEW_CHANGED); }
@Test(groups = "fast") public void testENT_REPAIR_SUB_RECREATE_NOT_EMPTY() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException { // MOVE AFTER TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(40)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CREATE, baseSubscription.getStartDate().plusDays(10), spec); final List<DeletedEvent> des = new LinkedList<SubscriptionBaseTimeline.DeletedEvent>(); des.add(testUtil.createDeletedEvent(bundleRepair.getSubscriptions().get(0).getExistingEvents().get(1).getEventId())); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), des, Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_SUB_RECREATE_NOT_EMPTY); }
@Test(groups = "fast") public void testENT_REPAIR_NEW_EVENT_BEFORE_LAST_BP_REMAINING() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException { // MOVE AFTER TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(40)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.<DeletedEvent>emptyList(), Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_NEW_EVENT_BEFORE_LAST_BP_REMAINING); }
@Test(groups = "fast") public void testENT_REPAIR_NON_EXISTENT_DELETE_EVENT() throws Exception { test.withException(new TestWithExceptionCallback() { @Override public void doTest() throws SubscriptionBaseRepairException { final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final DeletedEvent de = testUtil.createDeletedEvent(UUID.randomUUID()); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_NON_EXISTENT_DELETE_EVENT); }
@Override @BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); test = new TestWithException(); final DateTime startDate = clock.getUTCNow(); baseSubscription = testUtil.createSubscription(bundle, baseProduct, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, startDate); }