01: package org.vraptor.component;
02:
03: import org.vraptor.AbstractTest;
04: import org.vraptor.LogicRequest;
05: import org.vraptor.introspector.WebBeanProvider;
06: import org.vraptor.scope.Context;
07:
08: public class ComponentConstructorTest extends AbstractTest {
09:
10: public void testDoesntFindEnoughAttributes()
11: throws InvalidComponentException {
12: LogicRequest req = createLogicRequest();
13: BeanConstructor type = new ComponentConstructor(Questions.class
14: .getConstructors()[0]);
15: try {
16: type.newInstance(req, new WebBeanProvider());
17: fail();
18: } catch (ComponentInstantiationException e) {
19: // ok
20: }
21: }
22:
23: public void testConstructsWithAttributeInRequestContext()
24: throws InvalidComponentException,
25: ComponentInstantiationException {
26: LogicRequest req = createLogicRequest();
27: Context logic = req.getRequestContext();
28: logic.setAttribute(Type1.class.getName(), new Type1());
29: logic.setAttribute(Type2.class.getName(), new Type2());
30: logic.setAttribute(Type3.class.getName(), new Type3());
31: logic.setAttribute(Type4.class.getName(), new Type4());
32: BeanConstructor type = new ComponentConstructor(Questions.class
33: .getConstructors()[0]);
34: type.newInstance(req, new WebBeanProvider());
35: }
36:
37: public static class Questions {
38: public Questions(Type1 t1, Type2 t2, Type3 t3, Type4 t4) {
39: }
40: }
41:
42: public static class Type1 {
43: }
44:
45: public static class Type2 {
46: }
47:
48: public static class Type3 {
49: }
50:
51: public static class Type4 {
52: }
53:
54: }
|