| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package com.google.gitiles; |
| 16 | |
| 17 | import static com.google.common.base.Preconditions.checkNotNull; |
| 18 | |
| 19 | import org.eclipse.jgit.storage.dfs.DfsRepository; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import javax.servlet.http.HttpServletRequest; |
| 25 | |
| 26 | /** Gitiles access for testing. */ |
| 27 | public class TestGitilesAccess implements GitilesAccess.Factory { |
| 28 | private final DfsRepository repo; |
| 29 | |
| 30 | public TestGitilesAccess(DfsRepository repo) { |
| 31 | this.repo = checkNotNull(repo); |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public GitilesAccess forRequest(final HttpServletRequest req) { |
| 36 | return new GitilesAccess() { |
| 37 | @Override |
| 38 | public Map<String, RepositoryDescription> listRepositories(Set<String> branches) { |
| 39 | // TODO(dborowitz): Implement this, using the DfsRepositoryDescriptions to |
| 40 | // get the repository names. |
| 41 | throw new UnsupportedOperationException(); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public Object getUserKey() { |
| 46 | return "a user"; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public String getRepositoryName() { |
| 51 | return repo.getDescription().getRepositoryName(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public RepositoryDescription getRepositoryDescription() { |
| 56 | RepositoryDescription d = new RepositoryDescription(); |
| 57 | d.name = getRepositoryName(); |
| 58 | d.description = "a test data set"; |
| 59 | d.cloneUrl = TestGitilesUrls.URLS.getBaseGitUrl(req) + "/" + d.name; |
| 60 | return d; |
| 61 | } |
| 62 | }; |
| 63 | } |
| 64 | } |