@Test(groups = "fast") public void testSerializationWithAddOns() throws Exception { final SubscriptionUpdate subscription = new SubscriptionUpdate(); subscription.setPlanCode("gold"); subscription.setTimeframe(SubscriptionUpdate.Timeframe.now); subscription.setUnitAmountInCents(800); subscription.setQuantity(1); final SubscriptionAddOns addOns = new SubscriptionAddOns(); final SubscriptionAddOn addOn = new SubscriptionAddOn(); addOn.setAddOnCode("extra_users"); addOn.setQuantity(2); addOn.setUnitAmountInCents(1000); addOns.add(addOn); subscription.setAddOns(addOns); final String xml = xmlMapper.writeValueAsString(subscription); Assert.assertEquals(xml, "<subscription xmlns=\"\">" + "<timeframe>now</timeframe>" + "<unit_amount_in_cents>800</unit_amount_in_cents>" + "<quantity>1</quantity>" + "<subscription_add_ons>" + "<subscription_add_on>" + "<add_on_code>extra_users</add_on_code>" + "<unit_amount_in_cents>1000</unit_amount_in_cents>" + "<quantity>2</quantity>" + "</subscription_add_on>" + "</subscription_add_ons>" + "<plan_code>gold</plan_code>" + "</subscription>"); }
@Test(groups = "fast") public void testSerializationWithAddOns() throws Exception { final SubscriptionUpdate subscription = new SubscriptionUpdate(); subscription.setPlanCode("gold"); subscription.setTimeframe(SubscriptionUpdate.Timeframe.now); subscription.setUnitAmountInCents(800); subscription.setQuantity(1); final SubscriptionAddOns addOns = new SubscriptionAddOns(); final SubscriptionAddOn addOn = new SubscriptionAddOn(); addOn.setAddOnCode("extra_users"); addOn.setQuantity(2); addOn.setUnitAmountInCents(1000); addOns.add(addOn); subscription.setAddOns(addOns); final String xml = xmlMapper.writeValueAsString(subscription); Assert.assertEquals(xml, "<subscription xmlns=\"\">" + "<timeframe>now</timeframe>" + "<unit_amount_in_cents>800</unit_amount_in_cents>" + "<quantity>1</quantity>" + "<subscription_add_ons>" + "<subscription_add_on>" + "<add_on_code>extra_users</add_on_code>" + "<unit_amount_in_cents>1000</unit_amount_in_cents>" + "<quantity>2</quantity>" + "</subscription_add_on>" + "</subscription_add_ons>" + "<plan_code>gold</plan_code>" + "</subscription>"); }
/** * Creates a random {@link com.ning.billing.recurly.model.Subscription} object for use in tests * * @param currencyCode The currency code for which the subscription will be charged in * @param plan The associated plan * @param account The associated account * @param planAddOns AddOns for that subscription * @return The {@link com.ning.billing.recurly.model.Subscription} object */ public static Subscription createRandomSubscription(final String currencyCode, final Plan plan, final Account account, final Iterable<AddOn> planAddOns) { final Subscription sub = new Subscription(); // Make sure the quantity is > 0 sub.setQuantity(randomInteger(10) + 1); sub.setCurrency(randomCurrency()); sub.setPlanCode(plan.getPlanCode()); sub.setAccount(account); sub.setUnitAmountInCents(randomInteger(10)); sub.setCurrency(currencyCode); final SubscriptionAddOns addOns = new SubscriptionAddOns(); for (final AddOn addOn : planAddOns) { addOns.add(createRandomSubscriptionAddOn(addOn.getAddOnCode())); } sub.setAddOns(addOns); return sub; }
/** * Creates a random {@link com.ning.billing.recurly.model.Subscription} object for use in tests * * @param currencyCode The currency code for which the subscription will be charged in * @param plan The associated plan * @param account The associated account * @param planAddOns AddOns for that subscription * @return The {@link com.ning.billing.recurly.model.Subscription} object */ public static Subscription createRandomSubscription(final String currencyCode, final Plan plan, final Account account, final Iterable<AddOn> planAddOns) { final Subscription sub = new Subscription(); // Make sure the quantity is > 0 sub.setQuantity(randomInteger(10) + 1); sub.setCurrency(randomCurrency()); sub.setPlanCode(plan.getPlanCode()); sub.setAccount(account); sub.setUnitAmountInCents(randomInteger(10)); sub.setCurrency(currencyCode); final SubscriptionAddOns addOns = new SubscriptionAddOns(); for (final AddOn addOn : planAddOns) { addOns.add(createRandomSubscriptionAddOn(addOn.getAddOnCode())); } sub.setAddOns(addOns); return sub; }
/** * Creates a random {@link com.ning.billing.recurly.model.Subscription} object for use in tests given a seed * * @param seed The RNG seed * @return The {@link com.ning.billing.recurly.model.Subscription} object */ public static Subscription createRandomSubscription(final int seed) { final Subscription sub = new Subscription(); final Plan plan = createRandomPlan(seed); sub.setQuantity(randomInteger(10, seed) + 1); sub.setCurrency(randomCurrency(seed)); sub.setPlanCode(plan.getPlanCode()); sub.setAccount(createRandomAccount(seed)); sub.setUnitAmountInCents(randomInteger(10, seed)); sub.setCurrency(randomCurrency(seed)); final SubscriptionAddOns addOns = new SubscriptionAddOns(); for (int i = 0; i < 5; i++) { addOns.add(createRandomSubscriptionAddOn("code"+i)); } sub.setAddOns(addOns); return sub; }
/** * Creates a random {@link com.ning.billing.recurly.model.Subscription} object for use in tests given a seed * * @param seed The RNG seed * @return The {@link com.ning.billing.recurly.model.Subscription} object */ public static Subscription createRandomSubscription(final int seed) { final Subscription sub = new Subscription(); final Plan plan = createRandomPlan(seed); sub.setQuantity(randomInteger(10, seed) + 1); sub.setCurrency(randomCurrency(seed)); sub.setPlanCode(plan.getPlanCode()); sub.setAccount(createRandomAccount(seed)); sub.setUnitAmountInCents(randomInteger(10, seed)); sub.setCurrency(randomCurrency(seed)); final SubscriptionAddOns addOns = new SubscriptionAddOns(); for (int i = 0; i < 5; i++) { addOns.add(createRandomSubscriptionAddOn("code"+i)); } sub.setAddOns(addOns); return sub; }