Search in sources :

Example 81 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class TestEntitlementUtils method testCancellationIMM.

@Test(groups = "slow", description = "Verify add-ons blocking states are not impacted by IMM cancellations")
public void testCancellationIMM() throws Exception {
    // Approximate check, as the blocking state check (checkBlockingStatesDAO) could be a bit off
    final DateTime cancellationDateTime = clock.getUTCNow();
    final LocalDate cancellationDate = clock.getUTCToday();
    // Cancel the base plan
    testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.CANCEL, NextEvent.BLOCK);
    final DefaultEntitlement cancelledBaseEntitlement = (DefaultEntitlement) baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.IMMEDIATE, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Refresh the add-on state
    final DefaultEntitlement cancelledAddOnEntitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(addOnEntitlement.getId(), callContext);
    // Verify we compute the right blocking states for the "read" path...
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
    // ...and for the "write" path (which has been exercised in the cancel call above).
    checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDateTime, true);
    // Verify also the blocking states DAO doesn't add too many events (all on disk)
    checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDate, true);
    clock.addDays(30);
    // No new event
    assertListenerStatus();
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
    checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDateTime, true);
    checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDate, true);
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 82 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class TestEntitlementUtils method testCancellationEOT.

@Test(groups = "slow", description = "Verify add-ons blocking states are added for EOT cancellations")
public void testCancellationEOT() throws Exception {
    // Cancel the base plan
    final DefaultEntitlement cancelledBaseEntitlement = (DefaultEntitlement) baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.END_OF_TERM, BillingActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext);
    // No blocking event (EOT)
    assertListenerStatus();
    // Verify we compute the right blocking states for the "read" path...
    checkFutureBlockingStatesToCancel(addOnEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, addOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime);
    // and for the "write" path (which will be exercised when the future notification kicks in).
    checkActualBlockingStatesToCancel(cancelledBaseEntitlement, addOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime, false);
    // Verify also the blocking states DAO adds events not on disk
    checkBlockingStatesDAO(baseEntitlement, addOnEntitlement, baseEffectiveCancellationOrChangeDate, true);
    // Verify the notification kicks in
    testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.CANCEL, NextEvent.BLOCK);
    clock.addDays(30);
    assertListenerStatus();
    // Refresh the state
    final DefaultEntitlement cancelledAddOnEntitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(addOnEntitlement.getId(), callContext);
    // Verify we compute the right blocking states for the "read" path...
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
    // ...and for the "write" path (which has been exercised when the notification kicked in).
    checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, baseEffectiveEOTCancellationOrChangeDateTime, false);
    // Verify also the blocking states API doesn't add too many events (now on disk)
    checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, baseEffectiveCancellationOrChangeDate, true);
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Test(org.testng.annotations.Test)

Example 83 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class TestEntitlementUtils method testChangePlanEOTWith2AddOns.

