blob: 50877ba51399486b4be978fc0877728ae8964436 [file] [log] [blame]
Dave Borowitz9de65952012-08-13 16:09:45 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.gitiles;
16
17import static com.google.common.base.Preconditions.checkNotNull;
18
Dave Borowitzded109a2014-03-03 15:25:39 -050019import com.google.common.collect.ImmutableMap;
20
21import org.eclipse.jgit.internal.storage.dfs.DfsRepository;
22import org.eclipse.jgit.lib.Config;
23
Dave Borowitz9de65952012-08-13 16:09:45 -070024import java.util.Map;
25import java.util.Set;
26
27import javax.servlet.http.HttpServletRequest;
28
29/** Gitiles access for testing. */
30public class TestGitilesAccess implements GitilesAccess.Factory {
31 private final DfsRepository repo;
32
33 public TestGitilesAccess(DfsRepository repo) {
34 this.repo = checkNotNull(repo);
35 }
36
37 @Override
38 public GitilesAccess forRequest(final HttpServletRequest req) {
39 return new GitilesAccess() {
40 @Override
41 public Map<String, RepositoryDescription> listRepositories(Set<String> branches) {
Dave Borowitzd91bdf72013-01-10 20:07:32 -080042 if (branches != null && !branches.isEmpty()) {
43 throw new UnsupportedOperationException("branches set not yet supported");
44 }
45 RepositoryDescription desc = new RepositoryDescription();
46 desc.name = repo.getDescription().getRepositoryName();
47 desc.cloneUrl = TestGitilesUrls.URLS.getBaseGitUrl(req) + "/" + desc.name;
48 return ImmutableMap.of(desc.name, desc);
Dave Borowitz9de65952012-08-13 16:09:45 -070049 }
50
51 @Override
52 public Object getUserKey() {
53 return "a user";
54 }
55
56 @Override
57 public String getRepositoryName() {
58 return repo.getDescription().getRepositoryName();
59 }
60
61 @Override
62 public RepositoryDescription getRepositoryDescription() {
63 RepositoryDescription d = new RepositoryDescription();
64 d.name = getRepositoryName();
65 d.description = "a test data set";
66 d.cloneUrl = TestGitilesUrls.URLS.getBaseGitUrl(req) + "/" + d.name;
67 return d;
68 }
Dave Borowitzded109a2014-03-03 15:25:39 -050069
70 @Override
71 public Config getConfig() {
72 return new Config();
73 }
Dave Borowitz9de65952012-08-13 16:09:45 -070074 };
75 }
76}