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