Search in sources :

Example 11 with IdmFormValueDto

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

the class IdentityReportExecutorIntegrationTest method testDisabledIdentity.

@Test
@Transactional
public void testDisabledIdentity() throws IOException {
    // prepare test identities
    IdmIdentityDto identityOne = helper.createIdentity();
    IdmIdentityDto identityDisabled = helper.createIdentity();
    identityService.disable(identityDisabled.getId());
    // 
    // prepare report filter
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    IdmFormValueDto disabled = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentityFilter.PARAMETER_DISABLED));
    disabled.setValue(false);
    filter.getValues().add(disabled);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    // 
    // generate report
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<IdmIdentityDto> identityRoles = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<IdmIdentityDto>>() {
    });
    // 
    // test
    Assert.assertTrue(identityRoles.stream().anyMatch(i -> i.equals(identityOne)));
    Assert.assertFalse(identityRoles.stream().anyMatch(i -> i.equals(identityDisabled)));
    // 
    attachmentManager.deleteAttachments(report);
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) After(org.junit.After) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Qualifier(org.springframework.beans.factory.annotation.Qualifier) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) Before(org.junit.Before) InitTestData(eu.bcvsolutions.idm.InitTestData) IdentityReportXlsxRenderer(eu.bcvsolutions.idm.rpt.renderer.IdentityReportXlsxRenderer) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) Transactional(org.springframework.transaction.annotation.Transactional) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with IdmFormValueDto

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

the class DefaultRptReportManagerIntegrationTest method testGenerateReportWithFilter.

@Test
public void testGenerateReportWithFilter() throws IOException {
    RptReportDto report = new RptReportDto();
    report.setExecutorName(TestFilterReportExecutor.REPORT_NAME);
    IdmFormDto filter = new IdmFormDto();
    TestFilterReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestFilterReportExecutor.class);
    IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
    IdmFormValueDto username = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentity_.username.getName()));
    username.setValue(TestReportExecutor.identities.get(0).getUsername());
    filter.getValues().add(username);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    // 
    report = manager.generate(report);
    final UUID reportId = report.getId();
    Assert.assertNotNull(reportId);
    helper.waitForResult(res -> {
        return OperationState.isRunnable(reportService.get(reportId).getResult().getState());
    });
    Assert.assertNotNull(report.getData());
    Assert.assertEquals(mapper.writeValueAsString(Lists.newArrayList(TestReportExecutor.identities.get(0))), IOUtils.toString(attachmentManager.getAttachmentData(report.getData())));
    attachmentManager.deleteAttachments(report);
}
Also used : IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with IdmFormValueDto

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

the class DefaultIdmIdentityServiceIntegrationTest method testReferentialIntegrity.

@Test
public void testReferentialIntegrity() {
    IdmIdentityDto identity = helper.createIdentity();
    String username = identity.getUsername();
    // eav
    IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
    IdmFormValueDto value1 = new IdmFormValueDto(formDefinition.getMappedAttributeByCode(InitDemoData.FORM_ATTRIBUTE_PASSWORD));
    value1.setValue("one");
    formService.saveValues(identity.getId(), IdmIdentity.class, formDefinition, Lists.newArrayList(value1));
    // role with guarantee
    IdmRoleDto role = new IdmRoleDto();
    String roleName = "test_r_" + System.currentTimeMillis();
    role.setName(roleName);
    IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
    roleGuarantee.setRole(role.getId());
    roleGuarantee.setGuarantee(identity.getId());
    role.setGuarantees(Lists.newArrayList(roleGuarantee));
    role = roleService.save(role);
    // contract
    IdmIdentityContractDto contract = helper.createIdentityContact(identity);
    // contract guarantee
    IdmIdentityContractDto contract2 = helper.createIdentityContact(identityService.getByUsername(InitTestData.TEST_USER_1));
    contractGuaranteeService.save(new IdmContractGuaranteeDto(contract2.getId(), identity.getId()));
    // assigned role
    helper.createIdentityRole(contract, role);
    IdmIdentityRoleFilter identityRolefilter = new IdmIdentityRoleFilter();
    identityRolefilter.setIdentityId(identity.getId());
    assertEquals(1, role.getGuarantees().size());
    assertNotNull(identityService.getByUsername(username));
    assertNotNull(passwordService.findOneByIdentity(identity.getId()));
    assertEquals(1, formService.getValues(identity).size());
    assertEquals(username, roleGuaranteeRepository.findAllByRole_Id(role.getId()).get(0).getGuarantee().getUsername());
    assertEquals(1, identityRoleService.find(identityRolefilter, null).getTotalElements());
    // + default contract is created
    assertEquals(2, identityContractService.findAllByIdentity(identity.getId()).size());
    IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
    filter.setIdentityContractId(contract2.getId());
    List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
    assertEquals(1, guarantees.size());
    assertEquals(identity.getId(), guarantees.get(0).getGuarantee());
    // 
    identityService.delete(identity);
    role = roleService.get(role.getId());
    // 
    assertEquals(0, role.getGuarantees().size());
    assertNull(identityService.getByUsername(username));
    assertNull(passwordService.findOneByIdentity(identity.getId()));
    assertEquals(0, identityContractService.findAllByIdentity(identity.getId()).size());
    assertEquals(0, identityRoleService.find(identityRolefilter, null).getTotalElements());
    assertEquals(0, contractGuaranteeService.find(filter, null).getTotalElements());
// TODO: transactions?
// assertEquals(0, roleGuaranteeRepository.findAllByRole_Id(role.getId()).size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 14 with IdmFormValueDto

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

the class AbstractFormValueUnitTest method testDateValueAsLong.

@Test
public void testDateValueAsLong() {
    IdmFormValueDto formValue = new IdmFormValueDto();
    formValue.setPersistentType(PersistentType.DATETIME);
    DateTime current = new DateTime();
    formValue.setValue(current.toDate().getTime());
    assertEquals(current, formValue.getValue());
}
Also used : IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) DateTime(org.joda.time.DateTime) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 15 with IdmFormValueDto

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

the class AbstractFormValueUnitTest method uuidAsString.

@Test
public void uuidAsString() {
    IdmFormValueDto formValue = new IdmFormValueDto();
    formValue.setPersistentType(PersistentType.UUID);
    UUID uuid = UUID.randomUUID();
    formValue.setValue(uuid.toString());
    assertEquals(uuid, formValue.getValue());
}
Also used : IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) UUID(java.util.UUID) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Aggregations

IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)39 Test (org.junit.Test)24 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)23 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)19 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)13 FormableEntity (eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)12 Transactional (org.springframework.transaction.annotation.Transactional)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 UUID (java.util.UUID)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)8 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)6 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)6 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 SysConnectorKeyDto (eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto)3 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)3 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)3