From 0b131b731263fbddebf1026a71a4bba8ce64574f Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sun, 17 Dec 2017 19:49:40 +0100 Subject: [PATCH] Fix javadoc in org.eclipse.jgit.junit.http Change-Id: I8af6d07676a285f79635405e5891535a5adfd7e9 Signed-off-by: Matthias Sohn --- .../eclipse/jgit/junit/http/AccessEvent.java | 35 +++++- .../eclipse/jgit/junit/http/AppServer.java | 36 +++++- .../eclipse/jgit/junit/http/HttpTestCase.java | 108 +++++++++++++++++- .../jgit/junit/http/MockServletConfig.java | 13 +++ .../jgit/junit/http/RecordingLogger.java | 76 +++++++++++- .../jgit/junit/http/SimpleHttpServer.java | 31 +++++ .../jgit/junit/http/TestRequestLog.java | 1 + 7 files changed, 284 insertions(+), 16 deletions(-) diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java index 0154a7fc70..01c4360d1e 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AccessEvent.java @@ -51,7 +51,9 @@ import java.util.TreeMap; import org.eclipse.jetty.server.Request; 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 { private final String method; @@ -105,17 +107,27 @@ public class AccessEvent { return new TreeMap<>(parameterMap); } - /** @return {@code "GET"} or {@code "POST"} */ + /** + * Get the method. + * + * @return {@code "GET"} or {@code "POST"} + */ public String getMethod() { return method; } - /** @return path of the file on the server, e.g. {@code /git/HEAD}. */ + /** + * Get path. + * + * @return path of the file on the server, e.g. {@code /git/HEAD}. + */ public String getPath() { return uri; } /** + * Get request header + * * @param name * name of the request header to read. * @return first value of the request header; null if not sent. @@ -125,6 +137,8 @@ public class AccessEvent { } /** + * Get parameter + * * @param name * name of the request parameter to read. * @return first value of the request parameter; null if not sent. @@ -134,17 +148,27 @@ public class AccessEvent { return r != null && 1 <= r.length ? r[0] : null; } - /** @return all parameters in the request. */ + /** + * Get parameters + * + * @return all parameters in the request. + */ public Map getParameters() { return parameters; } - /** @return HTTP status code of the response, e.g. 200, 403, 500. */ + /** + * Get the status. + * + * @return HTTP status code of the response, e.g. 200, 403, 500. + */ public int getStatus() { return status; } /** + * Get response header. + * * @param name * name of the response header to read. * @return first value of the response header; null if not sent. @@ -153,6 +177,7 @@ public class AccessEvent { return responseHeaders.get(name); } + /** {@inheritDoc} */ @Override public String toString() { StringBuilder b = new StringBuilder(); diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java index e257cf65b6..9309fe7071 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java @@ -124,11 +124,16 @@ public class AppServer { private List filesToDelete = new ArrayList<>(); + /** + * Constructor for AppServer. + */ public AppServer() { this(0, -1); } /** + * Constructor for AppServer. + * * @param port * the http port number; may be zero to allocate a port * dynamically @@ -139,6 +144,8 @@ public class AppServer { } /** + * Constructor for AppServer. + * * @param port * for http, may be zero to allocate a port dynamically * @param sslPort @@ -268,6 +275,13 @@ public class AppServer { return ctx; } + /** + * Configure basic authentication. + * + * @param ctx + * @param methods + * @return servlet context handler + */ public ServletContextHandler authBasic(ServletContextHandler ctx, String... methods) { assertNotYetSetUp(); @@ -395,24 +409,38 @@ public class AppServer { } } - /** @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() { assertAlreadySetUp(); 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() { assertAlreadySetUp(); 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 getRequests() { return new ArrayList<>(log.getEvents()); } /** + * Get requests. + * * @param base * base URI used to access the server. * @param path @@ -424,6 +452,8 @@ public class AppServer { } /** + * Get requests. + * * @param path * the path to locate requests for. * @return all requests which match the given path. diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java index eabb0f2256..f8a210c1df 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/HttpTestCase.java @@ -67,19 +67,24 @@ import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteRefUpdate; 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 { + /** Constant master="Constants.R_HEADS + Constants.MASTER" */ protected static final String master = Constants.R_HEADS + Constants.MASTER; /** In-memory application server; subclass must start. */ protected AppServer server; + /** {@inheritDoc} */ @Override public void setUp() throws Exception { super.setUp(); server = createServer(); } + /** {@inheritDoc} */ @Override public void tearDown() throws Exception { server.tearDown(); @@ -87,29 +92,50 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { } /** - * 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 * port, which can be gotten once the server has been started via its - * {@link AppServer#getPort()} method. Subclasses may override if they need - * a more specialized server. + * {@link org.eclipse.jgit.junit.http.AppServer#getPort()} method. + * 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 */ protected AppServer createServer() { return new AppServer(); } + /** + * Create TestRepository + * + * @return the TestRepository + * @throws IOException + */ protected TestRepository createTestRepository() throws IOException { return new TestRepository<>(createBareRepository()); } + /** + * Convert path to URIish + * + * @param path + * @return the URIish + * @throws URISyntaxException + */ protected URIish toURIish(String path) throws URISyntaxException { URI u = server.getURI().resolve(path); 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) throws URISyntaxException { String p = app.getContextPath(); @@ -119,18 +145,45 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { return toURIish(p); } + /** + * Get requests. + * + * @return list of events + */ protected List getRequests() { return server.getRequests(); } + /** + * Get requests. + * + * @param base + * @param path + * + * @return list of events + */ protected List getRequests(URIish base, String path) { return server.getRequests(base, path); } + /** + * Get requests. + * + * @param path + * + * @return list of events + */ protected List getRequests(String path) { return server.getRequests(path); } + /** + * Run fsck + * + * @param db + * @param tips + * @throws Exception + */ protected static void fsck(Repository db, RevObject... tips) throws Exception { TestRepository tr = @@ -138,6 +191,12 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { tr.fsck(tips); } + /** + * Mirror refs + * + * @param refs + * @return set of RefSpecs + */ protected static Set mirror(String... refs) { HashSet r = new HashSet<>(); for (String name : refs) { @@ -149,6 +208,14 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { return r; } + /** + * Push a commit + * + * @param from + * @param q + * @return collection of RefUpdates + * @throws IOException + */ protected static Collection push(TestRepository from, RevCommit q) throws IOException { final Repository db = from.getRepository(); @@ -163,6 +230,13 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { 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) { final String objectName = id.name(); final String d = objectName.substring(0, 2); @@ -170,6 +244,14 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { 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) { if (path.startsWith("/")) fail("Cannot join absolute path " + path + " to URIish " + base); @@ -180,6 +262,14 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { return dir + path; } + /** + * Rewrite a url + * + * @param url + * @param newProtocol + * @param newPort + * @return the rewritten url + */ protected static String rewriteUrl(String url, String newProtocol, int newPort) { String newUrl = url; @@ -198,6 +288,14 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase { return newUrl; } + /** + * Extend a path + * + * @param uri + * @param pathComponents + * @return the extended URIish + * @throws URISyntaxException + */ protected static URIish extendPath(URIish uri, String pathComponents) throws URISyntaxException { String raw = uri.toString(); diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java index 03c0816f49..895070fece 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java @@ -51,18 +51,29 @@ import java.util.Map; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; +/** + * Mock ServletConfig + */ public class MockServletConfig implements ServletConfig { private final Map parameters = new HashMap<>(); + /** + * Set init parameter. + * + * @param name + * @param value + */ public void setInitParameter(String name, String value) { parameters.put(name, value); } + /** {@inheritDoc} */ @Override public String getInitParameter(String name) { return parameters.get(name); } + /** {@inheritDoc} */ @Override public Enumeration getInitParameterNames() { final Iterator i = parameters.keySet().iterator(); @@ -79,11 +90,13 @@ public class MockServletConfig implements ServletConfig { }; } + /** {@inheritDoc} */ @Override public String getServletName() { return "MOCK_SERVLET"; } + /** {@inheritDoc} */ @Override public ServletContext getServletContext() { return null; diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java index 4e35ff6422..33b5fc056a 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java @@ -50,18 +50,27 @@ import java.util.List; 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 { private static List 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() { synchronized (warnings) { warnings.clear(); } } - /** @return the warnings (if any) from the last execution */ + /** + * Get the warnings. + * + * @return the warnings (if any) from the last execution + */ public static List getWarnings() { synchronized (warnings) { ArrayList copy = new ArrayList<>(warnings); @@ -86,30 +95,48 @@ public class RecordingLogger implements Logger { private final String name; + /** + * Constructor for RecordingLogger. + */ public RecordingLogger() { this(""); } + /** + * Constructor for RecordingLogger. + * + * @param name + */ public RecordingLogger(final String name) { this.name = name; } + /** {@inheritDoc} */ @Override public Logger getLogger(@SuppressWarnings("hiding") String name) { return new RecordingLogger(name); } + /** {@inheritDoc} */ @Override public String getName() { return name; } + /** + * Warning + * + * @param msg + * @param arg0 + * @param arg1 + */ public void warn(String msg, Object arg0, Object arg1) { synchronized (warnings) { warnings.add(new Warning(MessageFormat.format(msg, arg0, arg1))); } } + /** {@inheritDoc} */ @Override public void warn(String msg, Throwable th) { synchronized (warnings) { @@ -117,47 +144,82 @@ public class RecordingLogger implements Logger { } } + /** + * Warning + * + * @param msg + * warning message + */ public void warn(String msg) { synchronized (warnings) { warnings.add(new Warning(msg)); } } + /** + * Debug log + * + * @param msg + * @param arg0 + * @param arg1 + */ public void debug(@SuppressWarnings("unused") String msg, @SuppressWarnings("unused") Object arg0, @SuppressWarnings("unused") Object arg1) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public void debug(String msg, Throwable th) { // Ignore (not relevant to test failures) } + /** + * Debug log + * + * @param msg + * debug message + */ public void debug(@SuppressWarnings("unused") String msg) { // Ignore (not relevant to test failures) } + /** + * Info + * + * @param msg + * @param arg0 + * @param arg1 + */ public void info(@SuppressWarnings("unused") String msg, @SuppressWarnings("unused") Object arg0, @SuppressWarnings("unused") Object arg1) { // Ignore (not relevant to test failures) } + /** + * Info + * + * @param msg + */ public void info(@SuppressWarnings("unused") String msg) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public boolean isDebugEnabled() { return false; } + /** {@inheritDoc} */ @Override public void setDebugEnabled(boolean enabled) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public void warn(String msg, Object... args) { synchronized (warnings) { @@ -171,6 +233,7 @@ public class RecordingLogger implements Logger { } } + /** {@inheritDoc} */ @Override public void warn(Throwable thrown) { synchronized (warnings) { @@ -178,36 +241,43 @@ public class RecordingLogger implements Logger { } } + /** {@inheritDoc} */ @Override public void info(String msg, Object... args) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public void info(Throwable thrown) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public void info(String msg, Throwable thrown) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public void debug(String msg, Object... args) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public void debug(Throwable thrown) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public void ignore(Throwable arg0) { // Ignore (not relevant to test failures) } + /** {@inheritDoc} */ @Override public void debug(String msg, long value) { // Ignore (not relevant to test failures) diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java index 0ea0721286..c5576f91e6 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/SimpleHttpServer.java @@ -71,15 +71,31 @@ public class SimpleHttpServer { private URIish secureUri; + /** + * Constructor for SimpleHttpServer. + * + * @param repository + */ public SimpleHttpServer(Repository repository) { this(repository, false); } + /** + * Constructor for SimpleHttpServer. + * + * @param repository + * @param withSsl + */ public SimpleHttpServer(Repository repository, boolean withSsl) { this.db = repository; server = new AppServer(0, withSsl ? 0 : -1); } + /** + * Start the server + * + * @throws Exception + */ public void start() throws Exception { ServletContextHandler sBasic = server.authBasic(smart("/sbasic")); server.setUp(); @@ -91,14 +107,29 @@ public class SimpleHttpServer { } } + /** + * Stop the server. + * + * @throws Exception + */ public void stop() throws Exception { server.tearDown(); } + /** + * Get the uri. + * + * @return the uri + */ public URIish getUri() { return uri; } + /** + * Get the secureUri. + * + * @return the secure uri + */ public URIish getSecureUri() { return secureUri; } diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java index c218c07a6c..43181f2e13 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/TestRequestLog.java @@ -105,6 +105,7 @@ class TestRequestLog extends HandlerWrapper { } } + /** {@inheritDoc} */ @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { -- 2.39.5