use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityFormDefaultValueGeneratorTest method testOnlySpecificFormDefinition.
@Test
public void testOnlySpecificFormDefinition() {
// prepare identity
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(getHelper().createName());
// prepare new form definition
IdmFormDefinitionDto formDefinition = createFormDefinition();
// prepare form attribute 1
String attrCode1 = getHelper().createName();
String attrDefaultValue1 = "true";
IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.BOOLEAN, formDefinition.getId());
// prepare form attribute 2
String attrCode2 = getHelper().createName();
String attrDefaultValue2 = "A";
IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.CHAR, formDefinition.getId());
// check eav before
List<IdmFormInstanceDto> eavs = identity.getEavs();
assertTrue(eavs.isEmpty());
// create generator
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityFormDefaultValueGenerator.FORM_DEFINITION_UUID, formDefinition.getId().toString())), 1, null);
// generate and check values after
identity = identityService.save(identity);
eavs = identity.getEavs();
assertFalse(eavs.isEmpty());
// get newly generated eav only for given form definition
IdmFormInstanceDto generatedEav = eavs.stream().filter(eav -> eav.getFormDefinition().getCode().equals(formDefinition.getCode())).findFirst().orElse(null);
assertNotNull(generatedEav);
// check values
List<IdmFormValueDto> values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att1.getId())).collect(Collectors.toList());
assertEquals(1, values.size());
IdmFormValueDto value = values.get(0);
assertEquals(attrDefaultValue1, value.getValue().toString());
values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att2.getId())).collect(Collectors.toList());
assertEquals(1, values.size());
value = values.get(0);
assertEquals(attrDefaultValue2, value.getValue().toString());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityFormDefaultValueGeneratorTest method testRegenerateOn.
@Test
public void testRegenerateOn() {
// prepare identity
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(getHelper().createName());
// prepare new form definition
IdmFormDefinitionDto formDefinition = createFormDefinition();
// prepare form attribute 1
String attrCode1 = getHelper().createName();
String attrDefaultValue1 = UUID.randomUUID().toString();
IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.UUID, formDefinition.getId());
// prepare form attribute 2
String attrCode2 = getHelper().createName();
String attrDefaultValue2 = "100";
IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.INT, formDefinition.getId());
// check eav before
List<IdmFormInstanceDto> eavs = identity.getEavs();
assertTrue(eavs.isEmpty());
// create generator
ValueGeneratorDto generator = getGenerator();
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), null), 1, null);
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
// IdmFormDefinitionDto formDefinition = formDefinitionService.get(formDefinitionId);
formInstance.setFormDefinition(formDefinition);
// create identity with given one EAV
String givenNewValue = UUID.randomUUID().toString();
List<IdmFormValueDto> givenValues = new ArrayList<>();
IdmFormValueDto givenValue = new IdmFormValueDto(att1);
givenValue.setValue(givenNewValue);
givenValues.add(givenValue);
formInstance.setValues(givenValues);
eavs.add(formInstance);
identity.setEavs(eavs);
// generate and check values after
identity = identityService.save(identity);
eavs = identity.getEavs();
assertFalse(eavs.isEmpty());
// get newly generated eav only for given form definition
IdmFormInstanceDto generatedEav = eavs.stream().filter(eav -> eav.getFormDefinition().getCode().equals(formDefinition.getCode())).findFirst().orElse(null);
assertNotNull(generatedEav);
// check values
List<IdmFormValueDto> values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att1.getId())).collect(Collectors.toList());
assertEquals(1, values.size());
IdmFormValueDto value = values.get(0);
assertEquals(attrDefaultValue1, value.getValue().toString());
values = generatedEav.getValues().stream().filter(val -> val.getFormAttribute().equals(att2.getId())).collect(Collectors.toList());
assertEquals(1, values.size());
value = values.get(0);
assertEquals(attrDefaultValue2, value.getValue().toString());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityUsernameGeneratorTest method generateMissingFirstName.
@Test
public void generateMissingFirstName() {
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.setLastName(lastName);
IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
assertEquals(identityDto.getLastName(), generatedDto.getLastName());
assertEquals(identityDto.getUsername(), generatedDto.getUsername());
assertEquals(identityDto.getFirstName(), generatedDto.getFirstName());
assertNull(generatedDto.getUsername());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityUsernameGeneratorTest method generateWithMoreGeneratorAndDisable.
@Test
public void generateWithMoreGeneratorAndDisable() {
String firstName = "firstName" + System.currentTimeMillis();
String lastName = "lastName" + System.currentTimeMillis();
String newFirstName = "f";
String newLastName = "l";
ValueGeneratorDto generator = getGenerator();
// first - this generator will be generate username
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);
// second
IdmGenerateValueDto createGenerator = this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_CHARACTERS_COUNT, "5", IdentityUsernameGenerator.CONNECTING_CHARACTER, "-", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 10, null);
createGenerator.setDisabled(true);
this.generatedAttributeService.save(createGenerator);
// the last
createGenerator = this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.CONNECTING_CHARACTER, ".", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 20, null);
createGenerator.setDisabled(true);
this.generatedAttributeService.save(createGenerator);
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(newFirstName + "*" + newLastName, generatedDto.getUsername());
}
use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.
the class IdentityUsernameGeneratorTest method generateWithMoreGeneratorAndRegenerate.
@Test
public void generateWithMoreGeneratorAndRegenerate() {
String firstName = "firstName" + System.currentTimeMillis();
String lastName = "lastName" + System.currentTimeMillis();
String newFirstName = "first";
ValueGeneratorDto generator = getGenerator();
// first
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, "--")), 1, null);
// second - this generator will be generate username
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_CHARACTERS_COUNT, "5", IdentityUsernameGenerator.CONNECTING_CHARACTER, "-", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 10, null);
// the last
this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.CONNECTING_CHARACTER, ".")), 20, Boolean.FALSE);
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(newFirstName + "-" + lastName.toLowerCase(), generatedDto.getUsername());
}
Aggregations