Commit d66e51ab authored by zonia3000's avatar zonia3000
Browse files

Added is_leaf property on GroupNode

parent 96361f84
......@@ -6,6 +6,7 @@ public class GroupNode {
private String groupName;
private Permission permission;
private boolean hasChildren;
private boolean leaf;
public String getGroupId() {
return groupId;
......@@ -38,4 +39,12 @@ public class GroupNode {
public void setHasChildren(boolean hasChildren) {
this.hasChildren = hasChildren;
}
public boolean isLeaf() {
return leaf;
}
public void setLeaf(boolean leaf) {
this.leaf = leaf;
}
}
......@@ -9,6 +9,8 @@ public class AddGroupRequest extends PaginatedModelRequest implements SearchFilt
@NotEmpty
private String newGroupName;
private boolean leaf;
private String searchFilter;
public String getNewGroupName() {
......@@ -27,6 +29,14 @@ public class AddGroupRequest extends PaginatedModelRequest implements SearchFilt
this.parentGroupId = parentGroupId;
}
public boolean isLeaf() {
return leaf;
}
public void setLeaf(boolean leaf) {
this.leaf = leaf;
}
@Override
public String getSearchFilter() {
return searchFilter;
......
......@@ -59,6 +59,7 @@ public class GroupsTreeBuilder {
GroupNode node = new GroupNode();
node.setGroupId(group.getId());
node.setGroupName(group.getName());
node.setLeaf(group.isLeaf());
node.setPermission(permission);
nodes.add(node);
});
......
package it.inaf.ia2.gms.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.inaf.ia2.gms.authn.SessionData;
import it.inaf.ia2.gms.model.GroupNode;
import it.inaf.ia2.gms.model.Permission;
import it.inaf.ia2.gms.model.request.AddGroupRequest;
import it.inaf.ia2.gms.model.response.GroupsTabResponse;
import it.inaf.ia2.gms.model.response.PaginatedData;
import it.inaf.ia2.gms.persistence.model.GroupEntity;
import it.inaf.ia2.gms.service.GroupsService;
import it.inaf.ia2.gms.service.GroupsTreeBuilder;
import it.inaf.ia2.gms.service.PermissionsService;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import org.junit.Before;
......@@ -14,10 +23,13 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import static org.mockito.Mockito.when;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@RunWith(MockitoJUnitRunner.class)
......@@ -26,9 +38,23 @@ public class GroupsControllerTest {
@Mock
private GroupsTabResponseBuilder groupsTabResponseBuilder;
@Mock
private GroupsService groupsService;
@Mock
private SessionData session;
@Mock
private PermissionsService permissionsService;
@Mock
private GroupsTreeBuilder groupsTreeBuilder;
@InjectMocks
private GroupsController controller;
private final ObjectMapper mapper = new ObjectMapper();
private MockMvc mockMvc;
@Before
......@@ -52,4 +78,31 @@ public class GroupsControllerTest {
.andExpect(jsonPath("$.groupsPanel", notNullValue()))
.andExpect(jsonPath("$.permission", is("ADMIN")));
}
@Test
public void testAddGroups() throws Exception {
AddGroupRequest request = new AddGroupRequest();
request.setNewGroupName("New Group");
request.setParentGroupId("abcd");
request.setLeaf(true);
request.setPaginatorPage(1);
request.setPaginatorPageSize(10);
GroupEntity parent = new GroupEntity();
when(groupsService.getGroupById(any())).thenReturn(parent);
when(permissionsService.getUserPermissionForGroup(any(), any())).thenReturn(Permission.ADMIN);
List<GroupNode> nodes = new ArrayList<>();
PaginatedData<GroupNode> paginatedData = new PaginatedData<>(nodes, 1, 10);
when(groupsTreeBuilder.listSubGroups(any(), any(), any())).thenReturn(paginatedData);
when(session.getUserId()).thenReturn("admin_id");
mockMvc.perform(post("/group")
.content(mapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(status().isCreated());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment