CRLUpdateJob implements AsyncJob { @Override public void execute(JobExecutionContext context) throws JobExecutionException { String filePath = config.getString(ConfigProperties.CRL_FILE_PATH, null); if (filePath == null || filePath.isEmpty()) { String errmsg = String.format("Invalid CRL path: %s", filePath); throw new JobExecutionException(errmsg, true); } try { log.info("Updating CRL file: {}", filePath); File crlFile = new File(filePath); this.crlFileUtil.syncCRLWithDB(crlFile); context.setJobResult("CRL Update completed successfully"); } catch (IOException e) { throw new JobExecutionException(e, true); } } @Inject  CRLUpdateJob(Configuration conf, CrlFileUtil crlFileUtil); @Override void execute(JobExecutionContext context); static final String JOB_KEY; static final String JOB_NAME; static final String DEFAULT_SCHEDULE; }
@Test public void executeFailsOnEmptyFilePath() { this.config.setProperty(ConfigProperties.CRL_FILE_PATH, ""); JobExecutionContext context = mock(JobExecutionContext.class); CRLUpdateJob job = this.createJobInstance(); assertThrows(JobExecutionException.class, () -> job.execute(context)); }
@Test public void executeFailsOnAbsentFilePath() { this.config.clearProperty(ConfigProperties.CRL_FILE_PATH); JobExecutionContext context = mock(JobExecutionContext.class); CRLUpdateJob job = this.createJobInstance(); assertThrows(JobExecutionException.class, () -> job.execute(context)); }
@Test public void execute() throws Exception { String crlPath = "/tmp/test.crl"; File crlFile = new File(crlPath); this.config.setProperty(ConfigProperties.CRL_FILE_PATH, crlPath); JobExecutionContext context = mock(JobExecutionContext.class); CRLUpdateJob job = this.createJobInstance(); job.execute(context); verify(this.crlFileUtil).syncCRLWithDB(eq(crlFile)); }