MultiPayloadMessageSplitter extends MessageSplitterImp { @Override public Iterable<AdaptrisMessage> splitMessage(AdaptrisMessage msg) { List<AdaptrisMessage> splitMessages = new ArrayList<>(); if (!(msg instanceof MultiPayloadAdaptrisMessage)) { log.warn("Message [{}] is not a multi-payload message!", msg.getUniqueId()); splitMessages.add(msg); } else { MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage)msg; for (String id : message.getPayloadIDs()) { message.switchPayload(id); try { AdaptrisMessage splitMessage = DefaultMessageFactory.getDefaultInstance().newMessage(message, null); splitMessage.setPayload(message.getPayload()); splitMessages.add(splitMessage); } catch (CloneNotSupportedException e) { log.error("Could not clone message [{}]", id, e); } } } log.info("Split multi-payload message into {} standard messages", splitMessages.size()); return splitMessages; }  @Override Iterable<AdaptrisMessage> splitMessage(AdaptrisMessage msg);  }
@Test public void testMessageSplitter() { List<AdaptrisMessage> response = (List<AdaptrisMessage>)splitter.splitMessage(message); assertEquals(2, response.size()); for (AdaptrisMessage message : response) { String content = message.getContent(); if (!PAYLOAD_1.equals(content) && !PAYLOAD_2.equals(content)) { fail(); } } }
@Test public void testWrongMessageType() { AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1); List<AdaptrisMessage> response = (List<AdaptrisMessage>)splitter.splitMessage(message); assertEquals(1, response.size()); }
@Test @SuppressWarnings("serial") public void testNonCloneableMessage() { List<AdaptrisMessage> response = (List<AdaptrisMessage>)splitter.splitMessage(new MultiPayloadAdaptrisMessageImp("bacon", new GuidGenerator(), DefaultMessageFactory.getDefaultInstance(), PAYLOAD_1.getBytes()) { @Override public MessageLifecycleEvent getMessageLifecycleEvent() { return new MessageLifecycleEvent() { @Override public List<MleMarker> getMleMarkers() { List<MleMarker> list = new ArrayList<>(); list.add(new MleMarker() { @Override public Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException(); } }); return list; } }; } }); assertEquals(0, response.size()); }