question: public void test_create_update ( ) throws IOException { final String id = "test" ; final Map < String , Object > metadata = new HashMap < String , Object > ( ) ; metadata . put ( FileMetadataSchema . ID , id ) ; metadata . put ( "foo" , "bar" ) ; final int version0 ; final long createTime0 ; final byte [ ] expected0 = new byte [ ] { 1 , 2 , 3 } ; { version0 = repo . create ( metadata ) ; metadata . put ( FileMetadataSchema . VERSION , Integer . valueOf ( version0 ) ) ; assertEquals ( "version" , 0 , version0 ) ; RepositoryDocumentImpl doc = ( RepositoryDocumentImpl ) repo . read ( id ) ; createTime0 = doc . getVersionCreateTime ( ) ; Map < String , Object > actual = doc . asMap ( ) ; assertEquals ( "id" , id , actual . get ( FileMetadataSchema . ID ) ) ; assertEquals ( "version" , version0 , actual . get ( FileMetadataSchema . VERSION ) ) ; assertEquals ( "user property" , "bar" , actual . get ( "foo" ) ) ; assertEquals ( "size" , metadata . size ( ) , actual . size ( ) ) ; repo . copyStream ( id , version0 , new ByteArrayInputStream ( expected0 ) ) ; assertEquals ( "version0" , expected0 , read ( repo . inputStream ( id , version0 ) ) ) ; } final int version1 ; final long createTime1 ; final byte [ ] expected1 = new byte [ ] { 4 , 5 , 6 } ; { metadata . put ( "foo" , "baz" ) ; DocumentImpl doc1 = new DocumentImpl ( metadata ) ; doc1 . copyStream ( expected1 ) ; version1 = repo . update ( doc1 ) ; assertEquals ( "version" , 1 , version1 ) ; metadata . put ( FileMetadataSchema . VERSION , Integer . valueOf ( version1 ) ) ; RepositoryDocumentImpl doc = ( RepositoryDocumentImpl ) repo . read ( id ) ; createTime1 = doc . getVersionCreateTime ( ) ; assertNotSame ( "createTime" , 0L , createTime1 ) ; assertNotSame ( "createTime" , createTime0 , createTime1 ) ; Map < String , Object > actual = doc . asMap ( ) ; assertEquals ( "id" , id , actual . get ( FileMetadataSchema . ID ) ) ; assertEquals ( "version" , version1 , actual . get ( FileMetadataSchema . VERSION ) ) ; assertEquals ( "user property" , "baz" , actual . get ( "foo" ) ) ; assertEquals ( "size" , metadata . size ( ) , actual . size ( ) ) ; assertEquals ( "version1" , expected1 , read ( repo . inputStream ( id , version1 ) ) ) ; assertEquals ( "version0" , new byte [ ] { } , read ( repo . inputStream ( id , version0 ) ) ) ; { ITPS tps = repo . readMetadata ( id , createTime1 - 1L ) ; ITPV tpv = tps . get ( FileMetadataSchema . VERSION ) ; assertEquals ( "version" , null , tpv . getValue ( ) ) ; } } }
target:  Create an empty file and write some data on it. Then update its metadata, verify the new metadata and the updated version, and then write some data on the new version. Verify the both file versions can be read.