Coverage Report - org.mule.tck.model.AbstractEntryPointDiscoveryTestCase
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractEntryPointDiscoveryTestCase
0%
0/37
0%
0/3
1.429
AbstractEntryPointDiscoveryTestCase$ComponentMethodMapping
0%
0/13
N/A
1.429
 
 1  
 /*
 2  
  * $Id: AbstractEntryPointDiscoveryTestCase.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.tck.model;
 12  
 
 13  
 import org.mule.impl.NoSatisfiableMethodsException;
 14  
 import org.mule.impl.RequestContext;
 15  
 import org.mule.tck.AbstractMuleTestCase;
 16  
 import org.mule.tck.testmodels.fruit.InvalidSatsuma;
 17  
 import org.mule.umo.UMODescriptor;
 18  
 import org.mule.umo.model.UMOEntryPoint;
 19  
 import org.mule.umo.model.UMOEntryPointResolver;
 20  
 import org.mule.util.ClassUtils;
 21  
 
 22  0
 public abstract class AbstractEntryPointDiscoveryTestCase extends AbstractMuleTestCase
 23  
 {
 24  
 
 25  
     /**
 26  
      * Tests entrypoint discovery when there is no discoverable method
 27  
      */
 28  
     public void testFailEntryPointDiscovery() throws Exception
 29  
     {
 30  0
         UMOEntryPointResolver epd = getEntryPointResolver();
 31  0
         UMODescriptor descriptor = getTestDescriptor("badSatsuma", InvalidSatsuma.class.getName());
 32  
 
 33  0
         UMOEntryPoint ep = null;
 34  
 
 35  
         try
 36  
         {
 37  0
             ep = epd.resolveEntryPoint(descriptor);
 38  
         }
 39  0
         catch (NoSatisfiableMethodsException e)
 40  
         {
 41  
             // expected
 42  0
             return;
 43  0
         }
 44  
 
 45  0
         assertNotNull(ep);
 46  
 
 47  
         try
 48  
         {
 49  0
             RequestContext.setEvent(getTestEvent("Hello"));
 50  0
             ep.invoke(new InvalidSatsuma(), RequestContext.getEventContext());
 51  0
             fail("Should have failed to find entrypoint on Satsuma");
 52  
 
 53  
         }
 54  0
         catch (Exception e)
 55  
         {
 56  
             // expected
 57  
         }
 58  
         finally
 59  
         {
 60  0
             RequestContext.setEvent(null);
 61  0
         }
 62  
 
 63  0
     }
 64  
 
 65  
     /**
 66  
      * Tests entrypoint discovery on object that has it's own event handler without
 67  
      * implementing any of the Mule event interfaces
 68  
      */
 69  
     public void testEntryPointDiscovery() throws Exception
 70  
     {
 71  0
         ComponentMethodMapping[] mappings = getComponentMappings();
 72  
 
 73  0
         for (int i = 0; i < mappings.length; i++)
 74  
         {
 75  0
             if (mappings[i].isShouldFail())
 76  
             {
 77  0
                 doExpectedFail(mappings[i]);
 78  
             }
 79  
             else
 80  
             {
 81  0
                 doExpectedPass(mappings[i]);
 82  
             }
 83  
         }
 84  0
     }
 85  
 
 86  
     private void doExpectedPass(ComponentMethodMapping mapping) throws Exception
 87  
     {
 88  0
         UMOEntryPointResolver epr = getEntryPointResolver();
 89  0
         UMODescriptor descriptor = getDescriptorToResolve(mapping.getComponentClass().getName());
 90  0
         UMOEntryPoint ep = epr.resolveEntryPoint(descriptor);
 91  0
         assertNotNull(ep);
 92  
         // TODO
 93  
         // if(!(ep instanceof DynamicEntryPoint)) {
 94  
         // assertEquals(ep.getName(), mapping.getMethodName());
 95  
         // assertEquals(ep.getParameterType(), mapping.getMethodArgumentType());
 96  
         // }
 97  0
     }
 98  
 
 99  
     private void doExpectedFail(ComponentMethodMapping mapping) throws Exception
 100  
     {
 101  0
         UMOEntryPointResolver epr = getEntryPointResolver();
 102  0
         UMODescriptor descriptor = getDescriptorToResolve(mapping.getComponentClass().getName());
 103  
 
 104  
         try
 105  
         {
 106  0
             UMOEntryPoint ep = epr.resolveEntryPoint(descriptor);
 107  0
             ep.invoke(ClassUtils.instanciateClass(mapping.getComponentClass(), ClassUtils.NO_ARGS),
 108  
                 getTestEventContext("blah"));
 109  0
             fail("Resolving should have failed for: " + mapping.toString());
 110  
         }
 111  0
         catch (Exception e)
 112  
         {
 113  
             // expected
 114  0
         }
 115  
 
 116  0
     }
 117  
 
 118  
     public UMODescriptor getDescriptorToResolve(String className) throws Exception
 119  
     {
 120  0
         return getTestDescriptor("myComponent", className);
 121  
     }
 122  
 
 123  
     public abstract UMOEntryPointResolver getEntryPointResolver();
 124  
 
 125  
     /**
 126  
      * @return an array of the the different components that can be resolved by the
 127  
      *         resolver and the method name to be resolved on each component
 128  
      */
 129  
     public abstract ComponentMethodMapping[] getComponentMappings();
 130  
 
 131  
     /**
 132  
      * <p>
 133  
      * <code>ComponentMethodMapping</code> is used to supply a component class and
 134  
      * the correct method to be resovled on the component.
 135  
      */
 136  0
     public class ComponentMethodMapping
 137  
     {
 138  
         private Class componentClass;
 139  
         private Class methodArgumentType;
 140  
         private String methodName;
 141  
         private boolean shouldFail;
 142  
 
 143  
         public ComponentMethodMapping(Class componentClass, String methodName, Class methodArgumentType)
 144  
         {
 145  0
             this(componentClass, methodName, methodArgumentType, false);
 146  0
         }
 147  
 
 148  
         public ComponentMethodMapping(Class componentClass,
 149  
                                       String methodName,
 150  
                                       Class methodArgumentType,
 151  
                                       boolean shouldFail)
 152  0
         {
 153  0
             this.componentClass = componentClass;
 154  0
             this.methodName = methodName;
 155  0
             this.methodArgumentType = methodArgumentType;
 156  0
             this.shouldFail = shouldFail;
 157  0
         }
 158  
 
 159  
         /**
 160  
          * @return Returns the componentClass.
 161  
          */
 162  
         public Class getComponentClass()
 163  
         {
 164  0
             return componentClass;
 165  
         }
 166  
 
 167  
         /**
 168  
          * @return Returns the methodName.
 169  
          */
 170  
         public String getMethodName()
 171  
         {
 172  0
             return methodName;
 173  
         }
 174  
 
 175  
         /**
 176  
          * @return Returns the methodName.
 177  
          */
 178  
         public Class getMethodArgumentType()
 179  
         {
 180  0
             return methodArgumentType;
 181  
         }
 182  
 
 183  
         /**
 184  
          * @return Returns the shouldFail.
 185  
          */
 186  
         public boolean isShouldFail()
 187  
         {
 188  0
             return shouldFail;
 189  
         }
 190  
 
 191  
         // @Override
 192  
         public String toString()
 193  
         {
 194  0
             return componentClass.getName() + "." + methodName + "(" + methodArgumentType.getName()
 195  
                    + "), Expected to fail= " + shouldFail;
 196  
         }
 197  
 
 198  
     }
 199  
 }