Coverage Report - org.mule.module.ibeans.config.MockIntegrationBeansAnnotationProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
MockIntegrationBeansAnnotationProcessor
0%
0/18
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: MockIntegrationBeansAnnotationProcessor.java 19191 2010-08-25 21:05:23Z tcarlson $
 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  
 package org.mule.module.ibeans.config;
 11  
 
 12  
 import org.mule.api.MuleContext;
 13  
 import org.mule.api.context.MuleContextAware;
 14  
 import org.mule.api.registry.InjectProcessor;
 15  
 import org.mule.module.ibeans.spi.MuleIBeansPlugin;
 16  
 import org.mule.util.annotation.AnnotationMetaData;
 17  
 import org.mule.util.annotation.AnnotationUtils;
 18  
 
 19  
 import java.lang.reflect.Field;
 20  
 import java.lang.reflect.InvocationHandler;
 21  
 import java.lang.reflect.Proxy;
 22  
 import java.util.List;
 23  
 
 24  
 import org.ibeans.annotation.MockIntegrationBean;
 25  
 import org.ibeans.impl.test.MockIBean;
 26  
 import org.ibeans.impl.test.MockIntegrationBeanInvocationHandler;
 27  
 import org.mockito.Mockito;
 28  
 
 29  
 /**
 30  
  * Will process any fields on an object with the {@link org.ibeans.annotation.MockIntegrationBean} annotation, inserting
 31  
  * a Mockito Mock object.  This is only used for testing.
 32  
  */
 33  
 public class MockIntegrationBeansAnnotationProcessor implements InjectProcessor, MuleContextAware
 34  
 {
 35  
     public static final String NAME = "_mockIntegrationBeanProcessor";
 36  
 
 37  
     private MuleIBeansPlugin plugin;
 38  
 
 39  
     public MockIntegrationBeansAnnotationProcessor()
 40  0
     {
 41  0
     }
 42  
 
 43  
     public void setMuleContext(MuleContext muleContext)
 44  
     {
 45  0
         this.plugin = new MuleIBeansPlugin(muleContext);
 46  0
     }
 47  
 
 48  
     public Object process(Object object)
 49  
     {
 50  0
         List<AnnotationMetaData> annos = AnnotationUtils.getFieldAnnotations(object.getClass(), MockIntegrationBean.class);
 51  
 
 52  0
         if (annos.size() > 0)
 53  
         {
 54  0
             for (AnnotationMetaData data : annos)
 55  
             {
 56  0
                 Field field = (Field) data.getMember();
 57  0
                 field.setAccessible(true);
 58  0
                 Object mockito = Mockito.mock(field.getType(), field.getName());
 59  
                 try
 60  
                 {
 61  
                     //InvocationHandler handler = new MockIBeanHandler(field.getType(), muleContext, mockito);
 62  0
                     InvocationHandler handler = new MockIntegrationBeanInvocationHandler(field.getType(), plugin, mockito);
 63  
 
 64  0
                     Object mock = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{field.getType(), MockIBean.class}, handler);
 65  
 
 66  0
                     field.set(object, mock);
 67  
                 }
 68  0
                 catch (Exception e)
 69  
                 {
 70  0
                     throw new RuntimeException(e);
 71  0
                 }
 72  0
             }
 73  
         }
 74  0
         return object;
 75  
     }
 76  
 }