Search in sources :

Example 86 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestServiceIntegrationTest method notRightForExecuteImmediatelyExceptionTest.

@Test(expected = RoleRequestException.class)
@Transactional
public void notRightForExecuteImmediatelyExceptionTest() {
    IdmIdentityDto testA = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto roleA = getHelper().createRole(100);
    this.logout();
    // Log as user without right for immediately execute role request (without
    // approval)
    Collection<GrantedAuthority> authorities = IdmAuthorityUtils.toAuthorities(moduleService.getAvailablePermissions()).stream().filter(authority -> {
        return !CoreGroupPermission.ROLE_REQUEST_EXECUTE.equals(authority.getAuthority()) && !CoreGroupPermission.ROLE_REQUEST_ADMIN.equals(authority.getAuthority()) && !IdmGroupPermission.APP_ADMIN.equals(authority.getAuthority());
    }).collect(Collectors.toList());
    SecurityContextHolder.getContext().setAuthentication(new IdmJwtAuthentication(testA, null, authorities, "test"));
    IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
    IdmRoleRequestDto request = new IdmRoleRequestDto();
    request.setApplicant(testA.getId());
    request.setExecuteImmediately(true);
    request.setRequestedByType(RoleRequestedByType.MANUALLY);
    request = roleRequestService.save(request);
    Assert.assertEquals(RoleRequestState.CONCEPT, request.getState());
    IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
    conceptA.setRoleRequest(request.getId());
    conceptA.setOperation(ConceptRoleRequestOperation.ADD);
    conceptA.setRole(roleA.getId());
    conceptA.setIdentityContract(contractA.getId());
    conceptA = conceptRoleRequestService.save(conceptA);
    Assert.assertEquals(RoleRequestState.CONCEPT, conceptA.getState());
    // We expect exception state (we don`t have right for execute without approval)
    getHelper().startRequestInternal(request, true, true);
}
Also used : IdmRoleRequestByIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) 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) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) Map(java.util.Map) After(org.junit.After) ModuleService(eu.bcvsolutions.idm.core.api.service.ModuleService) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) Collection(java.util.Collection) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) GrantedAuthority(org.springframework.security.core.GrantedAuthority) IOUtils(org.apache.commons.io.IOUtils) 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) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) FutureTask(java.util.concurrent.FutureTask) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) HashMap(java.util.HashMap) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) IdmAuthorityUtils(eu.bcvsolutions.idm.core.security.api.utils.IdmAuthorityUtils) ImmutableList(com.google.common.collect.ImmutableList) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) Qualifier(org.springframework.beans.factory.annotation.Qualifier) 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) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Executor(java.util.concurrent.Executor) Assert.assertNotNull(org.junit.Assert.assertNotNull) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) GrantedAuthority(org.springframework.security.core.GrantedAuthority) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 87 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestServiceIntegrationTest method testExecuteRequestForSameAutomaticRole.

