public CallContext toCallContext(final UUID accountId, final UUID tenantId) { return new DefaultCallContext(accountId, tenantId, createdBy, callOrigin, contextUserType, reasonCode, comments, userToken, createdDate, updatedDate); }
@Override public CallContext createCallContext(@Nullable final UUID accountId, @Nullable final UUID tenantId, final String userName, final CallOrigin callOrigin, final UserType userType, final String reasonCode, final String comment, final UUID userToken) { return new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, reasonCode, comment, userToken, clock); } }
@Override public AuditLogModelDao map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException { final UUID id = getUUID(r, "id"); final String tableName = r.getString("table_name"); final long targetRecordId = r.getLong("target_record_id"); final String changeType = r.getString("change_type"); final DateTime createdDate = getDateTime(r, "created_date"); final String createdBy = r.getString("created_by"); final String reasonCode = r.getString("reason_code"); final String comments = r.getString("comments"); final UUID userToken = getUUID(r, "user_token"); final EntityAudit entityAudit = new EntityAudit(id, TableName.valueOf(tableName), targetRecordId, ChangeType.valueOf(changeType), createdDate); // TODO - we have the tenant_record_id but not the tenant id here final DefaultCallContext callContext = new DefaultCallContext(null, null, createdBy, createdDate, reasonCode, comments, userToken); return new AuditLogModelDao(entityAudit, callContext); } }
@Test(groups = "fast") public void testEquals() throws Exception { final UUID accountId = UUID.randomUUID(); 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(accountId, tenantId, userName, createdDate, reasonCode, comment, userToken); Assert.assertEquals(callContext, callContext); final DefaultCallContext sameCallContext = new DefaultCallContext(accountId, tenantId, userName, createdDate, reasonCode, comment, userToken); Assert.assertEquals(sameCallContext, callContext); final DefaultCallContext otherCallContext = new DefaultCallContext(accountId, tenantId, UUID.randomUUID().toString(), createdDate, reasonCode, comment, userToken); Assert.assertNotEquals(otherCallContext, callContext); } }
@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 accountId = UUID.randomUUID(); 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 DefaultCallContext callContext = new DefaultCallContext(accountId, 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 DefaultCallContext otherCallContext = new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, userToken, clock); final AuditLogModelDao otherAuditLog = new AuditLogModelDao(entityAudit, otherCallContext); Assert.assertNotEquals(otherAuditLog, auditLog); } }
@Test(groups = "fast") public void testGetters() throws Exception { final UUID accountId = UUID.randomUUID(); 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(accountId, 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()); }
@Test(groups = "fast") public void testGetters() 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 accountId = UUID.randomUUID(); 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 DefaultCallContext callContext = new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, userToken, clock); final AuditLog auditLog = new DefaultAuditLog(new AuditLogModelDao(entityAudit, callContext), ObjectType.ACCOUNT_EMAIL, UUID.randomUUID()); Assert.assertEquals(auditLog.getChangeType(), changeType); Assert.assertNull(auditLog.getComment()); Assert.assertNotNull(auditLog.getCreatedDate()); Assert.assertNull(auditLog.getReasonCode()); Assert.assertEquals(auditLog.getUserName(), userName); Assert.assertEquals(auditLog.getUserToken(), userToken.toString()); }
@Test(groups = "slow", description = "Test Account creation with same External Key in different tenants") public void testCreateAccountWithSameExternalKeyInDifferentTenants() throws Exception { final AccountData accountData = createAccountData(); final Account account1 = accountUserApi.createAccount(accountData, callContext); try { // Same tenant accountUserApi.createAccount(accountData, callContext); Assert.fail(); } catch (final AccountApiException e) { assertEquals(e.getCode(), ErrorCode.ACCOUNT_ALREADY_EXISTS.getCode()); } final TenantSqlDao tenantSqlDao = dbi.onDemand(TenantSqlDao.class); final TenantModelDao tenant2 = new TenantModelDao(); tenantSqlDao.create(tenant2, internalCallContext); final CallContext callContext2 = new DefaultCallContext(account1.getId(), tenant2.getId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getUserToken(), clock); final Account account2 = accountUserApi.createAccount(accountData, callContext2); Assert.assertEquals(account1.getExternalKey(), account2.getExternalKey()); Assert.assertNotEquals(account1.getId(), account2.getId()); } }
public CallContext toCallContext(final UUID accountId, final UUID tenantId) { return new DefaultCallContext(accountId, tenantId, createdBy, callOrigin, contextUserType, reasonCode, comments, userToken, createdDate, updatedDate); }
@Override public CallContext createCallContext(@Nullable final UUID accountId, @Nullable final UUID tenantId, final String userName, final CallOrigin callOrigin, final UserType userType, final String reasonCode, final String comment, final UUID userToken) { return new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, reasonCode, comment, userToken, clock); } }
@Override public AuditLogModelDao map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException { final UUID id = getUUID(r, "id"); final String tableName = r.getString("table_name"); final long targetRecordId = r.getLong("target_record_id"); final String changeType = r.getString("change_type"); final DateTime createdDate = getDateTime(r, "created_date"); final String createdBy = r.getString("created_by"); final String reasonCode = r.getString("reason_code"); final String comments = r.getString("comments"); final UUID userToken = getUUID(r, "user_token"); final EntityAudit entityAudit = new EntityAudit(id, TableName.valueOf(tableName), targetRecordId, ChangeType.valueOf(changeType), createdDate); // TODO - we have the tenant_record_id but not the tenant id here final DefaultCallContext callContext = new DefaultCallContext(null, null, createdBy, createdDate, reasonCode, comments, userToken); return new AuditLogModelDao(entityAudit, callContext); } }
@Test(groups = "fast") public void testEquals() throws Exception { final UUID accountId = UUID.randomUUID(); 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(accountId, tenantId, userName, createdDate, reasonCode, comment, userToken); Assert.assertEquals(callContext, callContext); final DefaultCallContext sameCallContext = new DefaultCallContext(accountId, tenantId, userName, createdDate, reasonCode, comment, userToken); Assert.assertEquals(sameCallContext, callContext); final DefaultCallContext otherCallContext = new DefaultCallContext(accountId, tenantId, UUID.randomUUID().toString(), createdDate, reasonCode, comment, userToken); Assert.assertNotEquals(otherCallContext, callContext); } }
@TimedResource @POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Create a tenant", response = TenantJson.class) @ApiResponses(value = {@ApiResponse(code = 201, message = "Tenant created successfully"), @ApiResponse(code = 409, message = "Tenant already exists")}) public Response createTenant(final TenantJson json, @QueryParam(QUERY_TENANT_USE_GLOBAL_DEFAULT) @DefaultValue("false") 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.createCallContextNoAccountId(createdBy, reason, comment, request)); if (!useGlobalDefault) { final CallContext callContext = new DefaultCallContext(null, tenant.getId(), createdBy, CallOrigin.EXTERNAL, UserType.CUSTOMER, Context.getOrCreateUserToken(), clock); catalogUserApi.createDefaultEmptyCatalog(null, callContext); } return uriBuilder.buildResponse(uriInfo, TenantResource.class, "getTenant", tenant.getId(), request); }
private void setupTenant() throws TenantApiException { final UUID uuid = UUID.randomUUID(); final String externalKey = uuid.toString(); final String apiKey = externalKey + "-Key"; final String apiSecret = externalKey + "-$3cr3t"; // Only place where we use callContext tenant = tenantUserApi.createTenant(new DefaultTenant(uuid, init, init, externalKey, apiKey, apiSecret), callContext); testCallContext = new DefaultCallContext(null, tenant.getId(), "tester", CallOrigin.EXTERNAL, UserType.TEST, "good reason", "trust me", uuid, clock); }
@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 accountId = UUID.randomUUID(); 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 DefaultCallContext callContext = new DefaultCallContext(accountId, 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 DefaultCallContext otherCallContext = new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, userToken, clock); final AuditLogModelDao otherAuditLog = new AuditLogModelDao(entityAudit, otherCallContext); Assert.assertNotEquals(otherAuditLog, auditLog); } }
@Test(groups = "fast") public void testGetters() throws Exception { final UUID accountId = UUID.randomUUID(); 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(accountId, 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()); }
@Test(groups = "fast") public void testGetters() 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 accountId = UUID.randomUUID(); 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 DefaultCallContext callContext = new DefaultCallContext(accountId, tenantId, userName, callOrigin, userType, userToken, clock); final AuditLog auditLog = new DefaultAuditLog(new AuditLogModelDao(entityAudit, callContext), ObjectType.ACCOUNT_EMAIL, UUID.randomUUID()); Assert.assertEquals(auditLog.getChangeType(), changeType); Assert.assertNull(auditLog.getComment()); Assert.assertNotNull(auditLog.getCreatedDate()); Assert.assertNull(auditLog.getReasonCode()); Assert.assertEquals(auditLog.getUserName(), userName); Assert.assertEquals(auditLog.getUserToken(), userToken.toString()); }
@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, null, "loulou", CallOrigin.EXTERNAL, UserType.ADMIN, "no reason", "hum", UUID.randomUUID(), clock); final Tenant tenant = tenantUserApi.createTenant(tenantData, contextWithNoTenant); final CallContext contextWithTenant = new DefaultCallContext(null, 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; } }); }