diff --git a/api-data-store-server-java/src/main/java/ch/ethz/sis/afsclient/client/AfsClient.java b/api-data-store-server-java/src/main/java/ch/ethz/sis/afsclient/client/AfsClient.java index fa151f65157082e898a19c2fd80f4aea338551f6..f2eed8819c9e798f6e2db8eb178b3c1a79e1937c 100644 --- a/api-data-store-server-java/src/main/java/ch/ethz/sis/afsclient/client/AfsClient.java +++ b/api-data-store-server-java/src/main/java/ch/ethz/sis/afsclient/client/AfsClient.java @@ -187,31 +187,39 @@ public final class AfsClient implements PublicAPI @Override public void begin(final UUID transactionId) throws Exception { - + validateSessionToken(); + Map<String, Object> parameters = + Map.of("transactionId", transactionId, + "sessionToken", getSessionToken()); + request("POST", "begin", Map.of(), jsonObjectMapper.writeValue(parameters)); } @Override public Boolean prepare() throws Exception { - return null; + validateSessionToken(); + return request("POST", "prepare", Map.of()); } @Override public void commit() throws Exception { - + validateSessionToken(); + request("POST", "commit", Map.of()); } @Override public void rollback() throws Exception { - + validateSessionToken(); + request("POST", "rollback", Map.of()); } @Override public List<UUID> recover() throws Exception { - return null; + validateSessionToken(); + return request("POST", "recover", Map.of()); } private <T> T request(@NonNull final String httpMethod, @NonNull final String apiMethod, diff --git a/api-data-store-server-java/src/test/java/ch/ethz/sis/afsclient/client/AfsClientTest.java b/api-data-store-server-java/src/test/java/ch/ethz/sis/afsclient/client/AfsClientTest.java index 654a2a554b5917567fa950128645d9098cad49da..1d8b56026d2808e3a2d3f8b2442b3a6d8d55d280 100644 --- a/api-data-store-server-java/src/test/java/ch/ethz/sis/afsclient/client/AfsClientTest.java +++ b/api-data-store-server-java/src/test/java/ch/ethz/sis/afsclient/client/AfsClientTest.java @@ -5,6 +5,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.CoreMatchers.containsString; import java.net.URI; +import java.util.List; +import java.util.UUID; import org.junit.*; @@ -179,28 +181,61 @@ public class AfsClientTest } @Test - public void testBegin() + public void begin_methodIsPost() throws Exception { + login(); + + UUID transactionId = UUID.randomUUID(); + + httpServer.setNextResponse("{\"result\": null}"); + afsClient.begin(transactionId); + + assertEquals("POST", httpServer.getHttpExchange().getRequestMethod()); } @Test - public void testPrepare() + public void prepare_methodIsPost() throws Exception { + login(); + + httpServer.setNextResponse("{\"result\": true}"); + Boolean result = afsClient.prepare(); + + assertEquals("POST", httpServer.getHttpExchange().getRequestMethod()); + assertTrue(result); } @Test - public void testCommit() + public void commit_methodIsPost() throws Exception { + login(); + httpServer.setNextResponse("{\"result\": null}"); + + afsClient.commit(); + assertEquals("POST", httpServer.getHttpExchange().getRequestMethod()); } @Test - public void testRollback() + public void rollback_methodIsPost() throws Exception { + login(); + + httpServer.setNextResponse("{\"result\": null}"); + + afsClient.rollback(); + assertEquals("POST", httpServer.getHttpExchange().getRequestMethod()); } @Test - public void testRecover() + public void recover_methodIsPost() throws Exception { + login(); + + httpServer.setNextResponse("{\"result\": null}"); + + List<UUID> result = afsClient.recover(); + assertEquals("POST", httpServer.getHttpExchange().getRequestMethod()); + assertNull(result); } private void login() throws Exception