Search in sources :

Example 1 with ObjectMapper

use of org.killbill.billing.util.jackson.ObjectMapper in project killbill by killbill.

the class TestAdmin method testAdminInvoiceEndpoint.

@Test(groups = "slow")
public void testAdminInvoiceEndpoint() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final List<UUID> accounts = new LinkedList<UUID>();
    for (int i = 0; i < 5; i++) {
        final Account accountJson = createAccountWithDefaultPaymentMethod();
        assertNotNull(accountJson);
        accounts.add(accountJson.getAccountId());
        createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
        clock.addDays(2);
        crappyWaitForLackOfProperSynchonization();
        Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), i + 1);
        final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), false, false, false, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 1);
    }
    // Trigger first non-trial invoice
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
    Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
    for (final UUID accountId : accounts) {
        final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountId, false, false, false, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 2);
    }
    // Upload the config
    final ObjectMapper mapper = new ObjectMapper();
    final Map<String, String> perTenantProperties = new HashMap<String, String>();
    perTenantProperties.put("org.killbill.invoice.enabled", "false");
    final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
    killBillClient.postConfigurationPropertiesForTenant(perTenantConfig, requestOptions);
    crappyWaitForLackOfProperSynchonization();
    // Verify the second invoice isn't generated
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
    Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
    for (final UUID accountId : accounts) {
        final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountId, false, false, false, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 2);
    }
    // Fix one account
    final Response response = triggerInvoiceGenerationForParkedAccounts(1);
    Assert.assertEquals(response.getResponseBody(), "{\"" + accounts.get(0) + "\":\"OK\"}");
    Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 11);
    // Fix all accounts
    final Response response2 = triggerInvoiceGenerationForParkedAccounts(5);
    final Map<String, String> fixedAccounts = mapper.readValue(response2.getResponseBody(), new TypeReference<Map<String, String>>() {
    });
    Assert.assertEquals(fixedAccounts.size(), 4);
    Assert.assertEquals(fixedAccounts.get(accounts.get(1).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(2).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(3).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(4).toString()), "OK");
    Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 15);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) Response(com.ning.http.client.Response) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 2 with ObjectMapper

use of org.killbill.billing.util.jackson.ObjectMapper in project killbill by killbill.

the class TestPerTenantConfig method testFailedPaymentWithPerTenantRetryConfig.

