1   /*
2    * $Id: ObjectNameHelperTestCase.java 10489 2008-01-23 17:53:38Z dfeist $
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.test.integration.util;
12  
13  import org.mule.api.endpoint.ImmutableEndpoint;
14  import org.mule.tck.AbstractMuleTestCase;
15  
16  public class ObjectNameHelperTestCase extends AbstractMuleTestCase
17  {
18      public void testEndpointAutomaticNames() throws Exception
19      {
20  
21          ImmutableEndpoint ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
22              "test://cn=foo,name=queue");
23          muleContext.getRegistry().registerEndpoint(ep);
24          assertEquals("endpoint.test.cn.foo.name.queue", ep.getName());
25  
26          ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("test://cn=foo,name=queue");
27          assertEquals("endpoint.test.cn.foo.name.queue.1", ep.getName());
28  
29          // Test generating a unique name when there is a matching endpoint
30          ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("vm://my.queue");
31          assertEquals("endpoint.vm.my.queue", ep.getName());
32          ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
33              "pop3://ross:secret@mail.mycompany.com?subject=foo");
34          assertEquals("endpoint.pop3.ross.mycompany.com", ep.getName());
35      }
36  
37      public void testEndpointNames() throws Exception
38      {
39          ImmutableEndpoint ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
40              "test://cn=foo,name=queue?endpointName=foo");
41          muleContext.getRegistry().registerEndpoint(ep);
42          assertEquals("foo", ep.getName());
43  
44          ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
45              "test://cn=foo,name=queue?endpointName=this_is@aWierd-Name:x");
46          assertEquals("this.is.aWierd.Name.x", ep.getName());
47          muleContext.getRegistry().registerEndpoint(ep);
48  
49          // Test generating a unique name when there is a matching endpoint
50          ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
51              "test://cn=foo,name=queue?endpointName=this_is@aWierd-Name:x");
52          assertEquals("this.is.aWierd.Name.x", ep.getName());
53          ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
54              "test://cn=foo,name=queue?endpointName=this____is+another=@Wierd----Name:x:::");
55          assertEquals("this.is.another.Wierd.Name.x", ep.getName());
56      }
57  
58      public void testTestEndpoint() throws Exception
59      {
60          ImmutableEndpoint ep = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
61              "test://exception.listener");
62          muleContext.getRegistry().registerEndpoint(ep);
63          assertEquals("endpoint.test.exception.listener", ep.getName());
64      }
65  }