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