package com.ning.billing.invoice.tests.inAdvance.quarterly;
import static com.ning.billing.invoice.TestInvoiceHelper.*;
import java.math.BigDecimal;
import org.joda.time.LocalDate;
import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
public class TestDoubleProRation extends ProRationInAdvanceTestBase {
@Override
protected BillingPeriod getBillingPeriod() {
return BillingPeriod.QUARTERLY;
}
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnStartDate() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInFirstProRationPeriod() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 7);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnFirstBillingCycleDate() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 15);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue = ONE.add(FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInFullBillingPeriod() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 22);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnSecondBillingCycleDate() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 15);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 26);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnEndDate() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 27);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@Test(groups = "fast")
public void testDoubleProRation_TargetDateAfterEndDate() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 5, 7);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@Test(groups = "fast")
public void testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod() throws InvalidDateSequenceException {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 6, 26);
final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 27);
BigDecimal expectedValue;
expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
expectedValue = expectedValue.add(TWO);
expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
}