Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.javaswift.joss.instructions;

import org.apache.commons.io.IOUtils;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

import static junit.framework.Assert.assertEquals;

public class SegmentationPlanBoundedInputStreamTest extends SegmentationPlanTestBase {

@Test
public void getSegmentNumber() throws IOException {
String text = "Some text that needs to be read as several segments which we patch together again and compare to the original";
InputStream inputStream = IOUtils.toInputStream(text);
SegmentationPlan plan = new SegmentationPlanBoundedInputStream(inputStream, text.length(), 10L);
assertEquals(Long.valueOf(0L), plan.getSegmentNumber());
}

@Test
public void readItAll() throws IOException {
String text = "Some text that needs to be read as several segments which we patch together again and compare to the original";
InputStream inputStream = IOUtils.toInputStream(text);
SegmentationPlan plan = new SegmentationPlanBoundedInputStream(inputStream, text.length(), 10L);
assertTextEquals(plan, text);
plan.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.javaswift.joss.instructions;

import mockit.Injectable;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import java.io.*;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

public class UploadPayloadBounderInputStreamTest extends SegmentationPlanTestBase {

@Test
public void mustBeSegmented(@Injectable final InputStream inputStream) {
checkForRequiredSegmentation(inputStream, 12L, 9L, true);
}

@Test
public void mustNotBeSegmented(@Injectable final InputStream inputStream) {
checkForRequiredSegmentation(inputStream, 9L, 12L, false);
}

@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void getSegmentationPlan() throws IOException {
String text = "Some text that needs to be read as several segments which we patch together again and compare to the original";
InputStream inputStream = IOUtils.toInputStream(text);
UploadPayload payload = new UploadPayloadBoundedInputStream(inputStream, text.length());
assertNotNull(payload.getSegmentationPlan(10L));
}

protected UploadPayload createUploadPayload(final InputStream inputStream, final Long length) {
return new UploadPayloadBoundedInputStream(inputStream, length);
}

protected void checkForRequiredSegmentation(InputStream inputStream, Long length, Long segmentationSize, boolean expectSegmentation) {
UploadPayload payload = createUploadPayload(inputStream, length);
assertEquals(expectSegmentation, payload.mustBeSegmented(segmentationSize));
}
}