Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/439#discussion_r63425823
--- Diff:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestStandardProcessSession.java
---
@@ -323,6 +327,37 @@ public void process(final OutputStream outputStream)
throws IOException {
assertDisabled(outputStreamHolder.get());
}
+ @Test(expected=ProcessException.class)
+ public void testExportTo() throws IOException {
+ final ContentClaim claim = contentRepo.create(false);
+ final FlowFileRecord flowFileRecord = new
StandardFlowFileRecord.Builder()
+ .contentClaim(claim)
+ .addAttribute("uuid", "12345678-1234-1234-1234-123456789012")
+ .entryDate(System.currentTimeMillis())
+ .build();
+ flowFileQueue.put(flowFileRecord);
+ FlowFile flowFile = session.get();
+ assertNotNull(flowFile);
+
+ flowFile = session.append(flowFile, new OutputStreamCallback() {
+ @Override
+ public void process(OutputStream out) throws IOException {
+ out.write("Hello World".getBytes());
+ }
+ });
+
+ // should be OK
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ session.exportTo(flowFile, os);
+ assertEquals("Hello World", new String(os.toByteArray()));
+ os.close();
+
+ // should throw ProcessException because of IOException (from
processor code)
+ FileOutputStream mock = Mockito.mock(FileOutputStream.class);
+ doThrow(new IOException()).when(mock).write((byte[]) notNull(),
any(Integer.class), any(Integer.class));
+ session.exportTo(flowFile, mock);
--- End diff --
I would recommend wrapping this call in a try/catch and ensuring that
ProcessException is thrown here. Indicating that it is expected in the @Test
annotation can be somewhat error-prone, as several other method calls within
this method could actually throw ProcessException
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---