/** * This method reads in property file of wilma-message-search. * @throws Exception {@link PropertyLoader}, {@link ApplicationContext} can throw different exceptions. */ @PostConstruct void afterPropertiesSet() throws Exception { propertyLoader.loadProperties(); loadProperties(); startUpMessageGenerator.logStartUpMessage(); jmsConnectionConfigurer.setBrokerUrl(); indexTaskScheduler = applicationContext.getBean("indexTaskScheduler", IndexTaskScheduler.class); indexTaskScheduler.runReindexOnDemand(); indexTaskScheduler.startReindexScheduling(); }
/** * Runs reindexing on demand and writes back a response. * @param response used for writing back a response */ @RequestMapping(value = "/reindex", method = RequestMethod.GET) public void reindex(final HttpServletResponse response) { indexTaskScheduler.runReindexOnDemand(); PrintWriter writer; try { writer = response.getWriter(); writer.write("Reindexing!"); writer.flush(); } catch (IOException e) { logger.info("error occurred when accessing /reindex", e); } } }
@Test public final void testAfterPropertiesScheduleReindexing() throws Exception { //GIVEN in setup //WHEN underTest.afterPropertiesSet(); //THEN verify(indexTaskScheduler).startReindexScheduling(); }
@Test public void testReindexShouldRunReindexThenExceptionRaisedInGetWriter() throws IOException { //GIVEN IOException exception = new IOException(); doThrow(exception).when(response).getWriter(); //WHEN underTest.reindex(response); //THEN verify(indexTaskScheduler).runReindexOnDemand(); verify(logger).info("error occurred when accessing /reindex", exception); }
@Test public void testStartReindexScheduling() { //GIVEN given(configurationAccess.getProperties()).willReturn(properties); given(properties.getReindexTimer()).willReturn(CRON_EXPRESSION); given(cronTriggerFactory.create(CRON_EXPRESSION)).willReturn(cronTrigger); //WHEN underTest.startReindexScheduling(); //THEN verify(taskScheduler).schedule(luceneReindexerTask, cronTrigger); }
@Test public void testReindexShouldRunReindex() throws IOException { //GIVEN //WHEN underTest.reindex(response); //THEN verify(indexTaskScheduler).runReindexOnDemand(); }
@Test public final void testAfterPropertiesShouldBuildTheIndex() throws Exception { //GIVEN in setup //WHEN underTest.afterPropertiesSet(); //THEN verify(indexTaskScheduler).runReindexOnDemand(); }
@Test public void testRunReindexOnDemand() { //GIVEN Date now = new Date(); given(dateFactory.createNewDate()).willReturn(now); //WHEN underTest.runReindexOnDemand(); //THEN verify(taskScheduler).schedule(luceneReindexerTask, now); }