1212import static java .util .UUID .randomUUID ;
1313import static javax .ws .rs .core .MediaType .TEXT_PLAIN ;
1414import static org .apache .openejb .util .NetworkUtil .getNextAvailablePort ;
15+ import static org .hamcrest .MatcherAssert .assertThat ;
1516import static org .hamcrest .core .Is .is ;
16- import static org .junit .Assert .assertEquals ;
17- import static org .junit .Assert .assertFalse ;
18- import static org .junit .Assert .assertThat ;
1917import static org .junit .Assert .assertTrue ;
18+ import static org .junit .Assert .assertFalse ;
2019import static org .junit .Assert .fail ;
20+ import static org .junit .Assert .assertEquals ;
2121import static uk .gov .justice .services .test .utils .common .reflection .ReflectionUtils .setField ;
2222
2323import uk .gov .justice .services .file .alfresco .common .AlfrescoRestClient ;
@@ -42,11 +42,14 @@ public class AlfrescoFileRequesterIT {
4242 private static final String UNUSED_MIME_TYPE = "text/plain" ;
4343 private static final String UNUSED_FILE_NAME = "file.txt" ;
4444 private static final String ALFRESCO_WORKSPACE_PATH = "/service/api/node/content/workspace/SpacesStore/" ;
45+ private static final String ALFRESCO_WORKSPACE_PDF_TRANSFORMATION_PATH = "/service/api/requestpdf/workspace/SpacesStore/" ;
46+
4547
4648 private static int PORT = getNextAvailablePort ();
4749
4850 private static AlfrescoFileRequester fileRequester ;
4951
52+
5053 @ Rule
5154 public WireMockRule wireMock = new WireMockRule (PORT );
5255
@@ -66,7 +69,6 @@ public void shouldRequestFileFromAlfrescoInAttachmentMode() throws Exception {
6669 .withHeader ("cppuid" , equalTo ("user1234" )));
6770 }
6871
69-
7072 @ Test
7173 public void shouldReturnResponseFromAlfresco () throws IOException {
7274 final String fileId = randomUUID ().toString ();
@@ -86,6 +88,24 @@ public void shouldReturnResponseFromAlfresco() throws IOException {
8688
8789 }
8890
91+ @ Test
92+ public void shouldReturnPdfContentFromAlfresco () throws IOException {
93+ final String fileId = randomUUID ().toString ();
94+ final String mimeType = "application/pdf" ;
95+ final String fileName = "file123.txt" ;
96+ final String fileContent = "abcd" ;
97+
98+ stubFor (get (urlMatching (format ("/alfresco%s%s/%s" , ALFRESCO_WORKSPACE_PDF_TRANSFORMATION_PATH , fileId , fileName )))
99+ .withHeader ("cppuid" , equalTo ("user1234" ))
100+ .willReturn (aResponse ().withHeader ("Content-Type" , mimeType ).withBody (fileContent )));
101+
102+ final Optional <InputStream > inputStream = fileRequester .requestPdf (fileId , fileName );
103+ assertTrue (inputStream .isPresent ());
104+
105+ assertThat (IOUtils .toString (inputStream .get ()), is (fileContent ));
106+ }
107+
108+
89109 @ Test
90110 public void shouldReturnOptionalEmptyFromAlfrescoIfFileIsNotFound () {
91111 final String fileId = randomUUID ().toString ();
@@ -98,7 +118,6 @@ public void shouldReturnOptionalEmptyFromAlfrescoIfFileIsNotFound() {
98118 assertFalse (fileRequester .request (fileId , mimeType , fileName ).isPresent ());
99119 }
100120
101-
102121 @ Test
103122 public void shouldThrowAnExceptionIfAlfrescoServiceReturnedError () {
104123 final String fileId = randomUUID ().toString ();
@@ -115,7 +134,6 @@ public void shouldThrowAnExceptionIfAlfrescoServiceReturnedError() {
115134 }
116135 }
117136
118-
119137 @ Test
120138 public void shouldThrowAnExceptionIfAlfrescoServiceIsUnavailable () {
121139 final String fileId = randomUUID ().toString ();
@@ -131,6 +149,7 @@ public void shouldThrowAnExceptionIfAlfrescoServiceIsUnavailable() {
131149 private static AlfrescoFileRequester alfrescoFileRequesterWith (final String basePath ) {
132150 AlfrescoFileRequester fileRequester = new AlfrescoFileRequester ();
133151 fileRequester .alfrescoWorkspacePath = ALFRESCO_WORKSPACE_PATH ;
152+ fileRequester .alfrescoPdfContentWorkspacePath = ALFRESCO_WORKSPACE_PDF_TRANSFORMATION_PATH ;
134153 fileRequester .alfrescoReadUser = "user1234" ;
135154 fileRequester .restClient = new AlfrescoRestClient ();
136155 setField (fileRequester .restClient , "alfrescoBaseUri" , basePath );
0 commit comments