Search in sources :

Example 1 with CustomField

use of org.killbill.billing.client.model.CustomField in project killbill by killbill.

the class TestCustomField method testCustomFieldsPagination.

@Test(groups = "slow", description = "Can paginate through all custom fields")
public void testCustomFieldsPagination() throws Exception {
    final Account account = createAccount();
    for (int i = 0; i < 5; i++) {
        final CustomField customField = new CustomField();
        customField.setName(UUID.randomUUID().toString().substring(0, 5));
        customField.setValue(UUID.randomUUID().toString().substring(0, 5));
        killBillClient.createAccountCustomField(account.getAccountId(), customField, createdBy, reason, comment);
    }
    final CustomFields allCustomFields = killBillClient.getCustomFields();
    Assert.assertEquals(allCustomFields.size(), 5);
    CustomFields page = killBillClient.getCustomFields(0L, 1L);
    for (int i = 0; i < 5; i++) {
        Assert.assertNotNull(page);
        Assert.assertEquals(page.size(), 1);
        Assert.assertEquals(page.get(0), allCustomFields.get(i));
        page = page.getNext();
    }
    Assert.assertNull(page);
    for (final CustomField customField : allCustomFields) {
        doSearchCustomField(UUID.randomUUID().toString(), null);
        doSearchCustomField(customField.getName(), customField);
        doSearchCustomField(customField.getValue(), customField);
    }
    final CustomFields customFields = killBillClient.searchCustomFields(ObjectType.ACCOUNT.toString());
    Assert.assertEquals(customFields.size(), 5);
    Assert.assertEquals(customFields.getPaginationCurrentOffset(), 0);
    Assert.assertEquals(customFields.getPaginationTotalNbRecords(), 5);
    Assert.assertEquals(customFields.getPaginationMaxNbRecords(), 5);
}
Also used : Account(org.killbill.billing.client.model.Account) CustomFields(org.killbill.billing.client.model.CustomFields) CustomField(org.killbill.billing.client.model.CustomField) Test(org.testng.annotations.Test)

Example 2 with CustomField

use of org.killbill.billing.client.model.CustomField in project killbill by killbill.

the class TestAccount method testCustomFields.

@Test(groups = "slow", description = "Add custom fields to account")
public void testCustomFields() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    final Collection<CustomField> customFields = new LinkedList<CustomField>();
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "1", "value1", null));
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "2", "value2", null));
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "3", "value3", null));
    killBillClient.createAccountCustomFields(accountJson.getAccountId(), customFields, requestOptions);
    final List<CustomField> accountCustomFields = killBillClient.getAccountCustomFields(accountJson.getAccountId(), requestOptions);
    assertEquals(accountCustomFields.size(), 3);
    // Delete all custom fields for account
    killBillClient.deleteAccountCustomFields(accountJson.getAccountId(), requestOptions);
    final List<CustomField> remainingCustomFields = killBillClient.getAccountCustomFields(accountJson.getAccountId(), requestOptions);
    assertEquals(remainingCustomFields.size(), 0);
}
Also used : Account(org.killbill.billing.client.model.Account) CustomField(org.killbill.billing.client.model.CustomField) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 3 with CustomField

use of org.killbill.billing.client.model.CustomField in project killbill by killbill.

the class TestPaymentMethod method testPaymentMethodCustomFields.

@Test(groups = "slow", description = "Can create, retrieve and delete custom fields")
public void testPaymentMethodCustomFields() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final CustomField customField = new CustomField();
    customField.setObjectId(paymentMethodId);
    customField.setObjectType(ObjectType.PAYMENT_METHOD);
    customField.setName("testKey");
    customField.setValue("testValue");
    // Create custom field
    final CustomFields createdCustomFields = killBillClient.createPaymentMethodCustomField(paymentMethodId, customField, createdBy, reason, comment);
    Assert.assertEquals(createdCustomFields.size(), 1);
    final CustomField createdCustomField = createdCustomFields.get(0);
    Assert.assertEquals(createdCustomField.getName(), "testKey");
    Assert.assertEquals(createdCustomField.getValue(), "testValue");
    Assert.assertEquals(createdCustomField.getObjectId(), paymentMethodId);
    Assert.assertEquals(createdCustomField.getObjectType(), ObjectType.PAYMENT_METHOD);
    // Retrieve custom field
    final CustomFields retrievedCustomFields = killBillClient.getPaymentMethodCustomFields(paymentMethodId, AuditLevel.NONE);
    Assert.assertEquals(retrievedCustomFields.size(), 1);
    final CustomField retrievedCustomField = retrievedCustomFields.get(0);
    Assert.assertEquals(retrievedCustomField.getName(), "testKey");
    Assert.assertEquals(retrievedCustomField.getValue(), "testValue");
    Assert.assertEquals(retrievedCustomField.getObjectId(), paymentMethodId);
    Assert.assertEquals(retrievedCustomField.getObjectType(), ObjectType.PAYMENT_METHOD);
    // Delete custom field
    killBillClient.deletePaymentMethodCustomFields(paymentMethodId, Collections.<UUID>singletonList(createdCustomField.getCustomFieldId()), createdBy, reason, comment);
    final CustomFields deletedCustomFields = killBillClient.getPaymentMethodCustomFields(paymentMethodId, AuditLevel.NONE);
    Assert.assertEquals(deletedCustomFields.size(), 0);
}
Also used : Account(org.killbill.billing.client.model.Account) CustomFields(org.killbill.billing.client.model.CustomFields) CustomField(org.killbill.billing.client.model.CustomField) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.Account)3 CustomField (org.killbill.billing.client.model.CustomField)3 Test (org.testng.annotations.Test)3 CustomFields (org.killbill.billing.client.model.CustomFields)2 LinkedList (java.util.LinkedList)1 UUID (java.util.UUID)1