Esempio n. 1
0
 private SVNRepository createRepositoryConnection(
     final HttpServletRequest request, final RepositoryConfiguration configuration)
     throws SVNException {
   final Credentials credentials = extractCredentials(request, configuration);
   return repositoryConnectionFactory.createConnection(
       configuration.getName(), configuration.getSVNURL(), credentials);
 }
  @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);
    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();
    }
  }