use of org.apache.aries.blueprint.di.PassThroughRecipe in project aries by apache.
the class BeanRecipeTest method protectedClassAccess.
@Test
public void protectedClassAccess() throws Exception {
BlueprintContainerImpl container = new BlueprintContainerImpl(null, null, null, null, null, null, null, null, null, null);
BeanRecipe recipe = new BeanRecipe("a", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory().create()));
recipe.setFactoryMethod("getA");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
assertNotNull(recipe.create());
recipe = new BeanRecipe("b", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory().create()));
recipe.setFactoryMethod("getB");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
assertNotNull(recipe.create());
recipe = new BeanRecipe("c", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory().create()));
recipe.setFactoryMethod("getC");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
assertNotNull(recipe.create());
recipe = new BeanRecipe("d", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory().create()));
recipe.setFactoryMethod("getD");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
try {
assertNotNull(recipe.create());
fail("Should have thrown an exception");
} catch (ComponentDefinitionException e) {
// ok
}
recipe = new BeanRecipe("a", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory()));
recipe.setFactoryMethod("create");
recipe.setProperty("a", "a");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
assertNotNull(recipe.create());
recipe = new BeanRecipe("b", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory()));
recipe.setFactoryMethod("create");
recipe.setProperty("b", "b");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
assertNotNull(recipe.create());
recipe = new BeanRecipe("c", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory()));
recipe.setFactoryMethod("create");
recipe.setProperty("c", "c");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
assertNotNull(recipe.create());
recipe = new BeanRecipe("d", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory()));
recipe.setFactoryMethod("create");
recipe.setProperty("d", "d");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
try {
assertNotNull(recipe.create());
fail("Should have thrown an exception");
} catch (ComponentDefinitionException e) {
// ok
}
recipe = new BeanRecipe("a", container, null, false, false, false);
recipe.setFactoryComponent(new PassThroughRecipe("factory", new Factory()));
recipe.setFactoryMethod("create");
recipe.setInitMethod("init");
ExecutionContext.Holder.setContext(new BlueprintRepository(container));
assertNotNull(recipe.create());
}
Aggregations