use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.
the class TestSecurity method testUserPermission.
@Test(groups = "slow")
public void testUserPermission() throws KillBillClientException {
final String roleDefinition = "notEnoughToAddUserAndRoles";
final List<String> permissions = new ArrayList<String>();
for (Permission cur : Permission.values()) {
if (!cur.getGroup().equals("user")) {
permissions.add(cur.toString());
}
}
Response response = killBillClient.addRoleDefinition(new RoleDefinition(roleDefinition, permissions), createdBy, reason, comment);
Assert.assertEquals(response.getStatusCode(), 201);
final String username = "candy";
final String password = "lolipop";
response = killBillClient.addUserRoles(new UserRoles(username, password, ImmutableList.of(roleDefinition)), createdBy, reason, comment);
Assert.assertEquals(response.getStatusCode(), 201);
// Now 'login' as new user (along with roles to make an API call requiring permissions), and check behavior
logout();
login(username, password);
boolean success = false;
try {
killBillClient.addRoleDefinition(new RoleDefinition("dsfdsfds", ImmutableList.of("*")), createdBy, reason, comment);
success = true;
} catch (final Exception e) {
} finally {
Assert.assertFalse(success);
}
success = false;
try {
killBillClient.addUserRoles(new UserRoles("sdsd", "sdsdsd", ImmutableList.of(roleDefinition)), createdBy, reason, comment);
success = true;
} catch (final Exception e) {
} finally {
Assert.assertFalse(success);
}
}
use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.
the class TestTag method testTagErrorHandling.
@Test(groups = "slow", description = "Cannot add badly formatted TagDefinition")
public void testTagErrorHandling() throws Exception {
final TagDefinition[] tagDefinitions = { new TagDefinition(null, false, null, null, null), new TagDefinition(null, false, "something", null, null), new TagDefinition(null, false, null, "something", null) };
for (final TagDefinition tagDefinition : tagDefinitions) {
try {
killBillClient.createTagDefinition(tagDefinition, requestOptions);
fail();
} catch (final KillBillClientException e) {
}
}
}
use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.
the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionId.
@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionId() throws Exception {
final Account account = createAccountWithDefaultPaymentMethod();
final UUID paymentMethodId = account.getPaymentMethodId();
final BigDecimal amount = BigDecimal.TEN;
final String pending = PaymentPluginStatus.PENDING.toString();
final ImmutableMap<String, String> pendingPluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
final ImmutableMap<String, String> pluginProperties = ImmutableMap.of();
TransactionType transactionType = TransactionType.AUTHORIZE;
final String paymentExternalKey = UUID.randomUUID().toString();
final String authTransactionExternalKey = UUID.randomUUID().toString();
final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, pending, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
final PaymentTransaction completeTransactionByPaymentIdAndInvalidTransactionId = new PaymentTransaction();
completeTransactionByPaymentIdAndInvalidTransactionId.setPaymentId(initialPayment.getPaymentId());
completeTransactionByPaymentIdAndInvalidTransactionId.setTransactionId(UUID.randomUUID());
try {
killBillClient.completePayment(completeTransactionByPaymentIdAndInvalidTransactionId, pluginProperties, requestOptions);
fail("Payment completion should fail when invalid transaction id has been provided");
} catch (final KillBillClientException expected) {
}
final PaymentTransaction completeTransactionByPaymentIdAndTransactionId = new PaymentTransaction();
completeTransactionByPaymentIdAndTransactionId.setPaymentId(initialPayment.getPaymentId());
completeTransactionByPaymentIdAndTransactionId.setTransactionId(initialPayment.getTransactions().get(0).getTransactionId());
final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentIdAndTransactionId, pluginProperties, requestOptions);
verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), TransactionStatus.SUCCESS.name(), amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
}
use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.
the class TestTenantFilter method testTenantShouldOnlySeeOwnAccount.
@Test(groups = "slow")
public void testTenantShouldOnlySeeOwnAccount() throws Exception {
// Try to create an account without being logged-in
logoutTenant();
try {
killBillClient.createAccount(getAccount(), createdBy, reason, comment);
Assert.fail();
} catch (final KillBillClientException e) {
Assert.assertEquals(e.getResponse().getStatusCode(), Status.UNAUTHORIZED.getStatusCode());
}
// Create the tenant
final String apiKeyTenant1 = "pierre";
final String apiSecretTenant1 = "pierreIsFr3nch";
loginTenant(apiKeyTenant1, apiSecretTenant1);
final Tenant tenant1 = new Tenant();
tenant1.setApiKey(apiKeyTenant1);
tenant1.setApiSecret(apiSecretTenant1);
killBillClient.createTenant(tenant1, createdBy, reason, comment);
final Account account1 = createAccount();
Assert.assertEquals(killBillClient.getAccount(account1.getExternalKey()), account1);
logoutTenant();
// Create another tenant
final String apiKeyTenant2 = "stephane";
final String apiSecretTenant2 = "stephane1sAlsoFr3nch";
loginTenant(apiKeyTenant2, apiSecretTenant2);
final Tenant tenant2 = new Tenant();
tenant2.setApiKey(apiKeyTenant2);
tenant2.setApiSecret(apiSecretTenant2);
killBillClient.createTenant(tenant2, createdBy, reason, comment);
final Account account2 = createAccount();
Assert.assertEquals(killBillClient.getAccount(account2.getExternalKey()), account2);
// We should not be able to retrieve the first account as tenant2
Assert.assertNull(killBillClient.getAccount(account1.getExternalKey()));
// Same for tenant1 and account2
loginTenant(apiKeyTenant1, apiSecretTenant1);
Assert.assertNull(killBillClient.getAccount(account2.getExternalKey()));
}
use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.
the class TestPayment method testWithFailedPaymentAndWithoutFollowLocation.
@Test(groups = "slow")
public void testWithFailedPaymentAndWithoutFollowLocation() throws Exception {
final Account account = createAccountWithDefaultPaymentMethod();
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
final PaymentTransaction authTransaction = new PaymentTransaction();
authTransaction.setAmount(BigDecimal.ONE);
authTransaction.setCurrency(account.getCurrency());
authTransaction.setTransactionType(TransactionType.AUTHORIZE.name());
final RequestOptions requestOptionsWithoutFollowLocation = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withFollowLocation(false).build();
try {
killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, ImmutableMap.<String, String>of(), requestOptionsWithoutFollowLocation);
fail();
} catch (final KillBillClientException e) {
assertEquals(e.getResponse().getStatusCode(), 402);
assertEquals(e.getBillingException().getMessage(), "Payment decline by gateway. Error message: gatewayError");
}
}
Aggregations