ListRepositoriesController { @RequestMapping(method = RequestMethod.GET) public String listRepositoriesOrShowIfOnlyOne(final Model model) { if (!application.isConfigured()) { logger.debug("sventon not configured, redirecting to '/repos/listconfigs'"); return "redirect:/repos/listconfigs"; } if (application.getRepositoryConfigurationCount() > 1) { model.addAttribute("repositoryNames", application.getRepositoryNames()); model.addAttribute("isEditableConfig", application.isEditableConfig()); return "listRepositories"; } else if (application.getRepositoryConfigurationCount() == 1) { final RepositoryName repositoryName = application.getRepositoryNames().iterator().next(); return createListUrl(repositoryName, true); } return null; } @Autowired  ListRepositoriesController(final Application application); @RequestMapping(params = "logout=true") String logoutBeforeListRepositories(@RequestParam final boolean logout, @RequestParam final String repositoryName,
                                             @ModelAttribute final UserContext userContext, final Model model); @RequestMapping(method = RequestMethod.GET) String listRepositoriesOrShowIfOnlyOne(final Model model);  }
@Test public void listTwoConfiguredRepositories() throws Exception { final ListRepositoriesController ctrl = new ListRepositoriesController(application); assertEquals("redirect:/repos/listconfigs", ctrl.listRepositoriesOrShowIfOnlyOne(new ExtendedModelMap())); application.addConfiguration(createTestRepository("test1")); application.addConfiguration(createTestRepository("test2")); application.setConfigured(true); final ExtendedModelMap modelMap = new ExtendedModelMap(); assertEquals("listRepositories", ctrl.listRepositoriesOrShowIfOnlyOne(modelMap)); assertArrayEquals(Arrays.asList(new RepositoryName("test1"), new RepositoryName("test2")).toArray(), ((Set) modelMap.get("repositoryNames")).toArray()); }
@Test public void listRepositoriesNotConfigured() throws Exception { final ListRepositoriesController ctrl = new ListRepositoriesController(application); application.setConfigured(false); final ExtendedModelMap model = new ExtendedModelMap(); String view = ctrl.listRepositoriesOrShowIfOnlyOne(model); assertEquals("redirect:/repos/listconfigs", view); }
@Test public void listRepositoriesConfiguredButNoInstances() throws Exception { final ListRepositoriesController ctrl = new ListRepositoriesController(application); application.setConfigured(true); final ExtendedModelMap model = new ExtendedModelMap(); assertNull(ctrl.listRepositoriesOrShowIfOnlyOne(model)); }
@Test public void listOneConfiguredRepositories() throws Exception { final ListRepositoriesController ctrl = new ListRepositoriesController(application); assertEquals("redirect:/repos/listconfigs", ctrl.listRepositoriesOrShowIfOnlyOne(new ExtendedModelMap())); application.addConfiguration(createTestRepository("test1")); application.setConfigured(true); assertEquals("redirect:/repos/test1/list/", ctrl.listRepositoriesOrShowIfOnlyOne(null)); }