View Javadoc

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