Search in sources :

Example 1 with Binding

use of org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding in project felix by apache.

the class AbsBindingModuleTestCase method testConditionalBindings.

public void testConditionalBindings() throws Exception {
    final AnnotationVisitorFactory factory = mock(AnnotationVisitorFactory.class);
    final AnnotationVisitorFactory factory2 = mock(AnnotationVisitorFactory.class);
    AbsBindingModule module = new AbsBindingModule() {

        public void configure() {
            bind(Provides.class).when(on(ElementType.FIELD)).to(factory).when(on(ElementType.PARAMETER)).to(factory2);
        }
    };
    module.configure();
    Iterator<Binding> i = module.iterator();
    Binding one = i.next();
    assertNotNull(one);
    assertEquals(getType(Provides.class), one.getAnnotationType());
    assertEquals(factory, one.getFactory());
    // Second Binding
    Binding two = i.next();
    assertNotNull(two);
    assertEquals(getType(Provides.class), two.getAnnotationType());
    assertEquals(factory2, two.getFactory());
}
Also used : NullBinding(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding) Binding(org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding) Provides(org.apache.felix.ipojo.annotations.Provides)

Example 2 with Binding

use of org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding in project felix by apache.

the class AbsBindingModuleTestCase method testStereotypeBindings.

public void testStereotypeBindings() throws Exception {
    AbsBindingModule module = new AbsBindingModule() {

        public void configure() {
            bindStereotype(Bound.class).with(new ComponentLiteral() {

                @Override
                public boolean publicFactory() {
                    return false;
                }
            });
        }
    };
    module.configure();
    Iterator<Binding> i = module.iterator();
    Binding one = i.next();
    assertNotNull(one);
    assertEquals(getType(Bound.class), one.getAnnotationType());
    assertTrue(one.getFactory() instanceof StereotypeVisitorFactory);
}
Also used : NullBinding(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding) Binding(org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding) StereotypeVisitorFactory(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.StereotypeVisitorFactory)

Example 3 with Binding

use of org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding in project felix by apache.

the class AbsBindingModuleTestCase method testSimpleBinding.

public void testSimpleBinding() throws Exception {
    final AnnotationVisitorFactory factory = mock(AnnotationVisitorFactory.class);
    AbsBindingModule module = new AbsBindingModule() {

        public void configure() {
            bind(Provides.class).to(factory);
        }
    };
    module.configure();
    Iterator<Binding> i = module.iterator();
    Binding one = i.next();
    assertNotNull(one);
    assertEquals(getType(Provides.class), one.getAnnotationType());
    assertEquals(factory, one.getFactory());
    // Only 1 Binding
    assertFalse(i.hasNext());
}
Also used : NullBinding(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding) Binding(org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding) Provides(org.apache.felix.ipojo.annotations.Provides)

Example 4 with Binding

use of org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding in project felix by apache.

the class AbsBindingModuleTestCase method testTwoBindingsForSameAnnotation.

public void testTwoBindingsForSameAnnotation() throws Exception {
    final AnnotationVisitorFactory factory = mock(AnnotationVisitorFactory.class);
    final AnnotationVisitorFactory factory2 = mock(AnnotationVisitorFactory.class);
    AbsBindingModule module = new AbsBindingModule() {

        public void configure() {
            bind(Provides.class).to(factory);
            bind(Provides.class).to(factory2);
        }
    };
    module.configure();
    Iterator<Binding> i = module.iterator();
    Binding one = i.next();
    assertNotNull(one);
    assertEquals(getType(Provides.class), one.getAnnotationType());
    assertEquals(factory, one.getFactory());
    // Second Binding
    Binding two = i.next();
    assertNotNull(two);
    assertEquals(getType(Provides.class), two.getAnnotationType());
    assertEquals(factory2, two.getFactory());
}
Also used : NullBinding(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding) Binding(org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding) Provides(org.apache.felix.ipojo.annotations.Provides)

Example 5 with Binding

use of org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding in project felix by apache.

the class AbsBindingModuleTestCase method testConditionalBinding.

public void testConditionalBinding() throws Exception {
    final AnnotationVisitorFactory factory = mock(AnnotationVisitorFactory.class);
    AbsBindingModule module = new AbsBindingModule() {

        public void configure() {
            bind(Provides.class).when(on(ElementType.FIELD)).to(factory);
        }
    };
    module.configure();
    Iterator<Binding> i = module.iterator();
    Binding one = i.next();
    assertNotNull(one);
    assertEquals(getType(Provides.class), one.getAnnotationType());
    assertEquals(factory, one.getFactory());
    // Only 1 Binding
    assertFalse(i.hasNext());
}
Also used : NullBinding(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding) Binding(org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding) Provides(org.apache.felix.ipojo.annotations.Provides)

Aggregations

Binding (org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Binding)8 NullBinding (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.ignore.NullBinding)8 Provides (org.apache.felix.ipojo.annotations.Provides)5 Requires (org.apache.felix.ipojo.annotations.Requires)1 GenericVisitorFactory (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.GenericVisitorFactory)1 StereotypeVisitorFactory (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.stereotype.StereotypeVisitorFactory)1