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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations