AbstractDaemonTest: Allow changing GerritApi user

Change-Id: I82e0a459a6fc80fab3bbb595abcec5777c744b59
This commit is contained in:
Dave Borowitz
2014-06-17 17:37:26 -07:00
parent 5e4cae535b
commit 1c471044a6
2 changed files with 22 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
import com.google.common.base.Joiner;
import com.google.common.primitives.Chars;
import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context;
import com.google.gerrit.extensions.api.GerritApi;
import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.common.ChangeInfo;
@@ -128,9 +129,9 @@ public abstract class AbstractDaemonTest {
userSession = new RestSession(server, user);
initSsh(admin);
db = reviewDbProvider.open();
atrScope.set(atrScope.newContext(reviewDbProvider, sshSession,
identifiedUserFactory.create(Providers.of(db), admin.getId())));
sshSession = new SshSession(server, admin);
Context ctx = newRequestContext(admin);
atrScope.set(ctx);
sshSession = ctx.getSession();
project = new Project.NameKey("p");
createProject(sshSession, project.get());
git = cloneProject(sshSession.getUrl() + "/" + project.get());
@@ -198,6 +199,15 @@ public abstract class AbstractDaemonTest {
return gApi.changes().query(q).get();
}
private Context newRequestContext(TestAccount account) {
return atrScope.newContext(reviewDbProvider, new SshSession(server, admin),
identifiedUserFactory.create(Providers.of(db), account.getId()));
}
protected Context setApiUser(TestAccount account) {
return atrScope.set(newRequestContext(account));
}
protected static Gson newGson() {
return OutputFormat.JSON_COMPACT.newGson();
}

View File

@@ -253,4 +253,13 @@ public class ChangeIT extends AbstractDaemonTest {
assertEquals(r.getPatchSetId().get(), rev._number);
assertFalse(rev.actions.isEmpty());
}
@Test
public void queryChangesOwnerWithDifferentUsers() throws Exception {
PushOneCommit.Result r = createChange();
assertEquals(r.getChangeId(),
Iterables.getOnlyElement(query("owner:self")).changeId);
setApiUser(user);
assertTrue(query("owner:self").isEmpty());
}
}