Search in sources :

Example 11 with KillBillClientException

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);
    }
}
Also used : Response(com.ning.http.client.Response) UserRoles(org.killbill.billing.client.model.UserRoles) ArrayList(java.util.ArrayList) Permission(org.killbill.billing.security.Permission) RoleDefinition(org.killbill.billing.client.model.RoleDefinition) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 12 with KillBillClientException

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) {
        }
    }
}
Also used : TagDefinition(org.killbill.billing.client.model.TagDefinition) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 13 with KillBillClientException

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);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.Payment) KillBillClientException(org.killbill.billing.client.KillBillClientException) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 14 with KillBillClientException

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()));
}
Also used : Account(org.killbill.billing.client.model.Account) Tenant(org.killbill.billing.client.model.Tenant) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 15 with KillBillClientException

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");
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Aggregations

KillBillClientException (org.killbill.billing.client.KillBillClientException)21 Test (org.testng.annotations.Test)20 Account (org.killbill.billing.client.model.Account)13 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)7 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)6 UUID (java.util.UUID)5 Payment (org.killbill.billing.client.model.Payment)5 BigDecimal (java.math.BigDecimal)3 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)3 TransactionType (org.killbill.billing.payment.api.TransactionType)3 Response (com.ning.http.client.Response)2 RequestOptions (org.killbill.billing.client.RequestOptions)2 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)2 RoleDefinition (org.killbill.billing.client.model.RoleDefinition)2 Tenant (org.killbill.billing.client.model.Tenant)2 UserRoles (org.killbill.billing.client.model.UserRoles)2 Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Bundle (org.killbill.billing.client.model.Bundle)1