Skip to content

Commit f904a53

Browse files
authored
Merge pull request #33 from ccheraa/main
Added a few tests
2 parents 1295f0e + 18e5160 commit f904a53

File tree

2 files changed

+145
-9
lines changed

2 files changed

+145
-9
lines changed

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

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ public void createCollection() {
4141
final String colPath = "/db/fusion-studio-api-test-document-it-col-1";
4242
final ExtractableResponse<Response> collectionResponse = createCollection(colPath);
4343
assertEquals(colPath, collectionResponse.jsonPath().getString("uri"));
44+
readCollection(colPath);
45+
}
46+
47+
@Test
48+
public void createCollectionWithSpaceInName() {
49+
final String colPath = "/db/fusion-studio-api-test-document-it-col 2";
50+
final ExtractableResponse<Response> collectionResponse = createCollection(colPath);
51+
assertEquals(colPath, collectionResponse.jsonPath().getString("uri"));
52+
readCollection(colPath);
53+
}
54+
55+
@Test
56+
public void createCollectionWithPlusInName() {
57+
final String colPath = "/db/fusion-studio-api-test-document-it-col+3";
58+
final ExtractableResponse<Response> collectionResponse = createCollection(colPath);
59+
assertEquals(colPath, collectionResponse.jsonPath().getString("uri"));
60+
readCollection(colPath);
61+
}
62+
63+
@Test
64+
public void createCollectionWithUnicodeCharactersInName() {
65+
final String colPath = "/db/مجموعة-فيوجن-ستوديو";
66+
final ExtractableResponse<Response> collectionResponse = createCollection(colPath);
67+
assertEquals(colPath, collectionResponse.jsonPath().getString("uri"));
68+
readCollection(colPath);
4469
}
4570

4671
@Test
@@ -194,16 +219,54 @@ public void moveCollection() {
194219
body(matchesJsonSchemaInClasspath("collection-schema.json"));
195220
}
196221

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+
197246
private ExtractableResponse<Response> createCollection(final String path) {
198247
return
199-
given().
200-
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
201-
when().
202-
put(getApiBaseUri() + "/collection?uri=" + path).
203-
then().
204-
statusCode(SC_CREATED).
205-
assertThat().
206-
body(matchesJsonSchemaInClasspath("collection-schema.json")).
207-
extract();
248+
given().
249+
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
250+
when().
251+
put(getApiBaseUri() + "/collection?uri=" + path).
252+
then().
253+
statusCode(SC_CREATED).
254+
assertThat().
255+
body(matchesJsonSchemaInClasspath("collection-schema.json")).
256+
extract();
257+
}
258+
259+
private ExtractableResponse<Response> readCollection(final String path) {
260+
return
261+
given().
262+
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
263+
when().
264+
get(getApiBaseUri() + "/explorer?uri=" + path).
265+
then().
266+
statusCode(SC_OK).
267+
assertThat().
268+
body(matchesJsonSchemaInClasspath("collection-schema.json")).
269+
body("uri", equalTo(path)).
270+
extract();
208271
}
209272
}

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

Lines changed: 73 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,12 +28,14 @@
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;
3335
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
3436
import static java.nio.charset.StandardCharsets.UTF_8;
3537
import static org.apache.http.HttpStatus.*;
38+
import static org.hamcrest.core.IsEqual.equalTo;
3639
import static org.junit.jupiter.api.Assertions.*;
3740

3841
public 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

Comments
 (0)