Search in sources :

Example 6 with Tags

use of org.killbill.billing.client.model.Tags in project killbill by killbill.

the class TestOverdue method testControlTagOverdueConfig.

@Test(groups = "slow", description = "Allow overdue condition by control tag defined in overdue config xml file")
public void testControlTagOverdueConfig() throws Exception {
    final String overdueConfigPath = Resources.getResource("overdueWithControlTag.xml").getPath();
    killBillClient.uploadXMLOverdueConfig(overdueConfigPath, requestOptions);
    // Create an account without a payment method and assign a TEST tag
    final Account accountJson = createAccountNoPMBundleAndSubscription();
    final Tags accountTag = killBillClient.createAccountTag(accountJson.getAccountId(), ControlTagType.TEST.getId(), requestOptions);
    assertEquals(accountTag.get(0).getTagDefinitionId(), ControlTagType.TEST.getId());
    // Create an account without a TEST tag
    final Account accountJsonNoTag = createAccountNoPMBundleAndSubscription();
    // No payment will be triggered as the account doesn't have a payment method
    clock.addMonths(1);
    crappyWaitForLackOfProperSynchonization();
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final List<Invoice> invoicesNoTag = killBillClient.getInvoicesForAccount(accountJsonNoTag.getAccountId(), requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoicesNoTag.size(), 2);
    // We're still clear - see the configuration
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJsonNoTag.getAccountId(), requestOptions).getIsClearState());
    clock.addDays(30);
    crappyWaitForLackOfProperSynchonization();
    // This account is expected to move to OD1 state because it matches with controlTag defined
    Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getName(), "OD1");
    // This account is not expected to move to OD1 state because it does not match with controlTag defined
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJsonNoTag.getAccountId(), requestOptions).getIsClearState());
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 7 with Tags

use of org.killbill.billing.client.model.Tags 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, UUID.randomUUID().toString().substring(0, 5), UUID.randomUUID().toString(), ImmutableList.<ObjectType>of(ObjectType.ACCOUNT));
        final UUID tagDefinitionId = killBillClient.createTagDefinition(tagDefinition, requestOptions).getId();
        killBillClient.createAccountTag(account.getAccountId(), tagDefinitionId, requestOptions);
    }
    final Tags allTags = killBillClient.getTags(requestOptions);
    Assert.assertEquals(allTags.size(), 5);
    Tags page = killBillClient.getTags(0L, 1L, requestOptions);
    for (int i = 0; i < 5; i++) {
        Assert.assertNotNull(page);
        Assert.assertEquals(page.size(), 1);
        Assert.assertEquals(page.get(0), allTags.get(i));
        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 = killBillClient.getTagDefinition(tag.getTagDefinitionId(), requestOptions);
        doSearchTag(tagDefinition.getDescription(), tag);
    }
    final Tags tags = killBillClient.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.Account) TagDefinition(org.killbill.billing.client.model.TagDefinition) Tag(org.killbill.billing.client.model.Tag) UUID(java.util.UUID) SystemTags(org.killbill.billing.util.tag.dao.SystemTags) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 8 with Tags

use of org.killbill.billing.client.model.Tags 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 = createEntitlement(account.getAccountId(), "87544332", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
    for (final ControlTagType controlTagType : ControlTagType.values()) {
        killBillClient.createAccountTag(account.getAccountId(), controlTagType.getId(), requestOptions);
    }
    final TagDefinition bundleTagDefInput = new TagDefinition(null, false, "bundletagdef", "nothing special", ImmutableList.<ObjectType>of());
    final TagDefinition bundleTagDef = killBillClient.createTagDefinition(bundleTagDefInput, requestOptions);
    killBillClient.createBundleTag(subscriptionJson.getBundleId(), bundleTagDef.getId(), requestOptions);
    final Tags allBundleTags = killBillClient.getBundleTags(subscriptionJson.getBundleId(), AuditLevel.FULL, requestOptions);
    Assert.assertEquals(allBundleTags.size(), 1);
    final Tags allAccountTags = killBillClient.getAllAccountTags(account.getAccountId(), null, AuditLevel.FULL, requestOptions);
    Assert.assertEquals(allAccountTags.size(), ControlTagType.values().length + 1);
    final Tags allBundleTagsForAccount = killBillClient.getAllAccountTags(account.getAccountId(), ObjectType.BUNDLE.name(), AuditLevel.FULL, requestOptions);
    Assert.assertEquals(allBundleTagsForAccount.size(), 1);
}
Also used : Account(org.killbill.billing.client.model.Account) ControlTagType(org.killbill.billing.util.tag.ControlTagType) TagDefinition(org.killbill.billing.client.model.TagDefinition) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) SystemTags(org.killbill.billing.util.tag.dao.SystemTags) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 9 with Tags

