/entitlement/src/test/java/com/ning/billing/entitlement/api/user/TestUserApiScenarios.java

https://github.com/martinwesthead/killbill · Java · 99 lines · 58 code · 21 blank · 20 comment · 0 complexity · a6d42d2ffa494e9c305ca9e6299867d4 MD5 · raw file

  1. /*
  2. * Copyright 2010-2011 Ning, Inc.
  3. *
  4. * Ning licenses this file to you under the Apache License, version 2.0
  5. * (the "License"); you may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations
  14. * under the License.
  15. */
  16. package com.ning.billing.entitlement.api.user;
  17. import static org.testng.Assert.assertEquals;
  18. import static org.testng.Assert.assertTrue;
  19. import static org.testng.Assert.assertFalse;
  20. import org.joda.time.DateTime;
  21. import org.testng.Assert;
  22. import org.testng.annotations.Test;
  23. import com.google.inject.Guice;
  24. import com.google.inject.Injector;
  25. import com.google.inject.Stage;
  26. import com.ning.billing.catalog.api.BillingPeriod;
  27. import com.ning.billing.catalog.api.IDuration;
  28. import com.ning.billing.catalog.api.IPlanPhase;
  29. import com.ning.billing.catalog.api.PhaseType;
  30. import com.ning.billing.entitlement.api.ApiTestListener.NextEvent;
  31. import com.ning.billing.entitlement.glue.EngineModuleSqlMock;
  32. import com.ning.billing.util.clock.Clock;
  33. public class TestUserApiScenarios extends TestUserApiBase {
  34. @Override
  35. protected Injector getInjector() {
  36. return Guice.createInjector(Stage.DEVELOPMENT, new EngineModuleSqlMock());
  37. }
  38. @Test(enabled=true)
  39. public void testChangeIMMCancelUncancelChangeEOT() {
  40. log.info("Starting testChangeIMMCancelUncancelChangeEOT");
  41. try {
  42. Subscription subscription = createSubscription("Assault-Rifle", BillingPeriod.MONTHLY, "gunclubDiscount");
  43. IPlanPhase trialPhase = subscription.getCurrentPhase();
  44. assertEquals(trialPhase.getPhaseType(), PhaseType.TRIAL);
  45. testListener.pushExpectedEvent(NextEvent.CHANGE);
  46. subscription.changePlan("Pistol", BillingPeriod.ANNUAL, "gunclubDiscount");
  47. testListener.isCompleted(3000);
  48. // MOVE TO NEXT PHASE
  49. testListener.pushExpectedEvent(NextEvent.PHASE);
  50. clock.setDeltaFromReality(trialPhase.getDuration(), DAY_IN_MS);
  51. assertTrue(testListener.isCompleted(2000));
  52. // SET CTD
  53. IDuration ctd = getDurationMonth(1);
  54. DateTime expectedPhaseTrialChange = Clock.addDuration(subscription.getStartDate(), trialPhase.getDuration());
  55. DateTime newChargedThroughDate = Clock.addDuration(expectedPhaseTrialChange, ctd);
  56. billingApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate);
  57. subscription = (Subscription) entitlementApi.getSubscriptionFromId(subscription.getId());
  58. // CANCEL EOT
  59. testListener.pushExpectedEvent(NextEvent.CANCEL);
  60. subscription.cancel();
  61. assertFalse(testListener.isCompleted(2000));
  62. testListener.reset();
  63. // UNCANCEL
  64. subscription.uncancel();
  65. // CHANGE EOT
  66. testListener.pushExpectedEvent(NextEvent.CHANGE);
  67. subscription.changePlan("Pistol", BillingPeriod.MONTHLY, "gunclubDiscount");
  68. assertFalse(testListener.isCompleted(2000));
  69. clock.addDeltaFromReality(ctd);
  70. assertTrue(testListener.isCompleted(3000));
  71. } catch (EntitlementUserApiException e) {
  72. Assert.fail(e.getMessage());
  73. }
  74. }
  75. @Test(enabled=false)
  76. private void testChangeEOTCancelUncancelChangeIMM() {
  77. }
  78. }