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