private <T> ProducerFactory<T> factory(final Object mock) { return new ProducerFactory<T>() { @Override public <T1> Producer<T1> createProducer(final Bean<T1> bean) { return new Producer<T1>() { @Override public T1 produce(final CreationalContext<T1> ctx) { return (T1) mock; } @Override public void dispose(final T1 instance) { } @Override public Set<InjectionPoint> getInjectionPoints() { return Collections.emptySet(); } }; } }; }
@Test public void testProducer() { logger.info("starting producer spi test"); CDI<Object> cdi = current(); BeanManager beanManager = cdi.select(BeanManager.class).get(); AnnotatedField<? super AnotherFactory> field = this .<AnotherFactory, AnnotatedField<AnotherFactory>>getAnnotatedMember(AnotherFactory.class, "jessie", beanManager); Bean<AnotherFactory> declaringBean = cast(beanManager.resolve(beanManager.getBeans(AnotherFactory.class))); ProducerFactory<AnotherFactory> producerFactory = beanManager.getProducerFactory(field, declaringBean); Producer<Toy> producer = cast(producerFactory.createProducer(null)); assertNotNull(producer); assertTrue(producer.getInjectionPoints().isEmpty()); Toy jessie = producer.produce(beanManager.<Toy>createCreationalContext(null)); assertEquals("Jessie", jessie.getName()); }
@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)); }
<T, X extends CommandBus> void processCommandBusProducer( @Observes final ProcessProducer<T, X> processProducer, final BeanManager beanManager) { AnnotatedMember<T> annotatedMember = processProducer.getAnnotatedMember(); if (annotatedMember.isAnnotationPresent(AutoConfigure.class)) { Producer<X> originalProducer = processProducer.getProducer(); Producer<X> producer = new AutoConfiguringCommandBusProducer<>(originalProducer, annotatedMember, getAggregateRoots(), getCommandHandlers(), beanManager); processProducer.setProducer(producer); } }
<T, X extends EventStore> void processEventStoreProducer( @Observes final ProcessProducer<T, X> processProducer, final BeanManager beanManager) { AnnotatedMember<T> annotatedMember = processProducer.getAnnotatedMember(); if (annotatedMember.isAnnotationPresent(AutoConfigure.class)) { Producer<X> originalProducer = processProducer.getProducer(); Producer<X> producer = new AutoConfiguringEventStoreProducer<>(originalProducer, annotatedMember, getEventHandlers(), getSagas(), beanManager); processProducer.setProducer(producer); } }
<T, X extends Snapshotter> void processSnapshotterProducer( @Observes final ProcessProducer<T, X> processProducer, final BeanManager beanManager) { Producer<X> originalProducer = processProducer.getProducer(); AnnotatedMember<T> annotatedMember = processProducer.getAnnotatedMember(); if (annotatedMember.isAnnotationPresent(AutoConfigure.class)) { Producer<X> producer = new AutoConfiguringAggregateSnapshotterProducer<>(originalProducer, annotatedMember, getAggregateRoots(), beanManager); processProducer.setProducer(producer); } }
<T, X extends SagaRepository<?>> void processSagaRepositoryProducer( @Observes final ProcessProducer<T, X> processProducer, final BeanManager beanManager) { Producer<X> originalProducer = processProducer.getProducer(); AnnotatedMember<T> annotatedMember = processProducer.getAnnotatedMember(); if (annotatedMember.isAnnotationPresent(AutoConfigure.class)) { Producer<X> producer = new AutoConfiguringSagaRepositoryProducer<>(originalProducer, annotatedMember, beanManager); processProducer.setProducer(producer); } }
public AbstractAutoConfiguringProducer(final Producer<X> wrappedProducer, final AnnotatedMember<?> annotatedMember, final BeanManager beanManager) { this.wrappedProducer = wrappedProducer; this.beanManager = beanManager; this.annotatedMember = annotatedMember; }
public AutoConfiguringEventStoreProducer(final Producer<X> wrappedProducer, final AnnotatedMember<?> annotatedMember, final Set<HandlerInfo> eventHandlersInfo, final Set<SagaInfo> sagasInfo, final BeanManager beanManager) { super(wrappedProducer, annotatedMember, beanManager); this.eventHandlersInfo = eventHandlersInfo; this.sagaManagersInfo = SagaManagerInfo.from(sagasInfo); }
public AutoConfiguringCommandBusProducer(Producer<X> wrappedProducer, AnnotatedMember<?> annotatedMember, Set<AggregateRootInfo> aggregateRootsInfo, Set<HandlerInfo> commandHandlersInfo, BeanManager beanManager) { super(wrappedProducer, annotatedMember, beanManager); this.commandHandlersInfo = commandHandlersInfo; this.aggregateRootsInfo = aggregateRootsInfo; }
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; }
public EntityManagerProducerProxy(final Producer<EntityManager> proxied) { this.proxied = proxied; }
<T extends CamelContext> Producer<T> camelContextProducer(Producer<T> delegate, Annotated annotated, BeanManager manager, CdiCamelExtension extension) { CamelContextProducer<T> producer = new CamelContextProducer<>(delegate, annotated, manager, extension); return hasBundleContext ? new CamelContextOsgiProducer<>(producer) : producer; }
DelegateInjectionTarget(InjectionTarget<T> target, Producer<T> producer) { super(producer); this.delegate = target; }
CamelContextInjectionTarget(InjectionTarget<T> target, Producer<T> producer) { super(target, producer); }
CamelContextProducer(Producer<T> delegate, Annotated annotated, BeanManager manager, CdiCamelExtension extension) { super(delegate); this.annotated = annotated; this.manager = manager; this.extension = extension; }
DelegateProducer(Producer<T> delegate) { this.delegate = delegate; }
CamelContextOsgiProducer(Producer<T> delegate) { super(delegate); }
protected final Producer<X> getWrappedProducer() { return wrappedProducer; }
public AutoConfiguringAggregateSnapshotterProducer(final Producer<X> wrappedProducer, final AnnotatedMember<?> annotatedMember, final Set<AggregateRootInfo> aggregateRoots, final BeanManager beanManager) { super(wrappedProducer, annotatedMember, beanManager); this.aggregateRootsInfo = aggregateRoots; }
public AutoConfiguringSagaRepositoryProducer(final Producer<X> wrappedProducer, final AnnotatedMember<?> annotatedMember, final BeanManager beanManager) { super(wrappedProducer, annotatedMember, beanManager); }
public EntityManagerProducerWrapper(Producer<EntityManager> wrappedProducer) { this.wrappedProducer = wrappedProducer; }
public EntityManagerFactoryProducerWrapper(Producer<EntityManagerFactory> wrappedProducer, BeanManager beanManager) { this.wrappedProducer = wrappedProducer; this.beanManager = beanManager; }
<T extends CamelContext> Producer<T> camelContextProducer(Producer<T> delegate, Annotated annotated, BeanManager manager) { CamelContextProducer<T> producer = new CamelContextProducer<>(delegate, annotated, manager); return hasBundleContext ? new CamelContextOsgiProducer<>(producer) : producer; }
CamelContextProducer(Producer<T> delegate, Annotated annotated, BeanManager manager) { super(delegate); this.annotated = annotated; this.manager = manager; }
@Override public Producer<T> getProducer() { return new EjbProducer<T>(this, bean); }
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)); }