MultiPayloadStreamOutputParameter extends PayloadStreamOutputParameter implements DataOutputParameter<InputStreamWithEncoding> { @Override public void insert(InputStreamWithEncoding data, InterlokMessage m) throws InterlokException { if (m instanceof MultiPayloadAdaptrisMessage) { insert(data, m.resolve(getPayloadId()), (MultiPayloadAdaptrisMessage)m); } else { throw new InterlokException("Cannot insert payload into message type " + m.getClass().getName() + " as it does not support multiple payloads."); } }  String getPayloadId(); void setPayloadId(String payloadId); @Override void insert(InputStreamWithEncoding data, InterlokMessage m); void insert(InputStreamWithEncoding data, String id, MultiPayloadAdaptrisMessage m);  }
@Test public void testInsert() throws Exception { MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage)new MultiPayloadMessageFactory().newMessage(); try (InputStream in = new ByteArrayInputStream(PAYLOAD.getBytes())) { InputStreamWithEncoding stream = new InputStreamWithEncoding(in, ENCODING); MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter(); parameter.insert(stream, ID, message); } assertEquals(PAYLOAD, message.getContent(ID)); }
@Test public void testInsertUseDefaultId() throws Exception { MultiPayloadMessageFactory messageFactory = new MultiPayloadMessageFactory(); MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage)messageFactory.newMessage(); try (InputStream in = new ByteArrayInputStream(PAYLOAD.getBytes())) { InputStreamWithEncoding stream = new InputStreamWithEncoding(in, ENCODING); MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter(); parameter.insert(stream, null, message); } assertEquals(PAYLOAD, message.getContent(messageFactory.getDefaultPayloadId())); }
@Test public void testInsertNoEncoding() throws Exception { MultiPayloadMessageFactory messageFactory = new MultiPayloadMessageFactory(); MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage)messageFactory.newMessage(); try (InputStream in = new ByteArrayInputStream(PAYLOAD.getBytes())) { InputStreamWithEncoding stream = new InputStreamWithEncoding(in, null); MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter(); parameter.setContentEncoding(null); parameter.insert(stream, ID, message); } assertEquals(PAYLOAD, message.getContent(ID)); }
@Test public void testInsertNullStream() throws Exception { MultiPayloadMessageFactory messageFactory = new MultiPayloadMessageFactory(); MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage)messageFactory.newMessage(); try { InputStreamWithEncoding stream = new InputStreamWithEncoding(null, ENCODING); MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter(); parameter.insert(stream, ID, message); } catch (Exception e) { } }
@Test public void testWrongMessageType() { try { MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter(); AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage(); parameter.insert(null, message); fail(); } catch (Exception e) { } }