Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
range tests
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
fcrepo-http-commons/src/test/java/org/fcrepo/http/RangeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.fcrepo.http; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class RangeTest { | ||
@Test | ||
public void testUnboundedRange() { | ||
final Range range = new Range(5); | ||
|
||
assertEquals(5L, range.start()); | ||
assertEquals(-1L, range.end()); | ||
|
||
} | ||
@Test | ||
public void testRangeParsing() { | ||
final Range range = Range.convert("bytes=50-100"); | ||
|
||
assertEquals(50L, range.start()); | ||
assertEquals(100L, range.end()); | ||
assertEquals(51L, range.size()); | ||
assertTrue(range.hasRange()); | ||
|
||
} | ||
|
||
@Test | ||
public void testUnboundedUpperRangeParsing() { | ||
final Range range = Range.convert("bytes=50-"); | ||
|
||
assertEquals(50L, range.start()); | ||
assertEquals(-1L, range.end()); | ||
assertEquals(-1L, range.size()); | ||
assertTrue(range.hasRange()); | ||
|
||
} | ||
|
||
@Test | ||
public void testUnboundedLowerRangeParsing() { | ||
final Range range = Range.convert("bytes=-50"); | ||
|
||
assertEquals(0L, range.start()); | ||
assertEquals(50L, range.end()); | ||
assertEquals(51L, range.size()); | ||
assertTrue(range.hasRange()); | ||
|
||
} | ||
|
||
@Test | ||
public void testGarbageRangeParsing() { | ||
final Range range = Range.convert("something-thats-not-a-range"); | ||
|
||
assertFalse(range.hasRange()); | ||
assertEquals(0L, range.start()); | ||
assertEquals(-1L, range.end()); | ||
assertEquals(-1L, range.size()); | ||
|
||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
fcrepo-http-commons/src/test/java/org/fcrepo/responses/RangeRequestInputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.fcrepo.responses; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class RangeRequestInputStreamTest { | ||
@Test | ||
public void shouldLimitTheInputStream() throws IOException { | ||
InputStream in = new ByteArrayInputStream("0123456789".getBytes()); | ||
final RangeRequestInputStream out = new RangeRequestInputStream(in, 5L, 3L); | ||
final String s = IOUtils.toString(out); | ||
assertEquals("567", s); | ||
} | ||
|
||
|
||
@Test | ||
public void shouldAcceptUnboundedRanges() throws IOException { | ||
InputStream in = new ByteArrayInputStream("0123456789".getBytes()); | ||
final RangeRequestInputStream out = new RangeRequestInputStream(in, 0L, -1L); | ||
final String s = IOUtils.toString(out); | ||
assertEquals("0123456789", s); | ||
} | ||
} |