From a5e5cef0629aa6752854ed272aa7d3b613d6b91b Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Tue, 10 Feb 2015 15:01:20 +0100 Subject: Consider different users and repo suffixes in project importer Two URLs differing in users *and* repo suffixes (.git) should be treated the same. This was not handled properly with the last fix for bug 453892. In addition there is now also test cases for the relevant parts of ProjectReferenceImporter. Bug: 459551 Change-Id: I5308d089996cfc1be3a13120ef50e6cf23c5cf42 Signed-off-by: Christian Georgi --- .../internal/ProjectReferenceImporterTest.java | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java (limited to 'org.eclipse.egit.core.test') 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); + } + +} -- cgit v1.2.3