@Test public void testGetSystemConnection() { Mongo mongo = Mockito.mock(Mongo.class); DB db = Mockito.mock(DB.class); Mockito.when(db.getMongo()).thenReturn(mongo); Mockito.when(db.getName()).thenReturn("System"); Mockito.when(mongo.getDB(Mockito.anyString())).thenReturn(db); TenantAwareMongoDbFactory cm = new TenantAwareMongoDbFactory(mongo, "System"); Assert.assertNotNull(cm.getDb()); Assert.assertSame("System", cm.getDb().getName()); }
@Override public DB getDb() throws DataAccessException { String tenantId = TenantContext.getTenantId(); boolean isSystemCall = TenantContext.isSystemCall(); if (isSystemCall || tenantId == null) { return super.getDb(); } else { return super.getDb(getTenantDatabaseName(tenantId)); } }
TenantAwareMongoDbFactory extends SimpleMongoDbFactory { @Override public DB getDb() throws DataAccessException { String tenantId = TenantContext.getTenantId(); boolean isSystemCall = TenantContext.isSystemCall(); if (isSystemCall || tenantId == null) { return super.getDb(); } else { return super.getDb(getTenantDatabaseName(tenantId)); } } }
TenantAwareMongoDbFactory extends SimpleMongoDbFactory { @Override public DB getDb() throws DataAccessException { String tenantId = TenantContext.getTenantId(); boolean isSystemCall = TenantContext.isSystemCall(); if (isSystemCall || tenantId == null) { return super.getDb(); } else { return super.getDb(getTenantDatabaseName(tenantId)); } } TenantAwareMongoDbFactory(Mongo mongo, String systemDatabaseName); }
TenantAwareMongoDbFactory extends SimpleMongoDbFactory { @Override public DB getDb() throws DataAccessException { String tenantId = TenantContext.getTenantId(); boolean isSystemCall = TenantContext.isSystemCall(); if (isSystemCall || tenantId == null) { return super.getDb(); } else { return super.getDb(getTenantDatabaseName(tenantId)); } } TenantAwareMongoDbFactory(Mongo mongo, String systemDatabaseName); @Override DB getDb(); static String getTenantDatabaseName(String tenantId); }
TenantAwareMongoDbFactory extends SimpleMongoDbFactory { @Override public DB getDb() throws DataAccessException { String tenantId = TenantContext.getTenantId(); boolean isSystemCall = TenantContext.isSystemCall(); if (isSystemCall || tenantId == null) { return super.getDb(); } else { return super.getDb(getTenantDatabaseName(tenantId)); } } TenantAwareMongoDbFactory(Mongo mongo, String systemDatabaseName); @Override DB getDb(); static String getTenantDatabaseName(String tenantId);  }