Merge "Add support for custom Guice modules in tests"
This commit is contained in:
@@ -129,6 +129,7 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.gwtorm.server.SchemaFactory;
|
import com.google.gwtorm.server.SchemaFactory;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.jcraft.jsch.JSchException;
|
import com.jcraft.jsch.JSchException;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -394,13 +395,14 @@ public abstract class AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
|
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
|
||||||
|
Module module = createModule();
|
||||||
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() && !methodDesc.sandboxed()) {
|
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() && !methodDesc.sandboxed()) {
|
||||||
if (commonServer == null) {
|
if (commonServer == null) {
|
||||||
commonServer = GerritServer.initAndStart(classDesc, baseConfig);
|
commonServer = GerritServer.initAndStart(classDesc, baseConfig, module);
|
||||||
}
|
}
|
||||||
server = commonServer;
|
server = commonServer;
|
||||||
} else {
|
} else {
|
||||||
server = GerritServer.initAndStart(methodDesc, baseConfig);
|
server = GerritServer.initAndStart(methodDesc, baseConfig, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
server.getTestInjector().injectMembers(this);
|
server.getTestInjector().injectMembers(this);
|
||||||
@@ -443,6 +445,11 @@ public abstract class AbstractDaemonTest {
|
|||||||
testRepo = cloneProject(project, getCloneAsAccount(description));
|
testRepo = cloneProject(project, getCloneAsAccount(description));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Override to bind an additional Guice module */
|
||||||
|
public Module createModule() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected void initSsh() throws JSchException {
|
protected void initSsh() throws JSchException {
|
||||||
if (testRequiresSsh
|
if (testRequiresSsh
|
||||||
&& SshMode.useSsh()
|
&& SshMode.useSsh()
|
||||||
|
@@ -252,10 +252,12 @@ public class GerritServer implements AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @param desc server description.
|
* @param desc server description.
|
||||||
* @param baseConfig default config values; merged with config from {@code desc}.
|
* @param baseConfig default config values; merged with config from {@code desc}.
|
||||||
|
* @param testSysModule additional Guice module to use.
|
||||||
* @return started server.
|
* @return started server.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static GerritServer initAndStart(Description desc, Config baseConfig) throws Exception {
|
public static GerritServer initAndStart(
|
||||||
|
Description desc, Config baseConfig, @Nullable Module testSysModule) throws Exception {
|
||||||
Path site = TempFileUtil.createTempDirectory().toPath();
|
Path site = TempFileUtil.createTempDirectory().toPath();
|
||||||
baseConfig = new Config(baseConfig);
|
baseConfig = new Config(baseConfig);
|
||||||
baseConfig.setString("gerrit", null, "basePath", site.resolve("git").toString());
|
baseConfig.setString("gerrit", null, "basePath", site.resolve("git").toString());
|
||||||
@@ -264,7 +266,7 @@ public class GerritServer implements AutoCloseable {
|
|||||||
if (!desc.memory()) {
|
if (!desc.memory()) {
|
||||||
init(desc, baseConfig, site);
|
init(desc, baseConfig, site);
|
||||||
}
|
}
|
||||||
return start(desc, baseConfig, site, null, null, null);
|
return start(desc, baseConfig, site, testSysModule, null, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TempFileUtil.recursivelyDelete(site.toFile());
|
TempFileUtil.recursivelyDelete(site.toFile());
|
||||||
throw e;
|
throw e;
|
||||||
|
Reference in New Issue
Block a user