001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.http.commons.exceptionhandlers; 019 020import java.net.URI; 021import javax.ws.rs.core.Link; 022import javax.ws.rs.core.UriInfo; 023 024import org.fcrepo.kernel.api.exception.ConstraintViolationException; 025 026import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl; 027import static org.fcrepo.http.commons.test.util.TestHelpers.getServletContextImpl; 028import static org.fcrepo.kernel.api.RdfLexicon.CONSTRAINED_BY; 029import static org.junit.Assert.assertEquals; 030 031import javax.servlet.ServletContext; 032import org.junit.Before; 033import org.junit.Test; 034import org.junit.runner.RunWith; 035import org.mockito.Mock; 036import org.mockito.runners.MockitoJUnitRunner; 037 038/** 039 * ConstraintViolationExceptionMapperTest 040 * 041 * @author whikloj 042 * @since 2015-06-22 043 */ 044@RunWith(MockitoJUnitRunner.class) 045public class ConstraintViolationExceptionMapperTest { 046 047 private UriInfo mockInfo; 048 049 private ServletContext mockContext; 050 051 @Mock 052 private ConstraintViolationExceptionMapper mapper; 053 054 @Before 055 public void setUp() { 056 this.mockInfo = getUriInfoImpl(); 057 this.mockContext = getServletContextImpl(); 058 } 059 060 @Test 061 public void testBuildConstraintLink() { 062 final URI testLink = URI.create("http://localhost/fcrepo/static/constraints/ConstraintViolationException.rdf"); 063 064 final ConstraintViolationException ex = new ConstraintViolationException("This is an error."); 065 066 final Link link = ConstraintViolationExceptionMapper.buildConstraintLink(ex, mockContext, mockInfo); 067 068 assertEquals(link.getRel(), CONSTRAINED_BY.getURI()); 069 assertEquals(link.getUri(), testLink); 070 } 071}