|
14 | 14 | import static org.mockserver.model.HttpRequest.request; |
15 | 15 | import static org.mockserver.model.HttpResponse.response; |
16 | 16 |
|
| 17 | +import java.io.ByteArrayInputStream; |
| 18 | +import java.nio.charset.StandardCharsets; |
17 | 19 | import java.util.HashMap; |
18 | 20 |
|
19 | 21 | import org.eclipse.rdf4j.common.transaction.IsolationLevels; |
@@ -128,6 +130,60 @@ public void testCreateRepositoryFollowsRedirectOnPut(MockServerClient client) th |
128 | 130 | ); |
129 | 131 | } |
130 | 132 |
|
| 133 | + @Test |
| 134 | + public void testRemoveDataTransactionFollowsRedirectOnDelete(MockServerClient client) throws Exception { |
| 135 | + // Start transaction and get transaction URL |
| 136 | + String transactionStartUrl = Protocol.getTransactionsLocation(getRDF4JSession().getRepositoryURL()); |
| 137 | + HttpRequest transactionCreateRequest = request() |
| 138 | + .withMethod("POST") |
| 139 | + .withPath("/rdf4j-server/repositories/test/transactions"); |
| 140 | + client.when(transactionCreateRequest, Times.once()) |
| 141 | + .respond(response().withStatusCode(201).withHeader("Location", transactionStartUrl + "/1")); |
| 142 | + |
| 143 | + // First attempt: PUT .../transactions/1?action=DELETE responds with 301 and Location header |
| 144 | + String originalPath = "/rdf4j-server/repositories/test/transactions/1"; |
| 145 | + String redirectedPath = "/https/rdf4j-server/repositories/test/transactions/1"; |
| 146 | + String redirectLocation = "http://localhost:" + client.getPort() + redirectedPath + "?action=DELETE"; |
| 147 | + |
| 148 | + client.when( |
| 149 | + request() |
| 150 | + .withMethod("PUT") |
| 151 | + .withPath(originalPath) |
| 152 | + .withQueryStringParameter("action", "DELETE"), |
| 153 | + Times.once()) |
| 154 | + .respond(response().withStatusCode(301).withHeader("Location", redirectLocation)); |
| 155 | + |
| 156 | + // Redirect target responds successfully (204 No Content) |
| 157 | + client.when( |
| 158 | + request() |
| 159 | + .withMethod("PUT") |
| 160 | + .withPath(redirectedPath) |
| 161 | + .withQueryStringParameter("action", "DELETE"), |
| 162 | + Times.once()) |
| 163 | + .respond(response().withStatusCode(204)); |
| 164 | + |
| 165 | + // Begin transaction, then attempt removeData (DELETE action) which should follow redirect |
| 166 | + getRDF4JSession().beginTransaction(IsolationLevels.SERIALIZABLE); |
| 167 | + ByteArrayInputStream data = new ByteArrayInputStream("<s> <p> <o> .".getBytes(StandardCharsets.UTF_8)); |
| 168 | + getRDF4JSession().removeData(data, null, RDFFormat.NTRIPLES); |
| 169 | + |
| 170 | + // Verify original and redirected requests occurred with header preserved |
| 171 | + client.verify( |
| 172 | + request() |
| 173 | + .withMethod("PUT") |
| 174 | + .withPath(originalPath) |
| 175 | + .withQueryStringParameter("action", "DELETE") |
| 176 | + .withHeader(testHeader, testValue) |
| 177 | + ); |
| 178 | + client.verify( |
| 179 | + request() |
| 180 | + .withMethod("PUT") |
| 181 | + .withPath(redirectedPath) |
| 182 | + .withQueryStringParameter("action", "DELETE") |
| 183 | + .withHeader(testHeader, testValue) |
| 184 | + ); |
| 185 | + } |
| 186 | + |
131 | 187 | @Test |
132 | 188 | public void testUpdateRepositoryExecutesPost(MockServerClient client) throws Exception { |
133 | 189 | RepositoryConfig config = new RepositoryConfig("test"); |
|
0 commit comments