Search in sources :

Example 6 with TagDefinition

use of org.killbill.billing.client.model.gen.TagDefinition in project killbill by killbill.

the class TestTag method testTagsPagination.

@Test(groups = "slow", description = "Can paginate through all tags")
public void testTagsPagination() throws Exception {
    final Account account = createAccount();
    for (int i = 0; i < 5; i++) {
        final TagDefinition tagDefinition = new TagDefinition(null, false, "td-" + i, UUID.randomUUID().toString(), ImmutableList.<ObjectType>of(ObjectType.ACCOUNT), null);
        final UUID tagDefinitionId = tagDefinitionApi.createTagDefinition(tagDefinition, requestOptions).getId();
        accountApi.createAccountTags(account.getAccountId(), ImmutableList.<UUID>of(tagDefinitionId), requestOptions);
    }
    final Tags allTags = accountApi.getAccountTags(account.getAccountId(), requestOptions);
    Assert.assertEquals(allTags.size(), 5);
    Tags page = tagApi.getTags(0L, 1L, AuditLevel.NONE, requestOptions);
    for (int i = 0; i < 5; i++) {
        Assert.assertNotNull(page);
        Assert.assertEquals(page.size(), 1);
        final Tag targetTag = page.get(0);
        Assert.assertTrue(Iterables.any(allTags, new Predicate<Tag>() {

            @Override
            public boolean apply(@Nullable final Tag input) {
                return input.equals(targetTag);
            }
        }));
        page = page.getNext();
    }
    Assert.assertNull(page);
    for (final Tag tag : allTags) {
        doSearchTag(UUID.randomUUID().toString(), null);
        doSearchTag(tag.getTagId().toString(), tag);
        doSearchTag(tag.getTagDefinitionName(), tag);
        final TagDefinition tagDefinition = tagDefinitionApi.getTagDefinition(tag.getTagDefinitionId(), requestOptions);
        doSearchTag(tagDefinition.getDescription(), tag);
    }
    final Tags tags = tagApi.searchTags(ObjectType.ACCOUNT.toString(), requestOptions);
    Assert.assertEquals(tags.size(), 5);
    Assert.assertEquals(tags.getPaginationCurrentOffset(), 0);
    Assert.assertEquals(tags.getPaginationTotalNbRecords(), 5);
    Assert.assertEquals(tags.getPaginationMaxNbRecords(), 5);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) Tag(org.killbill.billing.client.model.gen.Tag) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) SystemTags(org.killbill.billing.util.tag.dao.SystemTags) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 7 with TagDefinition

use of org.killbill.billing.client.model.gen.TagDefinition in project killbill by killbill.

the class TestTag method testMultipleTagDefinitionOk.

@Test(groups = "slow", description = "Can create and delete TagDefinitions")
public void testMultipleTagDefinitionOk() throws Exception {
    List<TagDefinition> objFromJson = tagDefinitionApi.getTagDefinitions(requestOptions);
    final int sizeSystemTag = objFromJson.isEmpty() ? 0 : objFromJson.size();
    final TagDefinition inputBlue = new TagDefinition(null, false, "blue", "relaxing color", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
    tagDefinitionApi.createTagDefinition(inputBlue, requestOptions);
    final TagDefinition inputRed = new TagDefinition(null, false, "red", "hot color", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
    tagDefinitionApi.createTagDefinition(inputRed, requestOptions);
    final TagDefinition inputYellow = new TagDefinition(null, false, "yellow", "vibrant color", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
    tagDefinitionApi.createTagDefinition(inputYellow, requestOptions);
    final TagDefinition inputGreen = new TagDefinition(null, false, "green", "super relaxing color", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
    tagDefinitionApi.createTagDefinition(inputGreen, requestOptions);
    objFromJson = tagDefinitionApi.getTagDefinitions(requestOptions);
    assertNotNull(objFromJson);
    assertEquals(objFromJson.size(), 4 + sizeSystemTag);
    tagDefinitionApi.deleteTagDefinition(objFromJson.get(0).getId(), requestOptions);
    objFromJson = tagDefinitionApi.getTagDefinitions(requestOptions);
    assertNotNull(objFromJson);
    assertEquals(objFromJson.size(), 3 + sizeSystemTag);
}
Also used : TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) Test(org.testng.annotations.Test)

Example 8 with TagDefinition

use of org.killbill.billing.client.model.gen.TagDefinition in project killbill by killbill.

the class TestTag method testGetAllTagsByType.

@Test(groups = "slow", description = "Can search all tags for an account")
public void testGetAllTagsByType() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account account = createAccountWithDefaultPaymentMethod();
    final Subscription subscriptionJson = createSubscription(account.getAccountId(), "87544332", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    int nbAllowedControlTagType = 0;
    for (final ControlTagType controlTagType : ControlTagType.values()) {
        if (controlTagType.getApplicableObjectTypes().contains(ObjectType.ACCOUNT)) {
            accountApi.createAccountTags(account.getAccountId(), ImmutableList.<UUID>of(controlTagType.getId()), requestOptions);
            nbAllowedControlTagType++;
        }
    }
    final TagDefinition bundleTagDefInput = new TagDefinition(null, false, "bundletagdef", "nothing special", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
    final TagDefinition bundleTagDef = tagDefinitionApi.createTagDefinition(bundleTagDefInput, requestOptions);
    bundleApi.createBundleTags(subscriptionJson.getBundleId(), ImmutableList.<UUID>of(bundleTagDef.getId()), requestOptions);
    final Tags allBundleTags = bundleApi.getBundleTags(subscriptionJson.getBundleId(), requestOptions);
    Assert.assertEquals(allBundleTags.size(), 1);
    final Tags allAccountTags = accountApi.getAllTags(account.getAccountId(), null, requestOptions);
    Assert.assertEquals(allAccountTags.size(), nbAllowedControlTagType + 1);
    final Tags allBundleTagsForAccount = accountApi.getAllTags(account.getAccountId(), ObjectType.BUNDLE, requestOptions);
    Assert.assertEquals(allBundleTagsForAccount.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) ControlTagType(org.killbill.billing.util.tag.ControlTagType) TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) Subscription(org.killbill.billing.client.model.gen.Subscription) DateTime(org.joda.time.DateTime) Tags(org.killbill.billing.client.model.Tags) SystemTags(org.killbill.billing.util.tag.dao.SystemTags) Test(org.testng.annotations.Test)

Example 9 with TagDefinition

use of org.killbill.billing.client.model.gen.TagDefinition in project killbill by killbill.

the class TestPayment method testCreateTagForPaymentTransaction.

@Test(groups = "slow")
public void testCreateTagForPaymentTransaction() 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();
    final Tags paymentTransactionTag = paymentTransactionApi.createTransactionTags(paymentTransactionId, ImmutableList.<UUID>of(createdTagDefinition.getId()), requestOptions);
    Assert.assertNotNull(paymentTransactionTag);
    Assert.assertEquals(paymentTransactionTag.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)

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