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);
}
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();
}
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();
}
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);
}
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());
}
Aggregations