Search in sources :

Example 1 with CustomFields

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

the class TestCustomField method testCustomFieldTagAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testCustomFieldTagAuditLogsWithHistory() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    final CustomField customField = new CustomField();
    customField.setName("custom");
    customField.setValue(UUID.randomUUID().toString().substring(0, 5));
    final CustomFields body = new CustomFields();
    body.add(customField);
    CustomFields result = accountApi.createAccountCustomFields(accountJson.getAccountId(), body, requestOptions);
    // get all audit for the account
    final List<AuditLog> auditLogsJson = accountApi.getAccountAuditLogs(accountJson.getAccountId(), requestOptions);
    Assert.assertEquals(auditLogsJson.size(), 2);
    UUID objectId = null;
    for (AuditLog auditLog : auditLogsJson) {
        if (auditLog.getObjectType().equals(ObjectType.CUSTOM_FIELD)) {
            objectId = auditLog.getObjectId();
            break;
        }
    }
    assertNotNull(objectId);
    final List<AuditLog> customFieldAuditLogWithHistory = customFieldApi.getCustomFieldAuditLogsWithHistory(result.get(0).getCustomFieldId(), requestOptions);
    assertEquals(customFieldAuditLogWithHistory.size(), 1);
    assertEquals(customFieldAuditLogWithHistory.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(customFieldAuditLogWithHistory.get(0).getObjectType(), ObjectType.CUSTOM_FIELD);
    assertEquals(customFieldAuditLogWithHistory.get(0).getObjectId(), objectId);
    final LinkedHashMap history1 = (LinkedHashMap) customFieldAuditLogWithHistory.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("fieldName"), "custom");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) CustomFields(org.killbill.billing.client.model.CustomFields) CustomField(org.killbill.billing.client.model.gen.CustomField) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 2 with CustomFields

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

the class TestAccount method testGetAccountAuditLogs.

@Test(groups = "slow", description = "retrieve account logs")
public void testGetAccountAuditLogs() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    // generate more log data
    final CustomFields customFields = new CustomFields();
    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));
    accountApi.createAccountCustomFields(accountJson.getAccountId(), customFields, requestOptions);
    final CustomFields accountCustomFields = accountApi.getAccountCustomFields(accountJson.getAccountId(), requestOptions);
    assertEquals(accountCustomFields.size(), 3);
    final AuditLogs auditLogsJson = accountApi.getAccountAuditLogs(accountJson.getAccountId(), requestOptions);
    assertEquals(auditLogsJson.size(), 4);
    assertEquals(auditLogsJson.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogsJson.get(0).getObjectType(), ObjectType.ACCOUNT);
    assertEquals(auditLogsJson.get(0).getObjectId(), accountJson.getAccountId());
    assertEquals(auditLogsJson.get(1).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogsJson.get(1).getObjectType(), ObjectType.CUSTOM_FIELD);
    assertEquals(auditLogsJson.get(1).getObjectId(), accountCustomFields.get(0).getCustomFieldId());
    assertEquals(auditLogsJson.get(2).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogsJson.get(2).getObjectType(), ObjectType.CUSTOM_FIELD);
    assertEquals(auditLogsJson.get(2).getObjectId(), accountCustomFields.get(1).getCustomFieldId());
    assertEquals(auditLogsJson.get(3).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogsJson.get(3).getObjectType(), ObjectType.CUSTOM_FIELD);
    assertEquals(auditLogsJson.get(3).getObjectId(), accountCustomFields.get(2).getCustomFieldId());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) CustomFields(org.killbill.billing.client.model.CustomFields) AuditLogs(org.killbill.billing.client.model.AuditLogs) CustomField(org.killbill.billing.client.model.gen.CustomField) Test(org.testng.annotations.Test)

Example 3 with CustomFields

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

the class TestInvoiceItem method testCustomFields.

@Test(groups = "slow", description = "Add custom fields to invoice item")
public void testCustomFields() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Invoices invoicesJson = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    Assert.assertNotNull(invoicesJson);
    Assert.assertEquals(invoicesJson.size(), 2);
    final List<InvoiceItem> invoiceItems = invoicesJson.get(0).getItems();
    Assert.assertNotNull(invoiceItems);
    final CustomFields customFields = new CustomFields();
    customFields.add(new CustomField(null, invoiceItems.get(0).getInvoiceItemId(), ObjectType.INVOICE_ITEM, "1", "value1", null));
    customFields.add(new CustomField(null, invoiceItems.get(0).getInvoiceItemId(), ObjectType.INVOICE_ITEM, "2", "value2", null));
    customFields.add(new CustomField(null, invoiceItems.get(0).getInvoiceItemId(), ObjectType.INVOICE_ITEM, "3", "value3", null));
    invoiceItemApi.createInvoiceItemCustomFields(invoiceItems.get(0).getInvoiceItemId(), customFields, requestOptions);
    final List<CustomField> invoiceItemCustomFields = invoiceItemApi.getInvoiceItemCustomFields(invoiceItems.get(0).getInvoiceItemId(), requestOptions);
    Assert.assertEquals(invoiceItemCustomFields.size(), 3);
    // Delete all custom fields for account
    invoiceItemApi.deleteInvoiceItemCustomFields(invoiceItems.get(0).getInvoiceItemId(), null, requestOptions);
    final List<CustomField> remainingCustomFields = invoiceItemApi.getInvoiceItemCustomFields(invoiceItems.get(0).getInvoiceItemId(), requestOptions);
    Assert.assertEquals(remainingCustomFields.size(), 0);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) CustomFields(org.killbill.billing.client.model.CustomFields) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) CustomField(org.killbill.billing.client.model.gen.CustomField) Invoices(org.killbill.billing.client.model.Invoices) Test(org.testng.annotations.Test)