@Test
public void testExecuteRequestForSameAutomaticRole() {
    IdmRoleDto role = getHelper().createRole();
    IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
    // 
    // create two requests
    IdmRoleRequestDto requestOne = new IdmRoleRequestDto();
    requestOne.setApplicant(identity.getId());
    requestOne.setExecuteImmediately(true);
    requestOne.setRequestedByType(RoleRequestedByType.MANUALLY);
    requestOne.setState(RoleRequestState.EXECUTED);
    requestOne = roleRequestService.save(requestOne);
    Assert.assertEquals(RoleRequestState.CONCEPT, requestOne.getState());
    IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
    concept.setRoleRequest(requestOne.getId());
    concept.setState(RoleRequestState.EXECUTED);
    concept.setOperation(ConceptRoleRequestOperation.ADD);
    concept.setRole(role.getId());
    concept.setAutomaticRole(automaticRole.getId());
    concept.setIdentityContract(primeContract.getId());
    concept = conceptRoleRequestService.save(concept);
    Assert.assertEquals(RoleRequestState.CONCEPT, concept.getState());
    // 
    // create two requests
    IdmRoleRequestDto requestTwo = new IdmRoleRequestDto();
    requestTwo.setApplicant(identity.getId());
    requestTwo.setExecuteImmediately(true);
    requestTwo.setRequestedByType(RoleRequestedByType.MANUALLY);
    requestTwo.setState(RoleRequestState.EXECUTED);
    requestTwo = roleRequestService.save(requestTwo);
    Assert.assertEquals(RoleRequestState.CONCEPT, requestTwo.getState());
    concept = new IdmConceptRoleRequestDto();
    concept.setRoleRequest(requestTwo.getId());
    concept.setState(RoleRequestState.EXECUTED);
    concept.setOperation(ConceptRoleRequestOperation.ADD);
    concept.setRole(role.getId());
    concept.setAutomaticRole(automaticRole.getId());
    concept.setIdentityContract(primeContract.getId());
    concept = conceptRoleRequestService.save(concept);
    Assert.assertEquals(RoleRequestState.CONCEPT, concept.getState());
    getHelper().startRequestInternal(requestOne, true, true);
    requestOne = roleRequestService.get(requestOne.getId());
    Assert.assertEquals(RoleRequestState.EXECUTED, requestOne.getState());
    getHelper().startRequestInternal(requestTwo, true, true);
    requestTwo = roleRequestService.get(requestTwo.getId());
    Assert.assertEquals(RoleRequestState.EXECUTED, requestTwo.getState());
    // 
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().allMatch(ir -> ir.getAutomaticRole().equals(automaticRole.getId())));
}
Also used : IdmRoleRequestByIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) 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) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) Map(java.util.Map) After(org.junit.After) ModuleService(eu.bcvsolutions.idm.core.api.service.ModuleService) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) Collection(java.util.Collection) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) GrantedAuthority(org.springframework.security.core.GrantedAuthority) IOUtils(org.apache.commons.io.IOUtils) 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) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) FutureTask(java.util.concurrent.FutureTask) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) HashMap(java.util.HashMap) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) IdmAuthorityUtils(eu.bcvsolutions.idm.core.security.api.utils.IdmAuthorityUtils) ImmutableList(com.google.common.collect.ImmutableList) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) Qualifier(org.springframework.beans.factory.annotation.Qualifier) 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) SchedulerConfiguration(eu.bcvsolutions.idm.core.scheduler.api.config.SchedulerConfiguration) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Executor(java.util.concurrent.Executor) Assert.assertNotNull(org.junit.Assert.assertNotNull) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 88 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptServiceIntegrationTest method testDeployScriptFromAttachement.

