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