1   /*
2    * $Id: ConnectorServiceOverridesTestCase.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.transport.file;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.endpoint.EndpointBuilder;
15  import org.mule.api.endpoint.ImmutableEndpoint;
16  import org.mule.endpoint.EndpointURIEndpointBuilder;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.transformer.TransformerUtils;
19  import org.mule.transformer.simple.ByteArrayToSerializable;
20  import org.mule.transformer.simple.SerializableToByteArray;
21  import org.mule.transport.AbstractConnector;
22  import org.mule.transport.file.FileConnector;
23  
24  public class ConnectorServiceOverridesTestCase extends FunctionalTestCase
25  {
26  
27      protected String getConfigResources()
28      {
29          return "test-connector-config.xml";
30      }
31  
32      public void testServiceOverrides() throws InterruptedException
33      {
34          FileConnector c = (FileConnector) muleContext.getRegistry().lookupConnector("fileConnector2");
35          assertNotNull(c);
36          assertNotNull(c.getServiceOverrides());
37          assertEquals("org.mule.transformer.simple.ByteArrayToSerializable", c.getServiceOverrides().get(
38              "inbound.transformer"));
39          assertNotNull(TransformerUtils.firstOrNull(c.getDefaultInboundTransformers()));
40          assertNotNull(TransformerUtils.firstOrNull(c.getDefaultOutboundTransformers()));
41          assertTrue(TransformerUtils.firstOrNull(c.getDefaultInboundTransformers()) instanceof ByteArrayToSerializable);
42          assertTrue(TransformerUtils.firstOrNull(c.getDefaultOutboundTransformers()) instanceof SerializableToByteArray);
43      }
44  
45      public void testServiceOverrides2() throws InterruptedException
46      {
47          FileConnector c = (FileConnector) muleContext.getRegistry().lookupConnector("fileConnector1");
48          assertNotNull(c);
49          assertNull(c.getServiceOverrides());
50  
51          c = (FileConnector) muleContext.getRegistry().lookupConnector("fileConnector2");
52          assertNotNull(c);
53          assertNotNull(c.getServiceOverrides());
54  
55          c = (FileConnector) muleContext.getRegistry().lookupConnector("fileConnector3");
56          assertNotNull(c);
57          assertNull(c.getServiceOverrides());
58      }
59  
60      public void testServiceOverrides3() throws InterruptedException, MuleException
61      {
62          // EndpointURI uri = new MuleEndpointURI("file:///temp?connector=fileConnector1");
63          ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
64              "file:///temp?connector=fileConnector1");
65  
66          assertNotNull(endpoint);
67          assertNotNull(endpoint.getConnector());
68          assertNull(((AbstractConnector) endpoint.getConnector()).getServiceOverrides());
69  
70          FileConnector c = (FileConnector) muleContext.getRegistry().lookupConnector("fileConnector2");
71          assertNotNull(c);
72          assertNotNull(c.getServiceOverrides());
73  
74          EndpointBuilder builder = new EndpointURIEndpointBuilder("file:///temp?connector=fileConnector1",
75              muleContext);
76          builder.setConnector(c);
77          endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(builder);
78          assertNotNull(((AbstractConnector) endpoint.getConnector()).getServiceOverrides());
79  
80          EndpointBuilder builder2 = new EndpointURIEndpointBuilder("file:///temp?connector=fileConnector3",
81              muleContext);
82          builder.setConnector(c);
83          endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(builder2);
84          assertNull(((AbstractConnector) endpoint.getConnector()).getServiceOverrides());
85  
86          EndpointBuilder builder3 = new EndpointURIEndpointBuilder("file:///temp?connector=fileConnector2",
87              muleContext);
88          builder.setConnector(c);
89          endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(builder3);
90          assertNotNull(((AbstractConnector) endpoint.getConnector()).getServiceOverrides());
91  
92      }
93  }