use of com.linkedin.multipart.exceptions.StreamBusyException in project rest.li by linkedin.
the class TestMIMEReaderStateTransitions method testSinglePartMIMEReaderVerifyState.
@Test
public void testSinglePartMIMEReaderVerifyState() {
//This will cover drainPart() and most of requestPartData().
//The caveat is that requestPartData() requires a callback to be registered. This
//will be covered in the next test.
final EntityStream entityStream = mock(EntityStream.class);
final StreamRequest streamRequest = mock(StreamRequest.class);
when(streamRequest.getEntityStream()).thenReturn(entityStream);
when(streamRequest.getHeader(MultiPartMIMEUtils.CONTENT_TYPE_HEADER)).thenReturn("multipart/mixed; boundary=\"--123\"");
MultiPartMIMEReader reader = MultiPartMIMEReader.createAndAcquireStream(streamRequest);
final MultiPartMIMEReader.SinglePartMIMEReader singlePartMIMEReader = reader.new SinglePartMIMEReader(Collections.<String, String>emptyMap());
singlePartMIMEReader.setState(MultiPartMIMEReader.SingleReaderState.FINISHED);
try {
singlePartMIMEReader.verifyUsableState();
Assert.fail();
} catch (SinglePartFinishedException singlePartFinishedException) {
}
singlePartMIMEReader.setState(MultiPartMIMEReader.SingleReaderState.REQUESTED_DATA);
try {
singlePartMIMEReader.verifyUsableState();
Assert.fail();
} catch (StreamBusyException streamBusyException) {
}
singlePartMIMEReader.setState(MultiPartMIMEReader.SingleReaderState.REQUESTED_DRAIN);
try {
singlePartMIMEReader.verifyUsableState();
Assert.fail();
} catch (StreamBusyException streamBusyException) {
}
}
use of com.linkedin.multipart.exceptions.StreamBusyException in project rest.li by linkedin.
the class TestMIMEReaderStateTransitions method testDrainAllPartsMultiPartMIMEReader.
@Test
public void testDrainAllPartsMultiPartMIMEReader() {
final EntityStream entityStream = mock(EntityStream.class);
final StreamRequest streamRequest = mock(StreamRequest.class);
when(streamRequest.getEntityStream()).thenReturn(entityStream);
when(streamRequest.getHeader(MultiPartMIMEUtils.CONTENT_TYPE_HEADER)).thenReturn("multipart/mixed; boundary=\"--123\"");
MultiPartMIMEReader reader = MultiPartMIMEReader.createAndAcquireStream(streamRequest);
//Test each possible exception:
reader.setState(MultiPartMIMEReader.MultiPartReaderState.FINISHED);
try {
reader.drainAllParts();
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
}
reader.setState(MultiPartMIMEReader.MultiPartReaderState.READING_EPILOGUE);
try {
reader.drainAllParts();
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
}
reader.setState(MultiPartMIMEReader.MultiPartReaderState.CALLBACK_BOUND_AND_READING_PREAMBLE);
try {
reader.drainAllParts();
Assert.fail();
} catch (StreamBusyException streamBusyException) {
}
reader.setState(MultiPartMIMEReader.MultiPartReaderState.DRAINING);
try {
reader.drainAllParts();
Assert.fail();
} catch (StreamBusyException streamBusyException) {
}
//This is the desired top level reader state
reader.setState(MultiPartMIMEReader.MultiPartReaderState.READING_PARTS);
final MultiPartMIMEReader.SinglePartMIMEReader singlePartMIMEReader = reader.new SinglePartMIMEReader(Collections.<String, String>emptyMap());
//This is a undesired single part state
singlePartMIMEReader.setState(MultiPartMIMEReader.SingleReaderState.REQUESTED_DATA);
reader.setCurrentSinglePartMIMEReader(singlePartMIMEReader);
try {
reader.drainAllParts();
Assert.fail();
} catch (StreamBusyException streamBusyException) {
}
}
use of com.linkedin.multipart.exceptions.StreamBusyException in project rest.li by linkedin.
the class TestMIMEReaderStateTransitions method testRegisterCallbackMultiPartMIMEReader.
//MultiPartMIMEReader exceptions:
@Test
public void testRegisterCallbackMultiPartMIMEReader() {
final EntityStream entityStream = mock(EntityStream.class);
final StreamRequest streamRequest = mock(StreamRequest.class);
when(streamRequest.getEntityStream()).thenReturn(entityStream);
when(streamRequest.getHeader(MultiPartMIMEUtils.CONTENT_TYPE_HEADER)).thenReturn("multipart/mixed; boundary=\"--123\"");
MultiPartMIMEReader reader = MultiPartMIMEReader.createAndAcquireStream(streamRequest);
//Test each possible exception:
reader.setState(MultiPartMIMEReader.MultiPartReaderState.FINISHED);
try {
reader.registerReaderCallback(EMPTY_MULTI_PART_MIME_READER_CALLBACK);
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
}
reader.setState(MultiPartMIMEReader.MultiPartReaderState.READING_EPILOGUE);
try {
reader.registerReaderCallback(EMPTY_MULTI_PART_MIME_READER_CALLBACK);
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
}
reader.setState(MultiPartMIMEReader.MultiPartReaderState.CALLBACK_BOUND_AND_READING_PREAMBLE);
try {
reader.registerReaderCallback(EMPTY_MULTI_PART_MIME_READER_CALLBACK);
Assert.fail();
} catch (StreamBusyException streamBusyException) {
}
reader.setState(MultiPartMIMEReader.MultiPartReaderState.DRAINING);
try {
reader.registerReaderCallback(EMPTY_MULTI_PART_MIME_READER_CALLBACK);
Assert.fail();
} catch (StreamBusyException streamBusyException) {
}
//This is a desired top level reader state
reader.setState(MultiPartMIMEReader.MultiPartReaderState.READING_PARTS);
final MultiPartMIMEReader.SinglePartMIMEReader singlePartMIMEReader = reader.new SinglePartMIMEReader(Collections.<String, String>emptyMap());
//This is a undesired single part state
singlePartMIMEReader.setState(MultiPartMIMEReader.SingleReaderState.REQUESTED_DATA);
reader.setCurrentSinglePartMIMEReader(singlePartMIMEReader);
try {
reader.registerReaderCallback(EMPTY_MULTI_PART_MIME_READER_CALLBACK);
Assert.fail();
} catch (StreamBusyException streamBusyException) {
}
}
Aggregations