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.domain;
019
020import org.junit.Test;
021
022import java.text.ParseException;
023
024import static org.junit.Assert.assertEquals;
025import static org.junit.Assert.assertTrue;
026
027/**
028 * @author cabeer
029 * @author ajs6f
030 */
031public class SinglePreferTest  {
032
033    protected SinglePrefer createTestPreferTypeFromHeader(final String header) throws ParseException {
034        return new SinglePrefer(header);
035    }
036
037    @Test
038    public void testHasReturn() throws ParseException {
039        final SinglePrefer prefer = createTestPreferTypeFromHeader("return=representation");
040
041        assertTrue(prefer.hasReturn());
042    }
043
044    @Test
045    public void testGetReturn() throws ParseException {
046        final SinglePrefer prefer = createTestPreferTypeFromHeader("return=representation");
047
048        assertEquals("representation", prefer.getReturn().getValue());
049    }
050
051    @Test
052    public void testGetReturnParameters() throws ParseException {
053        final SinglePrefer prefer =
054                createTestPreferTypeFromHeader("return=representation; "
055                        + "include=\"http://www.w3.org/ns/ldp#PreferMinimalContainer\"");
056
057        assertTrue(prefer.hasReturn());
058        assertEquals("representation", prefer.getReturn().getValue());
059
060        final String returnParams = prefer.getReturn().getParams().get("include");
061        assertTrue(returnParams.contains("http://www.w3.org/ns/ldp#PreferMinimalContainer"));
062    }
063
064    @Test
065    public void testHasHandling() throws ParseException {
066        final SinglePrefer prefer = createTestPreferTypeFromHeader("handling=strict");
067
068        assertTrue(prefer.hasHandling());
069    }
070
071    @Test
072    public void testGetHandling() throws ParseException {
073        final SinglePrefer prefer = createTestPreferTypeFromHeader("handling=lenient");
074
075        assertEquals("lenient", prefer.getHandling().getValue());
076    }
077
078    @Test
079    public void testGetHandlingParameters() throws ParseException {
080        final SinglePrefer prefer =
081                createTestPreferTypeFromHeader("handling=lenient; some=\"parameter\"");
082
083        assertTrue(prefer.hasHandling());
084        assertEquals("lenient", prefer.getHandling().getValue());
085
086        final String returnParams = prefer.getHandling().getParams().get("some");
087        assertTrue(returnParams.contains("parameter"));
088    }
089}