Add integration test for new project creation The integration test suite had the use-case of removing a project but not the one for creating one. Because the integration test is still half-broken, due to the lack of the 2nd replication endpoint, rely on the direct instantiation of a FetchApiClient which would have been invoked if the remote end had notified the creation of a project. This half-integration test still verifies one of the two ends of creating a project which would highlight potential issues. Change-Id: I39b6d7837b63856e8c555b7b9b392feee72838af
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationIT.java index 5d4aeb4..4c00bae 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationIT.java
@@ -26,6 +26,7 @@ import com.google.gerrit.acceptance.UseLocalDisk; import com.google.gerrit.acceptance.config.GerritConfig; import com.google.gerrit.entities.Permission; +import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project.NameKey; import com.google.gerrit.entities.RefNames; import com.google.gerrit.extensions.api.changes.NotifyHandling; @@ -34,6 +35,7 @@ import com.google.gerrit.extensions.events.ProjectDeletedListener; import com.google.gerrit.extensions.restapi.RestApiException; import com.googlesource.gerrit.plugins.replication.AutoReloadConfigDecorator; +import com.googlesource.gerrit.plugins.replication.pull.client.FetchApiClient; import java.io.IOException; import java.util.Collection; import java.util.Collections; @@ -48,6 +50,7 @@ import org.eclipse.jgit.transport.PushResult; import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.RemoteRefUpdate.Status; +import org.eclipse.jgit.transport.URIish; import org.junit.Ignore; import org.junit.Test; @@ -293,6 +296,25 @@ @Test @GerritConfig(name = "gerrit.instanceId", value = TEST_REPLICATION_REMOTE) + public void shouldCreateNewProject() throws Exception { + NameKey projectToCreate = Project.nameKey(project.get() + "_created"); + + setReplicationSource(TEST_REPLICATION_REMOTE, "", Optional.of(projectToCreate.get())); + config.save(); + AutoReloadConfigDecorator autoReloadConfigDecorator = + getInstance(AutoReloadConfigDecorator.class); + autoReloadConfigDecorator.reload(); + Source source = + getInstance(SourcesCollection.class).getByRemoteName(TEST_REPLICATION_REMOTE).get(); + + FetchApiClient client = getInstance(FetchApiClient.Factory.class).create(source); + client.initProject(projectToCreate, new URIish(source.getApis().get(0))); + + waitUntil(() -> repoManager.list().contains(projectToCreate)); + } + + @Test + @GerritConfig(name = "gerrit.instanceId", value = TEST_REPLICATION_REMOTE) public void shouldReplicateProjectDeletion() throws Exception { String projectToDelete = project.get(); setReplicationSource(TEST_REPLICATION_REMOTE, "", Optional.of(projectToDelete));