private void removeAllEndpointUsers() { List<EndpointUserDto> endpointUsers = endpointService.findAllEndpointUsers(); for (EndpointUserDto endpointUser : endpointUsers) { endpointService.removeEndpointUserById(endpointUser.getId()); } }
/** * Create new instance of <code>MongoEndpointUser</code>. * @param dto data transfer object contain data that * assign on fields of new instance */ public MongoEndpointUser(EndpointUserDto dto) { this.id = dto.getId(); this.username = dto.getUsername(); this.externalId = dto.getExternalId(); this.tenantId = dto.getTenantId(); this.accessToken = dto.getAccessToken(); this.endpointIds = dto.getEndpointIds(); this.version = dto.getVersion(); }
/** * Create new instance of <code>CassandraEndpointUser</code>. * * @param dto data transfer object contain data that * assign on fields of new instance */ public CassandraEndpointUser(EndpointUserDto dto) { this.id = dto.getId(); this.username = dto.getUsername(); this.externalId = dto.getExternalId(); this.tenantId = dto.getTenantId(); this.accessToken = dto.getAccessToken(); this.endpointIds = dto.getEndpointIds(); this.version = dto.getVersion(); }
@Test public void removeEndpointUserByIdTest() { TenantDto tenantDto = generateTenantDto(); EndpointUserDto savedEndpointUserDto = generateEndpointUserDto(tenantDto.getId()); endpointService.removeEndpointUserById(savedEndpointUserDto.getId()); EndpointUserDto endpointUser = endpointService.findEndpointUserById(savedEndpointUserDto.getId()); Assert.assertNull(endpointUser); }
@Test public void testFindByEndpointUserId() throws Exception { EndpointProfileDto endpointProfileDto = generateEndpointProfile(null, null, null, null); EndpointUserDto endpointUserDto = generateEndpointUser(Arrays.asList(endpointProfileDto.getId())); List<CassandraEndpointProfile> found = endpointProfileDao.findByEndpointUserId(endpointUserDto.getId()); Assert.assertFalse(found.isEmpty()); Assert.assertEquals(endpointProfileDto, found.get(0).toDto()); }
@Test public void findUserConfigurationByUserIdTest() throws IOException { EndpointUserDto userDto = generateEndpointUserDto(null); ApplicationDto appDto = generateApplicationDto(); EndpointUserConfigurationDto firstUserConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); EndpointUserConfigurationDto secondUserConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); List<EndpointUserConfigurationDto> expectedList = new ArrayList<>(); expectedList.add(firstUserConfigurationDto); expectedList.add(secondUserConfigurationDto); generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); List<EndpointUserConfigurationDto> foundList = userConfigurationService.findUserConfigurationByUserId(userDto.getId()); Assert.assertEquals(expectedList.size(), foundList.size()); }
@Test public void testSave() throws Exception { EndpointUserDto expected = generateEndpointUser(); CassandraEndpointUser found = endpointUserDao.findById(expected.getId()); Assert.assertEquals(expected, found.toDto()); }
@Test public void removeByUserIdAndAppTokenAndSchemaVersionTest() throws IOException { EndpointUserDto userDto = generateEndpointUserDto(null); ApplicationDto appDto = generateApplicationDto(); ConfigurationSchemaDto schema = generateConfSchemaDto(null, appDto.getId(), 1).get(0); generateEndpointUserConfigurationDto(userDto, appDto, schema, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); userConfigurationService.removeByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), schema.getVersion()); EndpointUserConfigurationDto removed = userConfigurationService.findUserConfigurationByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), schema.getVersion()); Assert.assertNull(removed); List<EndpointUserConfigurationDto> foundList = userConfigurationService.findUserConfigurationByUserId(userDto.getId()); Assert.assertEquals(2, foundList.size()); }
@Test public void saveEndpointUserTest() { TenantDto tenantDto = generateTenantDto(); EndpointUserDto savedEndpointUserDto = generateEndpointUserDto(tenantDto.getId()); EndpointUserDto endpointUser = endpointService.findEndpointUserById(savedEndpointUserDto.getId()); Assert.assertEquals(savedEndpointUserDto, endpointUser); }
@Test public void findEndpointUserByIdTest() { TenantDto tenantDto = generateTenantDto(); EndpointUserDto savedEndpointUserDto = generateEndpointUserDto(tenantDto.getId()); EndpointUserDto endpointUser = endpointService.findEndpointUserById(savedEndpointUserDto.getId()); Assert.assertEquals(savedEndpointUserDto, endpointUser); }
@Test public void removeByExternalIdTest() { TenantDto tenant = generateTenantDto(); EndpointUserDto dto = generateEndpointUserDto(tenant.getId()); Assert.assertNotNull(dto); MongoEndpointUser found = endpointUserDao.findById(dto.getId()); Assert.assertNotNull(found); endpointUserDao.removeByExternalIdAndTenantId(found.getExternalId(), found.getTenantId()); found = endpointUserDao.findById(dto.getId()); Assert.assertNull(found); }
@Test public void findByExternalIdTest() { TenantDto tenant = generateTenantDto(); EndpointUserDto dto = generateEndpointUserDto(tenant.getId()); Assert.assertNotNull(dto); MongoEndpointUser foundUser = endpointUserDao.findById(dto.getId()); Assert.assertNotNull(foundUser); MongoEndpointUser found = endpointUserDao.findByExternalIdAndTenantId(foundUser.getExternalId(), foundUser.getTenantId().toString()); Assert.assertEquals(foundUser, found); }
@Test public void findById() { TenantDto tenant = generateTenantDto(); EndpointUserDto dto = generateEndpointUserDto(tenant.getId()); MongoEndpointUser user = endpointUserDao.findById(dto.getId()); Assert.assertNotNull(user); Assert.assertEquals(dto, user.toDto()); }
@Test public void generateAccessTokenTest() { TenantDto tenant = generateTenantDto(); EndpointUserDto dto = generateEndpointUserDto(tenant.getId()); Assert.assertNotNull(dto); String accessToken = endpointUserDao.generateAccessToken(dto.getExternalId(), dto.getTenantId().toString()); MongoEndpointUser found = endpointUserDao.findById(dto.getId()); Assert.assertEquals(accessToken, found.getAccessToken()); Assert.assertTrue(endpointUserDao.checkAccessToken(found.getExternalId(), found.getTenantId().toString(), accessToken)); Assert.assertFalse(endpointUserDao.checkAccessToken(found.getTenantId().toString(), found.getExternalId(), "invalid")); }
@Test public void convertToDtoTest() { TenantDto tenant = generateTenantDto(); EndpointUserDto dto = generateEndpointUserDto(tenant.getId()); Assert.assertNotNull(dto); MongoEndpointUser user = endpointUserDao.findById(dto.getId()); Assert.assertNotNull(user); dto = user.toDto(); MongoEndpointUser converted = new MongoEndpointUser(dto); Assert.assertEquals(user, converted); } }
@Test public void findUserConfigurationByUserIdAndAppTokenAndSchemaVersionTest() throws IOException { EndpointUserDto userDto = generateEndpointUserDto(null); ApplicationDto appDto = generateApplicationDto(); ConfigurationSchemaDto schema = generateConfSchemaDto(null, appDto.getId(), 1).get(0); EndpointUserConfigurationDto firstUserConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, schema, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); EndpointUserConfigurationDto found = userConfigurationService.findUserConfigurationByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), schema.getVersion()); Assert.assertEquals(firstUserConfigurationDto, found); }
@Test public void removeById() { TenantDto tenant = generateTenantDto(); EndpointUserDto dto = generateEndpointUserDto(tenant.getId()); MongoEndpointUser user = endpointUserDao.findById(dto.getId()); Assert.assertNotNull(user); endpointUserDao.removeById(user.getId()); user = endpointUserDao.findById(user.getId()); Assert.assertNull(user); }
@Test public void findByUserIdAndAppTokenAndSchemaVersionTest() throws IOException { EndpointUserDto userDto = generateEndpointUserDto(null); ApplicationDto appDto = generateApplicationDto(); ConfigurationSchemaDto schema = generateConfSchemaDto(null, appDto.getId(), 1).get(0); EndpointUserConfigurationDto firstUserConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, schema, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); generateEndpointUserConfigurationDto(null, null, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); MongoEndpointUserConfiguration found = endpointUserConfigurationDao.findByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), schema.getVersion()); Assert.assertEquals(firstUserConfigurationDto, found.toDto()); }
@Test public void generateEndpointUserAccessTokenTest() { TenantDto tenantDto = generateTenantDto(); EndpointUserDto savedEndpointUserDto = generateEndpointUserDto(tenantDto.getId()); Assert.assertNull(savedEndpointUserDto.getAccessToken()); String generatedAccessToken = endpointService.generateEndpointUserAccessToken(savedEndpointUserDto.getExternalId(), savedEndpointUserDto.getTenantId()); EndpointUserDto endpointUser = endpointService.findEndpointUserById(savedEndpointUserDto.getId()); Assert.assertNotNull(generatedAccessToken); Assert.assertEquals(generatedAccessToken, endpointUser.getAccessToken()); }
@Test public void findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersionNullTest() throws IOException { ApplicationDto appDto = generateApplicationDto(); EndpointUserDto userDto = generateEndpointUserDto(appDto.getTenantId()); EndpointUserConfigurationDto userConfigurationDto = generateEndpointUserConfigurationDto(userDto, appDto, null, readSchemaFileAsString(OVERRIDE_USER_DATA_JSON)); userConfigurationService.removeByUserIdAndAppTokenAndSchemaVersion(userDto.getId(), appDto.getApplicationToken(), userConfigurationDto.getSchemaVersion()); EndpointUserConfigurationDto endpointUserConfigurationDto = userConfigurationService.findUserConfigurationByExternalUIdAndAppTokenAndSchemaVersion( userDto.getExternalId(), appDto.getApplicationToken(), userConfigurationDto.getSchemaVersion(), appDto.getTenantId()); Assert.assertNull(endpointUserConfigurationDto); }