use of org.olat.repository.handlers.SharedFolderHandler in project OpenOLAT by OpenOLAT.
the class SharedFolderTest method getFiles_participant.
/**
* Participant can read the files and download them.
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void getFiles_participant() throws IOException, URISyntaxException {
// a shared folder with a participant
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-owner-");
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-part-");
RepositoryEntry sharedFolder = new SharedFolderHandler().createResource(owner, "Shared 2", "Shared files", null, Locale.ENGLISH);
VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(sharedFolder, true);
copyFileInResourceFolder(container, "portrait.jpg", "3_");
repositoryEntryRelationDao.addRole(participant, sharedFolder, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// participant want to see the file
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(participant.getName(), "A6B7C8"));
// check directories
URI uri = UriBuilder.fromUri(getFolderURI(sharedFolder)).path("files").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<FileVO> links = parseFileArray(body);
Assert.assertNotNull(links);
Assert.assertEquals(1, links.size());
Assert.assertTrue(links.get(0).getHref().contains("3_portrait.jpg"));
// download the file
URI fileUri = UriBuilder.fromUri(getFolderURI(sharedFolder)).path("files").path("3_portrait.jpg").build();
HttpGet fileMethod = conn.createGet(fileUri, "*/*", true);
HttpResponse fileResponse = conn.execute(fileMethod);
Assert.assertEquals(200, fileResponse.getStatusLine().getStatusCode());
byte[] fileBytes = EntityUtils.toByteArray(fileResponse.getEntity());
Assert.assertNotNull(fileBytes);
Assert.assertTrue(fileBytes.length > 10);
conn.shutdown();
}
use of org.olat.repository.handlers.SharedFolderHandler in project openolat by klemens.
the class SharedFolderTest method getFiles_participant.
/**
* Participant can read the files and download them.
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void getFiles_participant() throws IOException, URISyntaxException {
// a shared folder with a participant
Identity owner = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-owner-");
Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("shared-part-");
RepositoryEntry sharedFolder = new SharedFolderHandler().createResource(owner, "Shared 2", "Shared files", null, Locale.ENGLISH);
VFSContainer container = SharedFolderManager.getInstance().getNamedSharedFolder(sharedFolder, true);
copyFileInResourceFolder(container, "portrait.jpg", "3_");
repositoryEntryRelationDao.addRole(participant, sharedFolder, GroupRoles.participant.name());
dbInstance.commitAndCloseSession();
// participant want to see the file
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login(participant.getName(), "A6B7C8"));
// check directories
URI uri = UriBuilder.fromUri(getFolderURI(sharedFolder)).path("files").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<FileVO> links = parseFileArray(body);
Assert.assertNotNull(links);
Assert.assertEquals(1, links.size());
Assert.assertTrue(links.get(0).getHref().contains("3_portrait.jpg"));
// download the file
URI fileUri = UriBuilder.fromUri(getFolderURI(sharedFolder)).path("files").path("3_portrait.jpg").build();
HttpGet fileMethod = conn.createGet(fileUri, "*/*", true);
HttpResponse fileResponse = conn.execute(fileMethod);
Assert.assertEquals(200, fileResponse.getStatusLine().getStatusCode());
byte[] fileBytes = EntityUtils.toByteArray(fileResponse.getEntity());
Assert.assertNotNull(fileBytes);
Assert.assertTrue(fileBytes.length > 10);
conn.shutdown();
}
Aggregations