1010import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
1111import static java .lang .String .format ;
1212import static java .util .UUID .randomUUID ;
13-
14- import org .hamcrest .CoreMatchers ;
15- import org .jboss .resteasy .specimpl .MultivaluedMapImpl ;
16-
17- import static javax .ws .rs .core .HttpHeaders .CONTENT_TYPE ;
1813import static javax .ws .rs .core .MediaType .TEXT_PLAIN ;
19- import static javax .ws .rs .core .Response .Status .OK ;
2014import static org .apache .openejb .util .NetworkUtil .getNextAvailablePort ;
21- import static org .hamcrest .MatcherAssert .assertThat ;
2215import static org .hamcrest .core .Is .is ;
23- import static org .junit .Assert .*;
16+ import static org .junit .Assert .assertEquals ;
17+ import static org .junit .Assert .assertFalse ;
18+ import static org .junit .Assert .assertThat ;
19+ import static org .junit .Assert .assertTrue ;
20+ import static org .junit .Assert .fail ;
2421import static uk .gov .justice .services .test .utils .common .reflection .ReflectionUtils .setField ;
2522
2623import uk .gov .justice .services .file .alfresco .common .AlfrescoRestClient ;
2724import uk .gov .justice .services .file .api .FileOperationException ;
28- import uk .gov .justice .services .test .utils .core .rest .RestClient ;
2925
3026import java .io .IOException ;
3127import java .io .InputStream ;
3228import java .util .Optional ;
3329
3430import javax .ws .rs .ProcessingException ;
35- import javax .ws .rs .core .Response ;
36- import javax .ws .rs .core .MultivaluedMap ;
3731
3832import com .github .tomakehurst .wiremock .junit .WireMockRule ;
3933import org .apache .commons .io .IOUtils ;
@@ -48,17 +42,11 @@ public class AlfrescoFileRequesterIT {
4842 private static final String UNUSED_MIME_TYPE = "text/plain" ;
4943 private static final String UNUSED_FILE_NAME = "file.txt" ;
5044 private static final String ALFRESCO_WORKSPACE_PATH = "/service/api/node/content/workspace/SpacesStore/" ;
51- private static final String ALFRESCO_WORKSPACE_TRANSFORMATION_PATH = "service/api/node/workspace/SpacesStore/" ;
52-
5345
5446 private static int PORT = getNextAvailablePort ();
5547
5648 private static AlfrescoFileRequester fileRequester ;
5749
58- private RestClient restClient ;
59-
60- private MultivaluedMap <String ,Object > headers ;
61-
6250 @ Rule
6351 public WireMockRule wireMock = new WireMockRule (PORT );
6452
@@ -78,6 +66,7 @@ public void shouldRequestFileFromAlfrescoInAttachmentMode() throws Exception {
7866 .withHeader ("cppuid" , equalTo ("user1234" )));
7967 }
8068
69+
8170 @ Test
8271 public void shouldReturnResponseFromAlfresco () throws IOException {
8372 final String fileId = randomUUID ().toString ();
@@ -97,50 +86,6 @@ public void shouldReturnResponseFromAlfresco() throws IOException {
9786
9887 }
9988
100- @ Test
101- public void shouldReturnPdfContentFromAlfresco () throws IOException {
102- final String fileId = randomUUID ().toString ();
103- final String mimeType = "application/pdf" ;
104- final String fileName = "file123.txt" ;
105-
106- restClient = new RestClient ();
107-
108- headers = new MultivaluedMapImpl <>();
109- headers .add ("cppuid" , "user1234" );
110-
111- final Response readMaterialResponseAsPdf = restClient .query (format (basePathWithPort (PORT ) + "/%s%s?transformpdf=true" , ALFRESCO_WORKSPACE_TRANSFORMATION_PATH , fileId ), "*/*" , headers );
112-
113- assertThat (readMaterialResponseAsPdf .getStatus (), is (OK .getStatusCode ()));
114- assertThat (readMaterialResponseAsPdf .getHeaderString (CONTENT_TYPE ), CoreMatchers .equalTo ("application/pdf;charset=UTF-8" ));
115-
116- final Optional <InputStream > inputStream = fileRequester .request (fileId , mimeType , fileName , true );
117- assertTrue (inputStream .isPresent ());
118-
119- assertEquals (IOUtils .toString (inputStream .get ()).length (), readMaterialResponseAsPdf .readEntity (String .class ).length ());
120- }
121-
122- @ Test
123- public void shouldReturnOriginalContentFromAlfresco () throws IOException {
124- final String fileId = randomUUID ().toString ();
125- final String mimeType = "text/plain" ;
126- final String fileName = "file123.txt" ;
127-
128- restClient = new RestClient ();
129-
130- headers = new MultivaluedMapImpl <>();
131- headers .add ("cppuid" , "user1234" );
132-
133- final Response readMaterialResponseAsPdf = restClient .query (format (basePathWithPort (PORT ) + "/%s%s?transformpdf=false" , ALFRESCO_WORKSPACE_TRANSFORMATION_PATH , fileId ), "*/*" , headers );
134-
135- assertThat (readMaterialResponseAsPdf .getStatus (), is (OK .getStatusCode ()));
136- assertThat (readMaterialResponseAsPdf .getHeaderString (CONTENT_TYPE ), CoreMatchers .equalTo ("text/plain;charset=UTF-8" ));
137-
138- final Optional <InputStream > inputStream = fileRequester .request (fileId , mimeType , fileName , false );
139- assertTrue (inputStream .isPresent ());
140-
141- assertEquals (IOUtils .toString (inputStream .get ()).length (), readMaterialResponseAsPdf .readEntity (String .class ).length ());
142- }
143-
14489 @ Test
14590 public void shouldReturnOptionalEmptyFromAlfrescoIfFileIsNotFound () {
14691 final String fileId = randomUUID ().toString ();
@@ -153,6 +98,7 @@ public void shouldReturnOptionalEmptyFromAlfrescoIfFileIsNotFound() {
15398 assertFalse (fileRequester .request (fileId , mimeType , fileName ).isPresent ());
15499 }
155100
101+
156102 @ Test
157103 public void shouldThrowAnExceptionIfAlfrescoServiceReturnedError () {
158104 final String fileId = randomUUID ().toString ();
@@ -169,6 +115,7 @@ public void shouldThrowAnExceptionIfAlfrescoServiceReturnedError() {
169115 }
170116 }
171117
118+
172119 @ Test
173120 public void shouldThrowAnExceptionIfAlfrescoServiceIsUnavailable () {
174121 final String fileId = randomUUID ().toString ();
@@ -184,7 +131,6 @@ public void shouldThrowAnExceptionIfAlfrescoServiceIsUnavailable() {
184131 private static AlfrescoFileRequester alfrescoFileRequesterWith (final String basePath ) {
185132 AlfrescoFileRequester fileRequester = new AlfrescoFileRequester ();
186133 fileRequester .alfrescoWorkspacePath = ALFRESCO_WORKSPACE_PATH ;
187- fileRequester .alfrescoPdfContentWorkspacePath = "/" + ALFRESCO_WORKSPACE_TRANSFORMATION_PATH ;
188134 fileRequester .alfrescoReadUser = "user1234" ;
189135 fileRequester .restClient = new AlfrescoRestClient ();
190136 setField (fileRequester .restClient , "alfrescoBaseUri" , basePath );
0 commit comments