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.config.spring;
8   
9   import org.mule.util.concurrent.Latch;
10  import org.mule.api.MuleEventContext;
11  
12  import java.lang.reflect.Method;
13  
14  import org.springframework.aop.MethodBeforeAdvice;
15  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
16  
17  public class FunctionalTestAdvice implements MethodBeforeAdvice
18  {
19  
20      private Latch latch = new Latch();
21      private String message;
22  
23      public void before(Method method, Object[] args, Object target) throws Throwable
24      {
25          if (null != args && args.length == 1 && args[0] instanceof MuleEventContext)
26          {
27              message = ((MuleEventContext) args[0]).getMessageAsString();
28          }
29          latch.countDown();
30      }
31  
32      public String getMessage(long ms) throws InterruptedException
33      {
34          latch.await(ms, TimeUnit.MILLISECONDS);
35          return message;
36      }
37  
38  }