use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityUsernameGeneratorTest method generateDurignSaveIdentity.
@Test
public void generateDurignSaveIdentity() {
String firstName = "firstName" + System.currentTimeMillis();
String lastName = "lastName" + System.currentTimeMillis();
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 1, null);
IdmIdentityDto identityDto = new IdmIdentityDto();
identityDto.setFirstName(firstName.toString());
identityDto.setLastName(lastName.toString());
IdmIdentityDto generatedDto = identityService.save(identityDto);
assertEquals(identityDto.getLastName(), generatedDto.getLastName());
assertEquals(identityDto.getFirstName(), generatedDto.getFirstName());
assertNotNull(generatedDto.getUsername());
assertEquals(firstName.toLowerCase() + lastName.toLowerCase(), generatedDto.getUsername());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityUsernameGeneratorTest method generateShorterProperties2.
@Test
public void generateShorterProperties2() {
String firstName = "firstName" + System.currentTimeMillis();
String lastName = "lastName" + System.currentTimeMillis();
String newFirstName = "f";
String newLastName = "l";
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_CHARACTERS_COUNT, "1", IdentityUsernameGenerator.LAST_NAME_CHARACTERS_COUNT, "1", IdentityUsernameGenerator.CONNECTING_CHARACTER, "--", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 1, null);
IdmIdentityDto identityDto = new IdmIdentityDto();
identityDto.setFirstName(firstName);
identityDto.setLastName(lastName);
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
assertEquals(identityDto.getLastName(), generatedDto.getLastName());
assertEquals(identityDto.getFirstName(), generatedDto.getFirstName());
assertNotNull(generatedDto.getUsername());
assertEquals(newFirstName + "--" + newLastName, generatedDto.getUsername());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityUsernameGeneratorTest method generateGreenLine.
@Test
public void generateGreenLine() {
String firstName = "firstName-" + System.currentTimeMillis();
String lastName = "lastName-" + System.currentTimeMillis();
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 1, null);
IdmIdentityDto identityDto = new IdmIdentityDto();
identityDto.setFirstName(firstName);
identityDto.setLastName(lastName);
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
assertEquals(identityDto.getLastName(), generatedDto.getLastName());
assertEquals(identityDto.getFirstName(), generatedDto.getFirstName());
assertNotNull(generatedDto.getUsername());
assertEquals(firstName.toLowerCase() + lastName.toLowerCase(), generatedDto.getUsername());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityAnonymousUsernameGeneratorTest method generateUsernameWithoutPrefix.
/**
* Test that generator is able to cope with the situation when no prefix is used
*/
@Test
public // @Ignore
void generateUsernameWithoutPrefix() {
// existing users
List<String> existingUsers = Arrays.asList("testUserXXX01", "testUserXXX02", "testUserXXX03", "00", "01", /*"2",*/
"03", "04", "05", "06", /*"7",*/
"08", "09");
existingUsers.forEach(user -> {
identityService.save(new IdmIdentityDto(user));
});
int genPartLen = 2;
String prefix = "";
int generatedIndentitiesNum = 100;
int unavailableIndexCount = 0;
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 < generatedIndentitiesNum; i++) {
IdmIdentityDto identityDto = new IdmIdentityDto();
try {
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
identityService.save(generatedDto);
} catch (ResultCodeException ex) {
unavailableIndexCount++;
}
}
List<IdmIdentityDto> dtos = identityService.find(null).getContent();
Set<String> relevantDtos = dtos.stream().map(IdmIdentityDto::getUsername).filter(IdentityAnonymousUsernameGenerator.usernameFilterFactory(prefix, genPartLen)).collect(Collectors.toSet());
Assert.assertEquals(generatedIndentitiesNum, relevantDtos.size());
Assert.assertEquals(8, unavailableIndexCount);
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class AbstractGeneratorTest method createConfiguration.
/**
* Create configuration for generator with given values
*
* @param values
* @return
*/
protected ConfigurationMap createConfiguration(ImmutableMap<String, String> values) {
ValueGeneratorDto generator = getGenerator();
IdmFormDefinitionDto formDefinition = generator.getFormDefinition();
return this.createConfiguration(formDefinition, values);
}
Aggregations