@@ -0,0 +1,3284 @@
+// Copyright 2012 Google Inc. All Rights Reserved.%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A// http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.gitiles;%0A%0Aimport com.google.common.collect.ImmutableList;%0A%0Aimport org.eclipse.jgit.errors.RepositoryNotFoundException;%0Aimport org.eclipse.jgit.junit.TestRepository;%0Aimport org.eclipse.jgit.lib.Config;%0Aimport org.eclipse.jgit.lib.Repository;%0Aimport org.eclipse.jgit.storage.dfs.DfsRepository;%0Aimport org.eclipse.jgit.transport.resolver.RepositoryResolver;%0A%0Aimport java.util.Collections;%0Aimport java.util.Enumeration;%0A%0Aimport javax.servlet.ServletConfig;%0Aimport javax.servlet.ServletContext;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServletRequest;%0A%0A/** Static utility methods for creating %7B@link GitilesServlet%7Ds for testing. */%0Apublic class TestGitilesServlet %7B%0A  /**%0A   * Create a servlet backed by a single test repository.%0A   * %3Cp%3E%0A   * The servlet uses the same filter lists as a real servlet, but only knows%0A   * about a single repo, having the name returned by%0A   * %7B@link org.eclipse.jgit.storage.dfs.DfsRepositoryDescription#getRepositoryName()%7D.%0A   * Pass a %7B@link FakeHttpServletRequest%7D and %7B@link FakeHttpServletResponse%7D%0A   * to the servlet's %7B@code service%7D method to test.%0A   *%0A   * @param repo the test repo backing the servlet.%0A   * @return a servlet.%0A   */%0A  public static GitilesServlet create(final TestRepository%3CDfsRepository%3E repo)%0A      throws ServletException %7B%0A    final String repoName =%0A        repo.getRepository().getDescription().getRepositoryName();%0A    GitilesServlet servlet =%0A        new GitilesServlet(new Config(), new DebugRenderer(%0A            GitilesServlet.STATIC_PREFIX, null, null, repoName + %22 test site%22),%0A            TestGitilesUrls.URLS, new TestGitilesAccess(repo.getRepository()),%0A            new RepositoryResolver%3CHttpServletRequest%3E() %7B%0A              @Override%0A              public Repository open(HttpServletRequest req, String name)%0A                  throws RepositoryNotFoundException %7B%0A                if (!repoName.equals(name)) %7B%0A                  throw new RepositoryNotFoundException(name);%0A                %7D%0A                return repo.getRepository();%0A              %7D%0A            %7D, null, null);%0A%0A    servlet.init(new ServletConfig() %7B%0A      @Override%0A      public String getInitParameter(String name) %7B%0A        return null;%0A      %7D%0A%0A      @Override%0A      public Enumeration%3CString%3E getInitParameterNames() %7B%0A        return Collections.enumeration(ImmutableList.%3CString%3E of());%0A      %7D%0A%0A      @Override%0A      public ServletContext getServletContext() %7B%0A        return null;%0A      %7D%0A%0A      @Override%0A      public String getServletName() %7B%0A        return TestGitilesServlet.class.getName();%0A      %7D%0A    %7D);%0A    return servlet;%0A  %7D%0A%0A  private TestGitilesServlet() %7B%0A  %7D%0A%7D%0A

Add a method for creating a full-stack GitilesServlet for tests