use of org.killbill.billing.util.api.CustomFieldApiException in project killbill by killbill.
the class TestDefaultCustomFieldUserApi method testCustomFieldUpdate.
@Test(groups = "slow")
public void testCustomFieldUpdate() throws Exception {
final CustomField customField1 = new StringCustomField("gtqre", "value1", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate());
eventsListener.pushExpectedEvents(NextEvent.CUSTOM_FIELD);
customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField1), callContext);
assertListenerStatus();
final CustomField update1 = new StringCustomField(customField1.getId(), customField1.getFieldName(), "value2", customField1.getObjectType(), customField1.getObjectId(), callContext.getCreatedDate());
customFieldUserApi.updateCustomFields(ImmutableList.of(update1), callContext);
List<CustomField> all = customFieldUserApi.getCustomFieldsForAccount(accountId, callContext);
Assert.assertEquals(all.size(), 1);
Assert.assertEquals(all.get(0).getId(), update1.getId());
Assert.assertEquals(all.get(0).getObjectType(), update1.getObjectType());
Assert.assertEquals(all.get(0).getObjectId(), update1.getObjectId());
Assert.assertEquals(all.get(0).getFieldName(), update1.getFieldName());
Assert.assertEquals(all.get(0).getFieldValue(), "value2");
try {
customFieldUserApi.updateCustomFields(ImmutableList.<CustomField>of(new StringCustomField("gtqre", "value1", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate())), callContext);
Assert.fail("Updating custom field should fail");
} catch (final CustomFieldApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.CUSTOM_FIELD_DOES_NOT_EXISTS_FOR_ID.getCode());
}
try {
customFieldUserApi.updateCustomFields(ImmutableList.<CustomField>of(new StringCustomField(customField1.getId(), "wrongName", "value2", customField1.getObjectType(), customField1.getObjectId(), callContext.getCreatedDate())), callContext);
Assert.fail("Updating custom field should fail");
} catch (final CustomFieldApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.CUSTOM_FIELD_INVALID_UPDATE.getCode());
}
}
use of org.killbill.billing.util.api.CustomFieldApiException in project killbill by killbill.
the class TestDefaultCustomFieldUserApi method testCustomFieldBasic.
@Test(groups = "slow")
public void testCustomFieldBasic() throws Exception {
final CustomField customField1 = new StringCustomField("some123", "some 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate());
final CustomField customField2 = new StringCustomField("other123", "other 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate());
eventsListener.pushExpectedEvents(NextEvent.CUSTOM_FIELD, NextEvent.CUSTOM_FIELD);
customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField1, customField2), callContext);
assertListenerStatus();
// Verify operation is indeed transactional, and nothing was inserted
final CustomField customField3 = new StringCustomField("qrqrq123", "qrqrq 456", ObjectType.ACCOUNT, accountId, callContext.getCreatedDate());
try {
customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField3, customField1), callContext);
} catch (CustomFieldApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.CUSTOM_FIELD_ALREADY_EXISTS.getCode());
}
List<CustomField> all = customFieldUserApi.getCustomFieldsForAccount(accountId, callContext);
Assert.assertEquals(all.size(), 2);
eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
customFieldUserApi.addCustomFields(ImmutableList.<CustomField>of(customField3), callContext);
assertListenerStatus();
all = customFieldUserApi.getCustomFieldsForAccount(accountId, callContext);
Assert.assertEquals(all.size(), 3);
eventsListener.pushExpectedEvents(NextEvent.CUSTOM_FIELD, NextEvent.CUSTOM_FIELD);
customFieldUserApi.removeCustomFields(ImmutableList.of(customField1, customField3), callContext);
assertListenerStatus();
all = customFieldUserApi.getCustomFieldsForAccount(accountId, callContext);
Assert.assertEquals(all.size(), 1);
Assert.assertEquals(all.get(0).getId(), customField2.getId());
Assert.assertEquals(all.get(0).getObjectId(), accountId);
Assert.assertEquals(all.get(0).getObjectType(), ObjectType.ACCOUNT);
Assert.assertEquals(all.get(0).getFieldName(), customField2.getFieldName());
Assert.assertEquals(all.get(0).getFieldValue(), customField2.getFieldValue());
}
Aggregations