Multipart { private Multipart(){} private  Multipart(); static Builder multipart(final MultipartContext context);  }
@Test public void testMultipart_forNio() throws Exception { MultipartContext context = mock(MultipartContext.class); when(context.getContentType()).thenReturn("multipart/form-data;boundary=MUEYT2qJT0_ZzYUvVQLy_DlrLeADyxzmsA"); NioMultipartParserListener listener = mock(NioMultipartParserListener.class); PartBodyStreamStorageFactory partBodyStreamStorageFactory = mock(PartBodyStreamStorageFactory.class); NioMultipartParser parser = multipart(context).forNIO(listener); assertNotNull(parser); NioMultipartParser parser1 = multipart(context) .withBufferSize(500) .withHeadersSizeLimit(16000) .withMaxMemoryUsagePerBodyPart(100) .forNIO(listener); assertNotNull(parser1); NioMultipartParser parser2 = multipart(context) .withBufferSize(500) .withHeadersSizeLimit(16000) .withMaxMemoryUsagePerBodyPart(100) .saveTemporaryFilesTo(tempFolder.getRoot().getAbsolutePath()) .limitNestingPartsTo(2) .forNIO(listener); assertNotNull(parser2); NioMultipartParser parser3 = multipart(context) .withBufferSize(500) .withHeadersSizeLimit(16000) .withMaxMemoryUsagePerBodyPart(100) .usePartBodyStreamStorageFactory(partBodyStreamStorageFactory) .forNIO(listener); assertNotNull(parser3); }
@Test public void testMultipart_forBlockingIO() throws Exception { MultipartContext context = mock(MultipartContext.class); when(context.getContentType()).thenReturn("multipart/form-data;boundary=MUEYT2qJT0_ZzYUvVQLy_DlrLeADyxzmsA"); PartBodyStreamStorageFactory partBodyStreamStorageFactory = mock(PartBodyStreamStorageFactory.class); InputStream inputStream = mock(InputStream.class); CloseableIterator<ParserToken> parts = multipart(context).forBlockingIO(inputStream); assertNotNull(parts); CloseableIterator<ParserToken> parts1 = multipart(context) .withBufferSize(500) .withHeadersSizeLimit(16000) .withMaxMemoryUsagePerBodyPart(100) .forBlockingIO(inputStream); assertNotNull(parts1); CloseableIterator<ParserToken> parts2 = multipart(context) .withBufferSize(500) .withHeadersSizeLimit(16000) .withMaxMemoryUsagePerBodyPart(100) .saveTemporaryFilesTo(tempFolder.getRoot().getAbsolutePath()) .limitNestingPartsTo(2) .forBlockingIO(inputStream); assertNotNull(parts2); CloseableIterator<ParserToken> parts3 = multipart(context) .withBufferSize(500) .withHeadersSizeLimit(16000) .withMaxMemoryUsagePerBodyPart(100) .usePartBodyStreamStorageFactory(partBodyStreamStorageFactory) .forBlockingIO(inputStream); assertNotNull(parts3); }