use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TestDefaultAuditLog method testEquals.
@Test(groups = "fast")
public void testEquals() throws Exception {
final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
final long recordId = Long.MAX_VALUE;
final ChangeType changeType = ChangeType.DELETE;
final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
final UUID tenantId = UUID.randomUUID();
final String userName = UUID.randomUUID().toString();
final CallOrigin callOrigin = CallOrigin.EXTERNAL;
final UserType userType = UserType.CUSTOMER;
final UUID userToken = UUID.randomUUID();
final ClockMock clock = new ClockMock();
final CallContext callContext = new DefaultCallContext(tenantId, userName, callOrigin, userType, userToken, clock);
final AuditLogModelDao auditLog = new AuditLogModelDao(entityAudit, callContext);
Assert.assertEquals(auditLog, auditLog);
final AuditLogModelDao sameAuditLog = new AuditLogModelDao(entityAudit, callContext);
Assert.assertEquals(sameAuditLog, auditLog);
clock.addMonths(1);
final CallContext otherCallContext = new DefaultCallContext(tenantId, userName, callOrigin, userType, userToken, clock);
final AuditLogModelDao otherAuditLog = new AuditLogModelDao(entityAudit, otherCallContext);
Assert.assertNotEquals(otherAuditLog, auditLog);
}
use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TestDefaultCallContext method testGetters.
@Test(groups = "fast")
public void testGetters() throws Exception {
final UUID tenantId = UUID.randomUUID();
final String userName = UUID.randomUUID().toString();
final DateTime createdDate = clock.getUTCNow();
final String reasonCode = UUID.randomUUID().toString();
final String comment = UUID.randomUUID().toString();
final UUID userToken = UUID.randomUUID();
final DefaultCallContext callContext = new DefaultCallContext(tenantId, userName, createdDate, reasonCode, comment, userToken);
Assert.assertEquals(callContext.getTenantId(), tenantId);
Assert.assertEquals(callContext.getCreatedDate(), createdDate);
Assert.assertNull(callContext.getCallOrigin());
Assert.assertEquals(callContext.getComments(), comment);
Assert.assertEquals(callContext.getReasonCode(), reasonCode);
Assert.assertEquals(callContext.getUserName(), userName);
Assert.assertEquals(callContext.getUpdatedDate(), createdDate);
Assert.assertEquals(callContext.getUserToken(), userToken);
Assert.assertNull(callContext.getUserType());
}
use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TestDefaultCallContext method testEquals.
@Test(groups = "fast")
public void testEquals() throws Exception {
final UUID tenantId = UUID.randomUUID();
final String userName = UUID.randomUUID().toString();
final DateTime createdDate = clock.getUTCNow();
final String reasonCode = UUID.randomUUID().toString();
final String comment = UUID.randomUUID().toString();
final UUID userToken = UUID.randomUUID();
final DefaultCallContext callContext = new DefaultCallContext(tenantId, userName, createdDate, reasonCode, comment, userToken);
Assert.assertEquals(callContext, callContext);
final DefaultCallContext sameCallContext = new DefaultCallContext(tenantId, userName, createdDate, reasonCode, comment, userToken);
Assert.assertEquals(sameCallContext, callContext);
final DefaultCallContext otherCallContext = new DefaultCallContext(tenantId, UUID.randomUUID().toString(), createdDate, reasonCode, comment, userToken);
Assert.assertNotEquals(otherCallContext, callContext);
}
use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TenantResource method createTenant.
@TimedResource
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Create a tenant")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Tenant already exists") })
public Response createTenant(final TenantJson json, @QueryParam(QUERY_TENANT_USE_GLOBAL_DEFAULT) @DefaultValue("true") final Boolean useGlobalDefault, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws TenantApiException, CatalogApiException {
verifyNonNullOrEmpty(json, "TenantJson body should be specified");
verifyNonNullOrEmpty(json.getApiKey(), "TenantJson apiKey needs to be set", json.getApiSecret(), "TenantJson apiSecret needs to be set");
final TenantData data = json.toTenantData();
final Tenant tenant = tenantApi.createTenant(data, context.createContext(createdBy, reason, comment, request));
if (!useGlobalDefault) {
final CallContext callContext = new DefaultCallContext(tenant.getId(), createdBy, CallOrigin.EXTERNAL, UserType.CUSTOMER, Context.getOrCreateUserToken(), clock);
catalogUserApi.createDefaultEmptyCatalog(clock.getUTCNow(), callContext);
}
return uriBuilder.buildResponse(uriInfo, TenantResource.class, "getTenant", tenant.getId(), request);
}
use of org.killbill.billing.callcontext.DefaultCallContext in project killbill by killbill.
the class TestPublicBus method testTenantKVChange.
@Test(groups = "slow")
public void testTenantKVChange() throws Exception {
final TenantData tenantData = new DefaultTenant(null, clock.getUTCNow(), clock.getUTCNow(), "MY_TENANT", "key", "s3Cr3T");
final CallContext contextWithNoTenant = new DefaultCallContext(null, "loulou", CallOrigin.EXTERNAL, UserType.ADMIN, "no reason", "hum", UUID.randomUUID(), clock);
final Tenant tenant = tenantUserApi.createTenant(tenantData, contextWithNoTenant);
final CallContext contextWithTenant = new DefaultCallContext(tenant.getId(), "loulou", CallOrigin.EXTERNAL, UserType.ADMIN, "no reason", "hum", UUID.randomUUID(), clock);
final String tenantKey = TenantKey.PLUGIN_CONFIG_ + "FOO";
tenantUserApi.addTenantKeyValue(tenantKey, "FOO", contextWithTenant);
await().atMost(10, SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
// expecting TENANT_CONFIG_CHANGE
return externalBusCount.get() == 1;
}
});
}
Aggregations