Search in sources :

Example 6 with IdmIdentityProjectionDto

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

the class DefaultIdentityProjectionManagerIntegrationTest method testValidateBasicFields.

@Test
@Transactional
public void testValidateBasicFields() throws Exception {
    // prepare projection
    IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
    formProjection.setCode(getHelper().createName());
    formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
    formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
    IdmFormAttributeDto attributeExternalCode = new IdmFormAttributeDto();
    attributeExternalCode.setId(UUID.randomUUID());
    attributeExternalCode.setCode(IdmIdentity_.externalCode.getName());
    attributeExternalCode.setName(String.format("%s.%s", IdmIdentity.class.getSimpleName(), IdmIdentity_.externalCode.getName()));
    attributeExternalCode.setRequired(true);
    IdmFormAttributeDto attributeLastName = new IdmFormAttributeDto();
    attributeLastName.setId(UUID.randomUUID());
    attributeLastName.setCode(IdmIdentity_.lastName.getName());
    attributeLastName.setMax(BigDecimal.valueOf(3));
    IdmFormAttributeDto attributeValidTill = new IdmFormAttributeDto();
    attributeValidTill.setId(UUID.randomUUID());
    attributeValidTill.setCode(IdmIdentityContract_.validTill.getName());
    attributeValidTill.setName(String.format("%s.%s", IdmIdentityContract.class.getSimpleName(), IdmIdentityContract_.validTill.getName()));
    attributeValidTill.setRequired(true);
    attributeValidTill.setMax(BigDecimal.valueOf(3));
    IdmFormAttributeDto attributeWorkPosition = new IdmFormAttributeDto();
    attributeWorkPosition.setId(UUID.randomUUID());
    attributeWorkPosition.setCode(IdmIdentityContract_.workPosition.getName());
    attributeWorkPosition.setName(String.format("%s.%s", IdmIdentityContract.class.getSimpleName(), IdmIdentityContract_.workPosition.getName()));
    attributeWorkPosition.setRequired(true);
    formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attributeExternalCode, attributeLastName, attributeValidTill, attributeWorkPosition)));
    formProjection = projectionService.save(formProjection);
    // 
    // create identity with projection is defined
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    identity.setExternalCode(getHelper().createName());
    identity.setLastName("xxx");
    identity.setFormProjection(formProjection.getId());
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    // 
    // set contract
    IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
    primeContract.setMain(true);
    primeContract.setWorkPosition(getHelper().createTreeNode().getId());
    primeContract.setPosition(getHelper().createName());
    primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
    primeContract.setValidTill(LocalDate.now().plus(3l, ChronoUnit.DAYS));
    projection.setContract(primeContract);
    // 
    IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
    identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
    projection = manager.publish(identityProjectionEvent).getContent();
    IdmIdentityProjectionDto createdProjection = manager.get(projection);
    // 
    Assert.assertNotNull(createdProjection);
    Assert.assertNotNull(createdProjection.getId());
    Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
    // 
    // prime contract
    IdmIdentityContractDto createdPrimeContract = createdProjection.getContract();
    Assert.assertEquals(primeContract.getWorkPosition(), createdPrimeContract.getWorkPosition());
    Assert.assertEquals(primeContract.getPosition(), createdPrimeContract.getPosition());
    Assert.assertEquals(primeContract.getValidFrom(), createdPrimeContract.getValidFrom());
    Assert.assertEquals(primeContract.getValidTill(), createdPrimeContract.getValidTill());
    Assert.assertEquals(createdProjection.getIdentity().getId(), createdPrimeContract.getIdentity());
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with IdmIdentityProjectionDto

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

the class DefaultIdentityProjectionManagerIntegrationTest method testPreventToDeleteOtherContractWhenPrimeContractIsChanged.

@Test
@Transactional
public void testPreventToDeleteOtherContractWhenPrimeContractIsChanged() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
    IdmIdentityContractDto otherContract = getHelper().createContract(identity);
    List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
    Assert.assertEquals(2, contracts.size());
    Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(primeContract.getId())));
    Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(otherContract.getId())));
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    projection.setContract(otherContract);
    projection.setOtherContracts(Lists.newArrayList(primeContract));
    manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, projection));
    contracts = contractService.findAllByIdentity(identity.getId());
    Assert.assertEquals(2, contracts.size());
    Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(primeContract.getId())));
    Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(otherContract.getId())));
}
Also used : Lists(org.testng.collections.Lists) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) BigDecimal(java.math.BigDecimal) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) UUID(java.util.UUID) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) LocalDate(java.time.LocalDate) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MockMvcRequestBuilders.post(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post) IdmFormProjectionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormProjectionService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdentityProjectionEventType(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent.IdentityProjectionEventType) IdentityFormValueEvaluator(eu.bcvsolutions.idm.core.security.evaluator.eav.IdentityFormValueEvaluator) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) ApplicationContext(org.springframework.context.ApplicationContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SelfIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.SelfIdentityEvaluator) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with IdmIdentityProjectionDto

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

the class DefaultIdentityProjectionManagerIntegrationTest method testDeleteOtherContractWhenPrimeContractIsChanged.

