AbstractDaemonTest: Add user SSH session

Rename the adminSession and userSession members to adminRestSession
and userRestSession.

Rename sshSession to adminSshSession.  Add userSshSession.

Change-Id: Id705a04317d146cea48b6215e78d8f8ea7fa95a1
This commit is contained in:
David Pursehouse
2016-04-22 18:39:34 +09:00
parent 84cd28a063
commit 8f02dff77f
35 changed files with 199 additions and 196 deletions

View File

@@ -201,9 +201,10 @@ public abstract class AbstractDaemonTest {
protected GerritServer server; protected GerritServer server;
protected TestAccount admin; protected TestAccount admin;
protected TestAccount user; protected TestAccount user;
protected RestSession adminSession; protected RestSession adminRestSession;
protected RestSession userSession; protected RestSession userRestSession;
protected SshSession sshSession; protected SshSession adminSshSession;
protected SshSession userSshSession;
protected ReviewDb db; protected ReviewDb db;
protected Project.NameKey project; protected Project.NameKey project;
@@ -300,14 +301,18 @@ public abstract class AbstractDaemonTest {
accountCache.evict(admin.getId()); accountCache.evict(admin.getId());
accountCache.evict(user.getId()); accountCache.evict(user.getId());
adminSession = new RestSession(server, admin); adminRestSession = new RestSession(server, admin);
userSession = new RestSession(server, user); userRestSession = new RestSession(server, user);
initSsh(admin); initSsh(admin);
db = reviewDbProvider.open(); db = reviewDbProvider.open();
Context ctx = newRequestContext(admin); Context ctx = newRequestContext(user);
atrScope.set(ctx); atrScope.set(ctx);
sshSession = ctx.getSession(); userSshSession = ctx.getSession();
sshSession.open(); userSshSession.open();
ctx = newRequestContext(admin);
atrScope.set(ctx);
adminSshSession = ctx.getSession();
adminSshSession.open();
resourcePrefix = UNSAFE_PROJECT_NAME.matcher( resourcePrefix = UNSAFE_PROJECT_NAME.matcher(
description.getClassName() + "_" description.getClassName() + "_"
+ description.getMethodName() + "_").replaceAll(""); + description.getMethodName() + "_").replaceAll("");
@@ -423,7 +428,8 @@ public abstract class AbstractDaemonTest {
repo.close(); repo.close();
} }
db.close(); db.close();
sshSession.close(); adminSshSession.close();
userSshSession.close();
if (server != commonServer) { if (server != commonServer) {
server.stop(); server.stop();
} }

View File

@@ -171,7 +171,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME, modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
RawInputUtil.create(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED); RawInputUtil.create(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED);
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
adminSession.post(urlPublish()).assertNoContent(); adminRestSession.post(urlPublish()).assertNoContent();
edit = editUtil.byChange(change); edit = editUtil.byChange(change);
assertThat(edit.isPresent()).isFalse(); assertThat(edit.isPresent()).isFalse();
PatchSet newCurrentPatchSet = getCurrentPatchSet(changeId); PatchSet newCurrentPatchSet = getCurrentPatchSet(changeId);
@@ -189,7 +189,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME, modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
RawInputUtil.create(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED); RawInputUtil.create(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED);
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
adminSession.delete(urlEdit()).assertNoContent(); adminRestSession.delete(urlEdit()).assertNoContent();
edit = editUtil.byChange(change); edit = editUtil.byChange(change);
assertThat(edit.isPresent()).isFalse(); assertThat(edit.isPresent()).isFalse();
} }
@@ -203,9 +203,9 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat( assertThat(
modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME, modifier.modifyFile(editUtil.byChange(change).get(), FILE_NAME,
RawInputUtil.create(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED); RawInputUtil.create(CONTENT_NEW))).isEqualTo(RefUpdate.Result.FORCED);
adminSession.post(urlPublish()).assertForbidden(); adminRestSession.post(urlPublish()).assertForbidden();
setUseContributorAgreements(InheritableBoolean.FALSE); setUseContributorAgreements(InheritableBoolean.FALSE);
adminSession.post(urlPublish()).assertNoContent(); adminRestSession.post(urlPublish()).assertNoContent();
} }
@Test @Test
@@ -242,7 +242,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat(edit.getBasePatchSet().getPatchSetId()).isEqualTo( assertThat(edit.getBasePatchSet().getPatchSetId()).isEqualTo(
current.getPatchSetId() - 1); current.getPatchSetId() - 1);
Date beforeRebase = edit.getEditCommit().getCommitterIdent().getWhen(); Date beforeRebase = edit.getEditCommit().getCommitterIdent().getWhen();
adminSession.post(urlRebase()).assertNoContent(); adminRestSession.post(urlRebase()).assertNoContent();
edit = editUtil.byChange(change).get(); edit = editUtil.byChange(change).get();
assertByteArray(fileUtil.getContent(projectCache.get(edit.getChange().getProject()), assertByteArray(fileUtil.getContent(projectCache.get(edit.getChange().getProject()),
ObjectId.fromString(edit.getRevision().get()), FILE_NAME), CONTENT_NEW); ObjectId.fromString(edit.getRevision().get()), FILE_NAME), CONTENT_NEW);
@@ -268,7 +268,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, FILE_NAME, pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, FILE_NAME,
new String(CONTENT_NEW2), changeId2); new String(CONTENT_NEW2), changeId2);
push.to("refs/for/master").assertOkStatus(); push.to("refs/for/master").assertOkStatus();
adminSession.post(urlRebase()).assertConflict(); adminRestSession.post(urlRebase()).assertConflict();
} }
@Test @Test
@@ -362,13 +362,13 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test @Test
public void updateMessageRest() throws Exception { public void updateMessageRest() throws Exception {
adminSession.get(urlEditMessage()).assertNotFound(); adminRestSession.get(urlEditMessage()).assertNotFound();
EditMessage.Input in = new EditMessage.Input(); EditMessage.Input in = new EditMessage.Input();
in.message = String.format("New commit message\n\n" + in.message = String.format("New commit message\n\n" +
CONTENT_NEW2_STR + "\n\nChange-Id: %s\n", CONTENT_NEW2_STR + "\n\nChange-Id: %s\n",
change.getKey()); change.getKey());
adminSession.put(urlEditMessage(), in).assertNoContent(); adminRestSession.put(urlEditMessage(), in).assertNoContent();
RestResponse r = adminSession.getJsonAccept(urlEditMessage()); RestResponse r = adminRestSession.getJsonAccept(urlEditMessage());
r.assertOK(); r.assertOK();
assertThat(readContentFromJson(r)).isEqualTo(in.message); assertThat(readContentFromJson(r)).isEqualTo(in.message);
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
@@ -376,7 +376,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
.isEqualTo(in.message); .isEqualTo(in.message);
in.message = String.format("New commit message2\n\nChange-Id: %s\n", in.message = String.format("New commit message2\n\nChange-Id: %s\n",
change.getKey()); change.getKey());
adminSession.put(urlEditMessage(), in).assertNoContent(); adminRestSession.put(urlEditMessage(), in).assertNoContent();
edit = editUtil.byChange(change); edit = editUtil.byChange(change);
assertThat(edit.get().getEditCommit().getFullMessage()) assertThat(edit.get().getEditCommit().getFullMessage())
.isEqualTo(in.message); .isEqualTo(in.message);
@@ -389,7 +389,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test @Test
public void retrieveEdit() throws Exception { public void retrieveEdit() throws Exception {
adminSession.get(urlEdit()).assertNoContent(); adminRestSession.get(urlEdit()).assertNoContent();
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW); assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertThat(modifier.modifyFile(edit.get(), FILE_NAME, RawInputUtil.create(CONTENT_NEW))) assertThat(modifier.modifyFile(edit.get(), FILE_NAME, RawInputUtil.create(CONTENT_NEW)))
@@ -402,7 +402,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
edit = editUtil.byChange(change); edit = editUtil.byChange(change);
editUtil.delete(edit.get()); editUtil.delete(edit.get());
adminSession.get(urlEdit()).assertNoContent(); adminRestSession.get(urlEdit()).assertNoContent();
} }
@Test @Test
@@ -447,7 +447,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test @Test
public void createEditByDeletingExistingFileRest() throws Exception { public void createEditByDeletingExistingFileRest() throws Exception {
adminSession.delete(urlEditFile()).assertNoContent(); adminRestSession.delete(urlEditFile()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
exception.expect(ResourceNotFoundException.class); exception.expect(ResourceNotFoundException.class);
fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
@@ -456,13 +456,13 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test @Test
public void deletingNonExistingEditRest() throws Exception { public void deletingNonExistingEditRest() throws Exception {
adminSession.delete(urlEdit()).assertNotFound(); adminRestSession.delete(urlEdit()).assertNotFound();
} }
@Test @Test
public void deleteExistingFileRest() throws Exception { public void deleteExistingFileRest() throws Exception {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW); assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
adminSession.delete(urlEditFile()).assertNoContent(); adminRestSession.delete(urlEditFile()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
exception.expect(ResourceNotFoundException.class); exception.expect(ResourceNotFoundException.class);
fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
@@ -511,7 +511,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
Post.Input in = new Post.Input(); Post.Input in = new Post.Input();
in.oldPath = FILE_NAME; in.oldPath = FILE_NAME;
in.newPath = FILE_NAME3; in.newPath = FILE_NAME3;
adminSession.post(urlEdit(), in).assertNoContent(); adminRestSession.post(urlEdit(), in).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME3), CONTENT_OLD); ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME3), CONTENT_OLD);
@@ -524,7 +524,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
public void restoreDeletedFileInPatchSetRest() throws Exception { public void restoreDeletedFileInPatchSetRest() throws Exception {
Post.Input in = new Post.Input(); Post.Input in = new Post.Input();
in.restorePath = FILE_NAME; in.restorePath = FILE_NAME;
adminSession.post(urlEdit2(), in).assertNoContent(); adminRestSession.post(urlEdit2(), in).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change2); Optional<ChangeEdit> edit = editUtil.byChange(change2);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_OLD); ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_OLD);
@@ -550,12 +550,12 @@ public class ChangeEditIT extends AbstractDaemonTest {
public void createAndChangeEditInOneRequestRest() throws Exception { public void createAndChangeEditInOneRequestRest() throws Exception {
Put.Input in = new Put.Input(); Put.Input in = new Put.Input();
in.content = RawInputUtil.create(CONTENT_NEW); in.content = RawInputUtil.create(CONTENT_NEW);
adminSession.putRaw(urlEditFile(), in.content).assertNoContent(); adminRestSession.putRaw(urlEditFile(), in.content).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW); ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW);
in.content = RawInputUtil.create(CONTENT_NEW2); in.content = RawInputUtil.create(CONTENT_NEW2);
adminSession.putRaw(urlEditFile(), in.content).assertNoContent(); adminRestSession.putRaw(urlEditFile(), in.content).assertNoContent();
edit = editUtil.byChange(change); edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW2); ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW2);
@@ -566,7 +566,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW); assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
Put.Input in = new Put.Input(); Put.Input in = new Put.Input();
in.content = RawInputUtil.create(CONTENT_NEW); in.content = RawInputUtil.create(CONTENT_NEW);
adminSession.putRaw(urlEditFile(), in.content).assertNoContent(); adminRestSession.putRaw(urlEditFile(), in.content).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW); ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_NEW);
@@ -575,7 +575,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test @Test
public void emptyPutRequest() throws Exception { public void emptyPutRequest() throws Exception {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW); assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
adminSession.put(urlEditFile()).assertNoContent(); adminRestSession.put(urlEditFile()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), "".getBytes()); ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), "".getBytes());
@@ -583,7 +583,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test @Test
public void createEmptyEditRest() throws Exception { public void createEmptyEditRest() throws Exception {
adminSession.post(urlEdit()).assertNoContent(); adminRestSession.post(urlEdit()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_OLD); ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_OLD);
@@ -593,12 +593,12 @@ public class ChangeEditIT extends AbstractDaemonTest {
public void getFileContentRest() throws Exception { public void getFileContentRest() throws Exception {
Put.Input in = new Put.Input(); Put.Input in = new Put.Input();
in.content = RawInputUtil.create(CONTENT_NEW); in.content = RawInputUtil.create(CONTENT_NEW);
adminSession.putRaw(urlEditFile(), in.content).assertNoContent(); adminRestSession.putRaw(urlEditFile(), in.content).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertThat(modifier.modifyFile(edit.get(), FILE_NAME, RawInputUtil.create(CONTENT_NEW2))) assertThat(modifier.modifyFile(edit.get(), FILE_NAME, RawInputUtil.create(CONTENT_NEW2)))
.isEqualTo(RefUpdate.Result.FORCED); .isEqualTo(RefUpdate.Result.FORCED);
edit = editUtil.byChange(change); edit = editUtil.byChange(change);
RestResponse r = adminSession.getJsonAccept(urlEditFile()); RestResponse r = adminRestSession.getJsonAccept(urlEditFile());
r.assertOK(); r.assertOK();
assertThat(readContentFromJson(r)).isEqualTo( assertThat(readContentFromJson(r)).isEqualTo(
StringUtils.newStringUtf8(CONTENT_NEW2)); StringUtils.newStringUtf8(CONTENT_NEW2));
@@ -607,9 +607,9 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test @Test
public void getFileNotFoundRest() throws Exception { public void getFileNotFoundRest() throws Exception {
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW); assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
adminSession.delete(urlEditFile()).assertNoContent(); adminRestSession.delete(urlEditFile()).assertNoContent();
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
adminSession.get(urlEditFile()).assertNoContent(); adminRestSession.get(urlEditFile()).assertNoContent();
exception.expect(ResourceNotFoundException.class); exception.expect(ResourceNotFoundException.class);
fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()), fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME); ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME);
@@ -724,12 +724,12 @@ public class ChangeEditIT extends AbstractDaemonTest {
.isEqualTo(RefUpdate.Result.FORCED); .isEqualTo(RefUpdate.Result.FORCED);
edit = editUtil.byChange(change).get(); edit = editUtil.byChange(change).get();
RestResponse r = adminSession.getJsonAccept(urlRevisionFiles(edit)); RestResponse r = adminRestSession.getJsonAccept(urlRevisionFiles(edit));
Map<String, FileInfo> files = readContentFromJson( Map<String, FileInfo> files = readContentFromJson(
r, new TypeToken<Map<String, FileInfo>>() {}); r, new TypeToken<Map<String, FileInfo>>() {});
assertThat(files).containsKey(FILE_NAME); assertThat(files).containsKey(FILE_NAME);
r = adminSession.getJsonAccept(urlRevisionFiles()); r = adminRestSession.getJsonAccept(urlRevisionFiles());
files = readContentFromJson(r, new TypeToken<Map<String, FileInfo>>() {}); files = readContentFromJson(r, new TypeToken<Map<String, FileInfo>>() {});
assertThat(files).containsKey(FILE_NAME); assertThat(files).containsKey(FILE_NAME);
} }
@@ -742,11 +742,11 @@ public class ChangeEditIT extends AbstractDaemonTest {
.isEqualTo(RefUpdate.Result.FORCED); .isEqualTo(RefUpdate.Result.FORCED);
edit = editUtil.byChange(change).get(); edit = editUtil.byChange(change).get();
RestResponse r = adminSession.getJsonAccept(urlDiff(edit)); RestResponse r = adminRestSession.getJsonAccept(urlDiff(edit));
DiffInfo diff = readContentFromJson(r, DiffInfo.class); DiffInfo diff = readContentFromJson(r, DiffInfo.class);
assertThat(diff.diffHeader.get(0)).contains(FILE_NAME); assertThat(diff.diffHeader.get(0)).contains(FILE_NAME);
r = adminSession.getJsonAccept(urlDiff()); r = adminRestSession.getJsonAccept(urlDiff());
diff = readContentFromJson(r, DiffInfo.class); diff = readContentFromJson(r, DiffInfo.class);
assertThat(diff.diffHeader.get(0)).contains(FILE_NAME); assertThat(diff.diffHeader.get(0)).contains(FILE_NAME);
} }
@@ -866,7 +866,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
} }
private EditInfo toEditInfo(boolean files) throws Exception { private EditInfo toEditInfo(boolean files) throws Exception {
RestResponse r = adminSession.get(files ? urlGetFiles() : urlEdit()); RestResponse r = adminRestSession.get(files ? urlGetFiles() : urlEdit());
return readContentFromJson(r, EditInfo.class); return readContentFromJson(r, EditInfo.class);
} }

