use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityAnonymousUsernameGeneratorTest method find3AvailableUsernameOutOf100.
/**
* Test that generator is able to find remaining unused numbers
*/
@Test
public // @Ignore
void find3AvailableUsernameOutOf100() {
int genPartLen = 2;
int genPartMax = IdentityAnonymousUsernameGenerator.calcMaxValueForLen(genPartLen);
String prefix = "test_";
// init existing users
Set<Integer> excluded = new HashSet<Integer>();
excluded.add(15);
excluded.add(50);
excluded.add(95);
generateTestUsers(prefix, genPartMax, genPartLen, excluded);
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityAnonymousUsernameGenerator.USERNAME_PREFIX, prefix, IdentityAnonymousUsernameGenerator.GENERATED_NUMBER_LENGTH, String.valueOf(genPartLen))), 1, Boolean.FALSE);
for (int i = 0; i < excluded.size(); i++) {
IdmIdentityDto identityDto = new IdmIdentityDto();
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
identityService.save(generatedDto);
}
for (Integer val : excluded) {
IdmIdentityFilter identFilt = new IdmIdentityFilter();
identFilt.setUsername(IdentityAnonymousUsernameGenerator.createUsername(prefix, val, genPartLen));
List<IdmIdentityDto> results = identityService.find(identFilt, null).getContent();
Assert.assertEquals(1, results.size());
}
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityAnonymousUsernameGeneratorTest method numericPrefixWorksTest.
/**
* Numerical prefix works too
*/
@Test
public void numericPrefixWorksTest() {
int genPartLen = 1;
String prefix = "999";
// existing users
for (int i = 0; i < 10; ++i) {
if (i != 7) {
identityService.save(new IdmIdentityDto(prefix + i));
}
}
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityAnonymousUsernameGenerator.USERNAME_PREFIX, prefix, IdentityAnonymousUsernameGenerator.GENERATED_NUMBER_LENGTH, String.valueOf(genPartLen))), 1, Boolean.FALSE);
IdmIdentityDto identityDto = new IdmIdentityDto();
try {
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
identityDto = identityService.save(generatedDto);
} catch (ResultCodeException ex) {
fail();
}
Assert.assertEquals(prefix + "7", identityDto.getUsername());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityAnonymousUsernameGeneratorTest method potentiallyProblematicPrefixCharsTest.
/**
* Characters which could make troubles in used regex
*/
@Test
public void potentiallyProblematicPrefixCharsTest() {
int genPartLen = 1;
String prefix = "~!@#$%^&*()_+_)*&^%$#@!~";
// existing users
for (int i = 0; i < 10; ++i) {
if (i != 7) {
identityService.save(new IdmIdentityDto(prefix + i));
}
}
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityAnonymousUsernameGenerator.USERNAME_PREFIX, prefix, IdentityAnonymousUsernameGenerator.GENERATED_NUMBER_LENGTH, String.valueOf(genPartLen))), 1, Boolean.FALSE);
IdmIdentityDto identityDto = new IdmIdentityDto();
try {
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
identityDto = identityService.save(generatedDto);
} catch (ResultCodeException ex) {
fail();
}
Assert.assertEquals(prefix + "7", identityDto.getUsername());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityEmailGeneratorIntegrationTest method testWithoutUsername.
@Test
public void testWithoutUsername() {
String emailSuffix = "@example.tld";
IdmIdentityDto identityDto = new IdmIdentityDto();
identityDto.setFirstName(this.getHelper().createName());
identityDto.setLastName(this.getHelper().createName());
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityEmailGenerator.EMAIL_SUFFIX, emailSuffix, IdentityEmailGenerator.GENERATE_FROM_USERNAME, Boolean.TRUE.toString())), 1, null);
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
assertNull(generatedDto.getEmail());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityEmailGeneratorIntegrationTest method testRegenerate.
@Test
public void testRegenerate() {
String emailSuffix = "ex.tld";
String emailSuffix1 = "@test.tld";
String emailSuffix2 = "bcvsolutions.tld";
String username = this.getHelper().createName();
String email = "email@example.tdl";
IdmIdentityDto identityDto = new IdmIdentityDto();
identityDto.setFirstName(this.getHelper().createName());
identityDto.setLastName(this.getHelper().createName());
identityDto.setUsername(username);
identityDto.setEmail(email);
ValueGeneratorDto generator = getGenerator();
// first
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityEmailGenerator.EMAIL_SUFFIX, emailSuffix, IdentityEmailGenerator.GENERATE_FROM_USERNAME, Boolean.TRUE.toString())), 10, Boolean.FALSE);
// second
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityEmailGenerator.EMAIL_SUFFIX, emailSuffix1, IdentityEmailGenerator.GENERATE_FROM_USERNAME, Boolean.TRUE.toString())), 20, Boolean.FALSE);
// the last
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityEmailGenerator.EMAIL_SUFFIX, emailSuffix2, IdentityEmailGenerator.GENERATE_FROM_USERNAME, Boolean.TRUE.toString())), 30, Boolean.FALSE);
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
assertNotNull(generatedDto.getEmail());
assertEquals(email, generatedDto.getEmail());
}
Aggregations