Package org.apache.servicemix.nmr.api

Examples of org.apache.servicemix.nmr.api.Message


import junit.framework.TestCase;

public class MessageImplTest extends TestCase {

    public void testBody() {
        Message msg = new MessageImpl();
        assertNull(msg.getBody());
        msg.setBody("<hello>world</hello>");
        assertTrue(msg.getBody() instanceof String);
        assertNotNull(msg.getBody(String.class));
        assertNotNull(msg.getBody(byte[].class));
        msg.setBody("<hello>world</hello>", byte[].class);
        assertTrue(msg.getBody() instanceof byte[]);
    }
View Full Code Here


                }
                return super.loadClass(name, resolve);
            }
        };
        Class cls = cl.loadClass(MessageImpl.class.getName());
        Message msg = (Message) cls.newInstance();
        msg.setBody("<hello>world</hello>");
        assertNull(msg.getBody(byte[].class));
    }
View Full Code Here

        msg.setBody("<hello>world</hello>");
        assertNull(msg.getBody(byte[].class));
    }

    public void testHeaders() {
        Message msg = new MessageImpl();
        assertNotNull(msg.getHeaders());
        msg.setHeader("name", "value");
        assertEquals("value", msg.getHeader("name"));
        assertNotNull(msg.getHeader("name", byte[].class));
        assertNotNull(msg.removeHeader("name"));
        assertNull(msg.getHeader("name"));
        msg.setHeader(Exchange.class, new ExchangeImpl(Pattern.InOnly));
        assertNotNull(msg.getHeader(Exchange.class.getName(), Exchange.class));
        assertNotNull(msg.getHeader(Exchange.class));
        assertNotNull(msg.removeHeader(Exchange.class));
        assertNull(msg.getHeader(Exchange.class));
        assertTrue(msg.getHeaders().isEmpty());
        msg.setHeaders(createMap("key", "val"));
        assertNotNull(msg.getHeaders());
        assertFalse(msg.getHeaders().isEmpty());
        msg.setHeaders(null);
        assertNull(msg.getHeader("name"));
        assertNull(msg.getHeader(Exchange.class));
        assertNull(msg.getHeader("name", byte[].class));
        assertNull(msg.removeHeader("name"));
        msg.setHeaders(null);
        msg.setHeader(Exchange.class, new ExchangeImpl(Pattern.InOnly));
        assertNotNull(msg.getHeader(Exchange.class));
        msg.setHeaders(null);
        msg.setHeader("name", "value");
        assertNotNull(msg.getHeader("name"));
    }
View Full Code Here

        msg.setHeader("name", "value");
        assertNotNull(msg.getHeader("name"));
    }

    public void testContentType() {
        Message msg = new MessageImpl();
        assertNull(msg.getContentType());
        msg.setContentType("type");
        assertEquals("type", msg.getContentType());
    }
View Full Code Here

        msg.setContentType("type");
        assertEquals("type", msg.getContentType());
    }

    public void testContentEncoding() {
        Message msg = new MessageImpl();
        assertNull(msg.getContentEncoding());
        msg.setContentEncoding("enc");
        assertEquals("enc", msg.getContentEncoding());
    }
View Full Code Here

        msg.setContentEncoding("enc");
        assertEquals("enc", msg.getContentEncoding());
    }

    public void testAttachments() {
        Message msg = new MessageImpl();
        assertNull(msg.getAttachment("id"));
        msg.removeAttachment("id");
        assertNotNull(msg.getAttachments());
        assertNull(msg.getAttachment("id"));
        msg.addAttachment("id", "value");
        assertEquals("value", msg.getAttachment("id"));
        msg.removeAttachment("id");
        assertNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachments().isEmpty());
    }
View Full Code Here

        assertNull(msg.getAttachment("id"));
        assertTrue(msg.getAttachments().isEmpty());
    }

    public void testCopy() {
        Message msg = new MessageImpl();
        Message cpy = msg.copy();
        assertNotNull(cpy);

        msg = new MessageImpl();
        msg.setHeader("header", "value");
        msg.addAttachment("id", "att");
        cpy = msg.copy();
        assertNotNull(cpy);
        assertNotNull(cpy.getHeader("header"));
        assertNotNull(cpy.getAttachment("id"));
    }
View Full Code Here

        assertNotNull(cpy.getHeader("header"));
        assertNotNull(cpy.getAttachment("id"));
    }

    public void testWrite() throws Exception {
        Message msg = new MessageImpl();
        msg.setHeader("header", "value");
        msg.addAttachment("id", "att");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(baos);
        os.writeObject(msg);
        os.close();
        ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
        Message cpy = (Message) is.readObject();
        assertNotNull(cpy);
        assertNotNull(cpy.getHeader("header"));
        assertNotNull(cpy.getAttachment("id"));
    }
View Full Code Here

        assertNotNull(cpy.getHeader("header"));
        assertNotNull(cpy.getAttachment("id"));
    }

    public void testDisplay() {
        Message msg = new MessageImpl();
        msg.toString();
        msg.display(false);
    }
View Full Code Here

        sb.append("]\n");
        return sb.toString();
    }

    public static void display(Exchange exchange, Type type, StringBuffer sb) {
        Message message = exchange.getMessage(type, false);
        if (message != null) {
            sb.append("  ").append(type).append(": [").append('\n');
            sb.append("    content: ");
            try {
                if (message.getBody() != null) {
                    Object contents = message.getBody();
                    sb.append(convertDisplay(contents));
                } else {
                    sb.append("null");
                }
            } catch (Exception e) {
                sb.append("Unable to display: ").append(e);
            }
            sb.append('\n');
            if (message.getAttachments().size() > 0) {
                sb.append("    attachments: [").append('\n');
                for (String key : message.getAttachments().keySet()) {
                    Object contents = message.getAttachment(key);
                    sb.append("      ").append(key).append(" = ").append(convertDisplay(contents)).append('\n');
                }
                sb.append("    ]").append('\n');
            }
            if (message.getHeaders().size() > 0) {
                sb.append("    properties: [").append('\n');
                for (String key : message.getHeaders().keySet()) {
                    sb.append("      ").append(key).append(" = ");
                    Object contents = message.getHeader(key);
                    sb.append(convertDisplay(contents));
                    sb.append('\n');
                }
                sb.append("    ]").append('\n');
            }
View Full Code Here

TOP

Related Classes of org.apache.servicemix.nmr.api.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.