View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.util;
8   
9   import org.mule.api.endpoint.ImmutableEndpoint;
10  import org.mule.tck.junit4.AbstractMuleContextTestCase;
11  
12  import org.junit.Test;
13  
14  import static org.junit.Assert.assertEquals;
15  
16  public class ObjectNameHelperTestCase extends AbstractMuleContextTestCase
17  {
18      
19      @Test
20      public void testEndpointAutomaticNames() throws Exception
21      {
22          ImmutableEndpoint ep = muleContext.getEndpointFactory().getInboundEndpoint(
23              "test://cn=foo,name=queue");
24          muleContext.getRegistry().registerEndpoint(ep);
25          assertEquals("endpoint.test.cn.foo.name.queue", ep.getName());
26  
27          ep = muleContext.getEndpointFactory().getInboundEndpoint("test://cn=foo,name=queue");
28          assertEquals("endpoint.test.cn.foo.name.queue.1", ep.getName());
29  
30          // Test generating a unique name when there is a matching endpoint
31          ep = muleContext.getEndpointFactory().getInboundEndpoint("vm://my.queue");
32          assertEquals("endpoint.vm.my.queue", ep.getName());
33          ep = muleContext.getEndpointFactory().getInboundEndpoint(
34              "pop3://ross:secret@mail.mycompany.com?subject=foo");
35          assertEquals("endpoint.pop3.ross.mycompany.com", ep.getName());
36      }
37  
38      @Test
39      public void testEndpointNames() throws Exception
40      {
41          ImmutableEndpoint ep = muleContext.getEndpointFactory().getInboundEndpoint(
42              "test://cn=foo,name=queue?endpointName=foo");
43          muleContext.getRegistry().registerEndpoint(ep);
44          assertEquals("endpoint.test.cn.foo.name.queue", ep.getName());
45  
46          ep = muleContext.getEndpointFactory().getInboundEndpoint(
47              "test://cn=foo,name=queue?endpointName=this_is@aWierd-Name:x");
48          assertEquals("this.is.aWierd.Name.x", ep.getName());
49          muleContext.getRegistry().registerEndpoint(ep);
50  
51          // Test generating a unique name when there is a matching endpoint
52          ep = muleContext.getEndpointFactory().getInboundEndpoint(
53              "test://cn=foo,name=queue?endpointName=this_is@aWierd-Name:x");
54          assertEquals("this.is.aWierd.Name.x", ep.getName());
55          ep = muleContext.getEndpointFactory().getInboundEndpoint(
56              "test://cn=foo,name=queue?endpointName=this____is+another=@Wierd----Name:x:::");
57          assertEquals("this.is.another.Wierd.Name.x", ep.getName());
58      }
59  
60      @Test
61      public void testTestEndpoint() throws Exception
62      {
63          ImmutableEndpoint ep = muleContext.getEndpointFactory().getInboundEndpoint(
64              "test://exception.listener");
65          muleContext.getRegistry().registerEndpoint(ep);
66          assertEquals("endpoint.test.exception.listener", ep.getName());
67      }
68  
69  }