1717 */
1818package com .fusiondb .studio .api ;
1919
20+ import io .restassured .http .Header ;
2021import io .restassured .response .ExtractableResponse ;
2122import io .restassured .response .Response ;
2223import org .junit .jupiter .api .Assumptions ;
2728import static com .evolvedbinary .j8fu .tuple .Tuple .Tuple ;
2829import static com .fusiondb .studio .api .API .*;
2930import static io .restassured .RestAssured .given ;
31+ import static io .restassured .RestAssured .when ;
3032import static io .restassured .http .ContentType .JSON ;
3133import static io .restassured .http .ContentType .XML ;
3234import static io .restassured .internal .RestAssuredResponseOptionsGroovyImpl .BINARY ;
3335import static io .restassured .module .jsv .JsonSchemaValidator .matchesJsonSchemaInClasspath ;
3436import static java .nio .charset .StandardCharsets .UTF_8 ;
3537import static org .apache .http .HttpStatus .*;
38+ import static org .hamcrest .core .IsEqual .equalTo ;
3639import static org .junit .jupiter .api .Assertions .*;
3740
3841public class DocumentIT {
@@ -44,6 +47,37 @@ public void createXml() {
4447 final ExtractableResponse <Response > documentResponse = createXml (docPath , "<time>" + now + "</time>" );
4548 assertEquals (docPath , documentResponse .jsonPath ().getString ("uri" ));
4649 assertFalse (documentResponse .jsonPath ().getBoolean ("binaryDoc" ));
50+ readDocument (docPath );
51+ }
52+
53+ @ Test
54+ public void createXmlWithSpaceInName () {
55+ final String docPath = "/db/fusion-studio-api-test-document-it 2.xml" ;
56+ final long now = System .currentTimeMillis ();
57+ final ExtractableResponse <Response > documentResponse = createXml (docPath , "<time>" + now + "</time>" );
58+ assertEquals (docPath , documentResponse .jsonPath ().getString ("uri" ));
59+ assertFalse (documentResponse .jsonPath ().getBoolean ("binaryDoc" ));
60+ readDocument (docPath );
61+ }
62+
63+ @ Test
64+ public void createXmlWithPlusInName () {
65+ final String docPath = "/db/fusion-studio-api-test-document-it+3.xml" ;
66+ final long now = System .currentTimeMillis ();
67+ final ExtractableResponse <Response > documentResponse = createXml (docPath , "<time>" + now + "</time>" );
68+ assertEquals (docPath , documentResponse .jsonPath ().getString ("uri" ));
69+ assertFalse (documentResponse .jsonPath ().getBoolean ("binaryDoc" ));
70+ readDocument (docPath );
71+ }
72+
73+ @ Test
74+ public void createXmlWithUnicodeCharactersInName () {
75+ final String docPath = "/db/وثيقة-فيوجن-ستوديو.xml-4" ;
76+ final long now = System .currentTimeMillis ();
77+ final ExtractableResponse <Response > documentResponse = createXml (docPath , "<time >" + now + "</time>" );
78+ assertEquals (docPath , documentResponse .jsonPath ().getString ("uri" ));
79+ assertFalse (documentResponse .jsonPath ().getBoolean ("binaryDoc" ));
80+ readDocument (docPath );
4781 }
4882
4983 @ Test
@@ -55,6 +89,31 @@ public void createBinary() {
5589 assertTrue (documentResponse .jsonPath ().getBoolean ("binaryDoc" ));
5690 }
5791
92+ @ Test
93+ public void deleteDocument () {
94+ final String documentPath = "/db/fusion-studio-api-test-document-it-col-6" ;
95+
96+ // 1. create a document
97+ final long now = System .currentTimeMillis ();
98+ ExtractableResponse <Response > collectionResponse = createXml (documentPath , "<time>" + now + "</time>" );
99+ assertEquals (documentPath , collectionResponse .jsonPath ().getString ("uri" ));
100+
101+ // 2. delete the document
102+ given ().
103+ auth ().preemptive ().basic (DEFAULT_ADMIN_USERNAME , DEFAULT_ADMIN_PASSWORD ).
104+ header (new Header ("x-fs-move-source" , documentPath )).
105+ when ().
106+ delete (getApiBaseUri () + "/document?uri=" + documentPath ).
107+ then ().
108+ statusCode (SC_NO_CONTENT );
109+
110+ // 3. check the document no longer exists
111+ when ().
112+ get (getApiBaseUri () + "/explorer?uri=" + documentPath ).
113+ then ().
114+ statusCode (SC_FORBIDDEN ); //TODO(AR) should this be SC_NOT_FOUND?
115+ }
116+
58117 @ Test
59118 public void updateOwnerAndGroup () {
60119 final String docPath = "/db/fusion-studio-api-test-document-it-3.xml" ;
@@ -200,4 +259,18 @@ private ExtractableResponse<Response> createXml(final String path, final String
200259 body (matchesJsonSchemaInClasspath ("document-schema.json" )).
201260 extract ();
202261 }
262+
263+ private ExtractableResponse <Response > readDocument (final String path ) {
264+ return
265+ given ().
266+ auth ().preemptive ().basic (DEFAULT_ADMIN_USERNAME , DEFAULT_ADMIN_PASSWORD ).
267+ when ().
268+ get (getApiBaseUri () + "/explorer?uri=" + path ).
269+ then ().
270+ statusCode (SC_OK ).
271+ assertThat ().
272+ body (matchesJsonSchemaInClasspath ("document-schema.json" )).
273+ body ("uri" , equalTo (path )).
274+ extract ();
275+ }
203276}
0 commit comments