|
17 | 17 | */ |
18 | 18 | package com.fusiondb.studio.api; |
19 | 19 |
|
| 20 | +import io.restassured.http.Header; |
20 | 21 | import io.restassured.response.ExtractableResponse; |
21 | 22 | import io.restassured.response.Response; |
22 | 23 | import org.junit.jupiter.api.Test; |
|
26 | 27 | import static com.evolvedbinary.j8fu.tuple.Tuple.Tuple; |
27 | 28 | import static com.fusiondb.studio.api.API.*; |
28 | 29 | import static io.restassured.RestAssured.given; |
| 30 | +import static io.restassured.RestAssured.when; |
29 | 31 | import static io.restassured.http.ContentType.JSON; |
30 | | -import static io.restassured.http.ContentType.XML; |
31 | | -import static io.restassured.internal.RestAssuredResponseOptionsGroovyImpl.BINARY; |
32 | 32 | import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath; |
33 | | -import static java.nio.charset.StandardCharsets.UTF_8; |
34 | 33 | import static org.apache.http.HttpStatus.*; |
35 | 34 | import static org.junit.jupiter.api.Assertions.*; |
| 35 | +import static org.hamcrest.core.IsEqual.equalTo; |
36 | 36 |
|
37 | 37 | public class CollectionIT { |
38 | 38 |
|
@@ -116,6 +116,84 @@ public void updateMode() { |
116 | 116 | assertEquals("rwxr-----", collectionResponse.jsonPath().getString("mode")); |
117 | 117 | } |
118 | 118 |
|
| 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 | + |
119 | 197 | private ExtractableResponse<Response> createCollection(final String path) { |
120 | 198 | return |
121 | 199 | given(). |
|
0 commit comments