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 );
Date beginTime = Calendar.getInstance().getTime();
Thread.sleep( 1000 ); // when the test runs too fast, begin and lastModifiedDate are the same; manual pause
Calendar cal = Calendar.getInstance( Locale.US );
SimpleDateFormat df = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss Z", Locale.US );
cal.setTime( df.parse( "Wed, 4 Jul 2000 12:08:56 -0700" ) );
RepositoryFile newFile =
repo.createFile( parentFolder.getId(), new RepositoryFile.Builder( expectedName ).hidden( true ).versioned(
true ).createdDate( cal.getTime() ).build(), content, null );
assertEquals( cal.getTime(), repo.getVersionSummaries( newFile.getId() ).get( 0 ).getDate() );
Date endTime = Calendar.getInstance().getTime();
assertTrue( beginTime.before( newFile.getLastModifiedDate() ) );
assertTrue( endTime.after( newFile.getLastModifiedDate() ) );
assertNotNull( newFile.getId() );
RepositoryFile foundFile = repo.getFile( expectedAbsolutePath );
assertNotNull( foundFile );
assertEquals( expectedName, foundFile.getName() );
assertEquals( expectedAbsolutePath, foundFile.getPath() );
assertNotNull( foundFile.getCreatedDate() );
assertNotNull( foundFile.getLastModifiedDate() );
assertTrue( foundFile.isHidden() );
assertTrue( foundFile.getFileSize() > 0 );
SimpleRepositoryFileData contentFromRepo = repo.getDataForRead( foundFile.getId(), SimpleRepositoryFileData.class );
assertEquals( expectedEncoding, contentFromRepo.getEncoding() );
assertEquals( expectedMimeType, contentFromRepo.getMimeType() );
assertEquals( expectedDataString, IOUtils.toString( contentFromRepo.getStream(), expectedEncoding ) );
}