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 org.junit.Assert.assertEquals; 010import static org.junit.Assert.assertNotNull; 011 012import javax.ws.rs.core.Response; 013 014import org.junit.Before; 015import org.junit.Test; 016 017import org.apache.jena.query.QueryParseException; 018 019/** 020 * @author whikloj 021 * @since September 10, 2014 022 */ 023public class QueryParseExceptionMapperTest { 024 025 private QueryParseExceptionMapper testObj; 026 027 @Before 028 public void setUp() { 029 testObj = new QueryParseExceptionMapper(); 030 } 031 032 @Test 033 public void testInvalidNamespace() { 034 final QueryParseException input = new QueryParseException( 035 "Unresolved prefixed name: invalidNS:title", 14, 10); 036 final Response actual = testObj.toResponse(input); 037 assertEquals(BAD_REQUEST.getStatusCode(), actual.getStatus()); 038 assertEquals(actual.getEntity(), input.getMessage()); 039 } 040 041 @Test 042 public void testToResponse() { 043 final QueryParseException input = new QueryParseException("An error occurred", 14, 10); 044 final Response actual = testObj.toResponse(input); 045 assertEquals(BAD_REQUEST.getStatusCode(), actual.getStatus()); 046 assertNotNull(actual.getEntity()); 047 } 048}