Search in sources :

Example 11 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.

the class TestDefaultUserTagDefinitionDeletionEvent method testSerialization.

@Test(groups = "fast")
public void testSerialization() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = UUID.randomUUID();
    final DefaultUserTagDefinitionDeletionEvent event = new DefaultUserTagDefinitionDeletionEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultUserTagDefinitionDeletionEvent fromJson = objectMapper.readValue(json, DefaultUserTagDefinitionDeletionEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 12 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.

the class TagDefinitionResource method getTagDefinitions.

@TimedResource
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List tag definitions", response = TagDefinitionJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getTagDefinitions(@javax.ws.rs.core.Context final HttpServletRequest request, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode) {
    final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
    final List<TagDefinition> tagDefinitions = tagUserApi.getTagDefinitions(tenantContext);
    final Collection<TagDefinitionJson> result = new LinkedList<TagDefinitionJson>();
    for (final TagDefinition tagDefinition : tagDefinitions) {
        final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tagDefinition.getId(), ObjectType.TAG_DEFINITION, auditMode.getLevel(), tenantContext);
        result.add(new TagDefinitionJson(tagDefinition, auditLogs));
    }
    return Response.status(Status.OK).entity(result).build();
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TenantContext(org.killbill.billing.util.callcontext.TenantContext) TagDefinitionJson(org.killbill.billing.jaxrs.json.TagDefinitionJson) LinkedList(java.util.LinkedList) AuditLog(org.killbill.billing.util.audit.AuditLog) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.

the class TagDefinitionResource method getTagDefinition.

@TimedResource
@GET
@Path("/{tagDefinitionId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a tag definition", response = TagDefinitionJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tagDefinitionId supplied") })
public Response getTagDefinition(@PathParam("tagDefinitionId") final UUID tagDefId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException {
    final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
    final TagDefinition tagDefinition = tagUserApi.getTagDefinition(tagDefId, tenantContext);
    final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tagDefinition.getId(), ObjectType.TAG_DEFINITION, auditMode.getLevel(), tenantContext);
    final TagDefinitionJson json = new TagDefinitionJson(tagDefinition, auditLogs);
    return Response.status(Status.OK).entity(json).build();
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TenantContext(org.killbill.billing.util.callcontext.TenantContext) TagDefinitionJson(org.killbill.billing.jaxrs.json.TagDefinitionJson) AuditLog(org.killbill.billing.util.audit.AuditLog) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.

the class TestTagApi method testApiTagOnInvoice.

@Test(groups = "slow")
public void testApiTagOnInvoice() throws Exception {
    // 
    // Create necessary logic to end up with an Invoice object on that account.
    // 
    final String productName = "Shotgun";
    final BillingPeriod term = BillingPeriod.ANNUAL;
    final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
    final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(bpEntitlement);
    final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext);
    Assert.assertEquals(invoices.size(), 1);
    final Invoice invoice = invoices.get(0);
    Assert.assertEquals(invoice.getAccountId(), account.getId());
    // 
    // Create a new tag definition
    // 
    busHandler.pushExpectedEvents(NextEvent.TAG_DEFINITION);
    final TagDefinition tagDefinition = tagUserApi.createTagDefinition("foo", "foo desc", ImmutableSet.<ObjectType>of(ObjectType.ACCOUNT, ObjectType.INVOICE), callContext);
    assertListenerStatus();
    final TagDefinition tagDefinition2 = tagUserApi.getTagDefinition(tagDefinition.getId(), callContext);
    assertEquals(tagDefinition2.getApplicableObjectTypes().size(), 2);
    assertEquals(tagDefinition2.getApplicableObjectTypes().get(0), ObjectType.ACCOUNT);
    assertEquals(tagDefinition2.getApplicableObjectTypes().get(1), ObjectType.INVOICE);
    // 
    // Add 2 Tags on the invoice (1 invoice tag and 1 user tag)
    // 
    busHandler.pushExpectedEvents(NextEvent.TAG);
    tagUserApi.addTag(invoice.getId(), ObjectType.INVOICE, ControlTagType.WRITTEN_OFF.getId(), callContext);
    assertListenerStatus();
    busHandler.pushExpectedEvents(NextEvent.TAG);
    tagUserApi.addTag(invoice.getId(), ObjectType.INVOICE, tagDefinition.getId(), callContext);
    assertListenerStatus();
    List<Tag> tags = tagUserApi.getTagsForAccount(account.getId(), false, callContext);
    Assert.assertEquals(tags.size(), 2);
    checkTagsExists(tags);
    tags = tagUserApi.getTagsForObject(invoice.getId(), ObjectType.INVOICE, false, callContext);
    Assert.assertEquals(tags.size(), 2);
    checkTagsExists(tags);
    tags = tagUserApi.getTagsForAccountType(account.getId(), ObjectType.INVOICE, false, callContext);
    Assert.assertEquals(tags.size(), 2);
    checkTagsExists(tags);
    // 
    // Add a tag on the account itself and retry
    // 
    busHandler.pushExpectedEvents(NextEvent.TAG);
    tagUserApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_PAY_OFF.getId(), callContext);
    assertListenerStatus();
    tags = tagUserApi.getTagsForAccount(account.getId(), false, callContext);
    Assert.assertEquals(tags.size(), 3);
    checkTagsExists(tags);
    tags = tagUserApi.getTagsForObject(invoice.getId(), ObjectType.INVOICE, false, callContext);
    Assert.assertEquals(tags.size(), 2);
    checkTagsExists(tags);
    tags = tagUserApi.getTagsForAccountType(account.getId(), ObjectType.INVOICE, false, callContext);
    Assert.assertEquals(tags.size(), 2);
    checkTagsExists(tags);
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) Invoice(org.killbill.billing.invoice.api.Invoice) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Tag(org.killbill.billing.util.tag.Tag) Test(org.testng.annotations.Test)

