Skip to content

Commit 0e11344

Browse files
committed
Add tests around Collection Move and Copy
Closes #28
1 parent fc1e184 commit 0e11344

File tree

3 files changed

+112
-3
lines changed

3 files changed

+112
-3
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@
9999
<scope>test</scope>
100100
</dependency>
101101

102+
<dependency>
103+
<groupId>org.hamcrest</groupId>
104+
<artifactId>hamcrest</artifactId>
105+
<version>2.2</version>
106+
<scope>test</scope>
107+
</dependency>
108+
102109
</dependencies>
103110

104111
<build>

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

Lines changed: 81 additions & 3 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.Test;
@@ -26,13 +27,12 @@
2627
import static com.evolvedbinary.j8fu.tuple.Tuple.Tuple;
2728
import static com.fusiondb.studio.api.API.*;
2829
import static io.restassured.RestAssured.given;
30+
import static io.restassured.RestAssured.when;
2931
import static io.restassured.http.ContentType.JSON;
30-
import static io.restassured.http.ContentType.XML;
31-
import static io.restassured.internal.RestAssuredResponseOptionsGroovyImpl.BINARY;
3232
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
33-
import static java.nio.charset.StandardCharsets.UTF_8;
3433
import static org.apache.http.HttpStatus.*;
3534
import static org.junit.jupiter.api.Assertions.*;
35+
import static org.hamcrest.core.IsEqual.equalTo;
3636

3737
public class CollectionIT {
3838

@@ -116,6 +116,84 @@ public void updateMode() {
116116
assertEquals("rwxr-----", collectionResponse.jsonPath().getString("mode"));
117117
}
118118

119+
@Test
120+
public void copyCollection() {
121+
final String collectionPath = "/db/fusion-studio-api-test-document-it-col-4";
122+
123+
// 1. create the source collection
124+
ExtractableResponse<Response> collectionResponse = createCollection(collectionPath);
125+
assertEquals(collectionPath, collectionResponse.jsonPath().getString("uri"));
126+
127+
// 2. copy the source collection
128+
final String destCollectionPath = "/db/fusion-studio-api-test-document-it-col-4-copy";
129+
collectionResponse = given().
130+
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
131+
header(new Header("x-fs-copy-source", collectionPath)).
132+
when().
133+
put(getApiBaseUri() + "/collection?uri=" + destCollectionPath).
134+
then().
135+
statusCode(SC_CREATED).
136+
assertThat().
137+
header("Content-Location", equalTo(destCollectionPath)).
138+
body(matchesJsonSchemaInClasspath("collection-schema.json")).
139+
extract();
140+
assertEquals(destCollectionPath, collectionResponse.jsonPath().getString("uri"));
141+
142+
// 3. check the source collection still exists
143+
when().
144+
get(getApiBaseUri() + "/explorer?uri=" + collectionPath).
145+
then().
146+
statusCode(SC_OK).
147+
assertThat().
148+
body(matchesJsonSchemaInClasspath("collection-schema.json"));
149+
150+
// 4. check the destination collection, i.e. the copy, exists
151+
when().
152+
get(getApiBaseUri() + "/explorer?uri=" + destCollectionPath).
153+
then().
154+
statusCode(SC_OK).
155+
assertThat().
156+
body(matchesJsonSchemaInClasspath("collection-schema.json"));
157+
}
158+
159+
@Test
160+
public void moveCollection() {
161+
final String collectionPath = "/db/fusion-studio-api-test-document-it-col-5";
162+
163+
// 1. create the source collection
164+
ExtractableResponse<Response> collectionResponse = createCollection(collectionPath);
165+
assertEquals(collectionPath, collectionResponse.jsonPath().getString("uri"));
166+
167+
// 2. move the source collection
168+
final String destCollectionPath = "/db/fusion-studio-api-test-document-it-col-5-moved";
169+
collectionResponse = given().
170+
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
171+
header(new Header("x-fs-move-source", collectionPath)).
172+
when().
173+
put(getApiBaseUri() + "/collection?uri=" + destCollectionPath).
174+
then().
175+
statusCode(SC_CREATED).
176+
assertThat().
177+
header("Content-Location", equalTo(destCollectionPath)).
178+
body(matchesJsonSchemaInClasspath("collection-schema.json")).
179+
extract();
180+
assertEquals(destCollectionPath, collectionResponse.jsonPath().getString("uri"));
181+
182+
// 3. check the source collection no longer exists
183+
when().
184+
get(getApiBaseUri() + "/explorer?uri=" + collectionPath).
185+
then().
186+
statusCode(SC_FORBIDDEN); //TODO(AR) should this be SC_NOT_FOUND?
187+
188+
// 4. check the destination collection, i.e. the moved collection, exists
189+
when().
190+
get(getApiBaseUri() + "/explorer?uri=" + destCollectionPath).
191+
then().
192+
statusCode(SC_OK).
193+
assertThat().
194+
body(matchesJsonSchemaInClasspath("collection-schema.json"));
195+
}
196+
119197
private ExtractableResponse<Response> createCollection(final String path) {
120198
return
121199
given().

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ public void db() {
4848
body(matchesJsonSchemaInClasspath("explorer-schema.json"));
4949
}
5050

51+
@Test
52+
public void noSuchCollection() {
53+
when().
54+
get(getApiBaseUri() + "/explorer?uri=/db/no-such-collection").
55+
then().
56+
statusCode(SC_FORBIDDEN); //TODO(AR) should this be SC_NOT_FOUND?
57+
}
58+
59+
@Test
60+
public void noSuchXmlDocument() {
61+
when().
62+
get(getApiBaseUri() + "/explorer?uri=/db/no-such-document.xml").
63+
then().
64+
statusCode(SC_FORBIDDEN); //TODO(AR) should this be SC_NOT_FOUND?
65+
}
66+
67+
@Test
68+
public void noSuchBinaryDocument() {
69+
when().
70+
get(getApiBaseUri() + "/explorer?uri=/db/no-such-document.bin").
71+
then().
72+
statusCode(SC_FORBIDDEN); //TODO(AR) should this be SC_NOT_FOUND?
73+
}
74+
5175
@Test
5276
public void invalidUri() {
5377
when().

0 commit comments

Comments
 (0)