Skip to content

Commit

Permalink
Test for startTransactionalClient
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejritter committed Sep 12, 2022
1 parent 837afe5 commit 87d40ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Expand Up @@ -29,6 +29,10 @@ public TransactionalFcrepoClient(final FcrepoResponse.TransactionURI transaction
this.transactionURI = transactionURI;
}

public FcrepoResponse.TransactionURI getTransactionURI() {
return transactionURI;
}

@Override
public GetBuilder get(final URI url) {
final var builder = super.get(url);
Expand Down
Expand Up @@ -61,11 +61,7 @@ public void testTransactionCommit() throws Exception {
location = response.getTransactionUri().orElseThrow(() -> new IllegalStateException("No tx found"));
}

final var transactionalClient = FcrepoClient.client()
.credentials(FEDORA_ADMIN, FEDORA_ADMIN)
.authScope(HOSTNAME)
.transactionURI(location)
.build();
final var transactionalClient = client.transactionalClient(location);

final var container = UUID.randomUUID().toString();
try (final var response = transactionalClient.put(new URI(SERVER_ADDRESS + container)).perform()) {
Expand All @@ -79,6 +75,25 @@ public void testTransactionCommit() throws Exception {
}
}

@Test
public void testStartTransactionalClient() throws Exception {
// the same as testTransactionCommit but using startTransactionalClient
try (final var transactionalClient = client.transaction().startTransactionalClient(new URI(SERVER_ADDRESS))) {
final var txURI = transactionalClient.getTransactionURI();

final var container = UUID.randomUUID().toString();
try (final var response = transactionalClient.put(new URI(SERVER_ADDRESS + container)).perform()) {
assertEquals(CREATED.getStatusCode(), response.getStatusCode());
assertTrue(response.getTransactionUri().isPresent());
assertEquals(txURI.asString(), response.getTransactionUri().get().asString());
}

try (final var response = client.transaction().commit(txURI).perform()) {
assertEquals(NO_CONTENT.getStatusCode(), response.getStatusCode());
}
}
}

@Test
public void testTransactionKeepAlive() throws Exception {
final String expiry;
Expand Down

0 comments on commit 87d40ec

Please sign in to comment.