1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.http.test;
11
12 import javax.servlet.http.HttpServletRequest;
13
14 import org.eclipse.jgit.errors.RepositoryNotFoundException;
15 import org.eclipse.jgit.junit.TestRepository;
16 import org.eclipse.jgit.lib.Repository;
17 import org.eclipse.jgit.transport.resolver.RepositoryResolver;
18 import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
19
20
21
22
23 public final class TestRepositoryResolver
24 implements RepositoryResolver<HttpServletRequest> {
25
26 private final TestRepository<Repository> repo;
27
28 private final String repoName;
29
30
31
32
33
34
35
36
37
38
39 public TestRepositoryResolver(TestRepository<Repository> repo, String repoName) {
40 this.repo = repo;
41 this.repoName = repoName;
42 }
43
44
45 @Override
46 public Repository open(HttpServletRequest req, String name)
47 throws RepositoryNotFoundException, ServiceNotEnabledException {
48 if (!name.equals(repoName)) {
49 throw new RepositoryNotFoundException(name);
50 }
51 Repository db = repo.getRepository();
52 db.incrementOpen();
53 return db;
54 }
55 }