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.domain; 017 018import org.junit.Test; 019 020import java.text.ParseException; 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) throws ParseException { 032 return new SinglePrefer(header); 033 } 034 035 @Test 036 public void testHasReturn() throws ParseException { 037 final SinglePrefer prefer = createTestPreferTypeFromHeader("return=representation"); 038 039 assertTrue(prefer.hasReturn()); 040 } 041 042 @Test 043 public void testGetReturn() throws ParseException { 044 final SinglePrefer prefer = createTestPreferTypeFromHeader("return=representation"); 045 046 assertEquals("representation", prefer.getReturn().getValue()); 047 } 048 049 @Test 050 public void testGetReturnParameters() throws ParseException { 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() throws ParseException { 064 final SinglePrefer prefer = createTestPreferTypeFromHeader("handling=strict"); 065 066 assertTrue(prefer.hasHandling()); 067 } 068 069 @Test 070 public void testGetHandling() throws ParseException { 071 final SinglePrefer prefer = createTestPreferTypeFromHeader("handling=lenient"); 072 073 assertEquals("lenient", prefer.getHandling().getValue()); 074 } 075 076 @Test 077 public void testGetHandlingParameters() throws ParseException { 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}