List of usage examples for org.springframework.mock.web MockServletContext setContextPath
public void setContextPath(String contextPath)
From source file:org.sventon.repository.DefaultRepositoryChangeMonitorTest.java
@Test public void testUpdate() throws Exception { 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); final RepositoryConfiguration configuration = new RepositoryConfiguration("name"); configuration.setCacheUsed(true);//from ww w.j ava2 s .c om application.addConfiguration(configuration); application.setConfigured(true); final ObjectCache cache = createMemoryCache(); try { final List<RepositoryChangeListener> listeners = new ArrayList<RepositoryChangeListener>(); listeners.add(repositoryChangeListenerMock); final DefaultRepositoryChangeMonitor changeMonitor = new DefaultRepositoryChangeMonitor(); changeMonitor.setListeners(listeners); changeMonitor.setMaxRevisionCountPerUpdate(3); changeMonitor.setApplication(application); changeMonitor.setRepositoryService(repositoryServiceMock); assertFalse(application.isUpdating(configuration.getName())); expect(repositoryServiceMock.getLatestRevision(null)).andReturn(6L); expect(repositoryServiceMock.getLogEntriesFromRepositoryRoot(null, 1L, 3L)) .andReturn(firstBatchOfRevisions); repositoryChangeListenerMock.update(isA(RevisionUpdate.class)); expect(repositoryServiceMock.getLogEntriesFromRepositoryRoot(null, 4L, 6L)) .andReturn(secondBatchOfRevisions); repositoryChangeListenerMock.update(isA(RevisionUpdate.class)); replay(repositoryServiceMock); replay(repositoryChangeListenerMock); changeMonitor.update(configuration.getName(), null, cache); verify(repositoryServiceMock); verify(repositoryChangeListenerMock); assertFalse(application.isUpdating(configuration.getName())); } finally { cache.shutdown(); } }
From source file:org.sventon.web.ctrl.SubmitConfigurationsControllerTest.java
@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) { }/* ww w . j a v a 2 s . co m*/ }); final RepositoryConfiguration repositoryConfiguration1 = new RepositoryConfiguration("testrepos1"); repositoryConfiguration1.setRepositoryUrl("http://localhost/1"); repositoryConfiguration1.setUserCredentials(new Credentials("user1", "abc123")); repositoryConfiguration1.setCacheUsed(false); repositoryConfiguration1.setZippedDownloadsAllowed(false); final RepositoryConfiguration repositoryConfiguration2 = new RepositoryConfiguration("testrepos2"); repositoryConfiguration2.setRepositoryUrl("http://localhost/2"); 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()); // Will be null as it is a redirect view. //File should now be written assertTrue(configFile1.exists()); assertTrue(configFile2.exists()); FileUtils.deleteDirectory(configDirectory.getConfigRootDirectory()); assertFalse(configFile1.exists()); assertFalse(configFile2.exists()); assertTrue(application.isConfigured()); }
From source file:org.sventon.web.ctrl.template.GoToControllerTest.java
@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);//from ww w. j a v a 2s. c om ctrl.setServletContext(new MockServletContext()); ctrl.setApplication(application); ctrl.setRepositoryService(mockService); ctrl.setAvailableCharsets(new AvailableCharsets("UTF-8")); // Test NodeKind.FILE 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"); // Test NodeKind.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); // Test NodeKind.UNKNOWN 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()); }
From source file:org.sventon.web.ctrl.ListRepositoriesControllerTest.java
@Before public void setUp() throws Exception { ConfigDirectory configDirectory = TestUtils.getTestConfigDirectory(); configDirectory.setCreateDirectories(false); final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); application = new Application(configDirectory); final UserRepositoryContext context1 = new UserRepositoryContext(); context1.setCredentials(new Credentials("UID1", "PWD1")); final UserRepositoryContext context2 = new UserRepositoryContext(); context2.setCredentials(new Credentials("UID2", "PWD2")); userContext = new UserContext(); final RepositoryName repo1 = new RepositoryName("repo1"); final RepositoryName repo2 = new RepositoryName("repo2"); userContext.add(repo1, context1);/* ww w . ja v a2s.c o m*/ userContext.add(repo2, context2); }
From source file:org.sventon.web.command.ConfigCommandValidatorTest.java
@Test public void testValidate() throws Exception { 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); final ConfigCommandValidator validator = new ConfigCommandValidator(false); validator.setApplication(application); final ConfigCommand command = new ConfigCommand(); BindException exception = new BindException(command, "test"); validator.validate(command, exception); // An empty command is valid assertEquals(0, exception.getAllErrors().size()); // Invalid repository name command.setName("Illegal whitespace in name"); command.setRepositoryUrl("svn://domain.com/svn/"); command.setUserPassword(""); command.setUserName(""); validator.validate(command, exception); assertEquals(1, exception.getAllErrors().size()); assertEquals("config.error.illegal-name", exception.getFieldError("name").getCode()); exception = new BindException(command, "test"); // Empty name is not ok command.setName(""); command.setRepositoryUrl("svn://domain.com/svn/"); command.setUserPassword(""); command.setUserName(""); validator.validate(command, exception); assertEquals(1, exception.getAllErrors().size()); assertEquals("config.error.illegal-name", exception.getFieldError("name").getCode()); exception = new BindException(command, "test"); // Valid (typical) input command.setRepositoryUrl("svn://domain.com/svn/"); command.setName("default"); command.setUserPassword(""); command.setUserName(""); command.setCacheUserName(""); command.setCacheUserPassword(""); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); // Valid input, spaces will be trimmed command.setRepositoryUrl(" svn://domain.com/svn/ "); command.setUserPassword(""); command.setUserName(""); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setUserPassword(null);// w w w . j a v a 2 s .c o m command.setUserName(null); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); command.setRepositoryUrl(""); validator.validate(command, exception); assertEquals(1, exception.getAllErrors().size()); assertEquals("config.error.illegal-url", exception.getFieldError("repositoryUrl").getCode()); exception = new BindException(command, "test"); command.setRepositoryUrl("notavalidurl"); validator.validate(command, exception); assertEquals(1, exception.getAllErrors().size()); assertEquals("config.error.illegal-url", exception.getFieldError("repositoryUrl").getCode()); exception = new BindException(command, "test"); command.setRepositoryUrl("svn://domain.com/svn/"); command.setUserPassword(""); command.setUserName(""); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); //if user based access is used, test connection uid and pwd can be supplied command.setRepositoryUrl("svn://domain.com/svn/"); command.setName("default"); command.setUserPassword("admin"); command.setUserName("super-secret-pwd123"); command.setAccessMethod(USER); command.setCacheUserName(""); command.setCacheUserPassword(""); validator.validate(command, exception); assertEquals(0, exception.getAllErrors().size()); }
From source file:org.sventon.appl.ApplicationTest.java
@Test public void testApplicationWithoutConfigurations() throws Exception { try {/*from ww w . j a v a 2 s . c o m*/ new Application(null); fail("Should throw IAE"); } catch (IllegalArgumentException iae) { // expected } final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setCreateDirectories(false); configDirectory.setServletContext(servletContext); final Application application = new Application(configDirectory); assertFalse(application.isConfigured()); assertFalse(application.hasConfigurations()); }
From source file:org.sventon.appl.ApplicationTest.java
@Test public void testGetBaseURL() throws Exception { final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setCreateDirectories(false); configDirectory.setServletContext(servletContext); final Application application = new Application(configDirectory); assertNull(application.getBaseURL()); System.setProperty(Application.PROPERTY_KEY_SVENTON_BASE_URL, "not-a-url"); assertNull(application.getBaseURL()); System.setProperty(Application.PROPERTY_KEY_SVENTON_BASE_URL, "http://validurl"); assertEquals("http://validurl/", application.getBaseURL().toString()); System.setProperty(Application.PROPERTY_KEY_SVENTON_BASE_URL, "http://validurl:81/"); assertEquals("http://validurl:81/", application.getBaseURL().toString()); }
From source file:org.sventon.appl.ApplicationTest.java
@Test public void testGetConfigurationAsProperties() throws Exception { final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setCreateDirectories(false); configDirectory.setServletContext(servletContext); final Application application = new Application(configDirectory); final RepositoryConfiguration config1 = new RepositoryConfiguration("test1"); config1.setRepositoryUrl("http://repo1"); config1.setUserCredentials(new Credentials("", "")); final RepositoryConfiguration config2 = new RepositoryConfiguration("test2"); config2.setRepositoryUrl("http://repo2"); config2.setUserCredentials(new Credentials("", "")); assertEquals(0, application.getRepositoryConfigurationCount()); application.addConfiguration(config1); assertEquals(1, application.getRepositoryConfigurationCount()); application.addConfiguration(config2); assertEquals(2, application.getRepositoryConfigurationCount()); }
From source file:org.sventon.appl.ApplicationTest.java
@Test public void testLoadRepositoryConfigurations() throws Exception { final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final String configFileName = "sventon-config-test.tmp"; final Application application = new Application(configDirectory); application.setConfigurationFileName(configFileName); final String name = "defaultsvn"; final File configDir = new File(configDirectory.getRepositoriesDirectory(), name); assertTrue(configDir.mkdirs());//from w ww. ja va 2 s. c o m final File configFile = new File(configDir, configFileName); storeProperties(configFile, createDummyConfigProperties(name)); assertFalse(application.hasConfigurations()); assertFalse(application.isConfigured()); application.loadRepositoryConfigurations(application.getConfigDirectories()); assertEquals(1, application.getRepositoryConfigurationCount()); assertTrue(application.isConfigured()); }
From source file:org.sventon.appl.ApplicationTest.java
@Test public void testPersistRepositoryConfigurations() throws Exception { final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final File repos1 = new File(configDirectory.getRepositoriesDirectory(), "testrepos1"); final File repos2 = new File(configDirectory.getRepositoriesDirectory(), "testrepos2"); final Application application = new Application(configDirectory); application.setConfigurationFileName(CONFIG_FILE_NAME); final RepositoryConfiguration repositoryConfiguration1 = new RepositoryConfiguration("testrepos1"); repositoryConfiguration1.setRepositoryUrl("http://localhost/1"); repositoryConfiguration1.setUserCredentials(new Credentials("user1", "abc123")); repositoryConfiguration1.setCacheUsed(false); repositoryConfiguration1.setZippedDownloadsAllowed(false); final RepositoryConfiguration repositoryConfiguration2 = new RepositoryConfiguration("testrepos2"); repositoryConfiguration2.setRepositoryUrl("http://localhost/2"); repositoryConfiguration2.setUserCredentials(new Credentials("user2", "123abc")); repositoryConfiguration2.setCacheUsed(false); repositoryConfiguration2.setZippedDownloadsAllowed(false); application.addConfiguration(repositoryConfiguration1); application.addConfiguration(repositoryConfiguration2); assertFalse(new File(repos1, CONFIG_FILE_NAME).exists()); assertFalse(new File(repos2, CONFIG_FILE_NAME).exists()); application.persistRepositoryConfigurations(); //File should now be written assertTrue(new File(repos1, CONFIG_FILE_NAME).exists()); assertTrue(new File(repos2, CONFIG_FILE_NAME).exists()); }