Search in sources :

Example 1 with TagDefinition

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);
}
Also used : TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 2 with TagDefinition

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) {
        }
    }
}
Also used : TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) ObjectType(org.killbill.billing.ObjectType) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 3 with TagDefinition

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());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 4 with TagDefinition

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());
}
Also used : TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) Test(org.testng.annotations.Test)

Example 5 with TagDefinition

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);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) RequestOptions(org.killbill.billing.client.RequestOptions) Invoices(org.killbill.billing.client.model.Invoices) AuditLog(org.killbill.billing.client.model.gen.AuditLog) Tag(org.killbill.billing.client.model.gen.Tag) Test(org.testng.annotations.Test)

Aggregations

TagDefinition (org.killbill.billing.client.model.gen.TagDefinition)9 Test (org.testng.annotations.Test)9 Account (org.killbill.billing.client.model.gen.Account)6 UUID (java.util.UUID)4 Tags (org.killbill.billing.client.model.Tags)4 AuditLog (org.killbill.billing.client.model.gen.AuditLog)2 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)2 Payment (org.killbill.billing.client.model.gen.Payment)2 Tag (org.killbill.billing.client.model.gen.Tag)2 SystemTags (org.killbill.billing.util.tag.dao.SystemTags)2 Predicate (com.google.common.base.Predicate)1 LinkedHashMap (java.util.LinkedHashMap)1 Nullable (javax.annotation.Nullable)1 DateTime (org.joda.time.DateTime)1 ObjectType (org.killbill.billing.ObjectType)1 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 RequestOptions (org.killbill.billing.client.RequestOptions)1 Invoices (org.killbill.billing.client.model.Invoices)1 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)1 Subscription (org.killbill.billing.client.model.gen.Subscription)1