Skip to content

Commit

Permalink
Merge pull request #528 from fcrepo4/fix-session-factory
Browse files Browse the repository at this point in the history
Update SessionFactory to handle path parsing the correct way, with a hack for Grizzly's path handler behavior
  • Loading branch information
Andrew Woods committed Oct 15, 2014
2 parents 3d64df0 + b4b3481 commit caf36e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Expand Up @@ -199,7 +199,12 @@ protected Session getSessionFromTransaction(final HttpServletRequest servletRequ
*/
protected String getEmbeddedId(
final HttpServletRequest servletRequest, final Prefix prefix) {
final String requestPath = servletRequest.getRequestURI();
String requestPath = servletRequest.getPathInfo();

// http://stackoverflow.com/questions/18963562/grizzlys-request-getpathinfo-returns-always-null
if (requestPath == null && servletRequest.getContextPath().isEmpty()) {
requestPath = servletRequest.getRequestURI();
}

String id = null;
if (requestPath != null) {
Expand Down
Expand Up @@ -83,7 +83,8 @@ public void setUp() {

@Test
public void testGetSessionWithNullPath() throws RepositoryException {
when(mockRequest.getRequestURI()).thenReturn(null);
when(mockRequest.getPathInfo()).thenReturn(null);
when(mockRequest.getContextPath()).thenReturn("");
when(mockRepo.login(any(Credentials.class))).thenReturn(mockSession);
testObj.getSession(mockRequest);
verify(mockRepo).login(any(ServletCredentials.class));
Expand All @@ -97,14 +98,14 @@ public void testGetSessionUnauthenticated() throws RepositoryException {

@Test
public void testCreateSession() throws RepositoryException {
when(mockRequest.getRequestURI()).thenReturn("/some/path");
when(mockRequest.getPathInfo()).thenReturn("/some/path");
testObj.createSession(mockRequest);
verify(mockRepo).login(any(Credentials.class));
}

@Test
public void testGetSessionFromTransaction() throws RepositoryException {
when(mockRequest.getRequestURI()).thenReturn("/tx:123/some/path");
when(mockRequest.getPathInfo()).thenReturn("/tx:123/some/path");
when(mockTx.getSession()).thenReturn(mock(Session.class));
when(mockTxService.getTransaction("123", null)).thenReturn(mockTx);
final Session session = testObj.getSessionFromTransaction(mockRequest, "123");
Expand All @@ -113,7 +114,7 @@ public void testGetSessionFromTransaction() throws RepositoryException {

@Test
public void testGetSessionThrowException() throws RepositoryException {
when(mockRequest.getRequestURI()).thenReturn("/tx:123/some/path");
when(mockRequest.getPathInfo()).thenReturn("/tx:123/some/path");
when(mockTx.getSession()).thenReturn(mock(Session.class));
when(mockTxService.getTransaction("123", null)).thenThrow(
new TransactionMissingException(""));
Expand All @@ -132,7 +133,7 @@ public void testGetAuthenticatedSessionWithTransaction()
final String fedoraUser = "fedoraUser";
when(mockRequest.getUserPrincipal()).thenReturn(mockUser);
when(mockUser.getName()).thenReturn(fedoraUser);
when(mockRequest.getRequestURI()).thenReturn("/tx:123/some/path");
when(mockRequest.getPathInfo()).thenReturn("/tx:123/some/path");
when(mockTx.getSession()).thenReturn(txSession);
when(mockTx.isAssociatedWithUser(eq(fedoraUser))).thenReturn(true);
when(mockTxService.getTransaction("123", fedoraUser))
Expand All @@ -144,7 +145,7 @@ public void testGetAuthenticatedSessionWithTransaction()

@Test
public void testGetEmbeddedIdTx() {
when(mockRequest.getRequestURI()).thenReturn("/tx:123/some/path");
when(mockRequest.getPathInfo()).thenReturn("/tx:123/some/path");
final String txId = testObj.getEmbeddedId(mockRequest, SessionFactory.Prefix.TX);
assertEquals("txId should be 123", "123", txId);
}
Expand Down

0 comments on commit caf36e8

Please sign in to comment.