Search in sources :

Example 36 with ValueGeneratorDto

use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.

the class IdentityUsernameGeneratorTest method generateDiacriticAndUpper.

@Test
public void generateDiacriticAndUpper() {
    String firstName = "áčďéěžšǍÁ";
    String lastName = "óÉČŘčř-";
    String newFirstName = "acdeezsaa";
    String newLastName = "oecrcr-";
    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(newFirstName + newLastName, generatedDto.getUsername());
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Example 37 with ValueGeneratorDto

use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.

the class IdentityScriptValueGeneratorTest method testScriptReturnTreeNode.

@Test(expected = ResultCodeException.class)
public void testScriptReturnTreeNode() {
    IdmScriptDto script = createScript("");
    script.setScript("import " + IdmTreeNodeDto.class.getCanonicalName() + "; " + System.lineSeparator() + "return new IdmTreeNode();");
    scriptService.save(script);
    String username = this.getHelper().createName();
    IdmIdentityDto identityDto = new IdmIdentityDto();
    identityDto.setFirstName(this.getHelper().createName());
    identityDto.setLastName(this.getHelper().createName());
    identityDto.setUsername(username);
    ValueGeneratorDto generator = getGenerator();
    this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityScriptValueGenerator.SCRIPT_CODE, script.getCode())), 1, null);
    identityService.save(identityDto);
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Example 38 with ValueGeneratorDto

use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.

the class IdentityScriptValueGeneratorTest method testGreenLine.

@Test
public void testGreenLine() {
    IdmScriptDto script = createScript("import " + StringUtils.class.getCanonicalName() + ";" + System.lineSeparator() + "if (!valueGenerator.isRegenerateValue() && StringUtils.isNotEmpty(entity.getDescription())) {" + System.lineSeparator() + "	return entity;" + System.lineSeparator() + "}" + System.lineSeparator() + "" + System.lineSeparator() + "entity.setDescription(entity.getUsername() + 123);" + System.lineSeparator());
    String username = this.getHelper().createName();
    IdmIdentityDto identityDto = new IdmIdentityDto();
    identityDto.setFirstName(this.getHelper().createName());
    identityDto.setLastName(this.getHelper().createName());
    identityDto.setUsername(username);
    ValueGeneratorDto generator = getGenerator();
    this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityScriptValueGenerator.SCRIPT_CODE, script.getCode())), 1, null);
    IdmIdentityDto generatedDto = valueGeneratorManager.generate(identityDto);
    assertNotNull(generatedDto.getDescription());
    assertEquals(username + 123, generatedDto.getDescription());
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Example 39 with ValueGeneratorDto

use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.

the class IdentityScriptValueGeneratorTest method testGreenLineWithSave.

@Test
public void testGreenLineWithSave() {
    IdmScriptDto script = createScript("import " + StringUtils.class.getCanonicalName() + ";" + System.lineSeparator() + "if (!valueGenerator.isRegenerateValue() && StringUtils.isNotEmpty(entity.getDescription())) {" + System.lineSeparator() + "	return entity;" + System.lineSeparator() + "}" + System.lineSeparator() + "" + System.lineSeparator() + "entity.setDescription(entity.getUsername() + 666);" + System.lineSeparator());
    String username = this.getHelper().createName();
    IdmIdentityDto identityDto = new IdmIdentityDto();
    identityDto.setFirstName(this.getHelper().createName());
    identityDto.setLastName(this.getHelper().createName());
    identityDto.setUsername(username);
    ValueGeneratorDto generator = getGenerator();
    this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityScriptValueGenerator.SCRIPT_CODE, script.getCode())), 1, null);
    IdmIdentityDto generatedDto = identityService.save(identityDto);
    assertNotNull(generatedDto.getDescription());
    assertEquals(username + 666, generatedDto.getDescription());
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Example 40 with ValueGeneratorDto

use of eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto in project CzechIdMng by bcvsolutions.

the class IdentityFormDefaultValueGeneratorTest method testGreenLine.

@Test
public void testGreenLine() {
    // 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 = "100200";
    IdmFormAttributeDto att1 = createAttribute(attrCode1, attrDefaultValue1, PersistentType.LONG, formDefinition.getId());
    // prepare form attribute 2
    String attrCode2 = getHelper().createName();
    String attrDefaultValue2 = getHelper().createName() + getHelper().createName();
    IdmFormAttributeDto att2 = createAttribute(attrCode2, attrDefaultValue2, PersistentType.SHORTTEXT, 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);
    // generate and check values after
    identity = this.valueGeneratorManager.generate(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());
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) After(org.junit.After) IdmFormAttributeService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmFormDefinitionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService) Assert.assertFalse(org.junit.Assert.assertFalse) IdentityFormDefaultValueGenerator(eu.bcvsolutions.idm.core.generator.identity.IdentityFormDefaultValueGenerator) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert.assertEquals(org.junit.Assert.assertEquals) ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Aggregations

ValueGeneratorDto (eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto)59 AbstractGeneratorTest (eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)56 Test (org.junit.Test)56 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)54 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)9 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 IdmCacheManager (eu.bcvsolutions.idm.core.api.service.IdmCacheManager)7 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)7 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)7 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)7 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)7 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)7 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)7 IdmFormAttributeService (eu.bcvsolutions.idm.core.eav.api.service.IdmFormAttributeService)7 IdmFormDefinitionService (eu.bcvsolutions.idm.core.eav.api.service.IdmFormDefinitionService)7 IdentityFormDefaultValueGenerator (eu.bcvsolutions.idm.core.generator.identity.IdentityFormDefaultValueGenerator)7 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7