Skip to content

Commit 18e5160

Browse files
committed
Added tests for deleting items
1 parent 994869a commit 18e5160

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/test/java/com/fusiondb/studio/api/CollectionIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,30 @@ public void moveCollection() {
219219
body(matchesJsonSchemaInClasspath("collection-schema.json"));
220220
}
221221

222+
@Test
223+
public void deleteCollection() {
224+
final String collectionPath = "/db/fusion-studio-api-test-document-it-col-6";
225+
226+
// 1. create a collection
227+
ExtractableResponse<Response> collectionResponse = createCollection(collectionPath);
228+
assertEquals(collectionPath, collectionResponse.jsonPath().getString("uri"));
229+
230+
// 2. delete the collection
231+
given().
232+
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
233+
header(new Header("x-fs-move-source", collectionPath)).
234+
when().
235+
delete(getApiBaseUri() + "/collection?uri=" + collectionPath).
236+
then().
237+
statusCode(SC_NO_CONTENT);
238+
239+
// 3. check the collection no longer exists
240+
when().
241+
get(getApiBaseUri() + "/explorer?uri=" + collectionPath).
242+
then().
243+
statusCode(SC_FORBIDDEN); //TODO(AR) should this be SC_NOT_FOUND?
244+
}
245+
222246
private ExtractableResponse<Response> createCollection(final String path) {
223247
return
224248
given().

src/test/java/com/fusiondb/studio/api/DocumentIT.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package com.fusiondb.studio.api;
1919

20+
import io.restassured.http.Header;
2021
import io.restassured.response.ExtractableResponse;
2122
import io.restassured.response.Response;
2223
import org.junit.jupiter.api.Assumptions;
@@ -27,6 +28,7 @@
2728
import static com.evolvedbinary.j8fu.tuple.Tuple.Tuple;
2829
import static com.fusiondb.studio.api.API.*;
2930
import static io.restassured.RestAssured.given;
31+
import static io.restassured.RestAssured.when;
3032
import static io.restassured.http.ContentType.JSON;
3133
import static io.restassured.http.ContentType.XML;
3234
import static io.restassured.internal.RestAssuredResponseOptionsGroovyImpl.BINARY;
@@ -87,6 +89,31 @@ public void createBinary() {
8789
assertTrue(documentResponse.jsonPath().getBoolean("binaryDoc"));
8890
}
8991

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+
90117
@Test
91118
public void updateOwnerAndGroup() {
92119
final String docPath = "/db/fusion-studio-api-test-document-it-3.xml";

0 commit comments

Comments
 (0)