View Javadoc

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