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 java.net.URI; 009import javax.ws.rs.core.Link; 010import javax.ws.rs.core.UriInfo; 011 012import org.fcrepo.kernel.api.exception.ConstraintViolationException; 013 014import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl; 015import static org.fcrepo.http.commons.test.util.TestHelpers.getServletContextImpl; 016import static org.fcrepo.kernel.api.RdfLexicon.CONSTRAINED_BY; 017import static org.junit.Assert.assertEquals; 018 019import javax.servlet.ServletContext; 020import org.junit.Before; 021import org.junit.Test; 022import org.junit.runner.RunWith; 023import org.mockito.junit.MockitoJUnitRunner; 024 025/** 026 * ConstraintViolationExceptionMapperTest 027 * 028 * @author whikloj 029 * @since 2015-06-22 030 */ 031@RunWith(MockitoJUnitRunner.Silent.class) 032public class ConstraintViolationExceptionMapperTest { 033 034 private UriInfo mockInfo; 035 036 private ServletContext mockContext; 037 038 @Before 039 public void setUp() { 040 this.mockInfo = getUriInfoImpl(); 041 this.mockContext = getServletContextImpl(); 042 } 043 044 @Test 045 public void testBuildConstraintLink() { 046 final URI testLink = URI.create("http://localhost/fcrepo/static/constraints/ConstraintViolationException.rdf"); 047 048 final ConstraintViolationException ex = new ConstraintViolationException("This is an error."); 049 050 final Link link = ConstraintViolationExceptionMapper.buildConstraintLink(ex, mockContext, mockInfo); 051 052 assertEquals(link.getRel(), CONSTRAINED_BY.getURI()); 053 assertEquals(link.getUri(), testLink); 054 } 055}