Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixing transaction renewal and adding IT
  • Loading branch information
escowles committed May 21, 2014
1 parent ef798d9 commit 2dd40a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Expand Up @@ -72,29 +72,28 @@ public class FedoraTransactions extends AbstractResource {
* @throws RepositoryException
*/
@POST
public Response createTransaction(@PathParam("path")
final List<PathSegment> pathList, @Context
final HttpServletRequest req) throws RepositoryException {

LOGGER.debug("creating transaction at path {}", pathList);

if (!pathList.isEmpty()) {
return status(BAD_REQUEST).build();
}
public Response createTransaction(@PathParam("path") final List<PathSegment> pathList,
@Context final HttpServletRequest req) throws RepositoryException {

if (session instanceof TxSession) {
final Transaction t = txService.getTransaction(session);
LOGGER.debug("renewing transaction {}", t.getId());
t.updateExpiryDate();
return noContent().expires(t.getExpires()).build();
}

if (!pathList.isEmpty()) {
return status(BAD_REQUEST).build();
}

final Principal userPrincipal = req.getUserPrincipal();
String userName = null;
if (userPrincipal != null) {
userName = userPrincipal.getName();
}

final Transaction t = txService.beginTransaction(session, userName);
LOGGER.debug("created transaction {}", t.getId());

return created(
uriInfo.getBaseUriBuilder().path(FedoraNodes.class)
Expand Down
Expand Up @@ -160,6 +160,18 @@ public void testCreateDoStuffAndRollbackTransaction() throws Exception {

}

@Test
public void testTransactionKeepAlive() throws Exception {
/* create a tx */
final HttpPost createTx = new HttpPost(serverAddress + "fcr:tx");
final HttpResponse response = execute(createTx);
assertEquals(201, response.getStatusLine().getStatusCode());

final String txLocation = response.getFirstHeader("Location").getValue();
final HttpPost renewTx = new HttpPost(txLocation + "/fcr:tx");
assertEquals(204, getStatus(renewTx));
}

@Test
public void testCreateDoStuffAndCommitTransaction() throws Exception {
/* create a tx */
Expand Down

0 comments on commit 2dd40a5

Please sign in to comment.