repository = new MockUnifiedRepository( new MockUserProvider() );
repositoryWS = new DefaultUnifiedRepositoryWebService( repository );
}
public void testFileMetadata() throws Exception {
final RepositoryFile testfile =
repository.createFile( repository.getFile( "/etc" ).getId(), new RepositoryFile.Builder( "testfile" ).build(),
new SimpleRepositoryFileData( new ByteArrayInputStream( "test".getBytes() ),
"UTF-8", "text/plain" ), null );
//CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure the repository is setup correctly
assertNotNull( testfile );
assertNotNull( testfile.getId() );
final Map<String, Serializable> fileMetadata = repository.getFileMetadata( testfile.getId() );
assertNotNull( fileMetadata );
assertEquals( 0, fileMetadata.size() );
}
final List<StringKeyStringValueDto> metadata = new ArrayList<StringKeyStringValueDto>();
metadata.add( new StringKeyStringValueDto( "sample key", "sample value" ) );
metadata.add( new StringKeyStringValueDto( "complex key?", "\"an even more 'complex' value\"! {and them some}" ) );
repositoryWS.setFileMetadata( testfile.getId().toString(), metadata );
//CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure the repository sees the metadata
assertNotNull( testfile );
assertNotNull( testfile.getId() );
final Map<String, Serializable> fileMetadata = repository.getFileMetadata( testfile.getId() );
assertNotNull( fileMetadata );
assertEquals( 2, fileMetadata.size() );
}
//CHECKSTYLE IGNORE AvoidNestedBlocks FOR NEXT 3 LINES
{
// Make sure we can get the same metadata back via the web service
final List<StringKeyStringValueDto> fileMetadata = repositoryWS.getFileMetadata( testfile.getId().toString() );
assertNotNull( fileMetadata );
assertEquals( 2, fileMetadata.size() );
assertTrue( metadata.get( 0 ).equals( fileMetadata.get( 0 ) ) || metadata.get( 0 )
.equals( fileMetadata.get( 1 ) ) );
assertTrue( metadata.get( 1 ).equals( fileMetadata.get( 0 ) ) || metadata.get( 1 )