MultipartContentOperationPreprocessor extends OperationPreprocessorAdapter { @Override public OperationRequest preprocess(OperationRequest request) { if (isMultipart(request)) { List<OperationRequestPart> parts = request.getParts().stream() .map(this::replaceBinary) .collect(toList()); return requestFactory.create(request.getUri(), request.getMethod(), request.getContent(), request.getHeaders(), request.getParameters() , parts); } return request; }  @Override OperationRequest preprocess(OperationRequest request);  }
@Test public void shouldReplaceContent() throws URISyntaxException { OperationRequest request = createRequestWithContentType(MediaType.MULTIPART_FORM_DATA_VALUE); OperationRequest processedRequest = preprocessor.preprocess(request); assertArrayEquals(request.getContent(), processedRequest.getContent()); assertEquals(request.getHeaders(), processedRequest.getHeaders()); assertEquals(request.getMethod(), processedRequest.getMethod()); assertEquals(request.getUri(), processedRequest.getUri()); assertEquals(request.getParameters(), processedRequest.getParameters()); for (OperationRequestPart part : processedRequest.getParts()) { assertArrayEquals(EXPECTED_CONTENT, part.getContent()); } }
@Test public void shouldNotReplaceWhenNotMultipart() throws URISyntaxException { OperationRequest request = createRequestWithContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); OperationRequest processedRequest = preprocessor.preprocess(request); assertArrayEquals(request.getContent(), processedRequest.getContent()); assertEquals(request.getHeaders(), processedRequest.getHeaders()); assertEquals(request.getMethod(), processedRequest.getMethod()); assertEquals(request.getUri(), processedRequest.getUri()); assertEquals(request.getParameters(), processedRequest.getParameters()); OperationRequestPart[] expectedParts = request.getParts().toArray(new OperationRequestPart[0]); OperationRequestPart[] operationRequestParts = processedRequest.getParts().toArray(new OperationRequestPart[0]); for (int i = 0; i < operationRequestParts.length; i++) { assertEquals(expectedParts[i], operationRequestParts[i]); } }