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.junit.MockitoJUnitRunner;
036
037/**
038 * ConstraintViolationExceptionMapperTest
039 *
040 * @author whikloj
041 * @since 2015-06-22
042 */
043@RunWith(MockitoJUnitRunner.Silent.class)
044public class ConstraintViolationExceptionMapperTest {
045
046    private UriInfo mockInfo;
047
048    private ServletContext mockContext;
049
050    @Before
051    public void setUp() {
052        this.mockInfo = getUriInfoImpl();
053        this.mockContext = getServletContextImpl();
054    }
055
056    @Test
057    public void testBuildConstraintLink() {
058        final URI testLink = URI.create("http://localhost/fcrepo/static/constraints/ConstraintViolationException.rdf");
059
060        final ConstraintViolationException ex = new ConstraintViolationException("This is an error.");
061
062        final Link link = ConstraintViolationExceptionMapper.buildConstraintLink(ex, mockContext, mockInfo);
063
064        assertEquals(link.getRel(), CONSTRAINED_BY.getURI());
065        assertEquals(link.getUri(), testLink);
066    }
067}