Search in sources :

Example 1 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogTest method testDeleteCatalogEntry.

@Test
public void testDeleteCatalogEntry() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry2.getKey().toString()).build();
    HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    List<CatalogEntry> entries = catalogManager.getChildrenOf(root1);
    for (CatalogEntry entry : entries) {
        assertFalse(entry.getKey().equals(entry2.getKey()));
    }
    conn.shutdown();
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 2 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogTest method testUpdateCatalogEntryJson.

@Test
public void testUpdateCatalogEntryJson() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    CatalogEntryVO entry = new CatalogEntryVO();
    entry.setName("Entry-1-b");
    entry.setDescription("Entry-description-1-b");
    entry.setType(CatalogEntry.TYPE_NODE);
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    HttpPost method = conn.createPost(uri, MediaType.APPLICATION_JSON);
    method.addHeader("Content-Type", MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, entry);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    CatalogEntry updatedEntry = catalogManager.loadCatalogEntry(entry1);
    assertEquals("Entry-1-b", updatedEntry.getName());
    assertEquals("Entry-description-1-b", updatedEntry.getDescription());
    conn.shutdown();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 3 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogTest method testGetOwners.

@Test
public void testGetOwners() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).path("owners").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<UserVO> voes = parseUserArray(body);
    assertNotNull(voes);
    CatalogEntry entry = catalogManager.loadCatalogEntry(entry1.getKey());
    List<Identity> identities = BaseSecurityManager.getInstance().getIdentitiesOfSecurityGroup(entry.getOwnerGroup());
    assertNotNull(identities);
    assertEquals(identities.size(), voes.size());
    conn.shutdown();
}
Also used : UserVO(org.olat.user.restapi.UserVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 4 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogTest method testUpdateAndMoveCatalogEntryJson.

@Test
public void testUpdateAndMoveCatalogEntryJson() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    CatalogEntryVO entry = new CatalogEntryVO();
    entry.setName("Entry-2-moved-down");
    entry.setDescription("Entry-description-2-moved-down");
    entry.setType(CatalogEntry.TYPE_NODE);
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entryToMove2.getKey().toString()).queryParam("newParentKey", subEntry13move.getKey().toString()).build();
    HttpPost method = conn.createPost(uri, MediaType.APPLICATION_JSON);
    method.addHeader("Content-Type", MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, entry);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    CatalogEntry updatedEntry = catalogManager.loadCatalogEntry(entryToMove2);
    assertEquals("Entry-2-moved-down", updatedEntry.getName());
    assertEquals("Entry-description-2-moved-down", updatedEntry.getDescription());
    assertNotNull(updatedEntry.getParent());
    assertTrue(updatedEntry.getParent().equalsByPersistableKey(subEntry13move));
    conn.shutdown();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 5 with CatalogEntry

use of org.olat.repository.CatalogEntry in project OpenOLAT by OpenOLAT.

the class CatalogTest method testPutCategoryJson.

@Test
public void testPutCategoryJson() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    CatalogEntryVO subEntry = new CatalogEntryVO();
    subEntry.setName("Sub-entry-1");
    subEntry.setDescription("Sub-entry-description-1");
    subEntry.setType(CatalogEntry.TYPE_NODE);
    URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    method.addHeader("Content-Type", MediaType.APPLICATION_JSON);
    conn.addJsonEntity(method, subEntry);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    CatalogEntryVO vo = conn.parse(response, CatalogEntryVO.class);
    assertNotNull(vo);
    List<CatalogEntry> children = catalogManager.getChildrenOf(entry1);
    boolean saved = false;
    for (CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            saved = true;
            break;
        }
    }
    assertTrue(saved);
    conn.shutdown();
}
Also used : CatalogEntryVO(org.olat.restapi.support.vo.CatalogEntryVO) CatalogEntry(org.olat.repository.CatalogEntry) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Aggregations

CatalogEntry (org.olat.repository.CatalogEntry)122 Test (org.junit.Test)30 CatalogEntryVO (org.olat.restapi.support.vo.CatalogEntryVO)30 URI (java.net.URI)28 HttpResponse (org.apache.http.HttpResponse)28 Identity (org.olat.core.id.Identity)28 ArrayList (java.util.ArrayList)20 Path (javax.ws.rs.Path)18 SecurityGroup (org.olat.basesecurity.SecurityGroup)18 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Produces (javax.ws.rs.Produces)14 HttpPut (org.apache.http.client.methods.HttpPut)12 GET (javax.ws.rs.GET)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 HttpPost (org.apache.http.client.methods.HttpPost)10 OLATResourceable (org.olat.core.id.OLATResourceable)10 ContextEntry (org.olat.core.id.context.ContextEntry)10 LockResult (org.olat.core.util.coordinate.LockResult)10 CatalogManager (org.olat.repository.manager.CatalogManager)8 Link (org.olat.core.gui.components.link.Link)6