View File

@@ -75,7 +75,7 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
sshUrl = sshSession.getUrl(); sshUrl = adminSshSession.getUrl();
ProjectConfig cfg = projectCache.checkedGet(project).getConfig(); ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
patchSetLock = Util.patchSetLock(); patchSetLock = Util.patchSetLock();
cfg.getLabelSections().put(patchSetLock.getName(), patchSetLock); cfg.getLabelSections().put(patchSetLock.getName(), patchSetLock);

View File

@@ -51,7 +51,7 @@ public class CapabilitiesIT extends AbstractDaemonTest {
allowGlobalCapabilities(REGISTERED_USERS, all); allowGlobalCapabilities(REGISTERED_USERS, all);
try { try {
RestResponse r = RestResponse r =
userSession.get("/accounts/self/capabilities"); userRestSession.get("/accounts/self/capabilities");
r.assertOK(); r.assertOK();
CapabilityInfo info = (new Gson()).fromJson(r.getReader(), CapabilityInfo info = (new Gson()).fromJson(r.getReader(),
new TypeToken<CapabilityInfo>() {}.getType()); new TypeToken<CapabilityInfo>() {}.getType());
@@ -79,7 +79,7 @@ public class CapabilitiesIT extends AbstractDaemonTest {
@Test @Test
public void testCapabilitiesAdmin() throws Exception { public void testCapabilitiesAdmin() throws Exception {
RestResponse r = RestResponse r =
adminSession.get("/accounts/self/capabilities"); adminRestSession.get("/accounts/self/capabilities");
r.assertOK(); r.assertOK();
CapabilityInfo info = (new Gson()).fromJson(r.getReader(), CapabilityInfo info = (new Gson()).fromJson(r.getReader(),
new TypeToken<CapabilityInfo>() {}.getType()); new TypeToken<CapabilityInfo>() {}.getType());

View File

@@ -27,7 +27,7 @@ import org.junit.Test;
public class GetAccountDetailIT extends AbstractDaemonTest { public class GetAccountDetailIT extends AbstractDaemonTest {
@Test @Test
public void getDetail() throws Exception { public void getDetail() throws Exception {
RestResponse r = adminSession.get("/accounts/" + admin.username + "/detail/"); RestResponse r = adminRestSession.get("/accounts/" + admin.username + "/detail/");
AccountDetailInfo info = newGson().fromJson(r.getReader(), AccountDetailInfo.class); AccountDetailInfo info = newGson().fromJson(r.getReader(), AccountDetailInfo.class);
assertAccountInfo(admin, info); assertAccountInfo(admin, info);
Account account = accountCache.get(admin.getId()).getAccount(); Account account = accountCache.get(admin.getId()).getAccount();

View File

@@ -38,7 +38,7 @@ public class PutUsernameIT extends AbstractDaemonTest {
PutUsername.Input in = new PutUsername.Input(); PutUsername.Input in = new PutUsername.Input();
in.username = "myUsername"; in.username = "myUsername";
RestResponse r = RestResponse r =
adminSession.put("/accounts/" + createUser().get() + "/username", in); adminRestSession.put("/accounts/" + createUser().get() + "/username", in);
r.assertOK(); r.assertOK();
assertThat(newGson().fromJson(r.getReader(), String.class)).isEqualTo( assertThat(newGson().fromJson(r.getReader(), String.class)).isEqualTo(
in.username); in.username);
@@ -48,7 +48,7 @@ public class PutUsernameIT extends AbstractDaemonTest {
public void setExisting_Conflict() throws Exception { public void setExisting_Conflict() throws Exception {
PutUsername.Input in = new PutUsername.Input(); PutUsername.Input in = new PutUsername.Input();
in.username = admin.username; in.username = admin.username;
adminSession adminRestSession
.put("/accounts/" + createUser().get() + "/username", in) .put("/accounts/" + createUser().get() + "/username", in)
.assertConflict(); .assertConflict();
} }
@@ -57,14 +57,14 @@ public class PutUsernameIT extends AbstractDaemonTest {
public void setNew_MethodNotAllowed() throws Exception { public void setNew_MethodNotAllowed() throws Exception {
PutUsername.Input in = new PutUsername.Input(); PutUsername.Input in = new PutUsername.Input();
in.username = "newUsername"; in.username = "newUsername";
adminSession adminRestSession
.put("/accounts/" + admin.username + "/username", in) .put("/accounts/" + admin.username + "/username", in)
.assertMethodNotAllowed(); .assertMethodNotAllowed();
} }
@Test @Test
public void delete_MethodNotAllowed() throws Exception { public void delete_MethodNotAllowed() throws Exception {
adminSession adminRestSession
.put("/accounts/" + admin.username + "/username") .put("/accounts/" + admin.username + "/username")
.assertMethodNotAllowed(); .assertMethodNotAllowed();
} }

View File

@@ -178,14 +178,14 @@ public class CreateChangeIT extends AbstractDaemonTest {
// TODO(davido): Expose setting of account preferences in the API // TODO(davido): Expose setting of account preferences in the API
private void setSignedOffByFooter() throws Exception { private void setSignedOffByFooter() throws Exception {
RestResponse r = adminSession.get("/accounts/" + admin.email RestResponse r = adminRestSession.get("/accounts/" + admin.email
+ "/preferences"); + "/preferences");
r.assertOK(); r.assertOK();
GeneralPreferencesInfo i = GeneralPreferencesInfo i =
newGson().fromJson(r.getReader(), GeneralPreferencesInfo.class); newGson().fromJson(r.getReader(), GeneralPreferencesInfo.class);
i.signedOffBy = true; i.signedOffBy = true;
r = adminSession.put("/accounts/" + admin.email + "/preferences", i); r = adminRestSession.put("/accounts/" + admin.email + "/preferences", i);
r.assertOK(); r.assertOK();
GeneralPreferencesInfo o = newGson().fromJson(r.getReader(), GeneralPreferencesInfo o = newGson().fromJson(r.getReader(),
GeneralPreferencesInfo.class); GeneralPreferencesInfo.class);

View File

@@ -51,7 +51,7 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet); ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet); assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.NEW); assertThat(c.status).isEqualTo(ChangeStatus.NEW);
RestResponse r = deletePatchSet(changeId, ps, adminSession); RestResponse r = deletePatchSet(changeId, ps, adminRestSession);
assertThat(r.getEntityContent()).isEqualTo("Patch set is not a draft"); assertThat(r.getEntityContent()).isEqualTo("Patch set is not a draft");
r.assertConflict(); r.assertConflict();
} }
@@ -64,7 +64,7 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet); ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet); assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT); assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
RestResponse r = deletePatchSet(changeId, ps, userSession); RestResponse r = deletePatchSet(changeId, ps, userRestSession);
assertThat(r.getEntityContent()).isEqualTo("Not found: " + changeId); assertThat(r.getEntityContent()).isEqualTo("Not found: " + changeId);
r.assertNotFound(); r.assertNotFound();
} }
@@ -87,14 +87,14 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
assertThat(cd.patchSets()).hasSize(2); assertThat(cd.patchSets()).hasSize(2);
assertThat(cd.change().currentPatchSetId().get()).isEqualTo(2); assertThat(cd.change().currentPatchSetId().get()).isEqualTo(2);
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.DRAFT); assertThat(cd.change().getStatus()).isEqualTo(Change.Status.DRAFT);
deletePatchSet(changeId, ps, adminSession).assertNoContent(); deletePatchSet(changeId, ps, adminRestSession).assertNoContent();
cd = getChange(changeId); cd = getChange(changeId);
assertThat(cd.patchSets()).hasSize(1); assertThat(cd.patchSets()).hasSize(1);
assertThat(cd.change().currentPatchSetId().get()).isEqualTo(1); assertThat(cd.change().currentPatchSetId().get()).isEqualTo(1);
ps = getCurrentPatchSet(changeId); ps = getCurrentPatchSet(changeId);
deletePatchSet(changeId, ps, adminSession).assertNoContent(); deletePatchSet(changeId, ps, adminRestSession).assertNoContent();
assertThat(queryProvider.get().byKeyPrefix(changeId)).isEmpty(); assertThat(queryProvider.get().byKeyPrefix(changeId)).isEmpty();
if (notesMigration.writeChanges()) { if (notesMigration.writeChanges()) {

View File

@@ -53,7 +53,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet); ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet); assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.NEW); assertThat(c.status).isEqualTo(ChangeStatus.NEW);
RestResponse response = deleteChange(changeId, adminSession); RestResponse response = deleteChange(changeId, adminRestSession);
assertThat(response.getEntityContent()) assertThat(response.getEntityContent())
.isEqualTo("Change is not a draft: " + c._number); .isEqualTo("Change is not a draft: " + c._number);
response.assertConflict(); response.assertConflict();
@@ -69,7 +69,7 @@ public class DraftChangeIT extends AbstractDaemonTest {
ChangeInfo c = get(triplet); ChangeInfo c = get(triplet);
assertThat(c.id).isEqualTo(triplet); assertThat(c.id).isEqualTo(triplet);
assertThat(c.status).isEqualTo(ChangeStatus.DRAFT); assertThat(c.status).isEqualTo(ChangeStatus.DRAFT);
deleteChange(changeId, adminSession).assertNoContent(); deleteChange(changeId, adminRestSession).assertNoContent();
exception.expect(ResourceNotFoundException.class); exception.expect(ResourceNotFoundException.class);
get(triplet); get(triplet);
@@ -151,13 +151,13 @@ public class DraftChangeIT extends AbstractDaemonTest {
} }
private RestResponse publishChange(String changeId) throws Exception { private RestResponse publishChange(String changeId) throws Exception {
return adminSession.post("/changes/" + changeId + "/publish"); return adminRestSession.post("/changes/" + changeId + "/publish");
} }
private RestResponse publishPatchSet(String changeId) throws Exception { private RestResponse publishPatchSet(String changeId) throws Exception {
PatchSet patchSet = Iterables.getOnlyElement( PatchSet patchSet = Iterables.getOnlyElement(
queryProvider.get().byKeyPrefix(changeId)).currentPatchSet(); queryProvider.get().byKeyPrefix(changeId)).currentPatchSet();
return adminSession.post("/changes/" return adminRestSession.post("/changes/"
+ changeId + changeId
+ "/revisions/" + "/revisions/"
+ patchSet.getRevision().get() + patchSet.getRevision().get()

View File

@@ -22,7 +22,7 @@ public class IndexChangeIT extends AbstractDaemonTest {
@Test @Test
public void indexChange() throws Exception { public void indexChange() throws Exception {
String changeId = createChange().getChangeId(); String changeId = createChange().getChangeId();
adminSession adminRestSession
.post("/changes/" + changeId + "/index/") .post("/changes/" + changeId + "/index/")
.assertNoContent(); .assertNoContent();
} }
@@ -31,7 +31,7 @@ public class IndexChangeIT extends AbstractDaemonTest {
public void indexChangeOnNonVisibleBranch() throws Exception { public void indexChangeOnNonVisibleBranch() throws Exception {
String changeId = createChange().getChangeId(); String changeId = createChange().getChangeId();
blockRead("refs/heads/master"); blockRead("refs/heads/master");
userSession userRestSession
.post("/changes/" + changeId + "/index/") .post("/changes/" + changeId + "/index/")
.assertNotFound(); .assertNotFound();
} }

View File

@@ -33,28 +33,28 @@ public class CacheOperationsIT extends AbstractDaemonTest {
@Test @Test
public void flushAll() throws Exception { public void flushAll() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/project_list"); RestResponse r = adminRestSession.get("/config/server/caches/project_list");
CacheInfo cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class); CacheInfo cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(cacheInfo.entries.mem).isGreaterThan((long) 0); assertThat(cacheInfo.entries.mem).isGreaterThan((long) 0);
r = adminSession.post("/config/server/caches/", new PostCaches.Input(FLUSH_ALL)); r = adminRestSession.post("/config/server/caches/", new PostCaches.Input(FLUSH_ALL));
r.assertOK(); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/config/server/caches/project_list"); r = adminRestSession.get("/config/server/caches/project_list");
cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class); cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(cacheInfo.entries.mem).isNull(); assertThat(cacheInfo.entries.mem).isNull();
} }
@Test @Test
public void flushAll_Forbidden() throws Exception { public void flushAll_Forbidden() throws Exception {
userSession.post("/config/server/caches/", userRestSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH_ALL)).assertForbidden(); new PostCaches.Input(FLUSH_ALL)).assertForbidden();
} }
@Test @Test
public void flushAll_BadRequest() throws Exception { public void flushAll_BadRequest() throws Exception {
adminSession adminRestSession
.post("/config/server/caches/", .post("/config/server/caches/",
new PostCaches.Input(FLUSH_ALL, Arrays.asList("projects"))) new PostCaches.Input(FLUSH_ALL, Arrays.asList("projects")))
.assertBadRequest(); .assertBadRequest();
@@ -62,31 +62,31 @@ public class CacheOperationsIT extends AbstractDaemonTest {
@Test @Test
public void flush() throws Exception { public void flush() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/project_list"); RestResponse r = adminRestSession.get("/config/server/caches/project_list");
CacheInfo cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class); CacheInfo cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(cacheInfo.entries.mem).isGreaterThan((long)0); assertThat(cacheInfo.entries.mem).isGreaterThan((long)0);
r = adminSession.get("/config/server/caches/projects"); r = adminRestSession.get("/config/server/caches/projects");
cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class); cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(cacheInfo.entries.mem).isGreaterThan((long)1); assertThat(cacheInfo.entries.mem).isGreaterThan((long)1);
r = adminSession.post("/config/server/caches/", r = adminRestSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("accounts", "project_list"))); new PostCaches.Input(FLUSH, Arrays.asList("accounts", "project_list")));
r.assertOK(); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/config/server/caches/project_list"); r = adminRestSession.get("/config/server/caches/project_list");
cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class); cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(cacheInfo.entries.mem).isNull(); assertThat(cacheInfo.entries.mem).isNull();
r = adminSession.get("/config/server/caches/projects"); r = adminRestSession.get("/config/server/caches/projects");
cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class); cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(cacheInfo.entries.mem).isGreaterThan((long)1); assertThat(cacheInfo.entries.mem).isGreaterThan((long)1);
} }
@Test @Test
public void flush_Forbidden() throws Exception { public void flush_Forbidden() throws Exception {
userSession userRestSession
.post("/config/server/caches/", .post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects"))) new PostCaches.Input(FLUSH, Arrays.asList("projects")))
.assertForbidden(); .assertForbidden();
@@ -94,7 +94,7 @@ public class CacheOperationsIT extends AbstractDaemonTest {
@Test @Test
public void flush_BadRequest() throws Exception { public void flush_BadRequest() throws Exception {
adminSession adminRestSession
.post("/config/server/caches/", .post("/config/server/caches/",
new PostCaches.Input(FLUSH)) new PostCaches.Input(FLUSH))
.assertBadRequest(); .assertBadRequest();
@@ -102,16 +102,16 @@ public class CacheOperationsIT extends AbstractDaemonTest {
@Test @Test
public void flush_UnprocessableEntity() throws Exception { public void flush_UnprocessableEntity() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/projects"); RestResponse r = adminRestSession.get("/config/server/caches/projects");
CacheInfo cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class); CacheInfo cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(cacheInfo.entries.mem).isGreaterThan((long)0); assertThat(cacheInfo.entries.mem).isGreaterThan((long)0);
r = adminSession.post("/config/server/caches/", r = adminRestSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects", "unprocessable"))); new PostCaches.Input(FLUSH, Arrays.asList("projects", "unprocessable")));
r.assertUnprocessableEntity(); r.assertUnprocessableEntity();
r.consume(); r.consume();
r = adminSession.get("/config/server/caches/projects"); r = adminRestSession.get("/config/server/caches/projects");
cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class); cacheInfo = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(cacheInfo.entries.mem).isGreaterThan((long)0); assertThat(cacheInfo.entries.mem).isGreaterThan((long)0);
} }
@@ -121,12 +121,12 @@ public class CacheOperationsIT extends AbstractDaemonTest {
allowGlobalCapabilities(REGISTERED_USERS, allowGlobalCapabilities(REGISTERED_USERS,
GlobalCapability.FLUSH_CACHES, GlobalCapability.VIEW_CACHES); GlobalCapability.FLUSH_CACHES, GlobalCapability.VIEW_CACHES);
try { try {
RestResponse r = userSession.post("/config/server/caches/", RestResponse r = userRestSession.post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("projects"))); new PostCaches.Input(FLUSH, Arrays.asList("projects")));
r.assertOK(); r.assertOK();
r.consume(); r.consume();
userSession userRestSession
.post("/config/server/caches/", .post("/config/server/caches/",
new PostCaches.Input(FLUSH, Arrays.asList("web_sessions"))) new PostCaches.Input(FLUSH, Arrays.asList("web_sessions")))
.assertForbidden(); .assertForbidden();

View File

@@ -40,7 +40,7 @@ public class ConfirmEmailIT extends AbstractDaemonTest {
public void confirm() throws Exception { public void confirm() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input(); ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = emailTokenVerifier.encode(admin.getId(), "new.mail@example.com"); in.token = emailTokenVerifier.encode(admin.getId(), "new.mail@example.com");
adminSession adminRestSession
.put("/config/server/email.confirm", in) .put("/config/server/email.confirm", in)
.assertNoContent(); .assertNoContent();
} }
@@ -49,7 +49,7 @@ public class ConfirmEmailIT extends AbstractDaemonTest {
public void confirmForOtherUser_UnprocessableEntity() throws Exception { public void confirmForOtherUser_UnprocessableEntity() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input(); ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = emailTokenVerifier.encode(user.getId(), "new.mail@example.com"); in.token = emailTokenVerifier.encode(user.getId(), "new.mail@example.com");
adminSession adminRestSession
.put("/config/server/email.confirm", in) .put("/config/server/email.confirm", in)
.assertUnprocessableEntity(); .assertUnprocessableEntity();
} }
@@ -58,7 +58,7 @@ public class ConfirmEmailIT extends AbstractDaemonTest {
public void confirmInvalidToken_UnprocessableEntity() throws Exception { public void confirmInvalidToken_UnprocessableEntity() throws Exception {
ConfirmEmail.Input in = new ConfirmEmail.Input(); ConfirmEmail.Input in = new ConfirmEmail.Input();
in.token = "invalidToken"; in.token = "invalidToken";
adminSession adminRestSession
.put("/config/server/email.confirm", in) .put("/config/server/email.confirm", in)
.assertUnprocessableEntity(); .assertUnprocessableEntity();
} }

View File

@@ -28,43 +28,43 @@ public class FlushCacheIT extends AbstractDaemonTest {
@Test @Test
public void flushCache() throws Exception { public void flushCache() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/groups"); RestResponse r = adminRestSession.get("/config/server/caches/groups");
CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class); CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(result.entries.mem).isGreaterThan((long)0); assertThat(result.entries.mem).isGreaterThan((long)0);
r = adminSession.post("/config/server/caches/groups/flush"); r = adminRestSession.post("/config/server/caches/groups/flush");
r.assertOK(); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/config/server/caches/groups"); r = adminRestSession.get("/config/server/caches/groups");
result = newGson().fromJson(r.getReader(), CacheInfo.class); result = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(result.entries.mem).isNull(); assertThat(result.entries.mem).isNull();
} }
@Test @Test
public void flushCache_Forbidden() throws Exception { public void flushCache_Forbidden() throws Exception {
userSession userRestSession
.post("/config/server/caches/accounts/flush") .post("/config/server/caches/accounts/flush")
.assertForbidden(); .assertForbidden();
} }
@Test @Test
public void flushCache_NotFound() throws Exception { public void flushCache_NotFound() throws Exception {
adminSession adminRestSession
.post("/config/server/caches/nonExisting/flush") .post("/config/server/caches/nonExisting/flush")
.assertNotFound(); .assertNotFound();
} }
@Test @Test
public void flushCacheWithGerritPrefix() throws Exception { public void flushCacheWithGerritPrefix() throws Exception {
adminSession adminRestSession
.post("/config/server/caches/gerrit-accounts/flush") .post("/config/server/caches/gerrit-accounts/flush")
.assertOK(); .assertOK();
} }
@Test @Test
public void flushWebSessionsCache() throws Exception { public void flushWebSessionsCache() throws Exception {
adminSession adminRestSession
.post("/config/server/caches/web_sessions/flush") .post("/config/server/caches/web_sessions/flush")
.assertOK(); .assertOK();
} }
@@ -74,11 +74,11 @@ public class FlushCacheIT extends AbstractDaemonTest {
allowGlobalCapabilities(REGISTERED_USERS, allowGlobalCapabilities(REGISTERED_USERS,
GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES); GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES);
try { try {
RestResponse r = userSession.post("/config/server/caches/accounts/flush"); RestResponse r = userRestSession.post("/config/server/caches/accounts/flush");
r.assertOK(); r.assertOK();
r.consume(); r.consume();
userSession userRestSession
.post("/config/server/caches/web_sessions/flush") .post("/config/server/caches/web_sessions/flush")
.assertForbidden(); .assertForbidden();
} finally { } finally {

View File

@@ -27,7 +27,7 @@ public class GetCacheIT extends AbstractDaemonTest {
@Test @Test
public void getCache() throws Exception { public void getCache() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/accounts"); RestResponse r = adminRestSession.get("/config/server/caches/accounts");
r.assertOK(); r.assertOK();
CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class); CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class);
@@ -42,8 +42,8 @@ public class GetCacheIT extends AbstractDaemonTest {
assertThat(result.hitRatio.mem).isAtMost(100); assertThat(result.hitRatio.mem).isAtMost(100);
assertThat(result.hitRatio.disk).isNull(); assertThat(result.hitRatio.disk).isNull();
userSession.get("/config/server/version").consume(); userRestSession.get("/config/server/version").consume();
r = adminSession.get("/config/server/caches/accounts"); r = adminRestSession.get("/config/server/caches/accounts");
r.assertOK(); r.assertOK();
result = newGson().fromJson(r.getReader(), CacheInfo.class); result = newGson().fromJson(r.getReader(), CacheInfo.class);
assertThat(result.entries.mem).isEqualTo(2); assertThat(result.entries.mem).isEqualTo(2);
@@ -51,21 +51,21 @@ public class GetCacheIT extends AbstractDaemonTest {
@Test @Test
public void getCache_Forbidden() throws Exception { public void getCache_Forbidden() throws Exception {
userSession userRestSession
.get("/config/server/caches/accounts") .get("/config/server/caches/accounts")
.assertForbidden(); .assertForbidden();
} }
@Test @Test
public void getCache_NotFound() throws Exception { public void getCache_NotFound() throws Exception {
adminSession adminRestSession
.get("/config/server/caches/nonExisting") .get("/config/server/caches/nonExisting")
.assertNotFound(); .assertNotFound();
} }
@Test @Test
public void getCacheWithGerritPrefix() throws Exception { public void getCacheWithGerritPrefix() throws Exception {
adminSession adminRestSession
.get("/config/server/caches/gerrit-accounts") .get("/config/server/caches/gerrit-accounts")
.assertOK(); .assertOK();
} }

View File

@@ -30,7 +30,7 @@ public class GetTaskIT extends AbstractDaemonTest {
@Test @Test
public void getTask() throws Exception { public void getTask() throws Exception {
RestResponse r = RestResponse r =
adminSession.get("/config/server/tasks/" + getLogFileCompressorTaskId()); adminRestSession.get("/config/server/tasks/" + getLogFileCompressorTaskId());
r.assertOK(); r.assertOK();
TaskInfo info = TaskInfo info =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
@@ -43,13 +43,13 @@ public class GetTaskIT extends AbstractDaemonTest {
@Test @Test
public void getTask_NotFound() throws Exception { public void getTask_NotFound() throws Exception {
userSession userRestSession
.get("/config/server/tasks/" + getLogFileCompressorTaskId()) .get("/config/server/tasks/" + getLogFileCompressorTaskId())
.assertNotFound(); .assertNotFound();
} }
private String getLogFileCompressorTaskId() throws Exception { private String getLogFileCompressorTaskId() throws Exception {
RestResponse r = adminSession.get("/config/server/tasks/"); RestResponse r = adminRestSession.get("/config/server/tasks/");
List<TaskInfo> result = List<TaskInfo> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
new TypeToken<List<TaskInfo>>() {}.getType()); new TypeToken<List<TaskInfo>>() {}.getType());

View File

@@ -28,18 +28,18 @@ import java.util.List;
public class KillTaskIT extends AbstractDaemonTest { public class KillTaskIT extends AbstractDaemonTest {
private void killTask() throws Exception { private void killTask() throws Exception {
RestResponse r = adminSession.get("/config/server/tasks/"); RestResponse r = adminRestSession.get("/config/server/tasks/");
List<TaskInfo> result = newGson().fromJson(r.getReader(), List<TaskInfo> result = newGson().fromJson(r.getReader(),
new TypeToken<List<TaskInfo>>() {}.getType()); new TypeToken<List<TaskInfo>>() {}.getType());
r.consume(); r.consume();
int taskCount = result.size(); int taskCount = result.size();
assertThat(taskCount).isGreaterThan(0); assertThat(taskCount).isGreaterThan(0);
r = adminSession.delete("/config/server/tasks/" + result.get(0).id); r = adminRestSession.delete("/config/server/tasks/" + result.get(0).id);
r.assertNoContent(); r.assertNoContent();
r.consume(); r.consume();
r = adminSession.get("/config/server/tasks/"); r = adminRestSession.get("/config/server/tasks/");
result = newGson().fromJson(r.getReader(), result = newGson().fromJson(r.getReader(),
new TypeToken<List<TaskInfo>>() {}.getType()); new TypeToken<List<TaskInfo>>() {}.getType());
r.consume(); r.consume();
@@ -47,13 +47,13 @@ public class KillTaskIT extends AbstractDaemonTest {
} }
private void killTask_NotFound() throws Exception { private void killTask_NotFound() throws Exception {
RestResponse r = adminSession.get("/config/server/tasks/"); RestResponse r = adminRestSession.get("/config/server/tasks/");
List<TaskInfo> result = newGson().fromJson(r.getReader(), List<TaskInfo> result = newGson().fromJson(r.getReader(),
new TypeToken<List<TaskInfo>>() {}.getType()); new TypeToken<List<TaskInfo>>() {}.getType());
r.consume(); r.consume();
assertThat(result.size()).isGreaterThan(0); assertThat(result.size()).isGreaterThan(0);
userSession userRestSession
.delete("/config/server/tasks/" + result.get(0).id) .delete("/config/server/tasks/" + result.get(0).id)
.assertNotFound(); .assertNotFound();
} }

View File

@@ -35,7 +35,7 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test @Test
public void listCaches() throws Exception { public void listCaches() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/"); RestResponse r = adminRestSession.get("/config/server/caches/");
r.assertOK(); r.assertOK();
Map<String, CacheInfo> result = Map<String, CacheInfo> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
@@ -53,8 +53,8 @@ public class ListCachesIT extends AbstractDaemonTest {
assertThat(accountsCacheInfo.hitRatio.mem).isAtMost(100); assertThat(accountsCacheInfo.hitRatio.mem).isAtMost(100);
assertThat(accountsCacheInfo.hitRatio.disk).isNull(); assertThat(accountsCacheInfo.hitRatio.disk).isNull();
userSession.get("/config/server/version").consume(); userRestSession.get("/config/server/version").consume();
r = adminSession.get("/config/server/caches/"); r = adminRestSession.get("/config/server/caches/");
r.assertOK(); r.assertOK();
result = newGson().fromJson(r.getReader(), result = newGson().fromJson(r.getReader(),
new TypeToken<Map<String, CacheInfo>>() {}.getType()); new TypeToken<Map<String, CacheInfo>>() {}.getType());
@@ -63,14 +63,14 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test @Test
public void listCaches_Forbidden() throws Exception { public void listCaches_Forbidden() throws Exception {
userSession userRestSession
.get("/config/server/caches/") .get("/config/server/caches/")
.assertForbidden(); .assertForbidden();
} }
@Test @Test
public void listCacheNames() throws Exception { public void listCacheNames() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/?format=LIST"); RestResponse r = adminRestSession.get("/config/server/caches/?format=LIST");
r.assertOK(); r.assertOK();
List<String> result = List<String> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
@@ -82,7 +82,7 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test @Test
public void listCacheNamesTextList() throws Exception { public void listCacheNamesTextList() throws Exception {
RestResponse r = adminSession.get("/config/server/caches/?format=TEXT_LIST"); RestResponse r = adminRestSession.get("/config/server/caches/?format=TEXT_LIST");
r.assertOK(); r.assertOK();
String result = new String(Base64.decode(r.getEntityContent()), UTF_8.name()); String result = new String(Base64.decode(r.getEntityContent()), UTF_8.name());
List<String> list = Arrays.asList(result.split("\n")); List<String> list = Arrays.asList(result.split("\n"));
@@ -93,7 +93,7 @@ public class ListCachesIT extends AbstractDaemonTest {
@Test @Test
public void listCaches_BadRequest() throws Exception { public void listCaches_BadRequest() throws Exception {
adminSession adminRestSession
.get("/config/server/caches/?format=NONSENSE") .get("/config/server/caches/?format=NONSENSE")
.assertBadRequest(); .assertBadRequest();
} }

View File

@@ -29,7 +29,7 @@ public class ListTasksIT extends AbstractDaemonTest {
@Test @Test
public void listTasks() throws Exception { public void listTasks() throws Exception {
RestResponse r = adminSession.get("/config/server/tasks/"); RestResponse r = adminRestSession.get("/config/server/tasks/");
r.assertOK(); r.assertOK();
List<TaskInfo> result = List<TaskInfo> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),
@@ -50,7 +50,7 @@ public class ListTasksIT extends AbstractDaemonTest {
@Test @Test
public void listTasksWithoutViewQueueCapability() throws Exception { public void listTasksWithoutViewQueueCapability() throws Exception {
RestResponse r = userSession.get("/config/server/tasks/"); RestResponse r = userRestSession.get("/config/server/tasks/");
r.assertOK(); r.assertOK();
List<TaskInfo> result = List<TaskInfo> result =
newGson().fromJson(r.getReader(), newGson().fromJson(r.getReader(),

View File

@@ -73,7 +73,7 @@ public class ServerInfoIT extends AbstractDaemonTest {
@GerritConfig(name = "user.anonymousCoward", value = "Unnamed User"), @GerritConfig(name = "user.anonymousCoward", value = "Unnamed User"),
}) })
public void serverConfig() throws Exception { public void serverConfig() throws Exception {
RestResponse r = adminSession.get("/config/server/info/"); RestResponse r = adminRestSession.get("/config/server/info/");
ServerInfo i = newGson().fromJson(r.getReader(), ServerInfo.class); ServerInfo i = newGson().fromJson(r.getReader(), ServerInfo.class);
// auth // auth
@@ -129,9 +129,9 @@ public class ServerInfoIT extends AbstractDaemonTest {
Path plugins = tempSiteDir.newFolder("plugins").toPath(); Path plugins = tempSiteDir.newFolder("plugins").toPath();
Path jsplugin = plugins.resolve("js-plugin-1.js"); Path jsplugin = plugins.resolve("js-plugin-1.js");
Files.write(jsplugin, "Gerrit.install(function(self){});\n".getBytes(UTF_8)); Files.write(jsplugin, "Gerrit.install(function(self){});\n".getBytes(UTF_8));
sshSession.exec("gerrit plugin reload"); adminSshSession.exec("gerrit plugin reload");
RestResponse r = adminSession.get("/config/server/info/"); RestResponse r = adminRestSession.get("/config/server/info/");
ServerInfo i = newGson().fromJson(r.getReader(), ServerInfo.class); ServerInfo i = newGson().fromJson(r.getReader(), ServerInfo.class);
// plugin // plugin
@@ -140,7 +140,7 @@ public class ServerInfoIT extends AbstractDaemonTest {
@Test @Test
public void serverConfigWithDefaults() throws Exception { public void serverConfigWithDefaults() throws Exception {
RestResponse r = adminSession.get("/config/server/info/"); RestResponse r = adminRestSession.get("/config/server/info/");
ServerInfo i = newGson().fromJson(r.getReader(), ServerInfo.class); ServerInfo i = newGson().fromJson(r.getReader(), ServerInfo.class);
// auth // auth

View File

@@ -21,7 +21,7 @@ import org.junit.Test;
public class AddMemberIT extends AbstractDaemonTest { public class AddMemberIT extends AbstractDaemonTest {
@Test @Test
public void addNonExistingMember_NotFound() throws Exception { public void addNonExistingMember_NotFound() throws Exception {
adminSession adminRestSession
.put("/groups/Administrators/members/non-existing") .put("/groups/Administrators/members/non-existing")
.assertNotFound(); .assertNotFound();
} }

View File

@@ -37,7 +37,7 @@ public class BanCommitIT extends AbstractDaemonTest {
.create(); .create();
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/ban/", adminRestSession.put("/projects/" + project.get() + "/ban/",
BanCommit.Input.fromCommits(c.name())); BanCommit.Input.fromCommits(c.name()));
r.assertOK(); r.assertOK();
BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class); BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
@@ -55,11 +55,11 @@ public class BanCommitIT extends AbstractDaemonTest {
@Test @Test
public void banAlreadyBannedCommit() throws Exception { public void banAlreadyBannedCommit() throws Exception {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/ban/", adminRestSession.put("/projects/" + project.get() + "/ban/",
BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96")); BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"));
r.consume(); r.consume();
r = adminSession.put("/projects/" + project.get() + "/ban/", r = adminRestSession.put("/projects/" + project.get() + "/ban/",
BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96")); BanCommit.Input.fromCommits("a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"));
r.assertOK(); r.assertOK();
BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class); BanResultInfo info = newGson().fromJson(r.getReader(), BanResultInfo.class);
@@ -71,7 +71,7 @@ public class BanCommitIT extends AbstractDaemonTest {
@Test @Test
public void banCommit_Forbidden() throws Exception { public void banCommit_Forbidden() throws Exception {
userSession userRestSession
.put("/projects/" + project.get() + "/ban/", BanCommit.Input.fromCommits( .put("/projects/" + project.get() + "/ban/", BanCommit.Input.fromCommits(
"a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96")) "a8a477efffbbf3b44169bb9a1d3a334cbbd9aa96"))
.assertForbidden(); .assertForbidden();

View File

@@ -54,7 +54,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
@Test @Test
public void testCreateProjectHttp() throws Exception { public void testCreateProjectHttp() throws Exception {
String newProjectName = name("newProject"); String newProjectName = name("newProject");
RestResponse r = adminSession.put("/projects/" + newProjectName); RestResponse r = adminRestSession.put("/projects/" + newProjectName);
r.assertCreated(); r.assertCreated();
ProjectInfo p = newGson().fromJson(r.getReader(), ProjectInfo.class); ProjectInfo p = newGson().fromJson(r.getReader(), ProjectInfo.class);
assertThat(p.name).isEqualTo(newProjectName); assertThat(p.name).isEqualTo(newProjectName);
@@ -67,7 +67,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
@Test @Test
public void testCreateProjectHttpWhenProjectAlreadyExists_Conflict() public void testCreateProjectHttpWhenProjectAlreadyExists_Conflict()
throws Exception { throws Exception {
adminSession adminRestSession
.put("/projects/" + allProjects.get()) .put("/projects/" + allProjects.get())
.assertConflict(); .assertConflict();
} }
@@ -75,7 +75,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
@Test @Test
public void testCreateProjectHttpWhenProjectAlreadyExists_PreconditionFailed() public void testCreateProjectHttpWhenProjectAlreadyExists_PreconditionFailed()
throws Exception { throws Exception {
adminSession adminRestSession
.putWithHeader("/projects/" + allProjects.get(), .putWithHeader("/projects/" + allProjects.get(),
new BasicHeader(HttpHeaders.IF_NONE_MATCH, "*")) new BasicHeader(HttpHeaders.IF_NONE_MATCH, "*"))
.assertPreconditionFailed(); .assertPreconditionFailed();
@@ -85,7 +85,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
@UseLocalDisk @UseLocalDisk
public void testCreateProjectHttpWithUnreasonableName_BadRequest() public void testCreateProjectHttpWithUnreasonableName_BadRequest()
throws Exception { throws Exception {
adminSession adminRestSession
.put("/projects/" + Url.encode(name("invalid/../name"))) .put("/projects/" + Url.encode(name("invalid/../name")))
.assertBadRequest(); .assertBadRequest();
} }
@@ -94,7 +94,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
public void testCreateProjectHttpWithNameMismatch_BadRequest() throws Exception { public void testCreateProjectHttpWithNameMismatch_BadRequest() throws Exception {
ProjectInput in = new ProjectInput(); ProjectInput in = new ProjectInput();
in.name = name("otherName"); in.name = name("otherName");
adminSession adminRestSession
.put("/projects/" + name("someName"), in) .put("/projects/" + name("someName"), in)
.assertBadRequest(); .assertBadRequest();
} }
@@ -104,7 +104,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
throws Exception { throws Exception {
ProjectInput in = new ProjectInput(); ProjectInput in = new ProjectInput();
in.branches = Collections.singletonList(name("invalid ref name")); in.branches = Collections.singletonList(name("invalid ref name"));
adminSession adminRestSession
.put("/projects/" + name("newProject"), in) .put("/projects/" + name("newProject"), in)
.assertBadRequest(); .assertBadRequest();
} }

View File

@@ -43,7 +43,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
@Test @Test
public void testGcNotAllowed_Forbidden() throws Exception { public void testGcNotAllowed_Forbidden() throws Exception {
userSession userRestSession
.post("/projects/" + allProjects.get() + "/gc") .post("/projects/" + allProjects.get() + "/gc")
.assertForbidden(); .assertForbidden();
} }
@@ -57,7 +57,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
} }
private RestResponse POST(String endPoint) throws Exception { private RestResponse POST(String endPoint) throws Exception {
RestResponse r = adminSession.post(endPoint); RestResponse r = adminRestSession.post(endPoint);
r.consume(); r.consume();
return r; return r;
} }

View File

@@ -129,13 +129,13 @@ public class GetCommitIT extends AbstractDaemonTest {
} }
private void assertNotFound(ObjectId id) throws Exception { private void assertNotFound(ObjectId id) throws Exception {
userSession userRestSession
.get("/projects/" + project.get() + "/commits/" + id.name()) .get("/projects/" + project.get() + "/commits/" + id.name())
.assertNotFound(); .assertNotFound();
} }
private CommitInfo getCommit(ObjectId id) throws Exception { private CommitInfo getCommit(ObjectId id) throws Exception {
RestResponse r = userSession.get( RestResponse r = userRestSession.get(
"/projects/" + project.get() + "/commits/" + id.name()); "/projects/" + project.get() + "/commits/" + id.name());
r.assertOK(); r.assertOK();
CommitInfo result = newGson().fromJson(r.getReader(), CommitInfo.class); CommitInfo result = newGson().fromJson(r.getReader(), CommitInfo.class);

View File

@@ -29,7 +29,7 @@ public class SetParentIT extends AbstractDaemonTest {
public void setParent_Forbidden() throws Exception { public void setParent_Forbidden() throws Exception {
String parent = createProject("parent", null, true).get(); String parent = createProject("parent", null, true).get();
RestResponse r = RestResponse r =
userSession.put("/projects/" + project.get() + "/parent", userRestSession.put("/projects/" + project.get() + "/parent",
newParentInput(parent)); newParentInput(parent));
r.assertForbidden(); r.assertForbidden();
r.consume(); r.consume();
@@ -39,12 +39,12 @@ public class SetParentIT extends AbstractDaemonTest {
public void setParent() throws Exception { public void setParent() throws Exception {
String parent = createProject("parent", null, true).get(); String parent = createProject("parent", null, true).get();
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent", adminRestSession.put("/projects/" + project.get() + "/parent",
newParentInput(parent)); newParentInput(parent));
r.assertOK(); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/projects/" + project.get() + "/parent"); r = adminRestSession.get("/projects/" + project.get() + "/parent");
r.assertOK(); r.assertOK();
String newParent = String newParent =
newGson().fromJson(r.getReader(), String.class); newGson().fromJson(r.getReader(), String.class);
@@ -53,12 +53,12 @@ public class SetParentIT extends AbstractDaemonTest {
// When the parent name is not explicitly set, it should be // When the parent name is not explicitly set, it should be
// set to "All-Projects". // set to "All-Projects".
r = adminSession.put("/projects/" + project.get() + "/parent", r = adminRestSession.put("/projects/" + project.get() + "/parent",
newParentInput(null)); newParentInput(null));
r.assertOK(); r.assertOK();
r.consume(); r.consume();
r = adminSession.get("/projects/" + project.get() + "/parent"); r = adminRestSession.get("/projects/" + project.get() + "/parent");
r.assertOK(); r.assertOK();
newParent = newGson().fromJson(r.getReader(), String.class); newParent = newGson().fromJson(r.getReader(), String.class);
assertThat(newParent).isEqualTo(AllProjectsNameProvider.DEFAULT); assertThat(newParent).isEqualTo(AllProjectsNameProvider.DEFAULT);
@@ -68,7 +68,7 @@ public class SetParentIT extends AbstractDaemonTest {
@Test @Test
public void setParentForAllProjects_Conflict() throws Exception { public void setParentForAllProjects_Conflict() throws Exception {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + allProjects.get() + "/parent", adminRestSession.put("/projects/" + allProjects.get() + "/parent",
newParentInput(project.get())); newParentInput(project.get()));
r.assertConflict(); r.assertConflict();
r.consume(); r.consume();
@@ -77,19 +77,19 @@ public class SetParentIT extends AbstractDaemonTest {
@Test @Test
public void setInvalidParent_Conflict() throws Exception { public void setInvalidParent_Conflict() throws Exception {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent", adminRestSession.put("/projects/" + project.get() + "/parent",
newParentInput(project.get())); newParentInput(project.get()));
r.assertConflict(); r.assertConflict();
r.consume(); r.consume();
Project.NameKey child = createProject("child", project, true); Project.NameKey child = createProject("child", project, true);
r = adminSession.put("/projects/" + project.get() + "/parent", r = adminRestSession.put("/projects/" + project.get() + "/parent",
newParentInput(child.get())); newParentInput(child.get()));
r.assertConflict(); r.assertConflict();
r.consume(); r.consume();
String grandchild = createProject("grandchild", child, true).get(); String grandchild = createProject("grandchild", child, true).get();
r = adminSession.put("/projects/" + project.get() + "/parent", r = adminRestSession.put("/projects/" + project.get() + "/parent",
newParentInput(grandchild)); newParentInput(grandchild));
r.assertConflict(); r.assertConflict();
r.consume(); r.consume();
@@ -98,7 +98,7 @@ public class SetParentIT extends AbstractDaemonTest {
@Test @Test
public void setNonExistingParent_UnprocessibleEntity() throws Exception { public void setNonExistingParent_UnprocessibleEntity() throws Exception {
RestResponse r = RestResponse r =
adminSession.put("/projects/" + project.get() + "/parent", adminRestSession.put("/projects/" + project.get() + "/parent",
newParentInput("non-existing")); newParentInput("non-existing"));
r.assertUnprocessableEntity(); r.assertUnprocessableEntity();
r.consume(); r.consume();

View File

@@ -41,7 +41,7 @@ public class TagsIT extends AbstractDaemonTest {
@Test @Test
public void listTagsOfNonExistingProject() throws Exception { public void listTagsOfNonExistingProject() throws Exception {
adminSession adminRestSession
.get("/projects/non-existing/tags") .get("/projects/non-existing/tags")
.assertNotFound(); .assertNotFound();
} }
@@ -61,7 +61,7 @@ public class TagsIT extends AbstractDaemonTest {
@Test @Test
public void listTagsOfNonVisibleProject() throws Exception { public void listTagsOfNonVisibleProject() throws Exception {
blockRead("refs/*"); blockRead("refs/*");
userSession userRestSession
.get("/projects/" + project.get() + "/tags") .get("/projects/" + project.get() + "/tags")
.assertNotFound(); .assertNotFound();
} }

View File

@@ -654,7 +654,7 @@ public class GetRelatedIT extends AbstractDaemonTest {
throws Exception { throws Exception {
String url = String.format("/changes/%d/revisions/%d/related", String url = String.format("/changes/%d/revisions/%d/related",
changeId.get(), ps); changeId.get(), ps);
return newGson().fromJson(adminSession.get(url).getReader(), return newGson().fromJson(adminRestSession.get(url).getReader(),
RelatedInfo.class).changes; RelatedInfo.class).changes;
} }

View File

@@ -66,10 +66,10 @@ public class AbandonRestoreIT extends AbstractDaemonTest {
if (message != null) { if (message != null) {
command.append(" --message ").append(message); command.append(" --message ").append(message);
} }
String response = sshSession.exec(command.toString()); String response = adminSshSession.exec(command.toString());
assert_() assert_()
.withFailureMessage(sshSession.getError()) .withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()) .that(adminSshSession.hasError())
.isFalse(); .isFalse();
assertThat(response.toLowerCase(Locale.US)).doesNotContain("error"); assertThat(response.toLowerCase(Locale.US)).doesNotContain("error");
} }

View File

@@ -38,9 +38,9 @@ public class BanCommitIT extends AbstractDaemonTest {
.create(); .create();
String response = String response =
sshSession.exec("gerrit ban-commit " + project.get() + " " + c.name()); adminSshSession.exec("gerrit ban-commit " + project.get() + " " + c.name());
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isFalse(); .that(adminSshSession.hasError()).isFalse();
assertThat(response.toLowerCase(Locale.US)).doesNotContain("error"); assertThat(response.toLowerCase(Locale.US)).doesNotContain("error");
RemoteRefUpdate u = pushHead(testRepo, "refs/heads/master", false) RemoteRefUpdate u = pushHead(testRepo, "refs/heads/master", false)

View File

@@ -28,10 +28,10 @@ public class CreateGroupIT extends AbstractDaemonTest {
public void withDuplicateInternalGroupCaseSensitiveName_Conflict() public void withDuplicateInternalGroupCaseSensitiveName_Conflict()
throws Exception { throws Exception {
String newGroupName = "dupGroupA"; String newGroupName = "dupGroupA";
adminSession.put("/groups/" + newGroupName); adminRestSession.put("/groups/" + newGroupName);
sshSession.exec("gerrit create-group " + newGroupName); adminSshSession.exec("gerrit create-group " + newGroupName);
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isTrue(); .that(adminSshSession.hasError()).isTrue();
} }
@Test @Test
@@ -40,10 +40,10 @@ public class CreateGroupIT extends AbstractDaemonTest {
String newGroupName = "dupGroupB"; String newGroupName = "dupGroupB";
String newGroupNameLowerCase = newGroupName.toLowerCase(); String newGroupNameLowerCase = newGroupName.toLowerCase();
adminSession.put("/groups/" + newGroupName); adminRestSession.put("/groups/" + newGroupName);
sshSession.exec("gerrit create-group " + newGroupNameLowerCase); adminSshSession.exec("gerrit create-group " + newGroupNameLowerCase);
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isFalse(); .that(adminSshSession.hasError()).isFalse();
assertThat(groupCache.get(new AccountGroup.NameKey(newGroupName))) assertThat(groupCache.get(new AccountGroup.NameKey(newGroupName)))
.isNotNull(); .isNotNull();
assertThat(groupCache.get(new AccountGroup.NameKey(newGroupNameLowerCase))) assertThat(groupCache.get(new AccountGroup.NameKey(newGroupNameLowerCase)))
@@ -54,26 +54,26 @@ public class CreateGroupIT extends AbstractDaemonTest {
public void withDuplicateSystemGroupCaseSensitiveName_Conflict() public void withDuplicateSystemGroupCaseSensitiveName_Conflict()
throws Exception { throws Exception {
String newGroupName = "Registered Users"; String newGroupName = "Registered Users";
sshSession.exec("gerrit create-group " + newGroupName); adminSshSession.exec("gerrit create-group " + newGroupName);
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isTrue(); .that(adminSshSession.hasError()).isTrue();
} }
@Test @Test
public void withDuplicateSystemGroupCaseInsensitiveName_Conflict() public void withDuplicateSystemGroupCaseInsensitiveName_Conflict()
throws Exception { throws Exception {
String newGroupName = "Registered Users"; String newGroupName = "Registered Users";
sshSession.exec("gerrit create-group " + newGroupName); adminSshSession.exec("gerrit create-group " + newGroupName);
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isTrue(); .that(adminSshSession.hasError()).isTrue();
} }
@Test @Test
public void withNonDuplicateGroupName() throws Exception { public void withNonDuplicateGroupName() throws Exception {
String newGroupName = "newGroupB"; String newGroupName = "newGroupB";
sshSession.exec("gerrit create-group " + newGroupName); adminSshSession.exec("gerrit create-group " + newGroupName);
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isFalse(); .that(adminSshSession.hasError()).isFalse();
AccountGroup accountGroup = AccountGroup accountGroup =
groupCache.get(new AccountGroup.NameKey(newGroupName)); groupCache.get(new AccountGroup.NameKey(newGroupName));
assertThat(accountGroup).isNotNull(); assertThat(accountGroup).isNotNull();

View File

@@ -28,12 +28,12 @@ public class CreateProjectIT extends AbstractDaemonTest {
@Test @Test
public void withValidGroupName() throws Exception { public void withValidGroupName() throws Exception {
String newGroupName = "newGroup"; String newGroupName = "newGroup";
adminSession.put("/groups/" + newGroupName); adminRestSession.put("/groups/" + newGroupName);
String newProjectName = "newProject"; String newProjectName = "newProject";
sshSession.exec("gerrit create-project --branch master --owner " adminSshSession.exec("gerrit create-project --branch master --owner "
+ newGroupName + " " + newProjectName); + newGroupName + " " + newProjectName);
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isFalse(); .that(adminSshSession.hasError()).isFalse();
ProjectState projectState = ProjectState projectState =
projectCache.get(new Project.NameKey(newProjectName)); projectCache.get(new Project.NameKey(newProjectName));
assertThat(projectState).isNotNull(); assertThat(projectState).isNotNull();
@@ -42,13 +42,13 @@ public class CreateProjectIT extends AbstractDaemonTest {
@Test @Test
public void withInvalidGroupName() throws Exception { public void withInvalidGroupName() throws Exception {
String newGroupName = "newGroup"; String newGroupName = "newGroup";
adminSession.put("/groups/" + newGroupName); adminRestSession.put("/groups/" + newGroupName);
String wrongGroupName = "newG"; String wrongGroupName = "newG";
String newProjectName = "newProject"; String newProjectName = "newProject";
sshSession.exec("gerrit create-project --branch master --owner " adminSshSession.exec("gerrit create-project --branch master --owner "
+ wrongGroupName + " " + newProjectName); + wrongGroupName + " " + newProjectName);
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isTrue(); .that(adminSshSession.hasError()).isTrue();
ProjectState projectState = ProjectState projectState =
projectCache.get(new Project.NameKey(newProjectName)); projectCache.get(new Project.NameKey(newProjectName));
assertThat(projectState).isNull(); assertThat(projectState).isNull();

View File

@@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assert_;
import com.google.gerrit.acceptance.AbstractDaemonTest; import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.GcAssert; import com.google.gerrit.acceptance.GcAssert;
import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.acceptance.SshSession;
import com.google.gerrit.acceptance.UseLocalDisk; import com.google.gerrit.acceptance.UseLocalDisk;
import com.google.gerrit.common.data.GarbageCollectionResult; import com.google.gerrit.common.data.GarbageCollectionResult;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
@@ -59,10 +58,10 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
@UseLocalDisk @UseLocalDisk
public void testGc() throws Exception { public void testGc() throws Exception {
String response = String response =
sshSession.exec("gerrit gc \"" + project.get() + "\" \"" adminSshSession.exec("gerrit gc \"" + project.get() + "\" \""
+ project2.get() + "\""); + project2.get() + "\"");
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isFalse(); .that(adminSshSession.hasError()).isFalse();
assertNoError(response); assertNoError(response);
gcAssert.assertHasPackFile(project, project2); gcAssert.assertHasPackFile(project, project2);
gcAssert.assertHasNoPackFile(allProjects, project3); gcAssert.assertHasNoPackFile(allProjects, project3);
@@ -71,23 +70,21 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
@Test @Test
@UseLocalDisk @UseLocalDisk
public void testGcAll() throws Exception { public void testGcAll() throws Exception {
String response = sshSession.exec("gerrit gc --all"); String response = adminSshSession.exec("gerrit gc --all");
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isFalse(); .that(adminSshSession.hasError()).isFalse();
assertNoError(response); assertNoError(response);
gcAssert.assertHasPackFile(allProjects, project, project2, project3); gcAssert.assertHasPackFile(allProjects, project, project2, project3);
} }
@Test @Test
public void testGcWithoutCapability_Error() throws Exception { public void testGcWithoutCapability_Error() throws Exception {
SshSession s = new SshSession(server, user); userSshSession.exec("gerrit gc --all");
s.exec("gerrit gc --all"); assertThat(userSshSession.hasError()).isTrue();
assertThat(s.hasError()).isTrue(); String error = userSshSession.getError();
String error = s.getError();
assertThat(error).isNotNull(); assertThat(error).isNotNull();
assertError("One of the following capabilities is required to access this" assertError("One of the following capabilities is required to access this"
+ " resource: [runGC, maintainServer]", error); + " resource: [runGC, maintainServer]", error);
s.close();
} }
@Test @Test

View File

@@ -150,9 +150,9 @@ public class QueryIT extends AbstractDaemonTest {
public void shouldFailWithFilesWithoutPatchSetsOrCurrentPatchSetsOption() public void shouldFailWithFilesWithoutPatchSetsOrCurrentPatchSetsOption()
throws Exception { throws Exception {
String changeId = createChange().getChangeId(); String changeId = createChange().getChangeId();
sshSession.exec("gerrit query --files " + changeId); adminSshSession.exec("gerrit query --files " + changeId);
assertThat(sshSession.hasError()).isTrue(); assertThat(adminSshSession.hasError()).isTrue();
assertThat(sshSession.getError()).contains( assertThat(adminSshSession.getError()).contains(
"needs --patch-sets or --current-patch-set"); "needs --patch-sets or --current-patch-set");
} }
@@ -303,9 +303,9 @@ public class QueryIT extends AbstractDaemonTest {
private List<ChangeAttribute> executeSuccessfulQuery(String params) private List<ChangeAttribute> executeSuccessfulQuery(String params)
throws Exception { throws Exception {
String rawResponse = String rawResponse =
sshSession.exec("gerrit query --format=JSON " + params); adminSshSession.exec("gerrit query --format=JSON " + params);
assert_().withFailureMessage(sshSession.getError()) assert_().withFailureMessage(adminSshSession.getError())
.that(sshSession.hasError()).isFalse(); .that(adminSshSession.hasError()).isFalse();
return getChanges(rawResponse); return getChanges(rawResponse);
} }

View File

@@ -58,7 +58,7 @@ public class UploadArchiveIT extends AbstractDaemonTest {
String c = command(r, abbreviated); String c = command(r, abbreviated);
InputStream out = InputStream out =
sshSession.exec2("git-upload-archive " + project.get(), adminSshSession.exec2("git-upload-archive " + project.get(),
argumentsToInputStream(c)); argumentsToInputStream(c));
// Wrap with PacketLineIn to read ACK bytes from output stream // Wrap with PacketLineIn to read ACK bytes from output stream
@@ -101,7 +101,7 @@ public class UploadArchiveIT extends AbstractDaemonTest {
String c = command(r, abbreviated); String c = command(r, abbreviated);
InputStream out = InputStream out =
sshSession.exec2("git-upload-archive " + project.get(), adminSshSession.exec2("git-upload-archive " + project.get(),
argumentsToInputStream(c)); argumentsToInputStream(c));
// Wrap with PacketLineIn to read ACK bytes from output stream // Wrap with PacketLineIn to read ACK bytes from output stream