1212import static org .hamcrest .Matchers .is ;
1313import static org .hamcrest .Matchers .notNullValue ;
1414import static org .junit .Assert .assertFalse ;
15+ import static org .junit .Assert .assertTrue ;
1516import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
1617import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
1718import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
@@ -84,16 +85,16 @@ public void setup() throws Exception {
8485 .build ();
8586
8687 // create empty THUMBNAIL bundle
87- bundleService .create (context , publicItem , "THUMBNAIL " );
88-
89- String bitstreamContent = "ThisIsSomeDummyText" ;
90- InputStream is = IOUtils . toInputStream ( bitstreamContent , CharEncoding . UTF_8 );
91- bts = BitstreamBuilder .
92- createBitstream ( context , publicItem , is )
93- . withName ( "Bitstream " )
94- . withDescription ( "Description " )
95- . withMimeType ( "application/x-gzip" )
96- . build ();
88+ bundleService .create (context , publicItem , "ORIGINAL " );
89+
90+ try ( InputStream is = getClass (). getResourceAsStream ( "assetstore/logos.tgz" )) {
91+ bts = BitstreamBuilder .
92+ createBitstream ( context , publicItem , is )
93+ . withName ( "Bitstream" )
94+ . withDescription ( "Description " )
95+ . withMimeType ( "application/x-gtar " )
96+ . build ();
97+ }
9798
9899 // Allow composing of file preview in the config
99100 configurationService .setProperty ("create.file-preview.on-item-page-load" , true );
@@ -116,6 +117,8 @@ public void findByHandle() throws Exception {
116117 // There is no restriction, so the user could preview the file
117118 boolean canPreview = true ;
118119
120+ assertFalse ("Expects preview content not created yet." , previewContentService .hasPreview (context , bts ));
121+
119122 getClient ().perform (get (METADATABITSTREAM_SEARCH_BY_HANDLE_ENDPOINT )
120123 .param ("handle" , publicItem .getHandle ())
121124 .param ("fileGrpType" , FILE_GRP_TYPE ))
@@ -135,13 +138,13 @@ public void findByHandle() throws Exception {
135138 .value (hasItem (is ((int ) bts .getSizeBytes ()))))
136139 .andExpect (jsonPath ("$._embedded.metadatabitstreams[*].canPreview" )
137140 .value (Matchers .containsInAnyOrder (Matchers .is (canPreview ))))
138- .andExpect (jsonPath ("$._embedded.metadatabitstreams[* ].fileInfo" ).exists ( ))
141+ .andExpect (jsonPath ("$._embedded.metadatabitstreams[0 ].fileInfo" ).value ( Matchers . hasSize ( 2 ) ))
139142 .andExpect (jsonPath ("$._embedded.metadatabitstreams[*].checksum" )
140143 .value (Matchers .containsInAnyOrder (Matchers .containsString (bts .getChecksum ()))))
141144 .andExpect (jsonPath ("$._embedded.metadatabitstreams[*].href" )
142145 .value (Matchers .containsInAnyOrder (Matchers .containsString (url ))));
143146
144-
147+ assertTrue ( "Expects preview content created and stored." , previewContentService . hasPreview ( context , bts ));
145148 }
146149
147150 @ Test
0 commit comments