Search in sources :

Example 46 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

the class GroupMgmtTest method testCreateCourseGroupWithNewsAndContact.

@Test
public void testCreateCourseGroupWithNewsAndContact() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    // create the group
    GroupVO vo = new GroupVO();
    vo.setName("rest-g7-news");
    vo.setDescription("rest-g7 with news");
    vo.setType("BuddyGroup");
    URI request = UriBuilder.fromUri(getContextURI()).path("groups").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, vo);
    HttpResponse response = conn.execute(method);
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    GroupVO newGroupVo = conn.parse(response, GroupVO.class);
    assertNotNull(newGroupVo);
    // update the configuration
    GroupConfigurationVO configVo = new GroupConfigurationVO();
    configVo.setTools(new String[] { "hasContactForm", "hasNews" });
    configVo.setNews("<p>News!</p>");
    URI configRequest = UriBuilder.fromUri(getContextURI()).path("groups").path(newGroupVo.getKey().toString()).path("configuration").build();
    HttpPost configMethod = conn.createPost(configRequest, MediaType.APPLICATION_JSON);
    conn.addJsonEntity(configMethod, configVo);
    HttpResponse configResponse = conn.execute(configMethod);
    assertTrue(configResponse.getStatusLine().getStatusCode() == 200 || configResponse.getStatusLine().getStatusCode() == 201);
    EntityUtils.consume(configResponse.getEntity());
    // check group
    BusinessGroup bg = businessGroupService.loadBusinessGroup(newGroupVo.getKey());
    assertNotNull(bg);
    assertEquals(bg.getKey(), newGroupVo.getKey());
    assertEquals(bg.getName(), "rest-g7-news");
    assertEquals(bg.getDescription(), "rest-g7 with news");
    // check collaboration tools configuration
    CollaborationTools tools = CollaborationToolsFactory.getInstance().getCollaborationToolsIfExists(bg);
    assertNotNull(tools);
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_FOLDER));
    assertTrue(tools.isToolEnabled(CollaborationTools.TOOL_NEWS));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_CALENDAR));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_CHAT));
    assertTrue(tools.isToolEnabled(CollaborationTools.TOOL_CONTACT));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_FORUM));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_PORTFOLIO));
    assertFalse(tools.isToolEnabled(CollaborationTools.TOOL_WIKI));
    // Check news tools access configuration
    assertEquals("<p>News!</p>", tools.lookupNews());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) GroupConfigurationVO(org.olat.restapi.support.vo.GroupConfigurationVO) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) HttpResponse(org.apache.http.HttpResponse) GroupVO(org.olat.restapi.support.vo.GroupVO) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 47 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

the class GroupMgmtTest method testGetGroupsAdmin.

@Test
public void testGetGroupsAdmin() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("groups").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<GroupVO> groups = parseGroupArray(body);
    assertNotNull(groups);
    // g1, g2, g3 and g4 + from olat
    assertTrue(groups.size() >= 4);
    Set<Long> keys = new HashSet<Long>();
    for (GroupVO vo : groups) {
        keys.add(vo.getKey());
    }
    assertTrue(keys.contains(g1.getKey()));
    assertTrue(keys.contains(g2.getKey()));
    assertTrue(keys.contains(g3.getKey()));
    assertTrue(keys.contains(g4.getKey()));
}
Also used : InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) GroupVO(org.olat.restapi.support.vo.GroupVO) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 48 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

the class GroupMgmtTest method testGetGroups.

@Test
public void testGetGroups() throws IOException, URISyntaxException {
    assertTrue(conn.login("rest-four", "A6B7C8"));
    URI request = UriBuilder.fromUri(getContextURI()).path("groups").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<GroupVO> groups = parseGroupArray(body);
    assertNotNull(groups);
    // g1, g2, g3 and g4 + from olat
    assertTrue(groups.size() >= 2);
    Set<Long> keys = new HashSet<Long>();
    for (GroupVO vo : groups) {
        keys.add(vo.getKey());
    }
    assertTrue(keys.contains(g1.getKey()));
    assertTrue(keys.contains(g2.getKey()));
    assertFalse(keys.contains(g3.getKey()));
    assertFalse(keys.contains(g4.getKey()));
}
Also used : InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) GroupVO(org.olat.restapi.support.vo.GroupVO) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 49 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

the class CourseGroupMgmtTest method testUpdateCourseGroup.

@Test
public void testUpdateCourseGroup() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    GroupVO vo = new GroupVO();
    vo.setKey(g1.getKey());
    vo.setName("rest-g1-mod");
    vo.setDescription("rest-g1 description");
    vo.setMinParticipants(g1.getMinParticipants());
    vo.setMaxParticipants(g1.getMaxParticipants());
    vo.setType("LeanringGroup");
    URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + courseRepoEntry.getOlatResource().getResourceableId() + "/groups/" + g1.getKey()).build();
    HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, vo);
    HttpResponse response = conn.execute(method);
    EntityUtils.consume(response.getEntity());
    assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
    BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey());
    assertNotNull(bg);
    assertEquals(bg.getKey(), vo.getKey());
    assertEquals("rest-g1-mod", bg.getName());
    assertEquals("rest-g1 description", bg.getDescription());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BusinessGroup(org.olat.group.BusinessGroup) HttpResponse(org.apache.http.HttpResponse) GroupVO(org.olat.restapi.support.vo.GroupVO) URI(java.net.URI) Test(org.junit.Test)

Example 50 with GroupVO

use of org.olat.restapi.support.vo.GroupVO in project openolat by klemens.

the class CourseGroupMgmtTest method testPutCourseGroup.

@Test
public void testPutCourseGroup() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    GroupVO vo = new GroupVO();
    vo.setName("hello");
    vo.setDescription("hello description");
    vo.setMinParticipants(new Integer(-1));
    vo.setMaxParticipants(new Integer(-1));
    Long courseId = courseRepoEntry.getOlatResource().getResourceableId();
    URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + courseId + "/groups").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, vo);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    GroupVO responseVo = conn.parse(response, GroupVO.class);
    assertNotNull(responseVo);
    assertEquals(vo.getName(), responseVo.getName());
    BusinessGroup bg = businessGroupService.loadBusinessGroup(responseVo.getKey());
    assertNotNull(bg);
    assertEquals(bg.getKey(), responseVo.getKey());
    assertEquals(bg.getName(), vo.getName());
    assertEquals(bg.getDescription(), vo.getDescription());
    assertNull(bg.getMinParticipants());
    assertNull(bg.getMaxParticipants());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) HttpResponse(org.apache.http.HttpResponse) GroupVO(org.olat.restapi.support.vo.GroupVO) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Aggregations

GroupVO (org.olat.restapi.support.vo.GroupVO)54 URI (java.net.URI)36 HttpResponse (org.apache.http.HttpResponse)36 Test (org.junit.Test)36 BusinessGroup (org.olat.group.BusinessGroup)30 HttpGet (org.apache.http.client.methods.HttpGet)20 BusinessGroupService (org.olat.group.BusinessGroupService)16 InputStream (java.io.InputStream)14 Produces (javax.ws.rs.Produces)14 HttpPut (org.apache.http.client.methods.HttpPut)14 HttpPost (org.apache.http.client.methods.HttpPost)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 GET (javax.ws.rs.GET)8 Identity (org.olat.core.id.Identity)8 Consumes (javax.ws.rs.Consumes)6 Path (javax.ws.rs.Path)6 CollaborationTools (org.olat.collaboration.CollaborationTools)6 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)6 GroupConfigurationVO (org.olat.restapi.support.vo.GroupConfigurationVO)6 ArrayList (java.util.ArrayList)4