diff options
author | Christian Halstrick | 2015-02-18 09:19:14 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-02-18 09:19:17 +0000 |
commit | d93dd63d247f0d80de7dabef06a0a05e52a1f2b8 (patch) | |
tree | 70e2238ec06b670abcd6ee303aaf5f5d229f6e02 /org.eclipse.egit.core.test | |
parent | 067b019413d5dfa6fa2e322f70ee1bc2aa33da9c (diff) | |
parent | a5e5cef0629aa6752854ed272aa7d3b613d6b91b (diff) | |
download | egit-d93dd63d247f0d80de7dabef06a0a05e52a1f2b8.tar.gz egit-d93dd63d247f0d80de7dabef06a0a05e52a1f2b8.tar.xz egit-d93dd63d247f0d80de7dabef06a0a05e52a1f2b8.zip |
Merge "Consider different users and repo suffixes in project importer"
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r-- | org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java new file mode 100644 index 0000000000..cba88e6efa --- /dev/null +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (C) 2015, Christian Georgi (SAP SE) + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.core.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; + +import org.eclipse.egit.core.Activator; +import org.eclipse.egit.core.RepositoryUtil; +import org.eclipse.egit.core.test.GitTestCase; +import org.eclipse.egit.core.test.TestRepository; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.transport.URIish; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests {@link ProjectReferenceImporter} + */ +public class ProjectReferenceImporterTest extends GitTestCase { + + private TestRepository testRepository; + + private Repository repository; + + @Before + public void setUp() throws Exception { + super.setUp(); + testRepository = new TestRepository(gitDir); + repository = testRepository.getRepository(); + RepositoryUtil util = Activator.getDefault().getRepositoryUtil(); + util.addConfiguredRepository(repository.getDirectory()); + } + + @After + public void tearDown() throws Exception { + RepositoryUtil util = Activator.getDefault().getRepositoryUtil(); + util.removeDir(repository.getDirectory()); + testRepository.dispose(); + repository = null; + super.tearDown(); + } + + @Test + public void findRepository_SameURLs() throws Exception { + addRemote(repository, "origin", uri("ssh://user@host.com:42/repo")); + + File foundRepo = ProjectReferenceImporter + .findConfiguredRepository(uri("ssh://user@host.com:42/repo")); + assertEquals(repository.getDirectory(), foundRepo); + } + + @Test + public void findRepository_MultipleRemotes() throws Exception { + addRemote(repository, "remote_1", uri("ssh://user@host.com:42/repo")); + addRemote(repository, "remote_2", uri("http://host.com/other/repo")); + + File foundRepo = ProjectReferenceImporter + .findConfiguredRepository(uri("ssh://user@host.com:42/repo")); + assertEquals(repository.getDirectory(), foundRepo); + } + + @Test + public void findRepository_DifferentUsers() throws Exception { + addRemote(repository, "origin", uri("ssh://user_1@host.com:42/repo")); + + File foundRepo = ProjectReferenceImporter + .findConfiguredRepository(uri("ssh://user_2@host.com:42/repo")); + assertEquals(repository.getDirectory(), foundRepo); + + foundRepo = ProjectReferenceImporter + .findConfiguredRepository(uri("ssh://host.com:42/repo")); + assertEquals(repository.getDirectory(), foundRepo); + } + + @Test + public void findRepository_DifferentUsersAndRepoSuffixes() throws Exception { + addRemote(repository, "origin", uri("ssh://user_1@host.com:42/repo")); + + File foundRepo = ProjectReferenceImporter + .findConfiguredRepository(uri("ssh://user_2@host.com:42/repo.git")); + assertEquals(repository.getDirectory(), foundRepo); + } + + @Test + public void findRepository_DifferentRepos() throws Exception { + addRemote(repository, "origin", uri("ssh://host.com:42/repo_1")); + + File foundRepo = ProjectReferenceImporter + .findConfiguredRepository(uri("ssh://host.com:42/repo_2")); + assertNotEquals(repository.getDirectory(), foundRepo); + } + + private static void addRemote(Repository repository, String name, URIish url) + throws IOException { + StoredConfig config = repository.getConfig(); + config.setString("remote", name, "url", url.toString()); + config.save(); + } + + private static URIish uri(String s) throws URISyntaxException { + return new URIish(s); + } + +} |