@Test(groups = "slow", description = "Verify we don't mix add-ons for EOT changes")
public void testChangePlanEOTWith2AddOns() throws Exception {
    // Add a second ADD_ON (Laser-Scope is available, not included)
    testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK);
    final PlanPhaseSpecifier secondAddOnSpec = new PlanPhaseSpecifier("Laser-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null);
    final DefaultEntitlement secondAddOnEntitlement = (DefaultEntitlement) entitlementApi.addEntitlement(baseEntitlement.getBundleId(), secondAddOnSpec, null, clock.getUTCToday(), clock.getUTCToday(), false, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Change plan EOT to Assault-Rifle (Telescopic-Scope is included)
    final DefaultEntitlement changedBaseEntitlement = (DefaultEntitlement) baseEntitlement.changePlanWithDate(new PlanSpecifier("Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME), null, new LocalDate(2013, 10, 7), ImmutableList.<PluginProperty>of(), callContext);
    // No blocking event (EOT)
    assertListenerStatus();
    // Verify the blocking states DAO adds events not on disk for the first add-on...
    checkBlockingStatesDAO(changedBaseEntitlement, addOnEntitlement, baseEffectiveCancellationOrChangeDate, false);
    // ...but not for the second one
    final List<BlockingState> blockingStatesForSecondAddOn = blockingStatesForBlockedId(secondAddOnEntitlement.getId());
    Assert.assertEquals(blockingStatesForSecondAddOn.size(), 1);
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) PluginProperty(org.killbill.billing.payment.api.PluginProperty) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) BlockingState(org.killbill.billing.entitlement.api.BlockingState) LocalDate(org.joda.time.LocalDate) PlanSpecifier(org.killbill.billing.catalog.api.PlanSpecifier) Test(org.testng.annotations.Test)

Example 84 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class TestEntitlementUtils method testCancellationIMMBillingEOT.

// See https://github.com/killbill/killbill/issues/121
@Test(groups = "slow", description = "Verify add-ons blocking states are not impacted by EOT billing cancellations")
public void testCancellationIMMBillingEOT() throws Exception {
    // Approximate check, as the blocking state check (checkBlockingStatesDAO) could be a bit off
    final DateTime cancellationDateTime = clock.getUTCNow();
    final LocalDate cancellationDate = clock.getUTCToday();
    // Cancel the base plan
    testListener.pushExpectedEvents(NextEvent.BLOCK, NextEvent.BLOCK);
    final DefaultEntitlement cancelledBaseEntitlement = (DefaultEntitlement) baseEntitlement.cancelEntitlementWithPolicyOverrideBillingPolicy(EntitlementActionPolicy.IMMEDIATE, BillingActionPolicy.END_OF_TERM, ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    // Refresh the add-on state
    final DefaultEntitlement cancelledAddOnEntitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(addOnEntitlement.getId(), callContext);
    // Verify we compute the right blocking states for the "read" path...
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
    // ...and for the "write" path (which has been exercised in the cancel call above).
    checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDateTime, true);
    // Verify also the blocking states DAO doesn't add too many events (all on disk)
    checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDate, true);
    testListener.pushExpectedEvents(NextEvent.CANCEL, NextEvent.CANCEL);
    clock.addDays(30);
    assertListenerStatus();
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledAddOnEntitlement, null, null);
    checkFutureBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, null);
    checkActualBlockingStatesToCancel(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDateTime, true);
    checkBlockingStatesDAO(cancelledBaseEntitlement, cancelledAddOnEntitlement, cancellationDate, true);
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 85 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class PluginPropertySerializer method deserialize.

public static Iterable<PluginProperty> deserialize(final byte[] input) throws PluginPropertySerializerException {
    final List<PluginProperty> result = new ArrayList<PluginProperty>();
    try {
        final byte[] uncompressed = LZFDecoder.decode(input);
        final InputStream in = new ByteArrayInputStream(uncompressed);
        final JsonParser jsonParser = jsonFactory.createParser(in);
        PluginProperty prop = null;
        String key = null;
        JsonToken nextToken = jsonParser.nextToken();
        while (nextToken != null && nextToken != JsonToken.END_ARRAY) {
            if (nextToken != JsonToken.START_ARRAY) {
                if (nextToken == JsonToken.FIELD_NAME && key == null) {
                    key = jsonParser.getText();
                } else if (key != null) {
                    final Object value = mapper.readValue(jsonParser, Object.class);
                    prop = new PluginProperty(key, value, false);
                    key = null;
                } else if (nextToken == JsonToken.END_OBJECT) {
                    result.add(prop);
                    prop = null;
                }
            }
            nextToken = jsonParser.nextToken();
        }
        jsonParser.close();
        return result;
    } catch (final UnsupportedEncodingException e) {
        throw new PluginPropertySerializerException(e);
    } catch (final JsonParseException e) {
        throw new PluginPropertySerializerException(e);
    } catch (final IOException e) {
        throw new PluginPropertySerializerException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) PluginProperty(org.killbill.billing.payment.api.PluginProperty) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

PluginProperty (org.killbill.billing.payment.api.PluginProperty)105 UUID (java.util.UUID)45 Account (org.killbill.billing.account.api.Account)42 ApiOperation (io.swagger.annotations.ApiOperation)35 ApiResponses (io.swagger.annotations.ApiResponses)35 Produces (javax.ws.rs.Produces)35 TimedResource (org.killbill.commons.metrics.TimedResource)35 Test (org.testng.annotations.Test)33 Path (javax.ws.rs.Path)32 Payment (org.killbill.billing.payment.api.Payment)30 CallContext (org.killbill.billing.util.callcontext.CallContext)29 ArrayList (java.util.ArrayList)19 LocalDate (org.joda.time.LocalDate)19 Consumes (javax.ws.rs.Consumes)17 BigDecimal (java.math.BigDecimal)16 TenantContext (org.killbill.billing.util.callcontext.TenantContext)15 GET (javax.ws.rs.GET)14 POST (javax.ws.rs.POST)13 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)13 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)13