View Javadoc
1   package org.codehaus.plexus.component.configurator;
2   
3   import org.codehaus.plexus.component.repository.ComponentDescriptor;
4   import org.codehaus.plexus.component.builder.XBeanComponentBuilder;
5   import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
6   import org.codehaus.plexus.classworlds.realm.ClassRealm;
7   import org.apache.xbean.recipe.ConstructionException;
8   import org.apache.xbean.recipe.ObjectRecipe;
9   import org.apache.xbean.recipe.ExecutionContext;
10  import org.apache.xbean.recipe.DefaultExecutionContext;
11  
12  public class XBeanComponentConfiguratorTest extends AbstractComponentConfiguratorTest {
13      @Override
14      protected void configureComponent(Object component, ComponentDescriptor descriptor, ClassRealm realm) throws Exception {
15          XBeanComponentBuilder componentBuilder = new XBeanComponentBuilder();
16          ObjectRecipe recipe = componentBuilder.createObjectRecipe( component, descriptor, realm);
17  
18          // need a caller context
19          ExecutionContext executionContext = new DefaultExecutionContext();
20          executionContext.push(new ObjectRecipe(component.getClass()));
21  
22          // call the recipie setProperties directly, but setup the thead state first
23          ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
24          Thread.currentThread().setContextClassLoader(realm);
25          ExecutionContext.setContext(executionContext);
26          try
27          {
28              recipe.setProperties( component );
29          }
30          catch ( ConstructionException e )
31          {
32              throw new ComponentConfigurationException( "Failed to configure component", e );
33          }
34          finally
35          {
36              ExecutionContext.setContext(null);
37              Thread.currentThread().setContextClassLoader(oldClassLoader);
38          }
39      }
40  
41      protected void configureComponent(Object component, ComponentDescriptor descriptor, ClassRealm realm, ExpressionEvaluator expressionEvaluator) throws Exception {
42          this.configureComponent(component, descriptor, realm);    
43      }
44  
45      public void testComponentConfigurationWithPropertiesFieldsWithExpression() throws Exception {
46          // expression evalator is not supported since it is not used by normal AutoConfigurePhase
47      }
48  
49      public void testComponentConfigurationWithPropertiesFieldsWithExpressions() throws Exception {
50          // expression evalator is not supported since it is not used by normal AutoConfigurePhase
51      }
52  
53      public void testComponentConfigurationWithAmbiguousExpressionValue()
54          throws Exception
55      {
56          // expression evalator is not supported since it is not used by normal AutoConfigurePhase
57      }
58  
59      public void testComponentConfigurationWithPrimitiveValueConversion()
60          throws Exception
61      {
62          // expression evalator is not supported since it is not used by normal AutoConfigurePhase
63      }
64  
65      public void testComponentConfigurationWithUnresolvedExpressionContentForCompositeFieldOfNonInstantiatableType()
66          throws Exception
67      {
68          // expression evalator is not supported since it is not used by normal AutoConfigurePhase
69      }
70  
71      protected ComponentConfigurator getComponentConfigurator() throws Exception {
72          // this should never be called because the configureComponent is overridden
73          throw new UnsupportedOperationException();
74      }
75  }