1   /*
2    * $Id: MulticastMessageAdapterTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.multicast;
12  
13  import org.mule.tck.providers.AbstractMessageAdapterTestCase;
14  import org.mule.umo.MessagingException;
15  import org.mule.umo.provider.UMOMessageAdapter;
16  
17  import java.net.DatagramPacket;
18  
19  public class MulticastMessageAdapterTestCase extends AbstractMessageAdapterTestCase
20  {
21  
22      public Object getValidMessage() throws Exception
23      {
24          return new DatagramPacket("Hello".getBytes(), 5);
25      }
26  
27      public UMOMessageAdapter createAdapter(Object payload) throws MessagingException
28      {
29          return new MulticastMessageAdapter(payload);
30      }
31  
32      public void testMessageRetrieval() throws Exception
33      {
34          Object message = getValidMessage();
35          UMOMessageAdapter adapter = createAdapter(message);
36  
37          assertEquals(new String(((DatagramPacket)message).getData()), adapter.getPayloadAsString());
38          byte[] bytes = adapter.getPayloadAsBytes();
39          assertNotNull(bytes);
40  
41          String stringMessage = adapter.getPayloadAsString();
42          assertNotNull(stringMessage);
43  
44          assertNotNull(adapter.getPayload());
45  
46          try
47          {
48              adapter = createAdapter(getInvalidMessage());
49              fail("Message adapter should throw exception if an invalid messgae is set");
50          }
51          catch (Exception e)
52          {
53              // expected
54          }
55      }
56  
57  }