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 static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertFalse;
022import static org.junit.Assert.assertTrue;
023
024import org.junit.Test;
025
026/**
027 * <p>RangeTest class.</p>
028 *
029 * @author awoods
030 */
031public class RangeTest {
032    @Test
033    public void testUnboundedRange() {
034        final Range range = new Range(5);
035
036        assertEquals(5L, range.start());
037        assertEquals(-1L, range.end());
038
039    }
040    @Test
041    public void testRangeParsing() {
042        final Range range = Range.convert("bytes=50-100");
043
044        assertEquals(50L, range.start());
045        assertEquals(100L, range.end());
046        assertEquals(51L, range.size());
047        assertTrue(range.hasRange());
048
049    }
050
051    @Test
052    public void testUnboundedUpperRangeParsing() {
053        final Range range = Range.convert("bytes=50-");
054
055        assertEquals(50L, range.start());
056        assertEquals(-1L, range.end());
057        assertEquals(-1L, range.size());
058        assertTrue(range.hasRange());
059
060    }
061
062    @Test
063    public void testUnboundedLowerRangeParsing() {
064        final Range range = Range.convert("bytes=-50");
065
066        assertEquals(0L, range.start());
067        assertEquals(50L, range.end());
068        assertEquals(51L, range.size());
069        assertTrue(range.hasRange());
070
071    }
072
073    @Test
074    public void testGarbageRangeParsing() {
075        final Range range = Range.convert("something-thats-not-a-range");
076
077        assertFalse(range.hasRange());
078        assertEquals(0L, range.start());
079        assertEquals(-1L, range.end());
080        assertEquals(-1L, range.size());
081
082    }
083}