Example 15 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.

the class TestDefaultTagUserApiWithMockDao method testCreateTagDefinitionWithLowerCase.

@Test(groups = "fast")
public void testCreateTagDefinitionWithLowerCase() throws Exception {
    final String tagDefinitionName = "lowercase";
    final TagDefinitionModelDao tagDefinitionModelDao = new TagDefinitionModelDao();
    tagDefinitionModelDao.setName(tagDefinitionName);
    tagDefinitionModelDao.setApplicableObjectTypes(ObjectType.ACCOUNT.name());
    Mockito.when(tagDefinitionDao.create(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(tagDefinitionModelDao);
    final TagDefinition tagDefinition = tagUserApi.createTagDefinition(tagDefinitionName, "description", ImmutableSet.<ObjectType>of(ObjectType.ACCOUNT), context);
    assertEquals(tagDefinitionName, tagDefinition.getName());
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) Test(org.testng.annotations.Test)

Aggregations

TagDefinition (org.killbill.billing.util.tag.TagDefinition)33 UUID (java.util.UUID)27 Test (org.testng.annotations.Test)26 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)24 ObjectType (org.killbill.billing.ObjectType)12 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)9 ObjectMapper (org.killbill.billing.util.jackson.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Produces (javax.ws.rs.Produces)6 TimedResource (org.killbill.commons.metrics.TimedResource)6 GET (javax.ws.rs.GET)5 TenantContext (org.killbill.billing.util.callcontext.TenantContext)5 Path (javax.ws.rs.Path)4 TagDefinitionInternalEvent (org.killbill.billing.events.TagDefinitionInternalEvent)4 TagInternalEvent (org.killbill.billing.events.TagInternalEvent)4 AuditLog (org.killbill.billing.util.audit.AuditLog)4 Tag (org.killbill.billing.util.tag.Tag)4 HashMap (java.util.HashMap)3 TagDefinitionJson (org.killbill.billing.jaxrs.json.TagDefinitionJson)3