@Test
public void testDeployScriptFromAttachement() throws IOException {
    String scriptCode = getHelper().createName();
    String scriptOne = "<script> <code>" + scriptCode + "</code> <name>Test script 1</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> <service> <name>identityService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
    // create attachment
    IdmAttachmentDto attachment = new IdmAttachmentDto();
    attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
    attachment.setName("scriptOne.xml");
    attachment.setMimetype(MediaType.TEXT_XML_VALUE);
    attachment.setInputData(IOUtils.toInputStream(scriptOne));
    // owner and version is resolved after attachment is saved
    attachment = attachmentManager.saveAttachment(null, attachment);
    // deploy
    List<IdmScriptDto> results = scriptService.deploy(attachment);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(scriptCode, results.get(0).getCode());
    // 
    // test authorities
    IdmScriptAuthorityFilter authorityFilter = new IdmScriptAuthorityFilter();
    authorityFilter.setScriptId(results.get(0).getId());
    List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
    Assert.assertEquals(4, authorities.size());
    Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
    Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
    Assert.assertTrue(authorities.stream().anyMatch(a -> "identityService".equals(a.getService())));
    Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
    Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
    // 
    // deploy from archive
    IdmScriptDto scriptOneDto = scriptService.getByCode(scriptCode);
    String scriptCodeTwo = getHelper().createName();
    String scriptOneUpdateName = getHelper().createName();
    scriptOne = "<script> <code>" + scriptCode + "</code> <name>" + scriptOneUpdateName + "</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
    // create attachment
    String scriptTwo = "<script> <code>" + scriptCodeTwo + "</code> <name>Test script 2</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> <service> <name>identityService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
    IdmAttachmentDto attachmentOne = new IdmAttachmentDto();
    attachmentOne.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
    attachmentOne.setName("scriptOne.xml");
    attachmentOne.setMimetype(MediaType.TEXT_XML_VALUE);
    attachmentOne.setInputData(IOUtils.toInputStream(scriptOne));
    attachmentOne = attachmentManager.saveAttachment(null, attachmentOne);
    IdmAttachmentDto attachmentTwo = new IdmAttachmentDto();
    attachmentTwo.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
    attachmentTwo.setName("scriptTwo.xml");
    attachmentTwo.setMimetype(MediaType.TEXT_XML_VALUE);
    attachmentTwo.setInputData(IOUtils.toInputStream(scriptTwo));
    attachmentTwo = attachmentManager.saveAttachment(null, attachmentTwo);
    // zip
    File zipFolder = attachmentManager.createTempDirectory(null).toFile();
    File targetFileOne = new File(zipFolder.toString(), String.format("%s.xml", attachmentOne.getName()));
    Files.copy(attachmentManager.getAttachmentData(attachmentOne.getId()), targetFileOne.toPath(), StandardCopyOption.REPLACE_EXISTING);
    File targetFileTwo = new File(zipFolder.toString(), String.format("%s.xml", attachmentTwo.getName()));
    Files.copy(attachmentManager.getAttachmentData(attachmentTwo.getId()), targetFileTwo.toPath(), StandardCopyOption.REPLACE_EXISTING);
    // compress
    File zipFile = attachmentManager.createTempFile();
    ZipUtils.compress(zipFolder, zipFile.getPath());
    IdmAttachmentDto attachmentZip = new IdmAttachmentDto();
    attachmentZip.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
    attachmentZip.setInputData(new FileInputStream(zipFile));
    attachmentZip.setEncoding(AttachableEntity.DEFAULT_ENCODING);
    // zip ~ octet stream
    attachmentZip.setMimetype(AttachableEntity.DEFAULT_MIMETYPE);
    attachmentZip.setName("backup.zip");
    attachmentZip = attachmentManager.saveAttachment(null, attachmentZip);
    // deploy
    results = scriptService.deploy(attachmentZip);
    // 
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(scriptOneDto.getId())));
    Assert.assertTrue(results.stream().anyMatch(s -> s.getCode().equals(scriptCode) && s.getName().equals(scriptOneUpdateName)));
    Assert.assertTrue(results.stream().anyMatch(s -> s.getCode().equals(scriptCodeTwo)));
    // 
    // test authorities
    authorityFilter = new IdmScriptAuthorityFilter();
    authorityFilter.setScriptId(scriptOneDto.getId());
    authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
    Assert.assertEquals(3, authorities.size());
    Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
    Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
    Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
    Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
    // 
    authorityFilter = new IdmScriptAuthorityFilter();
    authorityFilter.setScriptId(scriptService.getByCode(scriptCodeTwo).getId());
    authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
    Assert.assertEquals(4, authorities.size());
    Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
    Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
    Assert.assertTrue(authorities.stream().anyMatch(a -> "identityService".equals(a.getService())));
    Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
    Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmScriptCategory(eu.bcvsolutions.idm.core.api.domain.IdmScriptCategory) IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) AttachableEntity(eu.bcvsolutions.idm.core.ecm.api.entity.AttachableEntity) ZonedDateTime(java.time.ZonedDateTime) Recoverable(eu.bcvsolutions.idm.core.api.service.Recoverable) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) StandardCopyOption(java.nio.file.StandardCopyOption) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) MediaType(org.springframework.http.MediaType) DecimalFormat(java.text.DecimalFormat) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) ApplicationContext(org.springframework.context.ApplicationContext) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) ZipUtils(eu.bcvsolutions.idm.core.api.utils.ZipUtils) Assert(org.junit.Assert) IdmScriptAuthorityService(eu.bcvsolutions.idm.core.api.service.IdmScriptAuthorityService) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter) File(java.io.File) FileInputStream(java.io.FileInputStream) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 89 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleServiceIntegrationTest method testGetRolesByIds.

