Search in sources :

Example 6 with IdmTreeType

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeType in project CzechIdMng by bcvsolutions.

the class TreeNodeAndTypeRestTest method changeType.

@Test
public void changeType() {
    IdmTreeType type = getIdmTreeType("TEST_TYPE_1", "TEST_TYPE_1");
    treeTypeRepository.save(type);
    IdmTreeType type2 = getIdmTreeType("TEST_TYPE_2", "TEST_TYPE_2");
    treeTypeRepository.save(type2);
    // save node trought rest
    Map<String, String> body = new HashMap<>();
    body.put("code", "TEST_NODE");
    body.put("name", "TEST_NODE");
    body.put("treeType", type.getId().toString());
    String jsonContent = toJson(body);
    int status = 0;
    Exception ex = null;
    // test save without privileges
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(403, status);
    // test with privileges
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").with(authentication(getAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(201, status);
    Page<IdmTreeNode> nodes = this.treeNodeRepository.findChildren(type.getId(), null, new PageRequest(0, 1));
    assertFalse(nodes.getContent().isEmpty());
    IdmTreeNode node = nodes.getContent().get(0);
    // change treeType
    body.put("id", node.getId().toString());
    body.put("name", node.getName() + "_update");
    body.put("treeType", type2.getId().toString());
    jsonContent = toJson(body);
    status = 0;
    ex = null;
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes/").with(authentication(getAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertEquals(400, status);
    assertNull(ex);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) HashMap(java.util.HashMap) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 7 with IdmTreeType

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeType in project CzechIdMng by bcvsolutions.

the class TreeNodeAndTypeRestTest method addChildrenToParent.

@Test
public void addChildrenToParent() {
    IdmTreeType type = getIdmTreeType("TEST_TYPE", "TEST_TYPE");
    treeTypeRepository.save(type);
    IdmTreeNode node1 = getIdmTreeNode(type, null, "TEST_ROOT", "TEST_ROOT");
    IdmTreeNode node2 = getIdmTreeNode(type, node1, "TEST_NODE_2", "TEST_NODE_2");
    IdmTreeNode node3 = getIdmTreeNode(type, node2, "TEST_NODE_3", "TEST_NODE_2");
    IdmTreeNode node4 = getIdmTreeNode(type, node3, "TEST_NODE_4", "TEST_NODE_2");
    treeNodeRepository.save(node1);
    treeNodeRepository.save(node2);
    treeNodeRepository.save(node3);
    treeNodeRepository.save(node4);
    // set parent of node4 to his children
    Map<String, String> body = new HashMap<>();
    body.put("id", node2.getId().toString());
    body.put("code", "TEST_NODE_2_update");
    body.put("name", "TEST_NODE_2_update");
    body.put("treeType", node4.getTreeType().getId().toString());
    body.put("parent", node4.getId().toString());
    String jsonContent = toJson(body);
    int status = 0;
    Exception ex = null;
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").with(authentication(getAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(400, status);
}
Also used : IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) HashMap(java.util.HashMap) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Aggregations

IdmTreeType (eu.bcvsolutions.idm.core.model.entity.IdmTreeType)7 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)5 Test (org.junit.Test)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)3 HashMap (java.util.HashMap)3 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)2 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)1 ForbiddenEntityException (eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 PageRequest (org.springframework.data.domain.PageRequest)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1