Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
unit tests for exception mappers
  • Loading branch information
barmintor committed May 3, 2013
1 parent 300599f commit e709a87
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fcrepo-http-commons/pom.xml
Expand Up @@ -11,10 +11,6 @@
<description>HTTP (JAX-RS) resources and helpers.</description>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
Expand Down Expand Up @@ -64,6 +60,7 @@
<artifactId>spring-context</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver</artifactId>
Expand Down Expand Up @@ -100,6 +97,10 @@
<artifactId>jersey-multipart</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
@@ -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());
}
}
@@ -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());
}
}
@@ -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());
}
}

0 comments on commit e709a87

Please sign in to comment.