use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionManagerTest method testDeleteRevisions_withSameFile.
/**
* The test create an original file and 3 revisions with exactly
* the same content. We delete the original and the first version.
* We check that version 2 and 3 survives and that the file exists.
*
* @throws IOException
*/
@Test
public void testDeleteRevisions_withSameFile() throws IOException {
OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/ver-" + UUID.randomUUID(), null);
String filename = getRandomName();
VFSLeaf file = rootTest.createChildLeaf(filename);
OutputStream out = file.getOutputStream(false);
InputStream in = VersionManagerTest.class.getResourceAsStream("test.txt");
int byteCopied = IOUtils.copy(in, out);
IOUtils.closeQuietly(in);
assertFalse(byteCopied == 0);
assertTrue(file instanceof Versionable);
// save a first version
Versionable versionedFile = (Versionable) file;
InputStream in1 = VersionManagerTest.class.getResourceAsStream("test.txt");
versionedFile.getVersions().addVersion(id2, "Version 1", in1);
IOUtils.closeQuietly(in1);
// save a second version
InputStream in2 = VersionManagerTest.class.getResourceAsStream("test.txt");
versionedFile.getVersions().addVersion(id2, "Version 2", in2);
IOUtils.closeQuietly(in2);
// save a third version
InputStream in3 = VersionManagerTest.class.getResourceAsStream("test.txt");
versionedFile.getVersions().addVersion(id2, "Version 3", in2);
IOUtils.closeQuietly(in3);
// delete revisions
versionManager.deleteRevisions(versionedFile, versionedFile.getVersions().getRevisions().subList(0, 2));
// check number of versions
VFSItem reloadFile = rootTest.resolve(filename);
assertTrue(reloadFile instanceof Versionable);
Versionable reloadedVersionedFile = (Versionable) reloadFile;
List<VFSRevision> revisions = reloadedVersionedFile.getVersions().getRevisions();
Assert.assertNotNull(revisions);
Assert.assertEquals(1, revisions.size());
// check surviving versions
Assert.assertEquals("Version 2", revisions.get(0).getComment());
Assert.assertEquals("Version 3", reloadedVersionedFile.getVersions().getComment());
// check that the last backup file exists
RevisionFileImpl revision2 = (RevisionFileImpl) revisions.get(0);
VFSLeaf revision2File = revision2.getFile();
Assert.assertNotNull(revision2File);
Assert.assertTrue(revision2File.exists());
// check if there is only one backup file
VFSContainer versionContainer = versionManager.getCanonicalVersionFolder(file.getParentContainer(), false);
Assert.assertNotNull(versionContainer);
List<VFSItem> items = versionContainer.getItems(new SystemItemFilter());
Assert.assertNotNull(items);
Assert.assertEquals(2, items.size());
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionManagerTest method testDeleteRevisions_withMissingRevisionFile.
/**
* The test create an original file and 5 versions. It manually
* delete the physical back up file. We delete the versions
* of the orginal, 1 and 2. At the end, there is only version 4
* and 5.
*
* @throws IOException
*/
@Test
public void testDeleteRevisions_withMissingRevisionFile() throws IOException {
OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/ver-" + UUID.randomUUID(), null);
String filename = getRandomName();
VFSLeaf file = rootTest.createChildLeaf(filename);
OutputStream out = file.getOutputStream(false);
InputStream in = new ByteArrayInputStream("Hello original".getBytes());
int byteCopied = IOUtils.copy(in, out);
IOUtils.closeQuietly(in);
assertFalse(byteCopied == 0);
assertTrue(file instanceof Versionable);
// save a first version
Versionable versionedFile = (Versionable) file;
InputStream in1 = new ByteArrayInputStream("Hello version 1".getBytes());
versionedFile.getVersions().addVersion(id2, "Version 1", in1);
IOUtils.closeQuietly(in1);
// save a second version
InputStream in2 = new ByteArrayInputStream("Hello version 2".getBytes());
versionedFile.getVersions().addVersion(id2, "Version 2", in2);
IOUtils.closeQuietly(in2);
// save a third version
InputStream in3 = new ByteArrayInputStream("Hello version 3".getBytes());
versionedFile.getVersions().addVersion(id2, "Version 3", in3);
IOUtils.closeQuietly(in3);
// save a fourth version
InputStream in4 = new ByteArrayInputStream("Hello version 4".getBytes());
versionedFile.getVersions().addVersion(id2, "Version 4", in4);
IOUtils.closeQuietly(in4);
// save a fourth version
InputStream in5 = new ByteArrayInputStream("Hello version 5".getBytes());
versionedFile.getVersions().addVersion(id2, "Version 5", in5);
IOUtils.closeQuietly(in5);
// delete a specific
VFSRevision rev3 = versionedFile.getVersions().getRevisions().get(3);
RevisionFileImpl toDeleteVersionImpl = (RevisionFileImpl) rev3;
VFSContainer versionContainerAlt = versionManager.getCanonicalVersionFolder(rootTest, false);
VFSItem itemToDelete = versionContainerAlt.resolve(toDeleteVersionImpl.getFilename());
itemToDelete.deleteSilently();
// delete revisions
List<VFSRevision> toDelete = new ArrayList<>(versionedFile.getVersions().getRevisions().subList(0, 3));
versionManager.deleteRevisions(versionedFile, toDelete);
// check number of versions
VFSItem reloadFile = rootTest.resolve(filename);
assertTrue(reloadFile instanceof Versionable);
Versionable reloadedVersionedFile = (Versionable) reloadFile;
List<VFSRevision> revisions = reloadedVersionedFile.getVersions().getRevisions();
Assert.assertNotNull(revisions);
Assert.assertEquals(1, revisions.size());
VFSRevision revision = revisions.get(0);
Assert.assertEquals("Version 4", revision.getComment());
Assert.assertEquals("Version 5", reloadedVersionedFile.getVersions().getComment());
// check if there is only one backup file
VFSContainer versionContainer = versionManager.getCanonicalVersionFolder(file.getParentContainer(), false);
Assert.assertNotNull(versionContainer);
List<VFSItem> items = versionContainer.getItems(new SystemItemFilter());
Assert.assertNotNull(items);
Assert.assertEquals(2, items.size());
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class VersionManagerTest method testVersionChecksum.
@Test
public void testVersionChecksum() throws IOException {
OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/ver-" + UUID.randomUUID(), null);
String filename = getRandomName();
VFSLeaf file = rootTest.createChildLeaf(filename);
OutputStream out = file.getOutputStream(false);
InputStream in = VersionManagerTest.class.getResourceAsStream("test.txt");
int byteCopied = IOUtils.copy(in, out);
IOUtils.closeQuietly(in);
assertFalse(byteCopied == 0);
assertTrue(file instanceof Versionable);
// save a first version
Versionable versionedFile = (Versionable) file;
InputStream in1 = VersionManagerTest.class.getResourceAsStream("test.txt");
versionedFile.getVersions().addVersion(id2, "Version 1", in1);
IOUtils.closeQuietly(in1);
// save a second version
InputStream in2 = VersionManagerTest.class.getResourceAsStream("test.txt");
versionedFile.getVersions().addVersion(id2, "Version 2", in2);
IOUtils.closeQuietly(in2);
// save a third version
InputStream in3 = VersionManagerTest.class.getResourceAsStream("test.txt");
versionedFile.getVersions().addVersion(id2, "Version 3", in2);
IOUtils.closeQuietly(in3);
// check if there is only one backup file
VFSContainer versionContainer = versionManager.getCanonicalVersionFolder(file.getParentContainer(), false);
Assert.assertNotNull(versionContainer);
List<VFSItem> items = versionContainer.getItems(new SystemItemFilter());
Assert.assertNotNull(items);
Assert.assertEquals(2, items.size());
// check number of versions
VFSItem reloadFile = rootTest.resolve(filename);
assertTrue(reloadFile instanceof Versionable);
Versionable reloadedVersionedFile = (Versionable) reloadFile;
List<VFSRevision> revisions = reloadedVersionedFile.getVersions().getRevisions();
Assert.assertNotNull(revisions);
Assert.assertEquals(3, revisions.size());
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class PFManagerTest method provideParticipantContainer.
@Test
public void provideParticipantContainer() {
// prepare
Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-15");
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(initialAuthor);
PFCourseNode pfNode = new PFCourseNode();
pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
// import "Demo course" into the bcroot_junittest
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
Long resourceableId = entry.getOlatResource().getResourceableId();
ICourse course = CourseFactory.loadCourse(resourceableId);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
Identity check3 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-3");
repositoryEntryRelationDao.addRole(check3, entry, GroupRoles.participant.name());
VFSContainer vfsContainer = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, check3, false);
Assert.assertNotNull(vfsContainer);
Assert.assertTrue(vfsContainer.exists());
}
use of org.olat.core.util.vfs.VFSContainer in project OpenOLAT by OpenOLAT.
the class PFManagerTest method provideCoachContainer.
@Test
public void provideCoachContainer() {
// prepare
Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-16");
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(initialAuthor);
PFCourseNode pfNode = new PFCourseNode();
pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
// import "Demo course" into the bcroot_junittest
RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
Long resourceableId = entry.getOlatResource().getResourceableId();
ICourse course = CourseFactory.loadCourse(resourceableId);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
Identity check4 = JunitTestHelper.createAndPersistIdentityAsRndUser("check-4");
repositoryEntryRelationDao.addRole(check4, entry, GroupRoles.coach.name());
VFSContainer vfsContainer = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, check4, false);
Assert.assertNotNull(vfsContainer);
}
Aggregations