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 ;
2424import uk .gov .justice .services .file .api .FileOperationException ;
25+ import uk .gov .justice .services .test .utils .core .rest .RestClient ;
2526
2627import java .io .IOException ;
2728import java .io .InputStream ;
2829import java .util .Optional ;
2930
3031import javax .ws .rs .ProcessingException ;
32+ import javax .ws .rs .core .MultivaluedMap ;
3133
3234import com .github .tomakehurst .wiremock .junit .WireMockRule ;
3335import org .apache .commons .io .IOUtils ;
@@ -42,11 +44,17 @@ public class AlfrescoFileRequesterIT {
4244 private static final String UNUSED_MIME_TYPE = "text/plain" ;
4345 private static final String UNUSED_FILE_NAME = "file.txt" ;
4446 private static final String ALFRESCO_WORKSPACE_PATH = "/service/api/node/content/workspace/SpacesStore/" ;
47+ private static final String ALFRESCO_WORKSPACE_PDF_TRANSFORMATION_PATH = "/service/api/requestpdf/workspace/SpacesStore/" ;
48+
4549
4650 private static int PORT = getNextAvailablePort ();
4751
4852 private static AlfrescoFileRequester fileRequester ;
4953
54+ private RestClient restClient ;
55+
56+ private MultivaluedMap <String , Object > headers ;
57+
5058 @ Rule
5159 public WireMockRule wireMock = new WireMockRule (PORT );
5260
@@ -66,7 +74,6 @@ public void shouldRequestFileFromAlfrescoInAttachmentMode() throws Exception {
6674 .withHeader ("cppuid" , equalTo ("user1234" )));
6775 }
6876
69-
7077 @ Test
7178 public void shouldReturnResponseFromAlfresco () throws IOException {
7279 final String fileId = randomUUID ().toString ();
@@ -86,6 +93,24 @@ public void shouldReturnResponseFromAlfresco() throws IOException {
8693
8794 }
8895
96+ @ Test
97+ public void shouldReturnPdfContentFromAlfresco () throws IOException {
98+ final String fileId = randomUUID ().toString ();
99+ final String mimeType = "application/pdf" ;
100+ final String fileName = "file123.txt" ;
101+ final String fileContent = "abcd" ;
102+
103+ stubFor (get (urlMatching (format ("/alfresco%s%s/%s" , ALFRESCO_WORKSPACE_PDF_TRANSFORMATION_PATH , fileId , fileName )))
104+ .withHeader ("cppuid" , equalTo ("user1234" ))
105+ .willReturn (aResponse ().withHeader ("Content-Type" , mimeType ).withBody (fileContent )));
106+
107+ final Optional <InputStream > inputStream = fileRequester .requestPdf (fileId , fileName );
108+ assertTrue (inputStream .isPresent ());
109+
110+ assertThat (IOUtils .toString (inputStream .get ()), is (fileContent ));
111+ }
112+
113+
89114 @ Test
90115 public void shouldReturnOptionalEmptyFromAlfrescoIfFileIsNotFound () {
91116 final String fileId = randomUUID ().toString ();
@@ -98,7 +123,6 @@ public void shouldReturnOptionalEmptyFromAlfrescoIfFileIsNotFound() {
98123 assertFalse (fileRequester .request (fileId , mimeType , fileName ).isPresent ());
99124 }
100125
101-
102126 @ Test
103127 public void shouldThrowAnExceptionIfAlfrescoServiceReturnedError () {
104128 final String fileId = randomUUID ().toString ();
@@ -115,7 +139,6 @@ public void shouldThrowAnExceptionIfAlfrescoServiceReturnedError() {
115139 }
116140 }
117141
118-
119142 @ Test
120143 public void shouldThrowAnExceptionIfAlfrescoServiceIsUnavailable () {
121144 final String fileId = randomUUID ().toString ();
@@ -131,6 +154,7 @@ public void shouldThrowAnExceptionIfAlfrescoServiceIsUnavailable() {
131154 private static AlfrescoFileRequester alfrescoFileRequesterWith (final String basePath ) {
132155 AlfrescoFileRequester fileRequester = new AlfrescoFileRequester ();
133156 fileRequester .alfrescoWorkspacePath = ALFRESCO_WORKSPACE_PATH ;
157+ fileRequester .alfrescoPdfContentWorkspacePath = ALFRESCO_WORKSPACE_PDF_TRANSFORMATION_PATH ;
134158 fileRequester .alfrescoReadUser = "user1234" ;
135159 fileRequester .restClient = new AlfrescoRestClient ();
136160 setField (fileRequester .restClient , "alfrescoBaseUri" , basePath );
0 commit comments