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.api.annotations.param;
8   
9   import org.mule.api.expression.RequiredValueException;
10  import org.mule.tck.junit4.AbstractMuleContextTestCase;
11  import org.mule.transformer.simple.ObjectToString;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertNotNull;
16  import static org.junit.Assert.assertNull;
17  import static org.junit.Assert.fail;
18  
19  public class LookupInjectionTestCase extends AbstractMuleContextTestCase
20  {
21      @Test
22      public void testInject() throws Exception
23      {
24          LookupComponent component = new LookupComponent();
25  
26          muleContext.getRegistry().registerObject("transformer1", new ObjectToString());
27          muleContext.getRegistry().registerObject("lookup", component);
28  
29          //Check that we got the transformers injected
30          assertNotNull(component.getTransformer1());
31          //optional
32          assertNull(component.getTransformer2());
33          assertNotNull(component.getTransformer3());
34  
35      }
36  
37      @Test
38      public void testInjectFail() throws Exception
39      {
40          try
41          {
42              muleContext.getRegistry().registerObject("lookup", new LookupComponent());
43              fail("Required object 'transformer1' not in the registry");
44          }
45          catch (RequiredValueException e)
46          {
47              //expected
48          }
49  
50  
51      }
52  }