Search in sources :

Example 46 with ValueGeneratorDto

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

the class IdentityUsernameGeneratorTest method testWhiteSpacesWithCharacter.

@Test
public void testWhiteSpacesWithCharacter() {
    String firstName = "  first Nam   e";
    String lastName = "last Na me ";
    String firtsNameResult = "..first.Nam...e";
    String lastNameResult = "last.Na.me.";
    ValueGeneratorDto generator = getGenerator();
    this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.FALSE.toString(), IdentityUsernameGenerator.REPLACE_WHITE_SPACES_CHARACTER, ".")), 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(lastNameResult.toLowerCase() + firtsNameResult.toLowerCase(), 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 47 with ValueGeneratorDto

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

the class IdentityUsernameGeneratorTest method generateShorterPropertiesWithEmptyString.

@Test
public void generateShorterPropertiesWithEmptyString() {
    String firstName = "firstName";
    String lastName = "lastName";
    ValueGeneratorDto generator = getGenerator();
    this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_CHARACTERS_COUNT, "", IdentityUsernameGenerator.LAST_NAME_CHARACTERS_COUNT, "", 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());
}
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 48 with ValueGeneratorDto

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

the class IdentityUsernameGeneratorTest method generateWithMoreGenerator.

@Test
public void generateWithMoreGenerator() {
    String firstName = "firstName" + System.currentTimeMillis();
    String lastName = "lastName" + System.currentTimeMillis();
    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.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.FIRST_NAME_CHARACTERS_COUNT, "5", IdentityUsernameGenerator.CONNECTING_CHARACTER, "-")), 10, null);
    // the last - this generator will be generate username
    this.createGenerator(getDtoType(), getGeneratorType(), this.createConfiguration(generator.getFormDefinition(), ImmutableMap.of(IdentityUsernameGenerator.CONNECTING_CHARACTER, ".", IdentityUsernameGenerator.FIRST_NAME_FIRST, Boolean.TRUE.toString())), 20, 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());
}
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 49 with ValueGeneratorDto

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

the class IdentityAnonymousUsernameGeneratorTest method generateNumberOfIdentities.

/**
 * This test generates defined number of identities with generated username.
 * It can be parameterized with genPartLen specifying the length of numeric part and
 * generatedIndentitiesNum saying number of generated users during test. Both has to conform formula
 * generatedIndentitiesNum <= 10^genPartLen (it's power not xor).
 */
@Test
public // @Ignore
void generateNumberOfIdentities() {
    int genPartLen = 2;
    int generatedIndentitiesNum = 100;
    String prefix = getHelper().createName() + "_";
    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);
        // System.out.println(String.valueOf(i)+" - generated: " + generatedDto.getUsername());
        } catch (ResultCodeException ex) {
        // we don't care solved in following Asserts
        }
    }
    IdmIdentityFilter identFilt = new IdmIdentityFilter();
    identFilt.setText(prefix);
    List<IdmIdentityDto> results = identityService.find(identFilt, null).getContent();
    // at least 99% has to be found
    Assert.assertTrue(0.99 * generatedIndentitiesNum < results.size());
    Set<String> usernameSet = results.stream().map(IdmIdentityDto::getUsername).collect(Collectors.toSet());
    Assert.assertEquals(results.size(), usernameSet.size());
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Example 50 with ValueGeneratorDto

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

the class IdentityAnonymousUsernameGeneratorTest method numericPartLengthMatterTest.

/*
	 * Tests that length of numbers matter. It means 07 is not same as 7
	 */
@Test
public void numericPartLengthMatterTest() {
    // existing users
    List<String> existingUsers = Arrays.asList("testUserXXX0", "testUserXXX1", "testUserXXX2", "testUserXXX3", "testUserXXX4", "testUserXXX5", "testUserXXX6", /*"testUserXXX7"*/
    "testUserXXX8", "testUserXXX9", "testUserXXX07");
    existingUsers.forEach(user -> {
        identityService.save(new IdmIdentityDto(user));
    });
    int genPartLen = 1;
    String prefix = "testUserXXX";
    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("testUserXXX7", identityDto.getUsername());
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) 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