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