Example 4 with CustomFields

use of org.killbill.billing.client.model.CustomFields 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 CustomFields customFields = new CustomFields();
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "1", "value1", EMPTY_AUDIT_LOGS));
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "2", "value2", EMPTY_AUDIT_LOGS));
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "3", "value3", EMPTY_AUDIT_LOGS));
    accountApi.createAccountCustomFields(accountJson.getAccountId(), customFields, requestOptions);
    final List<CustomField> accountCustomFields = accountApi.getAccountCustomFields(accountJson.getAccountId(), requestOptions);
    assertEquals(accountCustomFields.size(), 3);
    // Delete all custom fields for account
    accountApi.deleteAccountCustomFields(accountJson.getAccountId(), null, requestOptions);
    final List<CustomField> remainingCustomFields = accountApi.getAccountCustomFields(accountJson.getAccountId(), requestOptions);
    assertEquals(remainingCustomFields.size(), 0);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) CustomFields(org.killbill.billing.client.model.CustomFields) CustomField(org.killbill.billing.client.model.gen.CustomField) Test(org.testng.annotations.Test)

Example 5 with CustomFields

use of org.killbill.billing.client.model.CustomFields 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();
    final CustomFields input = new CustomFields();
    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));
        input.add(customField);
    }
    accountApi.createAccountCustomFields(account.getAccountId(), input, requestOptions);
    final CustomFields allCustomFields = accountApi.getAccountCustomFields(account.getAccountId(), requestOptions);
    Assert.assertEquals(allCustomFields.size(), 5);
    CustomFields page = customFieldApi.getCustomFields(0L, 1L, AuditLevel.NONE, requestOptions);
    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);
    }
    // Search by key
    final CustomFields customFields = customFieldApi.searchCustomFields(ObjectType.ACCOUNT.toString(), requestOptions);
    Assert.assertEquals(customFields.size(), 5);
    Assert.assertEquals(customFields.getPaginationCurrentOffset(), 0);
    Assert.assertEquals(customFields.getPaginationTotalNbRecords(), 5);
    Assert.assertEquals(customFields.getPaginationMaxNbRecords(), 5);
    // Search by type, name
    final CustomFields customFields2 = customFieldApi.searchCustomFieldsByTypeName(ObjectType.ACCOUNT.toString(), input.get(0).getName(), null, requestOptions);
    Assert.assertEquals(customFields2.size(), 1);
    Assert.assertEquals(customFields2.getPaginationCurrentOffset(), 0);
    Assert.assertEquals(customFields2.getPaginationTotalNbRecords(), 1);
    Assert.assertEquals(customFields2.getPaginationMaxNbRecords(), 5);
    // Search by type, name, value
    final CustomFields customFields3 = customFieldApi.searchCustomFieldsByTypeName(ObjectType.ACCOUNT.toString(), input.get(0).getName(), input.get(0).getValue(), requestOptions);
    Assert.assertEquals(customFields3.size(), 1);
    Assert.assertEquals(customFields3.getPaginationCurrentOffset(), 0);
    Assert.assertEquals(customFields3.getPaginationTotalNbRecords(), 1);
    Assert.assertEquals(customFields3.getPaginationMaxNbRecords(), 5);
    final CustomFields allAccountCustomFields = accountApi.getAllCustomFields(account.getAccountId(), null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(allAccountCustomFields.size(), 5);
    final CustomFields allBundleCustomFieldsForAccount = accountApi.getAllCustomFields(account.getAccountId(), ObjectType.ACCOUNT, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(allBundleCustomFieldsForAccount.size(), 5);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) CustomFields(org.killbill.billing.client.model.CustomFields) CustomField(org.killbill.billing.client.model.gen.CustomField) Test(org.testng.annotations.Test)

Aggregations

CustomFields (org.killbill.billing.client.model.CustomFields)8 Account (org.killbill.billing.client.model.gen.Account)7 CustomField (org.killbill.billing.client.model.gen.CustomField)7 Test (org.testng.annotations.Test)7 UUID (java.util.UUID)2 LinkedHashMap (java.util.LinkedHashMap)1 AuditLogs (org.killbill.billing.client.model.AuditLogs)1 Invoices (org.killbill.billing.client.model.Invoices)1 AuditLog (org.killbill.billing.client.model.gen.AuditLog)1 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)1