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