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.camel;
019
020import static java.net.URI.create;
021import static java.util.Collections.emptyList;
022import static java.util.Collections.singletonList;
023import static org.junit.Assert.assertEquals;
024import static org.junit.Assert.assertFalse;
025import static org.junit.Assert.assertTrue;
026
027import org.junit.Test;
028
029/**
030 * @author acoburn
031 */
032public class FcrepoPreferTest {
033
034    private final String embed = "http://fedora.info/definitions/v4/repository#EmbedResources";
035
036    private final String containment = "http://www.w3.org/ns/ldp#PreferContainment";
037
038    @Test
039    public void testPreferInclude() {
040        final FcrepoPrefer prefer = new FcrepoPrefer("return=representation; " +
041                "include=\"" + embed + "\"");
042        assertTrue(prefer.isRepresentation());
043        assertFalse(prefer.isMinimal());
044        assertEquals(singletonList(create(embed)), prefer.getInclude());
045        assertEquals(emptyList(), prefer.getOmit());
046    }
047
048    @Test
049    public void testPreferIncludeMultiple() {
050        final FcrepoPrefer prefer = new FcrepoPrefer("return=representation; " +
051                "include=\"" + embed + " " + containment + "\"");
052        assertTrue(prefer.isRepresentation());
053        assertFalse(prefer.isMinimal());
054        assertEquals(2, prefer.getInclude().size());
055        assertTrue(prefer.getInclude().contains(create(embed)));
056        assertTrue(prefer.getInclude().contains(create(containment)));
057        assertEquals(emptyList(), prefer.getOmit());
058    }
059
060    @Test
061    public void testPreferOmit() {
062        final FcrepoPrefer prefer = new FcrepoPrefer("return=representation; " +
063                "omit=\"" + embed + "\"");
064        assertTrue(prefer.isRepresentation());
065        assertFalse(prefer.isMinimal());
066        assertEquals(1, prefer.getOmit().size());
067        assertTrue(prefer.getOmit().contains(create(embed)));
068        assertEquals(emptyList(), prefer.getInclude());
069    }
070
071    @Test
072    public void testPreferOmitMultiple() {
073        final FcrepoPrefer prefer = new FcrepoPrefer("return=representation; " +
074                "omit=\"" + embed + " " + containment + "\"");
075        assertTrue(prefer.isRepresentation());
076        assertFalse(prefer.isMinimal());
077        assertEquals(2, prefer.getOmit().size());
078        assertTrue(prefer.getOmit().contains(create(embed)));
079        assertTrue(prefer.getOmit().contains(create(containment)));
080        assertEquals(emptyList(), prefer.getInclude());
081    }
082}