use of jnc.platform.win32.Handle in project killbill by killbill.
the class TestDefaultAuditDao method testRetrieveAuditsDirectly.
@Test(groups = "slow")
public void testRetrieveAuditsDirectly() throws Exception {
addTag();
// Verify we get an audit entry for the tag_history table
final Handle handle = dbi.open();
final String tagHistoryString = (String) handle.select("select id from tag_history limit 1").get(0).get("id");
handle.close();
for (final AuditLevel level : AuditLevel.values()) {
final List<AuditLog> auditLogs = auditDao.getAuditLogsForId(TableName.TAG_HISTORY, UUID.fromString(tagHistoryString), level, internalCallContext);
verifyAuditLogsForTag(auditLogs, level);
}
}
use of jnc.platform.win32.Handle in project killbill by killbill.
the class TestInvoicePayment method testWithIncompletePaymentAttempt.
@Test(groups = "slow")
public void testWithIncompletePaymentAttempt() throws Exception {
// 2012-05-01T00:03:42.000Z
clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0));
final AccountData accountData = getAccountData(0);
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
final DefaultEntitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), null, InvoiceItemType.FIXED, new BigDecimal("0")));
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 5, 1), callContext);
// 2012-05-31 => DAY 30 have to get out of trial {I0, P0}
addDaysAndCheckForCompletion(30, NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
Invoice invoice2 = invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 31), new LocalDate(2012, 6, 30), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext);
// Invoice is fully paid
final Payment originalPayment = paymentChecker.checkPayment(account.getId(), 1, callContext, new ExpectedPaymentCheck(new LocalDate(2012, 5, 31), new BigDecimal("249.95"), TransactionStatus.SUCCESS, invoice2.getId(), Currency.USD));
Assert.assertEquals(originalPayment.getPurchasedAmount().compareTo(new BigDecimal("249.95")), 0);
Assert.assertEquals(originalPayment.getRefundedAmount().compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(originalPayment.getTransactions().get(0).getProcessedAmount().compareTo(new BigDecimal("249.95")), 0);
Assert.assertEquals(invoice2.getBalance().compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(invoiceUserApi.getAccountBalance(account.getId(), callContext).compareTo(invoice2.getBalance()), 0);
final PaymentTransaction originalTransaction = originalPayment.getTransactions().get(0);
// Let 's hack invoice_payment table by hand to simulate a non completion of the payment (onSuccessCall was never called)
dbi.withHandle(new HandleCallback<Void>() {
@Override
public Void withHandle(final Handle handle) throws Exception {
handle.execute("update invoice_payments set success = false where payment_cookie_id = ?", originalTransaction.getExternalKey());
return null;
}
});
final Invoice updateInvoice2 = invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 31), new LocalDate(2012, 6, 30), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
// Invoice now shows as unpaid
Assert.assertEquals(updateInvoice2.getBalance().compareTo(originalPayment.getPurchasedAmount()), 0);
Assert.assertEquals(updateInvoice2.getPayments().size(), 1);
Assert.assertEquals(updateInvoice2.getPayments().get(0).getPaymentCookieId(), originalTransaction.getExternalKey());
//
// Now trigger invoice payment again (no new payment should be made as code should detect broken state and fix it by itself)
// We expect an INVOICE_PAYMENT that indicates the invoice was repaired, and also an exception because plugin aborts payment call since there is nothing to do.
//
busHandler.pushExpectedEvents(NextEvent.INVOICE_PAYMENT);
try {
invoicePaymentApi.createPurchaseForInvoicePayment(account, updateInvoice2.getId(), account.getPaymentMethodId(), null, updateInvoice2.getBalance(), updateInvoice2.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), PAYMENT_OPTIONS, callContext);
Assert.fail("The payment should not succeed (and yet it will repair the broken state....)");
} catch (final PaymentApiException expected) {
Assert.assertEquals(expected.getCode(), ErrorCode.PAYMENT_PLUGIN_API_ABORTED.getCode());
}
assertListenerStatus();
final Invoice updateInvoice3 = invoiceChecker.checkInvoice(account.getId(), 2, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 31), new LocalDate(2012, 6, 30), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
Assert.assertEquals(updateInvoice3.getBalance().compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(updateInvoice3.getPayments().size(), 1);
Assert.assertEquals(updateInvoice3.getPayments().get(0).getPaymentCookieId(), originalTransaction.getExternalKey());
Assert.assertTrue(updateInvoice3.getPayments().get(0).isSuccess());
Assert.assertEquals(invoiceUserApi.getAccountBalance(account.getId(), callContext).compareTo(invoice2.getBalance()), 0);
final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext);
Assert.assertEquals(payments.size(), 1);
Assert.assertEquals(payments.get(0).getTransactions().size(), 1);
}
use of jnc.platform.win32.Handle in project killbill by killbill.
the class TestMysqlGlobalLocker method testSimpleLocking.
// Used as a manual test to validate the simple DAO by stepping through that locking is done and release correctly
@Test(groups = "slow")
public void testSimpleLocking() throws IOException, LockFailedException {
final String lockName = UUID.randomUUID().toString();
final GlobalLock lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 3);
dbi.inTransaction(new TransactionCallback<Void>() {
@Override
public Void inTransaction(final Handle conn, final TransactionStatus status) throws Exception {
conn.execute("insert into dummy2 (dummy_id) values ('" + UUID.randomUUID().toString() + "')");
return null;
}
});
Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), false);
boolean gotException = false;
try {
locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 1);
} catch (LockFailedException e) {
gotException = true;
}
Assert.assertTrue(gotException);
lock.release();
Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), true);
}
use of jnc.platform.win32.Handle in project killbill by killbill.
the class TestDatabaseExportDao method testExportSimpleData.
@Test(groups = "slow")
public void testExportSimpleData() throws Exception {
// Empty database
final String dump = getDump();
Assert.assertEquals(dump, "");
final String accountId = UUID.randomUUID().toString();
final String accountEmail = UUID.randomUUID().toString().substring(0, 4) + '@' + UUID.randomUUID().toString().substring(0, 4);
final String accountName = UUID.randomUUID().toString().substring(0, 4);
final int firstNameLength = 4;
final String timeZone = "UTC";
final Date createdDate = new Date(12421982000L);
final String createdBy = UUID.randomUUID().toString().substring(0, 4);
final Date updatedDate = new Date(382910622000L);
final String updatedBy = UUID.randomUUID().toString().substring(0, 4);
final byte[] properties = LZFEncoder.encode(new byte[] { 'c', 'a', 'f', 'e' });
final String tableNameA = "test_database_export_dao_a";
final String tableNameB = "test_database_export_dao_b";
dbi.withHandle(new HandleCallback<Void>() {
@Override
public Void withHandle(final Handle handle) throws Exception {
handle.execute("drop table if exists " + tableNameA);
handle.execute("create table " + tableNameA + "(record_id serial unique," + "a_column char default 'a'," + "blob_column mediumblob," + "account_record_id bigint /*! unsigned */ not null," + "tenant_record_id bigint /*! unsigned */ not null default 0," + "primary key(record_id));");
handle.execute("drop table if exists " + tableNameB);
handle.execute("create table " + tableNameB + "(record_id serial unique," + "b_column char default 'b'," + "account_record_id bigint /*! unsigned */ not null," + "tenant_record_id bigint /*! unsigned */ not null default 0," + "primary key(record_id));");
handle.execute("insert into " + tableNameA + " (blob_column, account_record_id, tenant_record_id) values (?, ?, ?)", properties, internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
handle.execute("insert into " + tableNameB + " (account_record_id, tenant_record_id) values (?, ?)", internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
// Add row in accounts table
handle.execute("insert into accounts (record_id, id, external_key, email, name, first_name_length, reference_time, time_zone, created_date, created_by, updated_date, updated_by, tenant_record_id) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", internalCallContext.getAccountRecordId(), accountId, accountId, accountEmail, accountName, firstNameLength, createdDate, timeZone, createdDate, createdBy, updatedDate, updatedBy, internalCallContext.getTenantRecordId());
return null;
}
});
// Verify new dump
final String newDump = getDump();
Assert.assertEquals(newDump, "-- accounts record_id|id|external_key|email|name|first_name_length|currency|billing_cycle_day_local|parent_account_id|is_payment_delegated_to_parent|payment_method_id|reference_time|time_zone|locale|address1|address2|company_name|city|state_or_province|country|postal_code|phone|notes|migrated|created_date|created_by|updated_date|updated_by|tenant_record_id\n" + String.format("%s|%s|%s|%s|%s|%s||||false||%s|%s|||||||||||false|%s|%s|%s|%s|%s", internalCallContext.getAccountRecordId(), accountId, accountId, accountEmail, accountName, firstNameLength, "1970-05-24T18:33:02.000+00:00", timeZone, "1970-05-24T18:33:02.000+00:00", createdBy, "1982-02-18T20:03:42.000+00:00", updatedBy, internalCallContext.getTenantRecordId()) + "\n" + "-- " + tableNameA + " record_id|a_column|blob_column|account_record_id|tenant_record_id\n" + "1|a|WlYAAARjYWZl|" + internalCallContext.getAccountRecordId() + "|" + internalCallContext.getTenantRecordId() + "\n" + "-- " + tableNameB + " record_id|b_column|account_record_id|tenant_record_id\n" + "1|b|" + internalCallContext.getAccountRecordId() + "|" + internalCallContext.getTenantRecordId() + "\n");
}
use of jnc.platform.win32.Handle in project killbill by killbill.
the class TestInternalCallContextFactory method testCreateInternalCallContextWithAccountRecordIdFromSimpleObjectType.
@Test(groups = "slow")
public void testCreateInternalCallContextWithAccountRecordIdFromSimpleObjectType() throws Exception {
final UUID invoiceId = UUID.randomUUID();
final Long accountRecordId = 19384012L;
final ImmutableAccountData immutableAccountData = Mockito.mock(ImmutableAccountData.class);
Mockito.when(immutableAccountInternalApi.getImmutableAccountDataByRecordId(Mockito.<Long>eq(accountRecordId), Mockito.<InternalTenantContext>any())).thenReturn(immutableAccountData);
dbi.withHandle(new HandleCallback<Void>() {
@Override
public Void withHandle(final Handle handle) throws Exception {
handle.execute("insert into invoices (id, account_id, invoice_date, target_date, currency, status, migrated, created_by, created_date, account_record_id, tenant_record_id) values " + "(?, ?, ?, ?, 'USD', 'COMMITTED', '0', 'test', ?, ?, ?)", invoiceId.toString(), UUID.randomUUID().toString(), new Date(), new Date(), new Date(), accountRecordId, internalCallContext.getTenantRecordId());
return null;
}
});
final InternalCallContext context = internalCallContextFactory.createInternalCallContext(invoiceId, ObjectType.INVOICE, callContext);
// The account record id should have been looked up in the invoices table
Assert.assertEquals(context.getAccountRecordId(), accountRecordId);
verifyInternalCallContext(context);
}
Aggregations