Skip to content

Instantly share code, notes, and snippets.

@Scheduled(cronExpression = "0 0/10 * * * ?")
public class CdiAwareQuartzJob implements org.quartz.Job
{
@Inject
private MyService service;
@Override
public void execute(JobExecutionContext context)
throws JobExecutionException
{
@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());
@ApplicationScoped
public class ProjectStageAwareSchedulerController
{
@Inject
private Scheduler<Job> jobScheduler;
@Inject
private ProjectStage projectStage;
public void registerJobs()
public class ViewConfigValidator implements ServletContextListener
{
@Override
public void contextInitialized(ServletContextEvent sce)
{
ViewConfigResolver viewConfigResolver =
BeanProvider.getContextualReference(ViewConfigResolver.class);
for (ConfigDescriptor configDescriptor :
viewConfigResolver.getConfigDescriptors())
@RunWith(CdiTestRunner.class)
public class InjectionTest
{
@Inject
private MyCdiBean bean1;
@EJB //or @Inject
private MyEjb bean2;
@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 ManuallyMockedCdiBeanTest
{
@Inject
private MyCdiBean myCdiBean;
@Inject
private DynamicMockContext mockContext;
@Test
@RequestScoped
public class MyCdiBean
{
private int count = 0;
public int getCount()
{
return count;
}
@RunWith(CdiTestRunner.class)
public class MockitoMockedCdiBeanTest
{
@Inject
private MyCdiBean myCdiBean;
@Inject
private DynamicMockContext mockContext;
@Test
@ApplicationScoped
public class AsyncObserver
{
public void onEvent(@ObservesAsynchronous MyEvent event)
{
//...
}
}