Search in sources :

Example 1 with StringCustomField

use of org.killbill.billing.util.customfield.StringCustomField in project killbill by killbill.

the class TestCustomFieldApi method addCustomField.

private void addCustomField(String name, String value, UUID objectId, ObjectType type, DateTime createdDate) throws CustomFieldApiException {
    CustomField f = new StringCustomField(name, value, type, objectId, clock.getUTCNow());
    busHandler.pushExpectedEvents(NextEvent.CUSTOM_FIELD);
    List<CustomField> fields = new ArrayList<CustomField>();
    fields.add(f);
    customFieldApi.addCustomFields(fields, callContext);
    assertListenerStatus();
}
Also used : StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) StringCustomField(org.killbill.billing.util.customfield.StringCustomField) ArrayList(java.util.ArrayList)

Example 2 with StringCustomField

use of org.killbill.billing.util.customfield.StringCustomField in project killbill by killbill.

the class JaxRsResourceBase method createCustomFields.

protected Response createCustomFields(final UUID id, final List<CustomFieldJson> customFields, final CallContext context, final UriInfo uriInfo, final HttpServletRequest request) throws CustomFieldApiException {
    final LinkedList<CustomField> input = new LinkedList<CustomField>();
    for (final CustomFieldJson cur : customFields) {
        verifyNonNullOrEmpty(cur.getName(), "CustomFieldJson name needs to be set");
        verifyNonNullOrEmpty(cur.getValue(), "CustomFieldJson value needs to be set");
        input.add(new StringCustomField(cur.getName(), cur.getValue(), getObjectType(), id, context.getCreatedDate()));
    }
    customFieldUserApi.addCustomFields(input, context);
    return uriBuilder.buildResponse(uriInfo, this.getClass(), "getCustomFields", id, request);
}
Also used : StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomFieldJson(org.killbill.billing.jaxrs.json.CustomFieldJson) LinkedList(java.util.LinkedList)

Example 3 with StringCustomField

use of org.killbill.billing.util.customfield.StringCustomField in project killbill by killbill.

the class TestDefaultCustomFieldUserApi method testSaveCustomFieldWithAccountRecordId.

@Test(groups = "slow")
public void testSaveCustomFieldWithAccountRecordId() throws Exception {
    final UUID accountId = UUID.randomUUID();
    final Long accountRecordId = 19384012L;
    dbi.withHandle(new HandleCallback<Void>() {

        @Override
        public Void withHandle(final Handle handle) throws Exception {
            // Note: we always create an accounts table, see MysqlTestingHelper
            handle.execute("insert into accounts (record_id, id, email, name, first_name_length, is_notified_for_invoices, created_date, created_by, updated_date, updated_by) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", accountRecordId, accountId.toString(), "yo@t.com", "toto", 4, false, new Date(), "i", new Date(), "j");
            return null;
        }
    });
    checkPagination(0);
    final String cfName = UUID.randomUUID().toString().substring(1, 4);
    final String cfValue = UUID.randomUUID().toString().substring(1, 4);
    final CustomField customField = new StringCustomField(cfName, cfValue, ObjectType.ACCOUNT, accountId, callContext.getCreatedDate());
    eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
    customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField), callContext);
    assertListenerStatus();
    checkPagination(1);
    // Verify the field was saved
    final List<CustomField> customFields = customFieldUserApi.getCustomFieldsForObject(accountId, ObjectType.ACCOUNT, callContext);
    Assert.assertEquals(customFields.size(), 1);
    Assert.assertEquals(customFields.get(0).getFieldName(), customField.getFieldName());
    Assert.assertEquals(customFields.get(0).getFieldValue(), customField.getFieldValue());
    Assert.assertEquals(customFields.get(0).getObjectId(), customField.getObjectId());
    Assert.assertEquals(customFields.get(0).getObjectType(), customField.getObjectType());
    // Verify the account_record_id was populated
    dbi.withHandle(new HandleCallback<Void>() {

        @Override
        public Void withHandle(final Handle handle) throws Exception {
            final List<Map<String, Object>> values = handle.select("select account_record_id from custom_fields where object_id = ?", accountId.toString());
            Assert.assertEquals(values.size(), 1);
            Assert.assertEquals(values.get(0).keySet().size(), 1);
            Assert.assertEquals(Long.valueOf(values.get(0).get("account_record_id").toString()), accountRecordId);
            return null;
        }
    });
    eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
    customFieldUserApi.removeCustomFields(customFields, callContext);
    assertListenerStatus();
    List<CustomField> remainingCustomFields = customFieldUserApi.getCustomFieldsForObject(accountId, ObjectType.ACCOUNT, callContext);
    Assert.assertEquals(remainingCustomFields.size(), 0);
    checkPagination(0);
    // Add again the custom field
    final CustomField newCustomField = new StringCustomField(cfName, cfValue, ObjectType.ACCOUNT, accountId, callContext.getCreatedDate());
    eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
    customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(newCustomField), callContext);
    assertListenerStatus();
    remainingCustomFields = customFieldUserApi.getCustomFieldsForObject(accountId, ObjectType.ACCOUNT, callContext);
    Assert.assertEquals(remainingCustomFields.size(), 1);
    checkPagination(1);
    // Delete again
    eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
    customFieldUserApi.removeCustomFields(remainingCustomFields, callContext);
    assertListenerStatus();
    remainingCustomFields = customFieldUserApi.getCustomFieldsForObject(accountId, ObjectType.ACCOUNT, callContext);
    Assert.assertEquals(remainingCustomFields.size(), 0);
    checkPagination(0);
}
Also used : StringCustomField(org.killbill.billing.util.customfield.StringCustomField) Date(java.util.Date) Handle(org.skife.jdbi.v2.Handle) StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

CustomField (org.killbill.billing.util.customfield.CustomField)3 StringCustomField (org.killbill.billing.util.customfield.StringCustomField)3 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 UUID (java.util.UUID)1 CustomFieldJson (org.killbill.billing.jaxrs.json.CustomFieldJson)1 Handle (org.skife.jdbi.v2.Handle)1 Test (org.testng.annotations.Test)1