View Javadoc

1   /*
2    * $Id: XmppEndpointTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.xmpp;
12  
13  import org.mule.api.lifecycle.InitialisationException;
14  import org.mule.endpoint.MuleEndpointURI;
15  import org.mule.tck.AbstractMuleTestCase;
16  
17  public class XmppEndpointTestCase extends AbstractMuleTestCase
18  {
19      public void testEndpointWithoutMessageType() throws Exception
20      {
21          try
22          {
23              MuleEndpointURI uri = new MuleEndpointURI("xmpp://mule:secret@jabber.org", muleContext);
24              uri.initialise();
25              fail("There is no message type set on the endpoint");
26          }
27          catch (InitialisationException e)
28          {
29              // expected
30          }
31      }
32      
33      public void testValidMessageEndpoint() throws Exception
34      {
35          doTest("xmpp://MESSAGE/mule@jabber.org", "MESSAGE");
36      }
37          
38      public void testValidChatEndpoint() throws Exception
39      {
40          doTest("xmpp://CHAT/mule@jabber.org", "CHAT");
41      }
42      
43      public void testValidGroupchatEndpoint() throws Exception
44      {
45          doTest("xmpp://GROUPCHAT/mule@jabber.org", "GROUPCHAT");
46      }
47      
48      private void doTest(String uriInput, String expectedMessageType) throws Exception
49      {
50          MuleEndpointURI uri = new MuleEndpointURI(uriInput, muleContext);
51          uri.initialise();
52  
53          assertEquals("xmpp", uri.getScheme());
54          assertEquals(expectedMessageType, uri.getHost());
55          assertEquals("/mule@jabber.org", uri.getPath());
56      }
57  
58      public void testInvalidMessageTypeEndpoint() throws Exception
59      {
60          try
61          {
62              MuleEndpointURI uri = new MuleEndpointURI("xmpp://INVALID/mule@jabber.org", muleContext);
63              uri.initialise();
64              
65              fail("invalid message type not detected");
66          }
67          catch (InitialisationException e)
68          {
69              // expected
70          }
71      }
72  }