javax.enterprise.inject.spi.Producer Java Examples

The following examples show how to use javax.enterprise.inject.spi.Producer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JpaUnitCdiExtensionTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegisterProducer() {
    // GIVEN
    final JpaUnitCdiExtension extension = new JpaUnitCdiExtension();

    // WHEN
    extension.registerProducer(producer);

    // THEN
    verify(producer).getProducer();
    verify(producer).setProducer(producerCaptor.capture());
    verifyNoMoreInteractions(producer);

    final Producer<EntityManager> captured = producerCaptor.getValue();
    assertThat(captured, not(nullValue()));
    assertThat(captured, instanceOf(EntityManagerProducerProxy.class));
}
 
Example #2
Source File: MockAwareProducerWrapper.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public MockAwareProducerWrapper(BeanManager beanManager,
                                Producer<T> wrapped,
                                List<Type> beanTypes,
                                List<Annotation> qualifiers)
{
    this.beanManager = beanManager;
    this.wrapped = wrapped;
    this.beanTypes = beanTypes;
    this.qualifiers = qualifiers;
}
 
Example #3
Source File: AxonCdiExtension.java    From cdi with Apache License 2.0 4 votes vote down vote up
private <T> void addIfNotConfigured(Class<T> componentType, Producer<T> componentProducer,
        Supplier<T> componentSupplier, AfterBeanDiscovery afterBeanDiscovery) {
    if (componentProducer == null) {
        afterBeanDiscovery.addBean(new BeanWrapper<>(componentType, componentSupplier));
    }
}
 
Example #4
Source File: AxonCdiExtension.java    From cdi with Apache License 2.0 4 votes vote down vote up
private <T> T produce(BeanManager beanManager, Producer<T> producer) {
    return producer.produce(beanManager.createCreationalContext(null));
}
 
Example #5
Source File: EntityManagerProducerProxy.java    From jpa-unit with Apache License 2.0 4 votes vote down vote up
public EntityManagerProducerProxy(final Producer<EntityManager> proxied) {
    this.proxied = proxied;
}
 
Example #6
Source File: CdiPlugin.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Producer<T> getProducer() {
    return new EjbProducer<>(this, bean);
}
 
Example #7
Source File: MockExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public <X, T> void onProcessProducer(@Observes ProcessProducer<X, T> processProducer, BeanManager beanManager)
{
    if (!isActivated)
    {
        return;
    }

    for (MockFilter mockFilter : mockFilters)
    {
        if (!mockFilter.isMockedImplementationSupported(beanManager, processProducer.getAnnotatedMember()))
        {
            return;
        }
    }

    final Producer<T> originalProducer = processProducer.getProducer();
    AnnotatedMember<X> annotatedMember = processProducer.getAnnotatedMember();
    List<Annotation> qualifiers = new ArrayList<Annotation>();
    for (Annotation annotation : annotatedMember.getAnnotations())
    {
        if (beanManager.isQualifier(annotation.annotationType()))
        {
            qualifiers.add(annotation);
        }
    }

    Typed typed = annotatedMember.getAnnotation(Typed.class);

    List<Type> foundTypes = new ArrayList<Type>();
    if (typed != null)
    {
        Collections.addAll(foundTypes, typed.value());
    }
    else if (annotatedMember.getBaseType() instanceof Class)
    {
        foundTypes.addAll(extractTypes((Class)annotatedMember.getBaseType()));
    }

    if (foundTypes.isEmpty())
    {
        return;
    }

    processProducer.setProducer(new MockAwareProducerWrapper<T>(
        beanManager, originalProducer, foundTypes, qualifiers));
}