Search in sources :

Example 11 with Assert.assertTrue

use of org.junit.Assert.assertTrue 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 12 with Assert.assertTrue

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

the class DefaultIdmRoleServiceIntegrationTest method typeFilterTest.

@Test
public void typeFilterTest() {
    IdmRoleDto role = getHelper().createRole();
    // other
    IdmRoleDto roleTwo = getHelper().createRole();
    RoleType type = RoleType.SYSTEM;
    role.setRoleType(type);
    IdmRoleDto roleOne = roleService.save(role);
    IdmRoleFilter filter = new IdmRoleFilter();
    filter.setRoleType(type);
    Page<IdmRoleDto> result = roleService.find(filter, null);
    Assert.assertTrue(result.stream().anyMatch(r -> r.getId().equals(roleOne.getId())));
    Assert.assertTrue(result.stream().allMatch(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) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) RoleType(eu.bcvsolutions.idm.core.api.domain.RoleType) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 13 with Assert.assertTrue

use of org.junit.Assert.assertTrue 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 14 with Assert.assertTrue

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

the class DefaultSysProvisioningArchiveServiceIntegrationTest method differenceObjectMultipleTest.

@Test
public void differenceObjectMultipleTest() {
    String attrName = getHelper().createName();
    IcAttributeImpl icAttributeOne = new IcAttributeImpl(attrName, Lists.newArrayList("TESTExisting", "TESTRemoved"));
    IcConnectorObject connObjectOld = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeOne));
    IcAttributeImpl icAttributeTwo = new IcAttributeImpl(attrName, Lists.newArrayList("TESTExisting", "TESTNew"));
    IcConnectorObject connObjectNew = new IcConnectorObjectImpl(getHelper().createName(), new IcObjectClassImpl("__mock__"), ImmutableList.of(icAttributeTwo));
    List<SysAttributeDifferenceDto> diffs = service.evaluateProvisioningDifferences(connObjectOld, connObjectNew);
    List<SysAttributeDifferenceValueDto> values = diffs.get(0).getValues();
    Assert.assertEquals(1, diffs.size());
    Assert.assertTrue(diffs.get(0).isMultivalue());
    Assert.assertTrue(diffs.get(0).isChanged());
    Assert.assertNotNull(values);
    Assert.assertEquals(3, values.size());
    SysAttributeDifferenceValueDto value;
    value = values.stream().filter(item -> item.getChange() == null).findFirst().orElse(null);
    Assert.assertNotNull(value);
    Assert.assertEquals("TESTExisting", value.getValue());
    Assert.assertEquals("TESTExisting", value.getOldValue());
    value = values.stream().filter(item -> item.getChange() == SysValueChangeType.ADDED).findFirst().orElse(null);
    Assert.assertNotNull(value);
    Assert.assertEquals("TESTNew", value.getValue());
    Assert.assertEquals(null, value.getOldValue());
    value = values.stream().filter(item -> item.getChange() == SysValueChangeType.REMOVED).findFirst().orElse(null);
    Assert.assertNotNull(value);
    Assert.assertEquals("TESTRemoved", value.getValue());
    Assert.assertEquals("TESTRemoved", value.getOldValue());
}
Also used : ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) SysProvisioningOperationService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningOperationService) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) Page(org.springframework.data.domain.Page) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) List(java.util.List) SysProvisioningAttributeRepository(eu.bcvsolutions.idm.acc.repository.SysProvisioningAttributeRepository) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Assert.assertFalse(org.junit.Assert.assertFalse) SysProvisioningAttribute(eu.bcvsolutions.idm.acc.entity.SysProvisioningAttribute) DefaultAccTestHelper(eu.bcvsolutions.idm.acc.DefaultAccTestHelper) SysValueChangeType(eu.bcvsolutions.idm.acc.domain.SysValueChangeType) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysAttributeDifferenceValueDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceValueDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with Assert.assertTrue

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

the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testRemoveLastRuleRecount.

@Test
public void testRemoveLastRuleRecount() {
    // start transaction
    TransactionContextHolder.setContext(TransactionContextHolder.createEmptyContext());
    UUID transactionId = TransactionContextHolder.getContext().getTransactionId();
    // 
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto role = getHelper().createRole();
    // 
    IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
    // 
    IdmAutomaticRoleAttributeRuleDto automaticRoleRule = getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, identity.getUsername());
    this.recalculateSync(automaticRole.getId());
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, identityRoles.size());
    Assert.assertEquals(transactionId, identityRoles.get(0).getTransactionId());
    // 
    automaticRoleAttributeRuleService.delete(automaticRoleRule);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(identityRoles.isEmpty());
    // 
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(identityRoles.isEmpty());
    // 
    // check all LRT ended successfully
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setTransactionId(transactionId);
    List<IdmLongRunningTaskDto> lrts = longRunningTaskManager.findLongRunningTasks(filter, null).getContent();
    Assert.assertFalse(lrts.isEmpty());
    Assert.assertTrue(lrts.stream().allMatch(lrt -> lrt.getResultState() == OperationState.EXECUTED));
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) BaseCodeList(eu.bcvsolutions.idm.core.eav.api.domain.BaseCodeList) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ProcessAllAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByAttributeTaskExecutor) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) Assert.fail(org.junit.Assert.fail) Sort(org.springframework.data.domain.Sort) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) PageRequest(org.springframework.data.domain.PageRequest) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) UUID(java.util.UUID) Instant(java.time.Instant) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState) ZoneId(java.time.ZoneId) Serializable(java.io.Serializable) List(java.util.List) EventConfiguration(eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) Assert.assertFalse(org.junit.Assert.assertFalse) ProcessAutomaticRoleByAttributeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByAttributeTaskExecutor) LocalDate(java.time.LocalDate) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) ArrayList(java.util.ArrayList) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) IdmFormProjectionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormProjectionService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) BaseFaceType(eu.bcvsolutions.idm.core.eav.api.domain.BaseFaceType) Direction(org.springframework.data.domain.Sort.Direction) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) IdmAutomaticRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) Ignore(org.junit.Ignore) AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

Assert (org.junit.Assert)88 Assert.assertTrue (org.junit.Assert.assertTrue)88 Test (org.junit.Test)88 Assert.assertEquals (org.junit.Assert.assertEquals)84 List (java.util.List)82 Before (org.junit.Before)67 UUID (java.util.UUID)55 Assert.assertFalse (org.junit.Assert.assertFalse)54 Autowired (org.springframework.beans.factory.annotation.Autowired)53 Assert.assertNotNull (org.junit.Assert.assertNotNull)52 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)51 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)51 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)49 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)48 Transactional (org.springframework.transaction.annotation.Transactional)46 After (org.junit.After)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)42 ApplicationContext (org.springframework.context.ApplicationContext)38 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)37 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)36