001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.http.commons.exceptionhandlers; 007 008import static javax.ws.rs.core.Response.Status.BAD_REQUEST; 009import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; 010import static org.junit.Assert.assertEquals; 011import static org.junit.Assert.assertNotNull; 012 013import javax.ws.rs.core.Response; 014 015import org.fcrepo.kernel.api.exception.RepositoryException; 016import org.junit.Before; 017import org.junit.Test; 018 019/** 020 * @author escowles 021 * @since 2014-04-19 022 */ 023public class RepositoryExceptionMapperTest { 024 025 private RepositoryExceptionMapper testObj; 026 027 @Before 028 public void setUp() { 029 testObj = new RepositoryExceptionMapper(); 030 } 031 032 @Test 033 public void testInvalidNamespace() { 034 final RepositoryException input = new RepositoryException("Error converting \"abc:123\" from String to a Name"); 035 final Response actual = testObj.toResponse(input); 036 assertEquals(BAD_REQUEST.getStatusCode(), actual.getStatus()); 037 assertEquals(actual.getEntity(), input.getMessage()); 038 } 039 040 @Test 041 public void testToResponse() { 042 final RepositoryException input = new RepositoryException("An error occurred"); 043 final Response actual = testObj.toResponse(input); 044 assertEquals(INTERNAL_SERVER_ERROR.getStatusCode(), actual.getStatus()); 045 assertNotNull(actual.getEntity()); 046 } 047}