1   /*
2    * $Id: ConnectorServiceOverridesTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.providers.file;
12  
13  import org.mule.MuleManager;
14  import org.mule.impl.endpoint.MuleEndpoint;
15  import org.mule.impl.endpoint.MuleEndpointURI;
16  import org.mule.providers.AbstractConnector;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.transformers.simple.ByteArrayToSerializable;
19  import org.mule.transformers.simple.SerializableToByteArray;
20  import org.mule.umo.UMOException;
21  import org.mule.umo.endpoint.UMOEndpoint;
22  import org.mule.umo.endpoint.UMOEndpointURI;
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          // TODO initialised wait?
35          Thread.sleep(1000);
36          FileConnector c = (FileConnector)MuleManager.getInstance().lookupConnector("fileConnector2");
37          assertNotNull(c);
38          assertNotNull(c.getServiceOverrides());
39          assertEquals("org.mule.transformers.simple.ByteArrayToSerializable", c.getServiceOverrides().get(
40              "inbound.transformer"));
41          assertNotNull(c.getDefaultInboundTransformer());
42          assertNotNull(c.getDefaultOutboundTransformer());
43          assertTrue(c.getDefaultInboundTransformer() instanceof ByteArrayToSerializable);
44          assertTrue(c.getDefaultOutboundTransformer() instanceof SerializableToByteArray);
45      }
46  
47      public void testServiceOverrides2() throws InterruptedException
48      {
49          FileConnector c = (FileConnector)MuleManager.getInstance().lookupConnector("fileConnector1");
50          assertNotNull(c);
51          assertNull(c.getServiceOverrides());
52  
53          c = (FileConnector)MuleManager.getInstance().lookupConnector("fileConnector2");
54          assertNotNull(c);
55          assertNotNull(c.getServiceOverrides());
56  
57          c = (FileConnector)MuleManager.getInstance().lookupConnector("fileConnector3");
58          assertNotNull(c);
59          assertNull(c.getServiceOverrides());
60      }
61  
62      public void testServiceOverrides3() throws InterruptedException, UMOException
63      {
64          UMOEndpointURI uri = new MuleEndpointURI("file:///temp?connector=fileConnector1");
65          UMOEndpoint endpoint = MuleEndpoint.createEndpointFromUri(uri, UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
66  
67          assertNotNull(endpoint);
68          assertNotNull(endpoint.getConnector());
69          assertNull(((AbstractConnector)endpoint.getConnector()).getServiceOverrides());
70  
71          endpoint = new MuleEndpoint("file:///temp?connector=fileConnector1", true);
72  
73          FileConnector c = (FileConnector)MuleManager.getInstance().lookupConnector("fileConnector2");
74          assertNotNull(c);
75          assertNotNull(c.getServiceOverrides());
76          endpoint.setConnector(c);
77  
78          endpoint.initialise();
79          assertNotNull(((AbstractConnector)endpoint.getConnector()).getServiceOverrides());
80  
81          endpoint = new MuleEndpoint("file:///temp?connector=fileConnector3", true);
82          endpoint.initialise();
83          assertNull(((AbstractConnector)endpoint.getConnector()).getServiceOverrides());
84  
85          endpoint = new MuleEndpoint("file:///temp?connector=fileConnector2", true);
86          endpoint.initialise();
87          assertNotNull(((AbstractConnector)endpoint.getConnector()).getServiceOverrides());
88  
89      }
90  }