Skip to content

Instantly share code, notes, and snippets.

@RunWith(CdiTestRunner.class)
public class ManuallyMockedCdiBeanTest
{
@Inject
private MyCdiBean myCdiBean;
@Inject
private DynamicMockContext mockContext;
@Test
public class MonitoredMethodInvocationProcessor
{
//...
public void onMonitoredMethodInvocations(@Observes MonitoredMethodInvocationsEvent methodInvocationsEvent)
{
String userId = this.userHolder.getCurrentUserId();
for (MethodInvocationDescriptor methodInvocation : methodInvocationsEvent.getMethodInvocationDescriptors())
{
@RunWith(CdiTestRunner.class)
public class InjectionTest
{
@Inject
private MyCdiBean bean1;
@EJB //or @Inject
private MyEjb bean2;
@Test
public class ViewConfigValidator implements ServletContextListener
{
@Override
public void contextInitialized(ServletContextEvent sce)
{
ViewConfigResolver viewConfigResolver =
BeanProvider.getContextualReference(ViewConfigResolver.class);
for (ConfigDescriptor configDescriptor :
viewConfigResolver.getConfigDescriptors())
@ApplicationScoped
public class ProjectStageAwareSchedulerController
{
@Inject
private Scheduler<Job> jobScheduler;
@Inject
private ProjectStage projectStage;
public void registerJobs()
@ApplicationScoped
public class SchedulerController
{
@Inject
private Scheduler<Job> jobScheduler;
public void onPause(@Observes PauseJobEvent /*custom event*/ jobEvent)
{
//using it with events is optional
this.jobScheduler.pauseJob(jobEvent.getJobClass());
@Scheduled(cronExpression = "0 0/10 * * * ?")
public class CdiAwareQuartzJob implements org.quartz.Job
{
@Inject
private MyService service;
@Override
public void execute(JobExecutionContext context)
throws JobExecutionException
{
//starts the container once and one session + request per test-method
@RunWith(CdiTestRunner.class)
public class ContainerAndInjectionControl
{
@Inject
private ApplicationScopedBean applicationScopedBean;
@Inject
private SessionScopedBean sessionScopedBean;
public class MyActor extends UntypedActor
{
@Inject
private MyService myService;
@Override
public void onReceive(Object o) throws Exception
{
myService.process(/*...*/);
}
@os890
os890 / BeanManagerProvider.java
Created April 20, 2013 23:29
ds with multiple cdi implementations
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0