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.kernel.api.RdfLexicon.CONSTRAINED_BY; 028import static org.junit.Assert.assertEquals; 029 030import org.junit.Before; 031import org.junit.Test; 032import org.junit.runner.RunWith; 033import org.mockito.Mock; 034import org.mockito.runners.MockitoJUnitRunner; 035 036/** 037 * ConstraintViolationExceptionMapperTest 038 * 039 * @author whikloj 040 * @since 2015-06-22 041 */ 042@RunWith(MockitoJUnitRunner.class) 043public class ConstraintViolationExceptionMapperTest { 044 045 private UriInfo mockInfo; 046 047 @Mock 048 private ConstraintViolationExceptionMapper mapper; 049 050 @Before 051 public void setUp() { 052 this.mockInfo = getUriInfoImpl(); 053 } 054 055 @Test 056 public void testBuildConstraintLink() { 057 final URI testLink = URI.create("http://localhost/static/constraints/ConstraintViolationException.rdf"); 058 059 final ConstraintViolationException ex = new ConstraintViolationException("This is an error."); 060 061 final Link link = ConstraintViolationExceptionMapper.buildConstraintLink(ex, mockInfo); 062 063 assertEquals(link.getRel(), CONSTRAINED_BY.getURI()); 064 assertEquals(link.getUri(), testLink); 065 } 066}