Merge topic 'inline-2'
* changes: Add git rm command to acceptance test framework Add support for raw input to acceptance test framework
This commit is contained in:
commit
16454236d0
@ -135,6 +135,13 @@ public class GitUtil {
|
|||||||
addCmd.call();
|
addCmd.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void rm(Git gApi, String path)
|
||||||
|
throws GitAPIException, IOException {
|
||||||
|
gApi.rm()
|
||||||
|
.addFilepattern(path)
|
||||||
|
.call();
|
||||||
|
}
|
||||||
|
|
||||||
public static Commit createCommit(Git git, PersonIdent i, String msg)
|
public static Commit createCommit(Git git, PersonIdent i, String msg)
|
||||||
throws GitAPIException, IOException {
|
throws GitAPIException, IOException {
|
||||||
return createCommit(git, i, msg, null);
|
return createCommit(git, i, msg, null);
|
||||||
|
@ -39,7 +39,10 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
import com.google.inject.assistedinject.AssistedInject;
|
import com.google.inject.assistedinject.AssistedInject;
|
||||||
|
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
|
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
|
import org.eclipse.jgit.api.errors.InvalidTagNameException;
|
||||||
|
import org.eclipse.jgit.api.errors.NoHeadException;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.PersonIdent;
|
import org.eclipse.jgit.lib.PersonIdent;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
@ -130,6 +133,18 @@ public class PushOneCommit {
|
|||||||
public Result to(Git git, String ref)
|
public Result to(Git git, String ref)
|
||||||
throws GitAPIException, IOException {
|
throws GitAPIException, IOException {
|
||||||
add(git, fileName, content);
|
add(git, fileName, content);
|
||||||
|
return execute(git, ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result rm(Git git, String ref)
|
||||||
|
throws GitAPIException, IOException {
|
||||||
|
GitUtil.rm(git, fileName);
|
||||||
|
return execute(git, ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result execute(Git git, String ref) throws GitAPIException,
|
||||||
|
IOException, ConcurrentRefUpdateException, InvalidTagNameException,
|
||||||
|
NoHeadException {
|
||||||
Commit c;
|
Commit c;
|
||||||
if (changeId != null) {
|
if (changeId != null) {
|
||||||
c = amendCommit(git, i, subject, changeId);
|
c = amendCommit(git, i, subject, changeId);
|
||||||
|
@ -15,16 +15,22 @@
|
|||||||
package com.google.gerrit.acceptance;
|
package com.google.gerrit.acceptance;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.gerrit.extensions.restapi.RawInput;
|
||||||
import com.google.gerrit.server.OutputFormat;
|
import com.google.gerrit.server.OutputFormat;
|
||||||
|
|
||||||
import org.apache.http.client.methods.HttpDelete;
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.client.methods.HttpPut;
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.entity.BufferedHttpEntity;
|
||||||
|
import org.apache.http.entity.InputStreamEntity;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.message.BasicHeader;
|
import org.apache.http.message.BasicHeader;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class RestSession extends HttpSession {
|
public class RestSession extends HttpSession {
|
||||||
|
|
||||||
@ -53,6 +59,17 @@ public class RestSession extends HttpSession {
|
|||||||
return new RestResponse(getClient().execute(put));
|
return new RestResponse(getClient().execute(put));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RestResponse putRaw(String endPoint, RawInput stream) throws IOException {
|
||||||
|
Preconditions.checkNotNull(stream);
|
||||||
|
HttpPut put = new HttpPut(url + "/a" + endPoint);
|
||||||
|
put.addHeader(new BasicHeader("Content-Type", stream.getContentType()));
|
||||||
|
put.setEntity(new BufferedHttpEntity(
|
||||||
|
new InputStreamEntity(
|
||||||
|
stream.getInputStream(),
|
||||||
|
stream.getContentLength())));
|
||||||
|
return new RestResponse(getClient().execute(put));
|
||||||
|
}
|
||||||
|
|
||||||
public RestResponse post(String endPoint) throws IOException {
|
public RestResponse post(String endPoint) throws IOException {
|
||||||
return post(endPoint, null);
|
return post(endPoint, null);
|
||||||
}
|
}
|
||||||
@ -72,4 +89,28 @@ public class RestSession extends HttpSession {
|
|||||||
HttpDelete delete = new HttpDelete(url + "/a" + endPoint);
|
HttpDelete delete = new HttpDelete(url + "/a" + endPoint);
|
||||||
return new RestResponse(getClient().execute(delete));
|
return new RestResponse(getClient().execute(delete));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static RawInput newRawInput(final String content) throws IOException {
|
||||||
|
Preconditions.checkNotNull(content);
|
||||||
|
Preconditions.checkArgument(!content.isEmpty());
|
||||||
|
return new RawInput() {
|
||||||
|
byte bytes[] = content.getBytes("UTF-8");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
|
return new ByteArrayInputStream(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContentType() {
|
||||||
|
return "application/octet-stream";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getContentLength() {
|
||||||
|
return bytes.length;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user