Allow dynamic url creation in tests
Some tests require to create a repository with a non-default project name.
Change-Id: I8700ca053578a164635daa404de67bac3be3c902
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java
index 94e7fd5..14f8dfb 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java
@@ -81,7 +81,7 @@
SourceHttpClient.Factory httpClientFactory;
String url;
- protected abstract String getURL();
+ protected abstract String getURL(String projectName);
@Override
public void setUpTestPlugin() throws Exception {
@@ -107,7 +107,7 @@
revisionReader = plugin.getSysInjector().getInstance(RevisionReader.class);
source = plugin.getSysInjector().getInstance(SourcesCollection.class).getAll().get(0);
- url = getURL();
+ url = getURL(project.get());
}
protected HttpPost createRequest(String sendObjectPayload) {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectActionIT.java
index ec172ad..aad3903 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectActionIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectActionIT.java
@@ -176,9 +176,9 @@
}
@Override
- protected String getURL() {
+ protected String getURL(String projectName) {
return String.format(
"%s/a/projects/%s/pull-replication~apply-object",
- adminRestSession.url(), Url.encode(project.get()));
+ adminRestSession.url(), Url.encode(projectName));
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java
index 7b73df7..4ad8ce6 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java
@@ -76,9 +76,8 @@
}
@Override
- protected String getURL() {
+ protected String getURL(String projectName) {
return String.format(
- "%s/a/projects/%s/pull-replication~fetch",
- adminRestSession.url(), Url.encode(project.get()));
+ "%s/a/projects/%s/pull-replication~fetch", adminRestSession.url(), Url.encode(projectName));
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationActionIT.java
index 919ac34..4035fb8 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationActionIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationActionIT.java
@@ -27,7 +27,6 @@
public class ProjectInitializationActionIT extends ActionITBase {
public static final String INVALID_TEST_PROJECT_NAME = "\0";
- private String testProjectName = "new/Project";
@Test
public void shouldReturnUnauthorizedForUserWithoutPermissions() throws Exception {
@@ -51,6 +50,8 @@
@Test
public void shouldCreateRepository() throws Exception {
+ String newProjectName = "new/newProjectForPrimary";
+ url = getURL(newProjectName);
httpClientFactory
.create(source)
.execute(
@@ -59,7 +60,7 @@
getContext());
HttpGet getNewProjectRequest =
- new HttpGet(userRestSession.url() + "/a/projects/" + Url.encode("new/Project"));
+ new HttpGet(userRestSession.url() + "/a/projects/" + Url.encode(newProjectName));
httpClientFactory
.create(source)
.execute(
@@ -69,6 +70,8 @@
@Test
@GerritConfig(name = "container.replica", value = "true")
public void shouldCreateRepositoryWhenNodeIsAReplica() throws Exception {
+ String newProjectName = "new/newProjectForReplica";
+ url = getURL(newProjectName);
httpClientFactory
.create(source)
.execute(
@@ -81,8 +84,7 @@
@GerritConfig(name = "container.replica", value = "true")
public void shouldReturnInternalServerErrorIfProjectCannotBeCreatedWhenNodeIsAReplica()
throws Exception {
- testProjectName = INVALID_TEST_PROJECT_NAME;
- url = getURL();
+ url = getURL(INVALID_TEST_PROJECT_NAME);
httpClientFactory
.create(source)
@@ -116,10 +118,10 @@
}
@Override
- protected String getURL() {
+ protected String getURL(String projectName) {
return userRestSession.url()
+ "/"
- + getProjectInitializationUrl("pull-replication", Url.encode(testProjectName));
+ + getProjectInitializationUrl("pull-replication", Url.encode(projectName));
}
protected HttpPut createPutRequestWithHeaders() {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/UpdateHeadActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/UpdateHeadActionIT.java
index 18e002d..aa07a7c 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/UpdateHeadActionIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/UpdateHeadActionIT.java
@@ -161,7 +161,7 @@
}
@Override
- protected String getURL() {
- return String.format("%s/a/projects/%s/HEAD", adminRestSession.url(), project.get());
+ protected String getURL(String projectName) {
+ return String.format("%s/a/projects/%s/HEAD", adminRestSession.url(), projectName);
}
}