@Test
@Transactional
public void testDeleteOtherContractWhenPrimeContractIsChanged() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
    IdmIdentityContractDto otherContract = getHelper().createContract(identity);
    List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
    Assert.assertEquals(2, contracts.size());
    Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(primeContract.getId())));
    Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(otherContract.getId())));
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    projection.setContract(otherContract);
    manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, projection));
    contracts = contractService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, contracts.size());
    Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(otherContract.getId())));
}
Also used : Lists(org.testng.collections.Lists) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) BigDecimal(java.math.BigDecimal) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) UUID(java.util.UUID) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) InvalidFormException(eu.bcvsolutions.idm.core.api.exception.InvalidFormException) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) LocalDate(java.time.LocalDate) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MockMvcRequestBuilders.post(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post) IdmFormProjectionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormProjectionService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdentityProjectionEventType(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent.IdentityProjectionEventType) IdentityFormValueEvaluator(eu.bcvsolutions.idm.core.security.evaluator.eav.IdentityFormValueEvaluator) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) ApplicationContext(org.springframework.context.ApplicationContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SelfIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.SelfIdentityEvaluator) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) FormDefinitionAttributes(eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with IdmIdentityProjectionDto

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

the class DefaultIdentityProjectionManagerIntegrationTest method testProjectionDontSaveOtherContractsAndPositions.

@Test
@Transactional
public void testProjectionDontSaveOtherContractsAndPositions() {
    IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
    formProjection.setCode(getHelper().createName());
    formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
    formProjection = projectionService.save(formProjection);
    // 
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    identity.setFormProjection(formProjection.getId());
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    // 
    // set contract
    IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
    primeContract.setMain(true);
    primeContract.setWorkPosition(getHelper().createTreeNode().getId());
    primeContract.setPosition(getHelper().createName());
    primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
    primeContract.setValidFrom(LocalDate.now().plus(1l, ChronoUnit.DAYS));
    projection.setContract(primeContract);
    // 
    // set other contract
    IdmIdentityContractDto otherContractOne = new IdmIdentityContractDto();
    otherContractOne.setWorkPosition(getHelper().createTreeNode().getId());
    otherContractOne.setPosition(getHelper().createName());
    // preset uuid
    IdmIdentityContractDto otherContractTwo = new IdmIdentityContractDto(UUID.randomUUID());
    otherContractTwo.setWorkPosition(getHelper().createTreeNode().getId());
    otherContractTwo.setPosition(getHelper().createName());
    projection.setOtherContracts(Lists.newArrayList(otherContractOne, otherContractTwo));
    // 
    // set other contract position
    IdmContractPositionDto positionOne = new IdmContractPositionDto();
    positionOne.setWorkPosition(getHelper().createTreeNode().getId());
    positionOne.setPosition(getHelper().createName());
    IdmContractPositionDto positionTwo = new IdmContractPositionDto();
    positionTwo.setWorkPosition(getHelper().createTreeNode().getId());
    positionTwo.setPosition(getHelper().createName());
    positionTwo.setIdentityContract(otherContractTwo.getId());
    projection.setOtherPositions(Lists.newArrayList(positionOne, positionTwo));
    IdmIdentityProjectionDto createdProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
    // other contract
    Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
    // other position
    Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
}
Also used : IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdentityProjectionEvent(eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with IdmIdentityProjectionDto

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

the class DefaultIdentityProjectionManagerIntegrationTest method testSaveAndGetSimpleIdentityByRest.

@Test
@Transactional
public void testSaveAndGetSimpleIdentityByRest() throws Exception {
    IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
    IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
    projection.setContract(new IdmIdentityContractDto());
    // 
    String response = getMockMvc().perform(post(BaseController.BASE_PATH + "/identity-projection").with(authentication(getAdminAuthentication())).content(getMapper().writeValueAsString(projection)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().is2xxSuccessful()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    // 
    IdmIdentityProjectionDto createdProjection = getMapper().readValue(response, IdmIdentityProjectionDto.class);
    // 
    Assert.assertNotNull(createdProjection);
    Assert.assertNotNull(createdProjection.getId());
    Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
    Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
    Assert.assertNotNull(createdProjection.getContract());
    Assert.assertNotNull(createdProjection.getContract().getId());
    Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
    Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
    Assert.assertTrue(createdProjection.getIdentityRoles().isEmpty());
    // 
    response = getMockMvc().perform(get(BaseController.BASE_PATH + "/identity-projection/" + createdProjection.getIdentity().getUsername()).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    // 
    createdProjection = getMapper().readValue(response, IdmIdentityProjectionDto.class);
    // 
    Assert.assertNotNull(createdProjection);
    Assert.assertNotNull(createdProjection.getId());
    Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
    Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
    Assert.assertNotNull(createdProjection.getContract());
    Assert.assertNotNull(createdProjection.getContract().getId());
    Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
    Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
    Assert.assertTrue(createdProjection.getIdentityRoles().isEmpty());
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)34 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)32 Transactional (org.springframework.transaction.annotation.Transactional)24 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)23 Test (org.junit.Test)23 IdmFormProjectionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto)22 IdentityProjectionEvent (eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent)22 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)21 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)18 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)15 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)15 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)8 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)8 ForbiddenEntityException (eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)8 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)7 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)7 FormDefinitionAttributes (eu.bcvsolutions.idm.core.eav.api.dto.FormDefinitionAttributes)7