@Test(groups = "slow")
public void testFailedPaymentWithPerTenantRetryConfig() throws Exception {
    // Create the tenant
    final String apiKeyTenant1 = "tenantSuperTuned";
    final String apiSecretTenant1 = "2367$$ffr79";
    loginTenant(apiKeyTenant1, apiSecretTenant1);
    final Tenant tenant1 = new Tenant();
    tenant1.setApiKey(apiKeyTenant1);
    tenant1.setApiSecret(apiSecretTenant1);
    killBillClient.createTenant(tenant1, createdBy, reason, comment);
    // Configure our plugin to fail
    mockPaymentProviderPlugin.makeAllInvoicesFailWithError(true);
    // Upload the config
    final ObjectMapper mapper = new ObjectMapper();
    final HashMap<String, String> perTenantProperties = new HashMap<String, String>();
    perTenantProperties.put("org.killbill.payment.retry.days", "1,1,1");
    final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
    final TenantKey tenantKey = killBillClient.postConfigurationPropertiesForTenant(perTenantConfig, requestOptions);
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Payments payments = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments.size(), 1);
    Assert.assertEquals(payments.get(0).getTransactions().size(), 1);
    //
    // Because we have specified a retry interval of one day we should see the new attempt after moving clock 1 day (and not 8 days which is default)
    //
    //
    // Now unregister special per tenant config and we the first retry occurs one day after (and still fails), it now sets a retry date of 8 days
    //
    killBillClient.unregisterConfigurationForTenant(requestOptions);
    // org.killbill.tenant.broadcast.rate has been set to 1s
    crappyWaitForLackOfProperSynchonization(2000);
    clock.addDays(1);
    Awaitility.await().atMost(4, TimeUnit.SECONDS).pollInterval(Duration.ONE_SECOND).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return killBillClient.getPaymentsForAccount(accountJson.getAccountId()).get(0).getTransactions().size() == 2;
        }
    });
    final Payments payments2 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments2.size(), 1);
    Assert.assertEquals(payments2.get(0).getTransactions().size(), 2);
    Assert.assertEquals(payments2.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(payments2.get(0).getTransactions().get(1).getStatus(), TransactionStatus.PAYMENT_FAILURE.name());
    clock.addDays(1);
    crappyWaitForLackOfProperSynchonization(3000);
    // No retry with default config
    final Payments payments3 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments3.size(), 1);
    Assert.assertEquals(payments3.get(0).getTransactions().size(), 2);
    mockPaymentProviderPlugin.makeAllInvoicesFailWithError(false);
    clock.addDays(7);
    Awaitility.await().atMost(4, TimeUnit.SECONDS).pollInterval(Duration.ONE_SECOND).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return killBillClient.getPaymentsForAccount(accountJson.getAccountId()).get(0).getTransactions().size() == 3;
        }
    });
    final Payments payments4 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments4.size(), 1);
    Assert.assertEquals(payments4.get(0).getTransactions().size(), 3);
    Assert.assertEquals(payments4.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(payments4.get(0).getTransactions().get(1).getStatus(), TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(payments4.get(0).getTransactions().get(2).getStatus(), TransactionStatus.SUCCESS.name());
}
Also used : Account(org.killbill.billing.client.model.Account) Tenant(org.killbill.billing.client.model.Tenant) HashMap(java.util.HashMap) TenantKey(org.killbill.billing.client.model.TenantKey) Payments(org.killbill.billing.client.model.Payments) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 3 with ObjectMapper

use of org.killbill.billing.util.jackson.ObjectMapper in project killbill by killbill.

the class TestDefaultUserTagDefinitionDeletionEvent method testSerialization.

@Test(groups = "fast")
public void testSerialization() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = UUID.randomUUID();
    final DefaultUserTagDefinitionDeletionEvent event = new DefaultUserTagDefinitionDeletionEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultUserTagDefinitionDeletionEvent fromJson = objectMapper.readValue(json, DefaultUserTagDefinitionDeletionEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 4 with ObjectMapper

use of org.killbill.billing.util.jackson.ObjectMapper in project killbill by killbill.

the class TestDefaultControlTagCreationEvent method testSerialization.

@Test(groups = "fast")
public void testSerialization() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    final UUID tagId = UUID.randomUUID();
    final UUID objectId = UUID.randomUUID();
    final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = UUID.randomUUID();
    final DefaultControlTagCreationEvent event = new DefaultControlTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultControlTagCreationEvent fromJson = objectMapper.readValue(json, DefaultControlTagCreationEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : ObjectType(org.killbill.billing.ObjectType) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 5 with ObjectMapper

use of org.killbill.billing.util.jackson.ObjectMapper in project killbill by killbill.

the class TestDefaultControlTagDefinitionCreationEvent method testSerialization.

@Test(groups = "fast")
public void testSerialization() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = UUID.randomUUID();
    final DefaultControlTagDefinitionCreationEvent event = new DefaultControlTagDefinitionCreationEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultControlTagDefinitionCreationEvent fromJson = objectMapper.readValue(json, DefaultControlTagDefinitionCreationEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

ObjectMapper (org.killbill.billing.util.jackson.ObjectMapper)15 Test (org.testng.annotations.Test)15 UUID (java.util.UUID)12 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)8 TagDefinition (org.killbill.billing.util.tag.TagDefinition)8 ObjectType (org.killbill.billing.ObjectType)6 HashMap (java.util.HashMap)2 DateTime (org.joda.time.DateTime)2 Account (org.killbill.billing.client.model.Account)2 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)1 Response (com.ning.http.client.Response)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 LocalDate (org.joda.time.LocalDate)1 Invoice (org.killbill.billing.client.model.Invoice)1 Payments (org.killbill.billing.client.model.Payments)1 Tenant (org.killbill.billing.client.model.Tenant)1 TenantKey (org.killbill.billing.client.model.TenantKey)1 BroadcastInternalEvent (org.killbill.billing.events.BroadcastInternalEvent)1