use of com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method beforeTest.
protected void beforeTest(Description description) throws Exception {
// SystemReader must be overridden before creating any repos, since they read the user/system
// configs at initialization time, and are then stored in the RepositoryCache forever.
oldSystemReader = setFakeSystemReader(temporaryFolder.getRoot());
this.description = description;
GerritServer.Description classDesc = GerritServer.Description.forTestClass(description, configName);
GerritServer.Description methodDesc = GerritServer.Description.forTestMethod(description, configName);
testMethodDescription = methodDesc;
testRequiresSsh = classDesc.useSshAnnotation() || methodDesc.useSshAnnotation();
if (!testRequiresSsh) {
baseConfig.setString("sshd", null, "listenAddress", "off");
}
baseConfig.unset("gerrit", null, "canonicalWebUrl");
baseConfig.unset("httpd", null, "listenUrl");
baseConfig.setInt("index", null, "batchThreads", -1);
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
Module module = createModule();
Module auditModule = createAuditModule();
Module sshModule = createSshModule();
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() && !methodDesc.sandboxed()) {
if (commonServer == null) {
commonServer = GerritServer.initAndStart(temporaryFolder, classDesc, baseConfig, module, auditModule, sshModule);
}
server = commonServer;
} else {
server = GerritServer.initAndStart(temporaryFolder, methodDesc, baseConfig, module, auditModule, sshModule);
}
server.getTestInjector().injectMembers(this);
Transport.register(inProcessProtocol);
toClose = Collections.synchronizedList(new ArrayList<>());
admin = accountCreator.admin();
user = accountCreator.user1();
// Evict and reindex accounts in case tests modify them.
reindexAccount(admin.id());
reindexAccount(user.id());
adminRestSession = new RestSession(server, admin);
userRestSession = new RestSession(server, user);
anonymousRestSession = new RestSession(server, null);
initSsh();
resourcePrefix = UNSAFE_PROJECT_NAME.matcher(description.getClassName() + "_" + description.getMethodName() + "_").replaceAll("");
Context ctx = newRequestContext(admin);
atrScope.set(ctx);
ProjectInput in = projectInput(description);
gApi.projects().create(in);
project = Project.nameKey(in.name);
if (!classDesc.skipProjectClone()) {
testRepo = cloneProject(project, getCloneAsAccount(description));
}
// Set the clock step last, so that the test setup isn't consuming any timestamps after the
// clock has been set.
setTimeSettings(classDesc.useSystemTime(), classDesc.useClockStep(), classDesc.useTimezone());
setTimeSettings(methodDesc.useSystemTime(), methodDesc.useClockStep(), methodDesc.useTimezone());
}
use of com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method initSsh.
protected void initSsh() throws Exception {
if (testRequiresSsh && SshMode.useSsh() && (adminSshSession == null || userSshSession == null)) {
// Create Ssh sessions
SshSessionFactory.initSsh();
Context ctx = newRequestContext(user);
atrScope.set(ctx);
userSshSession = ctx.getSession();
userSshSession.open();
ctx = newRequestContext(admin);
atrScope.set(ctx);
adminSshSession = ctx.getSession();
adminSshSession.open();
}
}
use of com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context in project gerrit by GerritCodeReview.
the class EmailIT method setPreferredEmailToEmailFromCustomRealmThatDoesntExistAsExternalId.
@Test
public void setPreferredEmailToEmailFromCustomRealmThatDoesntExistAsExternalId() throws Exception {
String email = "foo@example.com";
ExternalId.Key mailtoExtIdKey = externalIdKeyFactory.create(ExternalId.SCHEME_MAILTO, email);
assertThat(externalIds.get(mailtoExtIdKey)).isEmpty();
assertThat(gApi.accounts().self().get().email).isNotEqualTo(email);
Context oldCtx = createContextWithCustomRealm(new RealmWithAdditionalEmails(admin.id(), email));
try {
gApi.accounts().self().email(email).setPreferred();
Optional<ExternalId> mailtoExtId = externalIds.get(mailtoExtIdKey);
assertThat(mailtoExtId).isPresent();
assertThat(mailtoExtId.get().accountId()).isEqualTo(admin.id());
assertThat(gApi.accounts().self().get().email).isEqualTo(email);
} finally {
atrScope.set(oldCtx);
}
}
use of com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method disableNoteDb.
protected AutoCloseable disableNoteDb() {
changeNotesArgs.failOnLoadForTest.set(true);
Context oldContext = atrScope.disableNoteDb();
return () -> {
changeNotesArgs.failOnLoadForTest.set(false);
atrScope.set(oldContext);
};
}
use of com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context in project gerrit by GerritCodeReview.
the class EmailIT method setPreferredEmailToEmailFromCustomRealmThatBelongsToOtherAccount.
@Test
public void setPreferredEmailToEmailFromCustomRealmThatBelongsToOtherAccount() throws Exception {
ExternalId mailToExtId = externalIdFactory.createEmail(user.id(), user.email());
assertThat(externalIds.get(mailToExtId.key())).isPresent();
Context oldCtx = createContextWithCustomRealm(new RealmWithAdditionalEmails(admin.id(), user.email()));
try {
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.accounts().self().email(user.email()).setPreferred());
assertThat(thrown).hasMessageThat().contains("email in use by another account");
} finally {
atrScope.set(oldCtx);
}
}
Aggregations