SubmitConfigurationsController extends AbstractController { @Override protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { if (!application.hasConfigurations()) { logger.warn("No repository has been configured and added"); return new ModelAndView("error/configurationError"); } application.persistRepositoryConfigurations(); application.initCaches(); if (!application.isConfigured()) { application.setConfigured(true); try { logger.debug("Starting up caches"); scheduler.triggerJob("repositoryChangeMonitorUpdateJobDetail", Scheduler.DEFAULT_GROUP); } catch (SchedulerException sx) { logger.warn(sx); } } logger.info("Configuration done!"); return new ModelAndView(new RedirectView("/repos/list", true)); }  void setApplication(final Application application); void setScheduler(final Scheduler scheduler);  }
@Test public void testHandleRequestInternal() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); final SubmitConfigurationsController ctrl = new SubmitConfigurationsController(); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); ctrl.setScheduler(new StdScheduler(null, null) { public void triggerJob(final String string, final String string1) { } }); final RepositoryConfiguration repositoryConfiguration1 = new RepositoryConfiguration("testrepos1"); repositoryConfiguration1.setRepositoryUrl("http: repositoryConfiguration1.setUserCredentials(new Credentials("user1", "abc123")); repositoryConfiguration1.setCacheUsed(false); repositoryConfiguration1.setZippedDownloadsAllowed(false); final RepositoryConfiguration repositoryConfiguration2 = new RepositoryConfiguration("testrepos2"); repositoryConfiguration2.setRepositoryUrl("http: repositoryConfiguration2.setUserCredentials(new Credentials("user2", "abc123")); repositoryConfiguration2.setCacheUsed(false); repositoryConfiguration2.setZippedDownloadsAllowed(false); application.addConfiguration(repositoryConfiguration1); application.addConfiguration(repositoryConfiguration2); application.setConfigured(false); ctrl.setApplication(application); ctrl.setServletContext(new MockServletContext()); final File configFile1 = new File(configDirectory.getRepositoriesDirectory(), "testrepos1"); final File configFile2 = new File(configDirectory.getRepositoriesDirectory(), "testrepos2"); assertFalse(configFile1.exists()); assertFalse(configFile2.exists()); final ModelAndView modelAndView = ctrl.handleRequestInternal(request, response); assertNotNull(modelAndView); assertNull(modelAndView.getViewName()); assertTrue(configFile1.exists()); assertTrue(configFile2.exists()); FileUtils.deleteDirectory(configDirectory.getConfigRootDirectory()); assertFalse(configFile1.exists()); assertFalse(configFile2.exists()); assertTrue(application.isConfigured()); }