GoToController extends AbstractTemplateController { @Override protected ModelAndView svnHandle(final SVNConnection connection, final BaseCommand command, final long headRevision, final UserRepositoryContext userRepositoryContext, final HttpServletRequest request, final HttpServletResponse response, final BindException exception) throws Exception { final String redirectUrl; DirEntry.Kind kind = null; try { kind = getRepositoryService().getNodeKind(connection, command.getPath(), command.getRevisionNumber()); logger.debug("Node kind of [" + command.getPath() + "]: " + kind); } catch (NoSuchRevisionException nsre) { logger.info(nsre.getMessage()); } if (DirEntry.Kind.DIR == kind) { redirectUrl = command.createListUrl(); } else if (DirEntry.Kind.FILE == kind) { redirectUrl = command.createShowFileUrl(); } else if (kind == null) { exception.rejectValue("revision", "goto.command.invalidrevision"); return prepareExceptionModelAndView(exception, command, getApplicationModel(command)); } else { exception.rejectValue("path", "goto.command.invalidpath"); return prepareExceptionModelAndView(exception, command, getApplicationModel(command)); } final Map<String, String> model = new HashMap<String, String>(); model.put("revision", command.getRevision().toString()); logger.debug("Redirecting to: " + redirectUrl); return new ModelAndView(new RedirectView(redirectUrl, true), model); }    }
@Test public void testSvnHandle() throws Exception { final RepositoryService mockService = EasyMock.createMock(RepositoryService.class); final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); final BaseCommand command = new BaseCommand(); command.setName(new RepositoryName("test")); command.setPath("/file.txt"); command.setRevision(Revision.create(12)); final GoToController ctrl = new GoToController(); final ConfigDirectory configDirectory = TestUtils.getTestConfigDirectory(); configDirectory.setCreateDirectories(false); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final Application application = new Application(configDirectory); application.setConfigured(true); ctrl.setServletContext(new MockServletContext()); ctrl.setApplication(application); ctrl.setRepositoryService(mockService); ctrl.setAvailableCharsets(new AvailableCharsets("UTF-8")); expect(mockService.getNodeKind(null, command.getPath(), command.getRevisionNumber())).andStubReturn(DirEntry.Kind.FILE); replay(mockService); ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, mockRequest, null, null); Map model = modelAndView.getModel(); verify(mockService); assertEquals(1, model.size()); RedirectView view = (RedirectView) modelAndView.getView(); assertEquals("/repos/test/show/file.txt", view.getUrl()); reset(mockService); command.setPath("/dir"); expect(mockService.getNodeKind(null, command.getPath(), command.getRevisionNumber())).andStubReturn(DirEntry.Kind.DIR); replay(mockService); modelAndView = ctrl.svnHandle(null, command, 100, null, mockRequest, null, null); model = modelAndView.getModel(); verify(mockService); assertEquals(1, model.size()); view = (RedirectView) modelAndView.getView(); assertEquals("/repos/test/list/dir/", view.getUrl()); reset(mockService); expect(mockService.getNodeKind(null, command.getPath(), command.getRevisionNumber())).andStubReturn(DirEntry.Kind.UNKNOWN); replay(mockService); final BindException errors = new BindException(command, "test"); assertEquals(0, errors.getAllErrors().size()); modelAndView = ctrl.svnHandle(null, command, 100, null, mockRequest, null, errors); model = modelAndView.getModel(); verify(mockService); assertEquals(10, model.size()); assertEquals("goto", modelAndView.getViewName()); }