View Javadoc

1   /*
2    * $Id: RouterTestUtils.java 20321 2010-11-24 15:21:24Z dfeist $
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.routing.outbound;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.construct.FlowConstruct;
15  import org.mule.api.endpoint.OutboundEndpoint;
16  import org.mule.tck.MuleTestUtils;
17  
18  import com.mockobjects.dynamic.AnyConstraintMatcher;
19  import com.mockobjects.dynamic.Mock;
20  
21  public class RouterTestUtils
22  {
23      private RouterTestUtils()
24      {
25          super();
26      }
27  
28      /** @return a mock endpoint */
29      public static Mock getMockEndpoint(OutboundEndpoint toMock)
30      {
31          Mock mockEndpoint = MuleTestUtils.getMockOutboundEndpoint();
32          mockEndpoint.matchAndReturn("getEndpointURI", toMock.getEndpointURI());
33          mockEndpoint.matchAndReturn("getAddress", toMock.getEndpointURI().getUri().toString());
34          mockEndpoint.matchAndReturn("toString", toMock.toString());
35          mockEndpoint.matchAndReturn("getExchangePattern", toMock.getExchangePattern());
36          mockEndpoint.matchAndReturn("getProperties", toMock.getProperties());
37          mockEndpoint.matchAndReturn("getFilter", toMock.getFilter());
38          mockEndpoint.matchAndReturn("getName", toMock.getName());
39          mockEndpoint.matchAndReturn("getResponseTransformers", toMock.getResponseTransformers());
40          mockEndpoint.matchAndReturn("hashCode", System.identityHashCode(mockEndpoint));
41          return mockEndpoint;
42      }
43  
44      /** @return an object that verifies that the argument list was a single MuleEvent */
45      public static AnyConstraintMatcher getArgListCheckerMuleEvent()
46      {
47          return new AnyConstraintMatcher()
48          {
49              @Override
50              public boolean matches(Object[] args)
51              {
52                  return args.length == 1 && args[0] instanceof MuleEvent;
53              }
54          };
55      }
56  
57      /** @return an object that verifies that the argument list was a single MuleEvent */
58      public static AnyConstraintMatcher getArgListCheckerFlowConstruct()
59      {
60          return new AnyConstraintMatcher()
61          {
62              @Override
63              public boolean matches(Object[] args)
64              {
65                  return args.length == 1 && (args[0] == null || args[0] instanceof FlowConstruct);
66              }
67          };
68      }
69  }