use of org.killbill.billing.client.model.Tags in project killbill by killbill.

the class TestOverdue method testExclusionControlTagOverdueConfig.

@Test(groups = "slow", description = "Allow overdue condition by exclusion control tag defined in overdue config xml file")
public void testExclusionControlTagOverdueConfig() throws Exception {
    final String overdueConfigPath = Resources.getResource("overdueWithExclusionControlTag.xml").getPath();
    killBillClient.uploadXMLOverdueConfig(overdueConfigPath, requestOptions);
    // Create an account without a payment method and assign a TEST tag
    final Account accountJson = createAccountNoPMBundleAndSubscription();
    final Tags accountTag = killBillClient.createAccountTag(accountJson.getAccountId(), ControlTagType.TEST.getId(), requestOptions);
    assertEquals(accountTag.get(0).getTagDefinitionId(), ControlTagType.TEST.getId());
    // Create an account without a TEST tag
    final Account accountJsonNoTag = createAccountNoPMBundleAndSubscription();
    // move a month a wait for invoicing
    // No payment will be triggered as the account doesn't have a payment method
    clock.addMonths(1);
    crappyWaitForLackOfProperSynchonization();
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final List<Invoice> invoicesNoTag = killBillClient.getInvoicesForAccount(accountJsonNoTag.getAccountId(), requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoicesNoTag.size(), 2);
    // We're still clear - see the configuration
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJsonNoTag.getAccountId(), requestOptions).getIsClearState());
    clock.addDays(30);
    crappyWaitForLackOfProperSynchonization();
    // This account is not expected to move to OD1 state because it does not match with exclusion controlTag defined
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
    // This account is expected to move to OD1 state because it matches with exclusion controlTag defined
    Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJsonNoTag.getAccountId(), requestOptions).getName(), "OD1");
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 10 with Tags

use of org.killbill.billing.client.model.Tags 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", null);
    final TagDefinition createdTagDefinition = killBillClient.createTagDefinition(tagDefinition, requestOptions);
    final Account account = createAccountWithDefaultPaymentMethod();
    final String externalPaymentKey = UUID.randomUUID().toString();
    final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
    final Payment payment = killBillClient.getPaymentByExternalKey(externalPaymentKey, requestOptions);
    assertEquals(payment.getPaymentId(), paymentId);
    UUID paymentTransactionId = payment.getTransactions().get(0).getTransactionId();
    final Tags paymentTransactionTag = killBillClient.createPaymentTransactionTag(paymentTransactionId, createdTagDefinition.getId(), requestOptions);
    Assert.assertNotNull(paymentTransactionTag);
    Assert.assertEquals(paymentTransactionTag.get(0).getTagDefinitionName(), tagDefinitionName);
}
Also used : TagDefinition(org.killbill.billing.client.model.TagDefinition) Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Aggregations

Tags (org.killbill.billing.client.model.Tags)11 Account (org.killbill.billing.client.model.Account)10 Test (org.testng.annotations.Test)9 UUID (java.util.UUID)5 TagDefinition (org.killbill.billing.client.model.TagDefinition)4 SystemTags (org.killbill.billing.util.tag.dao.SystemTags)4 Subscription (org.killbill.billing.client.model.Subscription)3 Invoice (org.killbill.billing.client.model.Invoice)2 Payment (org.killbill.billing.client.model.Payment)2 ControlTagType (org.killbill.billing.util.tag.ControlTagType)2 DateTime (org.joda.time.DateTime)1 RequestOptions (org.killbill.billing.client.RequestOptions)1 Tag (org.killbill.billing.client.model.Tag)1