Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
unit tests for exception mappers
- Loading branch information
Showing
4 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...-commons/src/test/java/org/fcrepo/exceptionhandlers/AccessControlExceptionMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.fcrepo.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.Status.FORBIDDEN; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import javax.jcr.security.AccessControlException; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class AccessControlExceptionMapperTest { | ||
|
||
private AccessControlExceptionMapper testObj; | ||
|
||
@Before | ||
public void setUp() { | ||
testObj = new AccessControlExceptionMapper(); | ||
} | ||
|
||
@Test | ||
public void testToResponse() { | ||
AccessControlException input = new AccessControlException(); | ||
Response actual = testObj.toResponse(input); | ||
assertEquals(FORBIDDEN.getStatusCode(), actual.getStatus()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...p-commons/src/test/java/org/fcrepo/exceptionhandlers/PathNotFoundExceptionMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.fcrepo.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.Status.NOT_FOUND; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import javax.jcr.PathNotFoundException; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class PathNotFoundExceptionMapperTest { | ||
|
||
private PathNotFoundExceptionMapper testObj; | ||
|
||
@Before | ||
public void setUp() { | ||
testObj = new PathNotFoundExceptionMapper(); | ||
} | ||
|
||
@Test | ||
public void testToResponse() { | ||
PathNotFoundException input = new PathNotFoundException(); | ||
Response actual = testObj.toResponse(input); | ||
assertEquals(NOT_FOUND.getStatusCode(), actual.getStatus()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...-http-commons/src/test/java/org/fcrepo/exceptionhandlers/WildcardExceptionMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.fcrepo.exceptionhandlers; | ||
|
||
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import javax.ws.rs.core.Response; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class WildcardExceptionMapperTest { | ||
|
||
private WildcardExceptionMapper testObj; | ||
|
||
@Before | ||
public void setUp() { | ||
testObj = new WildcardExceptionMapper(); | ||
} | ||
|
||
@Test | ||
public void testToResponse() { | ||
Exception input = new Exception(); | ||
Response actual = testObj.toResponse(input); | ||
assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), actual.getStatus()); | ||
assertTrue(actual.getEntity() != null); | ||
testObj.showStackTrace = false; | ||
actual = testObj.toResponse(input); | ||
assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), actual.getStatus()); | ||
assertEquals(null, actual.getEntity()); | ||
} | ||
} |