Fix javadoc in org.eclipse.jgit.junit.http

Change-Id: I8af6d07676a285f79635405e5891535a5adfd7e9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2017-12-17 19:49:40 +01:00
parent 60b5111e4a
commit 0b131b7312
7 changed files with 284 additions and 16 deletions

View File

@ -51,7 +51,9 @@
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response; import org.eclipse.jetty.server.Response;
/** A single request made through {@link AppServer}. */ /**
* A single request made through {@link org.eclipse.jgit.junit.http.AppServer}.
*/
public class AccessEvent { public class AccessEvent {
private final String method; private final String method;
@ -105,17 +107,27 @@ private static Map<String, String[]> clone(Map parameterMap) {
return new TreeMap<>(parameterMap); return new TreeMap<>(parameterMap);
} }
/** @return {@code "GET"} or {@code "POST"} */ /**
* Get the <code>method</code>.
*
* @return {@code "GET"} or {@code "POST"}
*/
public String getMethod() { public String getMethod() {
return method; return method;
} }
/** @return path of the file on the server, e.g. {@code /git/HEAD}. */ /**
* Get <code>path</code>.
*
* @return path of the file on the server, e.g. {@code /git/HEAD}.
*/
public String getPath() { public String getPath() {
return uri; return uri;
} }
/** /**
* Get request header
*
* @param name * @param name
* name of the request header to read. * name of the request header to read.
* @return first value of the request header; null if not sent. * @return first value of the request header; null if not sent.
@ -125,6 +137,8 @@ public String getRequestHeader(String name) {
} }
/** /**
* Get parameter
*
* @param name * @param name
* name of the request parameter to read. * name of the request parameter to read.
* @return first value of the request parameter; null if not sent. * @return first value of the request parameter; null if not sent.
@ -134,17 +148,27 @@ public String getParameter(String name) {
return r != null && 1 <= r.length ? r[0] : null; return r != null && 1 <= r.length ? r[0] : null;
} }
/** @return all parameters in the request. */ /**
* Get <code>parameters</code>
*
* @return all parameters in the request.
*/
public Map<String, String[]> getParameters() { public Map<String, String[]> getParameters() {
return parameters; return parameters;
} }
/** @return HTTP status code of the response, e.g. 200, 403, 500. */ /**
* Get the <code>status</code>.
*
* @return HTTP status code of the response, e.g. 200, 403, 500.
*/
public int getStatus() { public int getStatus() {
return status; return status;
} }
/** /**
* Get response header.
*
* @param name * @param name
* name of the response header to read. * name of the response header to read.
* @return first value of the response header; null if not sent. * @return first value of the response header; null if not sent.
@ -153,6 +177,7 @@ public String getResponseHeader(String name) {
return responseHeaders.get(name); return responseHeaders.get(name);
} }
/** {@inheritDoc} */
@Override @Override
public String toString() { public String toString() {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();

View File

@ -124,11 +124,16 @@ public class AppServer {
private List<File> filesToDelete = new ArrayList<>(); private List<File> filesToDelete = new ArrayList<>();
/**
* Constructor for <code>AppServer</code>.
*/
public AppServer() { public AppServer() {
this(0, -1); this(0, -1);
} }
/** /**
* Constructor for <code>AppServer</code>.
*
* @param port * @param port
* the http port number; may be zero to allocate a port * the http port number; may be zero to allocate a port
* dynamically * dynamically
@ -139,6 +144,8 @@ public AppServer(int port) {
} }
/** /**
* Constructor for <code>AppServer</code>.
*
* @param port * @param port
* for http, may be zero to allocate a port dynamically * for http, may be zero to allocate a port dynamically
* @param sslPort * @param sslPort
@ -268,6 +275,13 @@ public ServletContextHandler addContext(String path) {
return ctx; return ctx;
} }
/**
* Configure basic authentication.
*
* @param ctx
* @param methods
* @return servlet context handler
*/
public ServletContextHandler authBasic(ServletContextHandler ctx, public ServletContextHandler authBasic(ServletContextHandler ctx,
String... methods) { String... methods) {
assertNotYetSetUp(); assertNotYetSetUp();
@ -395,24 +409,38 @@ public URI getURI() {
} }
} }
/** @return the local port number the server is listening on. */ /**
* Get port.
*
* @return the local port number the server is listening on.
*/
public int getPort() { public int getPort() {
assertAlreadySetUp(); assertAlreadySetUp();
return connector.getLocalPort(); return connector.getLocalPort();
} }
/** @return the HTTPS port or -1 if not configured. */ /**
* Get secure port.
*
* @return the HTTPS port or -1 if not configured.
*/
public int getSecurePort() { public int getSecurePort() {
assertAlreadySetUp(); assertAlreadySetUp();
return secureConnector != null ? secureConnector.getLocalPort() : -1; return secureConnector != null ? secureConnector.getLocalPort() : -1;
} }
/** @return all requests since the server was started. */ /**
* Get requests.
*
* @return all requests since the server was started.
*/
public List<AccessEvent> getRequests() { public List<AccessEvent> getRequests() {
return new ArrayList<>(log.getEvents()); return new ArrayList<>(log.getEvents());
} }
/** /**
* Get requests.
*
* @param base * @param base
* base URI used to access the server. * base URI used to access the server.
* @param path * @param path
@ -424,6 +452,8 @@ public List<AccessEvent> getRequests(URIish base, String path) {
} }
/** /**
* Get requests.
*
* @param path * @param path
* the path to locate requests for. * the path to locate requests for.
* @return all requests which match the given path. * @return all requests which match the given path.

View File

@ -67,19 +67,24 @@
import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.URIish;
/** Base class for HTTP related transport testing. */ /**
* Base class for HTTP related transport testing.
*/
public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { public abstract class HttpTestCase extends LocalDiskRepositoryTestCase {
/** Constant <code>master="Constants.R_HEADS + Constants.MASTER"</code> */
protected static final String master = Constants.R_HEADS + Constants.MASTER; protected static final String master = Constants.R_HEADS + Constants.MASTER;
/** In-memory application server; subclass must start. */ /** In-memory application server; subclass must start. */
protected AppServer server; protected AppServer server;
/** {@inheritDoc} */
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
server = createServer(); server = createServer();
} }
/** {@inheritDoc} */
@Override @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
server.tearDown(); server.tearDown();
@ -87,29 +92,50 @@ public void tearDown() throws Exception {
} }
/** /**
* Creates the {@linkAppServer}.This default implementation creates a server * Create the {@linkAppServer}.This default implementation creates a server
* without SSLsupport listening for HTTP connections on a dynamically chosen * without SSLsupport listening for HTTP connections on a dynamically chosen
* port, which can be gotten once the server has been started via its * port, which can be gotten once the server has been started via its
* {@link AppServer#getPort()} method. Subclasses may override if they need * {@link org.eclipse.jgit.junit.http.AppServer#getPort()} method.
* a more specialized server. * Subclasses may override if they need a more specialized server.
* *
* @return the {@link AppServer}. * @return the {@link org.eclipse.jgit.junit.http.AppServer}.
* @since 4.9 * @since 4.9
*/ */
protected AppServer createServer() { protected AppServer createServer() {
return new AppServer(); return new AppServer();
} }
/**
* Create TestRepository
*
* @return the TestRepository
* @throws IOException
*/
protected TestRepository<Repository> createTestRepository() protected TestRepository<Repository> createTestRepository()
throws IOException { throws IOException {
return new TestRepository<>(createBareRepository()); return new TestRepository<>(createBareRepository());
} }
/**
* Convert path to URIish
*
* @param path
* @return the URIish
* @throws URISyntaxException
*/
protected URIish toURIish(String path) throws URISyntaxException { protected URIish toURIish(String path) throws URISyntaxException {
URI u = server.getURI().resolve(path); URI u = server.getURI().resolve(path);
return new URIish(u.toString()); return new URIish(u.toString());
} }
/**
* Convert a path relative to the app's context path to a URIish
*
* @param app
* @param name
* @return the warnings (if any) from the last execution
* @throws URISyntaxException
*/
protected URIish toURIish(ServletContextHandler app, String name) protected URIish toURIish(ServletContextHandler app, String name)
throws URISyntaxException { throws URISyntaxException {
String p = app.getContextPath(); String p = app.getContextPath();
@ -119,18 +145,45 @@ protected URIish toURIish(ServletContextHandler app, String name)
return toURIish(p); return toURIish(p);
} }
/**
* Get requests.
*
* @return list of events
*/
protected List<AccessEvent> getRequests() { protected List<AccessEvent> getRequests() {
return server.getRequests(); return server.getRequests();
} }
/**
* Get requests.
*
* @param base
* @param path
*
* @return list of events
*/
protected List<AccessEvent> getRequests(URIish base, String path) { protected List<AccessEvent> getRequests(URIish base, String path) {
return server.getRequests(base, path); return server.getRequests(base, path);
} }
/**
* Get requests.
*
* @param path
*
* @return list of events
*/
protected List<AccessEvent> getRequests(String path) { protected List<AccessEvent> getRequests(String path) {
return server.getRequests(path); return server.getRequests(path);
} }
/**
* Run fsck
*
* @param db
* @param tips
* @throws Exception
*/
protected static void fsck(Repository db, RevObject... tips) protected static void fsck(Repository db, RevObject... tips)
throws Exception { throws Exception {
TestRepository<? extends Repository> tr = TestRepository<? extends Repository> tr =
@ -138,6 +191,12 @@ protected static void fsck(Repository db, RevObject... tips)
tr.fsck(tips); tr.fsck(tips);
} }
/**
* Mirror refs
*
* @param refs
* @return set of RefSpecs
*/
protected static Set<RefSpec> mirror(String... refs) { protected static Set<RefSpec> mirror(String... refs) {
HashSet<RefSpec> r = new HashSet<>(); HashSet<RefSpec> r = new HashSet<>();
for (String name : refs) { for (String name : refs) {
@ -149,6 +208,14 @@ protected static Set<RefSpec> mirror(String... refs) {
return r; return r;
} }
/**
* Push a commit
*
* @param from
* @param q
* @return collection of RefUpdates
* @throws IOException
*/
protected static Collection<RemoteRefUpdate> push(TestRepository from, protected static Collection<RemoteRefUpdate> push(TestRepository from,
RevCommit q) throws IOException { RevCommit q) throws IOException {
final Repository db = from.getRepository(); final Repository db = from.getRepository();
@ -163,6 +230,13 @@ protected static Collection<RemoteRefUpdate> push(TestRepository from,
return Collections.singleton(u); return Collections.singleton(u);
} }
/**
* Create loose object path
*
* @param base
* @param id
* @return path of the loose object
*/
public static String loose(URIish base, AnyObjectId id) { public static String loose(URIish base, AnyObjectId id) {
final String objectName = id.name(); final String objectName = id.name();
final String d = objectName.substring(0, 2); final String d = objectName.substring(0, 2);
@ -170,6 +244,14 @@ public static String loose(URIish base, AnyObjectId id) {
return join(base, "objects/" + d + "/" + f); return join(base, "objects/" + d + "/" + f);
} }
/**
* Join a base URIish and a path
*
* @param base
* @param path
* a relative path
* @return the joined path
*/
public static String join(URIish base, String path) { public static String join(URIish base, String path) {
if (path.startsWith("/")) if (path.startsWith("/"))
fail("Cannot join absolute path " + path + " to URIish " + base); fail("Cannot join absolute path " + path + " to URIish " + base);
@ -180,6 +262,14 @@ public static String join(URIish base, String path) {
return dir + path; return dir + path;
} }
/**
* Rewrite a url
*
* @param url
* @param newProtocol
* @param newPort
* @return the rewritten url
*/
protected static String rewriteUrl(String url, String newProtocol, protected static String rewriteUrl(String url, String newProtocol,
int newPort) { int newPort) {
String newUrl = url; String newUrl = url;
@ -198,6 +288,14 @@ protected static String rewriteUrl(String url, String newProtocol,
return newUrl; return newUrl;
} }
/**
* Extend a path
*
* @param uri
* @param pathComponents
* @return the extended URIish
* @throws URISyntaxException
*/
protected static URIish extendPath(URIish uri, String pathComponents) protected static URIish extendPath(URIish uri, String pathComponents)
throws URISyntaxException { throws URISyntaxException {
String raw = uri.toString(); String raw = uri.toString();

View File

@ -51,18 +51,29 @@
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
/**
* Mock ServletConfig
*/
public class MockServletConfig implements ServletConfig { public class MockServletConfig implements ServletConfig {
private final Map<String, String> parameters = new HashMap<>(); private final Map<String, String> parameters = new HashMap<>();
/**
* Set init parameter.
*
* @param name
* @param value
*/
public void setInitParameter(String name, String value) { public void setInitParameter(String name, String value) {
parameters.put(name, value); parameters.put(name, value);
} }
/** {@inheritDoc} */
@Override @Override
public String getInitParameter(String name) { public String getInitParameter(String name) {
return parameters.get(name); return parameters.get(name);
} }
/** {@inheritDoc} */
@Override @Override
public Enumeration<String> getInitParameterNames() { public Enumeration<String> getInitParameterNames() {
final Iterator<String> i = parameters.keySet().iterator(); final Iterator<String> i = parameters.keySet().iterator();
@ -79,11 +90,13 @@ public String nextElement() {
}; };
} }
/** {@inheritDoc} */
@Override @Override
public String getServletName() { public String getServletName() {
return "MOCK_SERVLET"; return "MOCK_SERVLET";
} }
/** {@inheritDoc} */
@Override @Override
public ServletContext getServletContext() { public ServletContext getServletContext() {
return null; return null;

View File

@ -50,18 +50,27 @@
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
/** Logs warnings into an array for later inspection. */ /**
* Log warnings into an array for later inspection.
*/
public class RecordingLogger implements Logger { public class RecordingLogger implements Logger {
private static List<Warning> warnings = new ArrayList<>(); private static List<Warning> warnings = new ArrayList<>();
/** Clear the warnings, automatically done by {@link AppServer#setUp()} */ /**
* Clear the warnings, automatically done by
* {@link org.eclipse.jgit.junit.http.AppServer#setUp()}
*/
public static void clear() { public static void clear() {
synchronized (warnings) { synchronized (warnings) {
warnings.clear(); warnings.clear();
} }
} }
/** @return the warnings (if any) from the last execution */ /**
* Get the <code>warnings</code>.
*
* @return the warnings (if any) from the last execution
*/
public static List<Warning> getWarnings() { public static List<Warning> getWarnings() {
synchronized (warnings) { synchronized (warnings) {
ArrayList<Warning> copy = new ArrayList<>(warnings); ArrayList<Warning> copy = new ArrayList<>(warnings);
@ -86,30 +95,48 @@ public Warning(Throwable thrown) {
private final String name; private final String name;
/**
* Constructor for <code>RecordingLogger</code>.
*/
public RecordingLogger() { public RecordingLogger() {
this(""); this("");
} }
/**
* Constructor for <code>RecordingLogger</code>.
*
* @param name
*/
public RecordingLogger(final String name) { public RecordingLogger(final String name) {
this.name = name; this.name = name;
} }
/** {@inheritDoc} */
@Override @Override
public Logger getLogger(@SuppressWarnings("hiding") String name) { public Logger getLogger(@SuppressWarnings("hiding") String name) {
return new RecordingLogger(name); return new RecordingLogger(name);
} }
/** {@inheritDoc} */
@Override @Override
public String getName() { public String getName() {
return name; return name;
} }
/**
* Warning
*
* @param msg
* @param arg0
* @param arg1
*/
public void warn(String msg, Object arg0, Object arg1) { public void warn(String msg, Object arg0, Object arg1) {
synchronized (warnings) { synchronized (warnings) {
warnings.add(new Warning(MessageFormat.format(msg, arg0, arg1))); warnings.add(new Warning(MessageFormat.format(msg, arg0, arg1)));
} }
} }
/** {@inheritDoc} */
@Override @Override
public void warn(String msg, Throwable th) { public void warn(String msg, Throwable th) {
synchronized (warnings) { synchronized (warnings) {
@ -117,47 +144,82 @@ public void warn(String msg, Throwable th) {
} }
} }
/**
* Warning
*
* @param msg
* warning message
*/
public void warn(String msg) { public void warn(String msg) {
synchronized (warnings) { synchronized (warnings) {
warnings.add(new Warning(msg)); warnings.add(new Warning(msg));
} }
} }
/**
* Debug log
*
* @param msg
* @param arg0
* @param arg1
*/
public void debug(@SuppressWarnings("unused") String msg, public void debug(@SuppressWarnings("unused") String msg,
@SuppressWarnings("unused") Object arg0, @SuppressWarnings("unused") Object arg0,
@SuppressWarnings("unused") Object arg1) { @SuppressWarnings("unused") Object arg1) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public void debug(String msg, Throwable th) { public void debug(String msg, Throwable th) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/**
* Debug log
*
* @param msg
* debug message
*/
public void debug(@SuppressWarnings("unused") String msg) { public void debug(@SuppressWarnings("unused") String msg) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/**
* Info
*
* @param msg
* @param arg0
* @param arg1
*/
public void info(@SuppressWarnings("unused") String msg, public void info(@SuppressWarnings("unused") String msg,
@SuppressWarnings("unused") Object arg0, @SuppressWarnings("unused") Object arg0,
@SuppressWarnings("unused") Object arg1) { @SuppressWarnings("unused") Object arg1) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/**
* Info
*
* @param msg
*/
public void info(@SuppressWarnings("unused") String msg) { public void info(@SuppressWarnings("unused") String msg) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
return false; return false;
} }
/** {@inheritDoc} */
@Override @Override
public void setDebugEnabled(boolean enabled) { public void setDebugEnabled(boolean enabled) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public void warn(String msg, Object... args) { public void warn(String msg, Object... args) {
synchronized (warnings) { synchronized (warnings) {
@ -171,6 +233,7 @@ public void warn(String msg, Object... args) {
} }
} }
/** {@inheritDoc} */
@Override @Override
public void warn(Throwable thrown) { public void warn(Throwable thrown) {
synchronized (warnings) { synchronized (warnings) {
@ -178,36 +241,43 @@ public void warn(Throwable thrown) {
} }
} }
/** {@inheritDoc} */
@Override @Override
public void info(String msg, Object... args) { public void info(String msg, Object... args) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public void info(Throwable thrown) { public void info(Throwable thrown) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public void info(String msg, Throwable thrown) { public void info(String msg, Throwable thrown) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public void debug(String msg, Object... args) { public void debug(String msg, Object... args) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public void debug(Throwable thrown) { public void debug(Throwable thrown) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public void ignore(Throwable arg0) { public void ignore(Throwable arg0) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)
} }
/** {@inheritDoc} */
@Override @Override
public void debug(String msg, long value) { public void debug(String msg, long value) {
// Ignore (not relevant to test failures) // Ignore (not relevant to test failures)

View File

@ -71,15 +71,31 @@ public class SimpleHttpServer {
private URIish secureUri; private URIish secureUri;
/**
* Constructor for <code>SimpleHttpServer</code>.
*
* @param repository
*/
public SimpleHttpServer(Repository repository) { public SimpleHttpServer(Repository repository) {
this(repository, false); this(repository, false);
} }
/**
* Constructor for <code>SimpleHttpServer</code>.
*
* @param repository
* @param withSsl
*/
public SimpleHttpServer(Repository repository, boolean withSsl) { public SimpleHttpServer(Repository repository, boolean withSsl) {
this.db = repository; this.db = repository;
server = new AppServer(0, withSsl ? 0 : -1); server = new AppServer(0, withSsl ? 0 : -1);
} }
/**
* Start the server
*
* @throws Exception
*/
public void start() throws Exception { public void start() throws Exception {
ServletContextHandler sBasic = server.authBasic(smart("/sbasic")); ServletContextHandler sBasic = server.authBasic(smart("/sbasic"));
server.setUp(); server.setUp();
@ -91,14 +107,29 @@ public void start() throws Exception {
} }
} }
/**
* Stop the server.
*
* @throws Exception
*/
public void stop() throws Exception { public void stop() throws Exception {
server.tearDown(); server.tearDown();
} }
/**
* Get the <code>uri</code>.
*
* @return the uri
*/
public URIish getUri() { public URIish getUri() {
return uri; return uri;
} }
/**
* Get the <code>secureUri</code>.
*
* @return the secure uri
*/
public URIish getSecureUri() { public URIish getSecureUri() {
return secureUri; return secureUri;
} }

View File

@ -105,6 +105,7 @@ List<AccessEvent> getEvents() {
} }
} }
/** {@inheritDoc} */
@Override @Override
public void handle(String target, Request baseRequest, HttpServletRequest request, public void handle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException { HttpServletResponse response) throws IOException, ServletException {