Search in sources :

Example 21 with IdmTreeTypeDto

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

the class DefaultIdmTreeNodeServiceIntegrationTest method testMoveChildren.

/**
 * Move childern to new parent a delete previous parent
 */
@Test
@Transactional
public void testMoveChildren() {
    IdmTreeTypeDto treeType = getHelper().createTreeType();
    // create root node
    IdmTreeNodeDto root = getHelper().createTreeNode(treeType, null);
    IdmTreeNodeDto subRoot = getHelper().createTreeNode(treeType, root);
    // create children
    IdmTreeNodeDto nodeOne = getHelper().createTreeNode(treeType, subRoot);
    IdmTreeNodeDto nodeTwo = getHelper().createTreeNode(treeType, subRoot);
    IdmTreeNodeDto nodeThree = getHelper().createTreeNode(treeType, subRoot);
    // 
    Assert.assertEquals(4, treeNodeForestContentService.findAllChildren(root.getId(), null).getTotalElements());
    Assert.assertEquals(3, treeNodeForestContentService.findAllChildren(subRoot.getId(), null).getTotalElements());
    // 
    // move children to other parent
    IdmTreeNodeDto subRootTwo = getHelper().createTreeNode(treeType, root);
    nodeOne.setParent(subRootTwo.getId());
    nodeOne = service.save(nodeOne);
    nodeTwo.setParent(subRootTwo.getId());
    nodeTwo = service.save(nodeTwo);
    nodeThree.setParent(subRootTwo.getId());
    nodeThree = service.save(nodeThree);
    // 
    // delete previous parent
    service.delete(subRoot);
    // 
    Assert.assertEquals(4, treeNodeForestContentService.findAllChildren(root.getId(), null).getTotalElements());
    Assert.assertEquals(3, treeNodeForestContentService.findAllChildren(subRootTwo.getId(), null).getTotalElements());
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with IdmTreeTypeDto

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

the class DefaultIdmTreeNodeServiceIntegrationTest method testEmptyCode.

@Transactional
@Test(expected = ResultCodeException.class)
public void testEmptyCode() {
    IdmTreeTypeDto treeType = getHelper().createTreeType();
    IdmTreeNodeDto node = new IdmTreeNodeDto();
    node.setTreeType(treeType.getId());
    node.setName("test-" + getHelper().createName());
    node.setCode("    ");
    service.save(node);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with IdmTreeTypeDto

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

the class DefaultIdmTreeNodeServiceIntegrationTest method testForestIndexAfterBulkMoveWithTransaction.

@Test
@Transactional
public void testForestIndexAfterBulkMoveWithTransaction() {
    int rootCount = 5;
    // prepare new tree type
    IdmTreeTypeDto treeType = getHelper().createTreeType();
    // create root nodes
    for (int i = 0; i < rootCount; i++) {
        getHelper().createTreeNode(treeType, null);
    }
    // move nodes to the first node
    IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
    filter.setTreeTypeId(treeType.getId());
    List<IdmTreeNodeDto> nodes = service.find(filter, null).getContent();
    IdmTreeNodeDto root = nodes.get(0);
    for (int i = 0; i < nodes.size(); i++) {
        IdmTreeNodeDto node = nodes.get(i);
        if (node.equals(root)) {
            continue;
        }
        node.setParent(root.getId());
        node = service.save(node);
    }
    // check
    Assert.assertEquals(1L, service.findRoots(treeType.getId(), null).getTotalElements());
    Assert.assertEquals(rootCount - 1, service.findChildrenByParent(root.getId(), null).getTotalElements());
    Assert.assertEquals(rootCount - 1, treeNodeForestContentService.findDirectChildren(root.getId(), null).getTotalElements());
    Assert.assertEquals(rootCount - 1, treeNodeForestContentService.findAllChildren(root.getId(), null).getTotalElements());
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with IdmTreeTypeDto

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

the class DefaultIdmTreeNodeServiceIntegrationTest method testRebuildIndex.

@Test
public void testRebuildIndex() {
    IdmTreeTypeDto treeType = getHelper().createTreeType();
    IdmTreeNodeDto node1 = getHelper().createTreeNode(treeType, null);
    IdmTreeNodeDto node2 = getHelper().createTreeNode(treeType, node1);
    IdmTreeNodeDto node3 = getHelper().createTreeNode(treeType, node2);
    IdmTreeNodeDto node4 = getHelper().createTreeNode(treeType, node3);
    // before index will be droped
    IdmTreeNodeFilter filter = new IdmTreeNodeFilter();
    filter.setParent(node2.getId());
    filter.setRecursively(true);
    // 
    List<IdmTreeNodeDto> results = service.find(filter, null).getContent();
    // 
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(n -> n.equals(node3)));
    Assert.assertTrue(results.stream().anyMatch(n -> n.equals(node4)));
    // 
    // drop indexes
    forestIndexService.dropIndexes(IdmTreeNode.toForestTreeType(treeType.getId()));
    // 
    results = service.find(filter, null).getContent();
    Assert.assertEquals(0, results.size());
    // 
    // reindex tree type
    service.rebuildIndexes(treeType.getId());
    // 
    results = service.find(filter, null).getContent();
    Assert.assertEquals(2, results.size());
    Assert.assertTrue(results.stream().anyMatch(n -> n.equals(node3)));
    Assert.assertTrue(results.stream().anyMatch(n -> n.equals(node4)));
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) Lists(org.testng.collections.Lists) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ForestIndexService(eu.bcvsolutions.forest.index.service.api.ForestIndexService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdmTreeNodeForestContentService(eu.bcvsolutions.idm.core.model.service.api.IdmTreeNodeForestContentService) Before(org.junit.Before) IdmForestIndexEntity(eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) RecursionType(eu.bcvsolutions.idm.core.api.domain.RecursionType) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) TreeNodeEvent(eu.bcvsolutions.idm.core.model.event.TreeNodeEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) ProcessSkippedAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) LocalDate(java.time.LocalDate) TreeNodeEventType(eu.bcvsolutions.idm.core.model.event.TreeNodeEvent.TreeNodeEventType) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ProcessAllAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByTreeTaskExecutor) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 25 with IdmTreeTypeDto

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

the class DefaultIdmTreeNodeServiceIntegrationTest method testBadTreeTypeCreate.

@Test
@Transactional
public void testBadTreeTypeCreate() {
    IdmTreeTypeDto parent1 = getHelper().createTreeType();
    IdmTreeTypeDto parent2 = getHelper().createTreeType();
    // 
    IdmTreeNodeDto node1 = getHelper().createTreeNode(parent1, null);
    IdmTreeNodeDto node2 = getHelper().createTreeNode(parent1, node1);
    IdmTreeNodeDto node3 = getHelper().createTreeNode(parent1, node2);
    // 
    try {
        getHelper().createTreeNode(parent2, node1);
        Assert.fail();
    } catch (TreeNodeException ex) {
        Assert.assertTrue(ex.getMessage().contains("bad type"));
    } catch (Exception e) {
        Assert.fail();
    }
    // 
    try {
        getHelper().createTreeNode(parent2, node3);
        Assert.fail();
    } catch (TreeNodeException ex) {
        Assert.assertTrue(ex.getMessage().contains("bad type"));
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)123 Test (org.junit.Test)91 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)89 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)64 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)44 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)33 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)32 UUID (java.util.UUID)26 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)21 IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)21 Transactional (org.springframework.transaction.annotation.Transactional)19 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)18 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)18 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)18 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)16 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)13 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)11 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)11 LocalDate (java.time.LocalDate)10