final String expectedMimeType = "text/plain";
final String expectedName = "helloworld.[~!@#$%^&*(){}|.,]-=_+|;'?<:>~.xaction";
final String expectedAbsolutePath =
ClientRepositoryPaths.getUserHomeFolderPath( USERNAME_SUZY ) + "/helloworld.[~!@#$%^&*(){}|.,]-=_+|;'?<:>~.xaction";
final SimpleRepositoryFileData content =
new SimpleRepositoryFileData( dataStream, expectedEncoding, expectedMimeType );
RepositoryFile newFile =
repo.createFile( parentFolder.getId(), new RepositoryFile.Builder( expectedName ).versioned( true ).build(),
content, null );
// Make sure the file was created
RepositoryFile foundFile = repo.getFile( expectedAbsolutePath );
assertNotNull( foundFile );
// Modify file
final SimpleRepositoryFileData modContent =
new SimpleRepositoryFileData( modDataStream, expectedEncoding, expectedMimeType );
repo.updateFile( foundFile, modContent, null );
// Verify versions
List<VersionSummary> origVerList = repo.getVersionSummaries( foundFile.getId() );
assertEquals( 2, origVerList.size() );
SimpleRepositoryFileData result =
repo.getDataAtVersionForRead( foundFile.getId(), origVerList.get( 0 ).getId(), SimpleRepositoryFileData.class );
SimpleRepositoryFileData modResult =
repo.getDataAtVersionForRead( foundFile.getId(), origVerList.get( 1 ).getId(), SimpleRepositoryFileData.class );
assertEquals( expectedDataString, IOUtils.toString( result.getStream(), expectedEncoding ) );
assertEquals( expectedModDataString, IOUtils.toString( modResult.getStream(), expectedEncoding ) );
// Remove first version
repo.deleteFileAtVersion( foundFile.getId(), origVerList.get( 0 ).getId() );
// Verify version removal
List<VersionSummary> newVerList = repo.getVersionSummaries( foundFile.getId() );
assertEquals( 1, newVerList.size() );
SimpleRepositoryFileData newModResult =
repo.getDataAtVersionForRead( foundFile.getId(), newVerList.get( 0 ).getId(), SimpleRepositoryFileData.class );
assertEquals( expectedModDataString, IOUtils.toString( newModResult.getStream(), expectedEncoding ) );
}