DefaultSerializableMessageTranslator implements SerializableMessageTranslator { @Override public SerializableMessage translate(AdaptrisMessage message) throws CoreException { SerializableAdaptrisMessage serializedMsg = new SerializableAdaptrisMessage(); if (message instanceof FileBackedMessage && message.getSize() > DEFAULT_LMS_BOUNDARY) { serializedMsg.setContent(buildFileDetails(((FileBackedMessage) message).currentSource())); } else { serializedMsg.setContent(message.getContent()); } serializedMsg.setUniqueId(message.getUniqueId()); serializedMsg.setContentEncoding(message.getContentEncoding()); serializedMsg.setMetadata(message.getMetadata()); serializedMsg.setNextServiceId(message.getNextServiceId()); if(message.getObjectHeaders().containsKey(CoreConstants.OBJ_METADATA_EXCEPTION)) serializedMsg.addMetadata(CoreConstants.OBJ_METADATA_EXCEPTION, ((Throwable) message.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION)).getMessage()); return serializedMsg; } DefaultSerializableMessageTranslator(); @Override AdaptrisMessageFactory currentMessageFactory(); @Override void registerMessageFactory(AdaptrisMessageFactory messageFactory); @Override SerializableMessage translate(AdaptrisMessage message); @Override AdaptrisMessage translate(SerializableMessage message);  }
@Test public void testMetadataTranslated() throws Exception { AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage(); message.addMetadata("key1", "value1"); message.addMetadata("key2", "value2"); message.addMetadata("key3", "value3"); DefaultSerializableMessageTranslator translator = new DefaultSerializableMessageTranslator(); SerializableMessage translated = translator.translate(message); assertEquals("value1", translated.getMessageHeaders().get("key1")); assertEquals("value2", translated.getMessageHeaders().get("key2")); assertEquals("value3", translated.getMessageHeaders().get("key3")); }
@Test public void testPayloadTranslated() throws Exception { AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage("SomePayload"); DefaultSerializableMessageTranslator translator = new DefaultSerializableMessageTranslator(); SerializableMessage translated = translator.translate(message); assertEquals("SomePayload", translated.getContent()); }
@Test public void testUniqueId() throws Exception { AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage("SomePayload"); DefaultSerializableMessageTranslator translator = new DefaultSerializableMessageTranslator(); SerializableMessage translated = translator.translate(message); assertEquals(message.getUniqueId(), translated.getUniqueId()); }
@Test public void testCharEncoding() throws Exception { AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage("SomePayload"); message.setContentEncoding("UTF-8"); DefaultSerializableMessageTranslator translator = new DefaultSerializableMessageTranslator(); SerializableMessage translated = translator.translate(message); assertEquals(message.getContentEncoding(), translated.getContentEncoding()); }
@Test public void testExceptionMessage() throws Exception { AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage(); message.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception("An Error Happened")); DefaultSerializableMessageTranslator translator = new DefaultSerializableMessageTranslator(); SerializableMessage translated = translator.translate(message); assertEquals("An Error Happened", translated.getMessageHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION)); }