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.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 @@ private static Map<String, String[]> clone(Map 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() {
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() {
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 String getRequestHeader(String name) {
}
/**
* 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 String getParameter(String name) {
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() {
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() {
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 String getResponseHeader(String name) {
return responseHeaders.get(name);
}
/** {@inheritDoc} */
@Override
public String toString() {
StringBuilder b = new StringBuilder();

View File

@ -124,11 +124,16 @@ public class AppServer {
private List<File> filesToDelete = new ArrayList<>();
/**
* Constructor for <code>AppServer</code>.
*/
public AppServer() {
this(0, -1);
}
/**
* Constructor for <code>AppServer</code>.
*
* @param port
* the http port number; may be zero to allocate a port
* dynamically
@ -139,6 +144,8 @@ public AppServer(int port) {
}
/**
* Constructor for <code>AppServer</code>.
*
* @param port
* for http, may be zero to allocate a port dynamically
* @param sslPort
@ -268,6 +275,13 @@ public ServletContextHandler addContext(String path) {
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 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() {
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<AccessEvent> getRequests() {
return new ArrayList<>(log.getEvents());
}
/**
* Get requests.
*
* @param base
* base URI used to access the server.
* @param path
@ -424,6 +452,8 @@ public List<AccessEvent> getRequests(URIish base, String path) {
}
/**
* Get requests.
*
* @param path
* the path to locate requests for.
* @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.URIish;
/** Base class for HTTP related transport testing. */
/**
* Base class for HTTP related transport testing.
*/
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;
/** 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 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
* 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<Repository> 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 @@ protected URIish toURIish(ServletContextHandler app, String name)
return toURIish(p);
}
/**
* Get requests.
*
* @return list of events
*/
protected List<AccessEvent> getRequests() {
return server.getRequests();
}
/**
* Get requests.
*
* @param base
* @param path
*
* @return list of events
*/
protected List<AccessEvent> getRequests(URIish base, String path) {
return server.getRequests(base, path);
}
/**
* Get requests.
*
* @param path
*
* @return list of events
*/
protected List<AccessEvent> 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<? extends Repository> tr =
@ -138,6 +191,12 @@ protected static void fsck(Repository db, RevObject... tips)
tr.fsck(tips);
}
/**
* Mirror refs
*
* @param refs
* @return set of RefSpecs
*/
protected static Set<RefSpec> mirror(String... refs) {
HashSet<RefSpec> r = new HashSet<>();
for (String name : refs) {
@ -149,6 +208,14 @@ protected static Set<RefSpec> mirror(String... refs) {
return r;
}
/**
* Push a commit
*
* @param from
* @param q
* @return collection of RefUpdates
* @throws IOException
*/
protected static Collection<RemoteRefUpdate> push(TestRepository from,
RevCommit q) throws IOException {
final Repository db = from.getRepository();
@ -163,6 +230,13 @@ protected static Collection<RemoteRefUpdate> push(TestRepository from,
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 static String loose(URIish base, AnyObjectId id) {
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 static String join(URIish base, String 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,
int newPort) {
String newUrl = url;
@ -198,6 +288,14 @@ protected static String rewriteUrl(String url, String newProtocol,
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();

View File

@ -51,18 +51,29 @@
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
/**
* Mock ServletConfig
*/
public class MockServletConfig implements ServletConfig {
private final Map<String, String> 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<String> getInitParameterNames() {
final Iterator<String> i = parameters.keySet().iterator();
@ -79,11 +90,13 @@ public String nextElement() {
};
}
/** {@inheritDoc} */
@Override
public String getServletName() {
return "MOCK_SERVLET";
}
/** {@inheritDoc} */
@Override
public ServletContext getServletContext() {
return null;

View File

@ -50,18 +50,27 @@
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<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() {
synchronized (warnings) {
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() {
synchronized (warnings) {
ArrayList<Warning> copy = new ArrayList<>(warnings);
@ -86,30 +95,48 @@ public Warning(Throwable thrown) {
private final String name;
/**
* Constructor for <code>RecordingLogger</code>.
*/
public RecordingLogger() {
this("");
}
/**
* Constructor for <code>RecordingLogger</code>.
*
* @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 void warn(String msg, Throwable th) {
}
}
/**
* 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 void warn(String msg, Object... args) {
}
}
/** {@inheritDoc} */
@Override
public void warn(Throwable thrown) {
synchronized (warnings) {
@ -178,36 +241,43 @@ public void warn(Throwable thrown) {
}
}
/** {@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)

View File

@ -71,15 +71,31 @@ public class SimpleHttpServer {
private URIish secureUri;
/**
* Constructor for <code>SimpleHttpServer</code>.
*
* @param repository
*/
public SimpleHttpServer(Repository repository) {
this(repository, false);
}
/**
* Constructor for <code>SimpleHttpServer</code>.
*
* @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 void start() throws Exception {
}
}
/**
* Stop the server.
*
* @throws Exception
*/
public void stop() throws Exception {
server.tearDown();
}
/**
* Get the <code>uri</code>.
*
* @return the uri
*/
public URIish getUri() {
return uri;
}
/**
* Get the <code>secureUri</code>.
*
* @return the secure uri
*/
public URIish getSecureUri() {
return secureUri;
}

View File

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