View Javadoc

1   /*
2    * $Id: LookupInjectionTestCase.java 20320 2010-11-24 15:03:31Z 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  package org.mule.api.annotations.param;
11  
12  import org.mule.api.expression.RequiredValueException;
13  import org.mule.tck.AbstractMuleTestCase;
14  import org.mule.transformer.simple.ObjectToString;
15  
16  public class LookupInjectionTestCase extends AbstractMuleTestCase
17  {
18      public void testInject() throws Exception
19      {
20          LookupComponent component = new LookupComponent();
21  
22          muleContext.getRegistry().registerObject("transformer1", new ObjectToString());
23          muleContext.getRegistry().registerObject("lookup", component);
24  
25          //Check that we got the transformers injected
26          assertNotNull(component.getTransformer1());
27          //optional
28          assertNull(component.getTransformer2());
29          assertNotNull(component.getTransformer3());
30  
31      }
32  
33      public void testInjectFail() throws Exception
34      {
35          try
36          {
37              muleContext.getRegistry().registerObject("lookup", new LookupComponent());
38              fail("Required object 'transformer1' not in the registry");
39          }
40          catch (RequiredValueException e)
41          {
42              //expected
43          }
44  
45  
46      }
47  }