use of org.killbill.billing.client.model.gen.TagDefinition in project killbill by killbill.
the class TestPayment method testGetTagsForPaymentTransaction.
@Test(groups = "slow")
public void testGetTagsForPaymentTransaction() throws Exception {
UUID tagDefinitionId = UUID.randomUUID();
String tagDefinitionName = "payment-transaction";
TagDefinition tagDefinition = new TagDefinition(tagDefinitionId, false, tagDefinitionName, "description", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
final TagDefinition createdTagDefinition = tagDefinitionApi.createTagDefinition(tagDefinition, requestOptions);
final Account account = createAccountWithDefaultPaymentMethod();
final String externalPaymentKey = UUID.randomUUID().toString();
final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
final Payment payment = paymentApi.getPaymentByExternalKey(externalPaymentKey, NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(payment.getPaymentId(), paymentId);
UUID paymentTransactionId = payment.getTransactions().get(0).getTransactionId();
paymentTransactionApi.createTransactionTags(paymentTransactionId, ImmutableList.<UUID>of(createdTagDefinition.getId()), requestOptions);
final Tags paymentTransactionTags = paymentTransactionApi.getTransactionTags(paymentTransactionId, requestOptions);
Assert.assertNotNull(paymentTransactionTags);
Assert.assertEquals(paymentTransactionTags.get(0).getTagDefinitionName(), tagDefinitionName);
}
use of org.killbill.billing.client.model.gen.TagDefinition 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, ImmutableList.<ObjectType>of(ObjectType.ACCOUNT), null), new TagDefinition(null, false, "something", null, ImmutableList.<ObjectType>of(ObjectType.INVOICE), null), new TagDefinition(null, false, null, "something", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null) };
for (final TagDefinition tagDefinition : tagDefinitions) {
try {
tagDefinitionApi.createTagDefinition(tagDefinition, requestOptions);
fail();
} catch (final KillBillClientException e) {
}
}
}
use of org.killbill.billing.client.model.gen.TagDefinition in project killbill by killbill.
the class TestTag method testGetTagAuditLogsWithHistory.
@Test(groups = "slow", description = "retrieve account logs")
public void testGetTagAuditLogsWithHistory() throws Exception {
final Account accountJson = createAccount();
assertNotNull(accountJson);
final TagDefinition accountTagDefInput = new TagDefinition().setName("tag_name").setDescription("nothing special").setApplicableObjectTypes(ImmutableList.<ObjectType>of(ObjectType.ACCOUNT));
final TagDefinition accountTagDef = tagDefinitionApi.createTagDefinition(accountTagDefInput, requestOptions);
accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(accountTagDef.getId()), 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.TAG)) {
objectId = auditLog.getObjectId();
break;
}
}
assertNotNull(objectId);
final List<AuditLog> tagAuditLogWithHistories = tagApi.getTagAuditLogsWithHistory(objectId, requestOptions);
assertEquals(tagAuditLogWithHistories.size(), 1);
assertEquals(tagAuditLogWithHistories.get(0).getChangeType(), ChangeType.INSERT.toString());
assertEquals(tagAuditLogWithHistories.get(0).getObjectType(), ObjectType.TAG);
assertEquals(tagAuditLogWithHistories.get(0).getObjectId(), objectId);
final LinkedHashMap history1 = (LinkedHashMap) tagAuditLogWithHistories.get(0).getHistory();
assertNotNull(history1);
assertEquals(history1.get("tagDefinitionId"), accountTagDef.getId().toString());
assertEquals(history1.get("objectId"), accountJson.getAccountId().toString());
assertEquals(history1.get("objectType"), ObjectType.ACCOUNT.toString());
}
use of org.killbill.billing.client.model.gen.TagDefinition in project killbill by killbill.
the class TestTag method testTagDefinitionOk.
@Test(groups = "slow", description = "Can create a TagDefinition")
public void testTagDefinitionOk() throws Exception {
final TagDefinition input = new TagDefinition(null, false, "blue", "relaxing color", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
final TagDefinition objFromJson = tagDefinitionApi.createTagDefinition(input, requestOptions);
assertNotNull(objFromJson);
assertEquals(objFromJson.getName(), input.getName());
assertEquals(objFromJson.getDescription(), input.getDescription());
}
use of org.killbill.billing.client.model.gen.TagDefinition in project killbill by killbill.
the class TestInvoiceItem method testTags.
@Test(groups = "slow", description = "Add tags to invoice item")
public void testTags() 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);
// Create tag definition
final TagDefinition input = new TagDefinition(null, false, "tagtest", "invoice item tag test", ImmutableList.<ObjectType>of(ObjectType.INVOICE_ITEM), null);
final TagDefinition objFromJson = tagDefinitionApi.createTagDefinition(input, requestOptions);
Assert.assertNotNull(objFromJson);
Assert.assertEquals(objFromJson.getName(), input.getName());
Assert.assertEquals(objFromJson.getDescription(), input.getDescription());
// Add a tag
final Multimap<String, String> followQueryParams = HashMultimap.create();
followQueryParams.put(JaxrsResource.QUERY_ACCOUNT_ID, accountJson.getAccountId().toString());
final RequestOptions followRequestOptions = requestOptions.extend().withQueryParamsForFollow(followQueryParams).build();
invoiceItemApi.createInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), followRequestOptions);
// Retrieves all tags
final List<Tag> tags1 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(tags1.size(), 1);
Assert.assertEquals(tags1.get(0).getTagDefinitionId(), objFromJson.getId());
// Verify adding the same tag a second time doesn't do anything
invoiceItemApi.createInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), followRequestOptions);
// Retrieves all tags again
final List<Tag> tags2 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(tags2, tags1);
// Verify audit logs
Assert.assertEquals(tags2.get(0).getAuditLogs().size(), 1);
final AuditLog auditLogJson = tags2.get(0).getAuditLogs().get(0);
Assert.assertEquals(auditLogJson.getChangeType(), "INSERT");
Assert.assertEquals(auditLogJson.getChangedBy(), createdBy);
Assert.assertEquals(auditLogJson.getReasonCode(), reason);
Assert.assertEquals(auditLogJson.getComments(), comment);
Assert.assertNotNull(auditLogJson.getChangeDate());
Assert.assertNotNull(auditLogJson.getUserToken());
// remove it
invoiceItemApi.deleteInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), requestOptions);
final List<Tag> tags3 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(tags3.size(), 0);
tagDefinitionApi.deleteTagDefinition(objFromJson.getId(), requestOptions);
List<TagDefinition> objsFromJson = tagDefinitionApi.getTagDefinitions(requestOptions);
Assert.assertNotNull(objsFromJson);
Boolean isFound = false;
for (TagDefinition tagDefinition : objsFromJson) {
isFound |= tagDefinition.getId().equals(objFromJson.getId());
}
Assert.assertFalse(isFound);
}
Aggregations