@Test
public void testGetRolesByIds() {
    IdmRoleDto roleOne = getHelper().createRole();
    IdmRoleDto roleTwo = getHelper().createRole();
    // 
    List<IdmRoleDto> roles = roleService.getRolesByIds(StringUtils.join(Lists.newArrayList(roleOne.getId(), roleTwo.getId()), ','));
    // 
    Assert.assertEquals(2, roles.size());
    Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleOne.getId())));
    Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleTwo.getId())));
}
Also used : RoleType(eu.bcvsolutions.idm.core.api.domain.RoleType) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) StringUtils(org.apache.commons.lang3.StringUtils) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) IdmAuthorizationPolicyFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAuthorizationPolicyFilter) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleGuaranteeRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleGuaranteeRoleService) Page(org.springframework.data.domain.Page) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) Modifier(java.lang.reflect.Modifier) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleGuaranteeRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) ImmutableList(com.google.common.collect.ImmutableList) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmRoleCatalogueRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueRoleDto) 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) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmRole_(eu.bcvsolutions.idm.core.model.entity.IdmRole_) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleGuaranteeRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeRoleFilter) IdmRoleGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmRoleGuaranteeService) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmRoleCatalogueRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleCatalogueRoleService) Field(java.lang.reflect.Field) ApplicationContext(org.springframework.context.ApplicationContext) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) BaseDtoController(eu.bcvsolutions.idm.core.api.rest.BaseDtoController) IdmAuthorizationPolicyService(eu.bcvsolutions.idm.core.api.service.IdmAuthorizationPolicyService) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 90 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideValidationReqex.

@Test
public void testSubDefinitionOverrideValidationReqex() {
    String regex = "regex";
    // Create role with attribute (include the sub-definition)
    IdmRoleDto role = createRoleWithAttributes();
    IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
    filter.setRole(role.getId());
    List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
    Assert.assertEquals(2, list.size());
    IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
    Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
    // Set regex validation on false to IP attribute in the sub-definition
    list.stream().filter(roleFormAttributeDto -> {
        IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
        return formAttributeDto.getCode().equals(IP);
    }).forEach(roleFormAttributeDto -> {
        Assert.assertNull(roleFormAttributeDto.getRegex());
        roleFormAttributeDto.setRegex(regex);
        roleFormAttributeService.save(roleFormAttributeDto);
    });
    // Load sub-definition by role
    formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
    Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
    IdmFormAttributeDto ipFormAttribute = formAttributeSubdefinition.getFormAttributes().stream().filter(attributeDto -> {
        return attributeDto.getCode().equals(IP);
    }).findFirst().orElse(null);
    Assert.assertNotNull(ipFormAttribute);
    Assert.assertEquals(regex, ipFormAttribute.getRegex());
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) ImmutableList(com.google.common.collect.ImmutableList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleFormAttribute_(eu.bcvsolutions.idm.core.model.entity.IdmRoleFormAttribute_) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

Assert.assertEquals (org.junit.Assert.assertEquals)282 Assert (org.junit.Assert)277 Test (org.junit.Test)276 List (java.util.List)233 Assert.assertTrue (org.junit.Assert.assertTrue)191 Before (org.junit.Before)166 ArrayList (java.util.ArrayList)134 Assert.assertNotNull (org.junit.Assert.assertNotNull)133 Map (java.util.Map)121 Assert.assertFalse (org.junit.Assert.assertFalse)116 Arrays (java.util.Arrays)113 UUID (java.util.UUID)108 Autowired (org.springframework.beans.factory.annotation.Autowired)105 Collections (java.util.Collections)102 After (org.junit.After)99 HashMap (java.util.HashMap)96 Assert.assertNull (org.junit.Assert.assertNull)94 Collectors (java.util.stream.Collectors)93 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)91 IOException (java.io.IOException)85