Search in sources :

Example 51 with ValueGeneratorDto

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());
    }
}
Also used : ValueGeneratorDto(eu.bcvsolutions.idm.core.api.dto.ValueGeneratorDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractGeneratorTest(eu.bcvsolutions.idm.core.api.generator.AbstractGeneratorTest)

Example 52 with ValueGeneratorDto

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());
}
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)

Example 53 with ValueGeneratorDto

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());
}
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)

Example 54 with ValueGeneratorDto

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());
}
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 55 with ValueGeneratorDto

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());
}
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)

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