Merge branch 'Indore-2017.1.x'
[teamcity/git-plugin.git] / git-tests / src / jetbrains / buildServer / buildTriggers / vcs / git / tests / WellKnownHostingsTest.java
1 /*
2  * Copyright 2000-2017 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package jetbrains.buildServer.buildTriggers.vcs.git.tests;
18
19 import jetbrains.buildServer.BaseTestCase;
20 import jetbrains.buildServer.buildTriggers.vcs.git.VcsHostingRepo;
21 import jetbrains.buildServer.buildTriggers.vcs.git.WellKnownHostingsUtil;
22 import org.eclipse.jgit.transport.URIish;
23 import org.testng.annotations.Test;
24
25 import java.net.URISyntaxException;
26
27 @Test
28 public class WellKnownHostingsTest extends BaseTestCase {
29   public void test_github_https() throws URISyntaxException {
30     String url = "https://github.com/JetBrains/teamcity-commit-hooks.git";
31     VcsHostingRepo repo = WellKnownHostingsUtil.getGitHubRepo(new URIish(url));
32     assertNotNull(repo);
33     assertEquals("https://github.com/JetBrains/teamcity-commit-hooks", repo.repositoryUrl());
34     assertEquals("JetBrains", repo.owner());
35     assertEquals("teamcity-commit-hooks", repo.repoName());
36   }
37
38   public void test_github_ssh() throws URISyntaxException {
39     String url = "git@github.com:JetBrains/teamcity-commit-hooks.git";
40     VcsHostingRepo repo = WellKnownHostingsUtil.getGitHubRepo(new URIish(url));
41     assertNotNull(repo);
42     assertEquals("https://github.com/JetBrains/teamcity-commit-hooks", repo.repositoryUrl());
43     assertEquals("JetBrains", repo.owner());
44     assertEquals("teamcity-commit-hooks", repo.repoName());
45   }
46
47   public void test_gitlab_https() throws URISyntaxException {
48     String url = "https://pavelsher@gitlab.com/pavelsher/testgitrepo.git";
49     VcsHostingRepo repo = WellKnownHostingsUtil.getGitlabRepo(new URIish(url));
50     assertNotNull(repo);
51     assertEquals("https://gitlab.com/pavelsher/testgitrepo", repo.repositoryUrl());
52     assertEquals("pavelsher", repo.owner());
53     assertEquals("testgitrepo", repo.repoName());
54   }
55
56   public void test_gitlab_ssh() throws URISyntaxException {
57     String url = "git@gitlab.com:pavelsher/testgitrepo.git";
58     VcsHostingRepo repo = WellKnownHostingsUtil.getGitlabRepo(new URIish(url));
59     assertNotNull(repo);
60     assertEquals("https://gitlab.com/pavelsher/testgitrepo", repo.repositoryUrl());
61     assertEquals("pavelsher", repo.owner());
62     assertEquals("testgitrepo", repo.repoName());
63   }
64
65   public void test_bitbucket_https() throws URISyntaxException {
66     String url = "https://owner@bitbucket.org/owner/testgitrepo.git";
67     VcsHostingRepo repo = WellKnownHostingsUtil.getBitbucketRepo(new URIish(url));
68     assertNotNull(repo);
69     assertEquals("https://bitbucket.org/owner/testgitrepo", repo.repositoryUrl());
70     assertEquals("owner", repo.owner());
71     assertEquals("testgitrepo", repo.repoName());
72   }
73
74   public void test_bitbucket_ssh() throws URISyntaxException {
75     String url = "git@bitbucket.org:owner/testgitrepo.git";
76     VcsHostingRepo repo = WellKnownHostingsUtil.getBitbucketRepo(new URIish(url));
77     assertNotNull(repo);
78     assertEquals("https://bitbucket.org/owner/testgitrepo", repo.repositoryUrl());
79     assertEquals("owner", repo.owner());
80     assertEquals("testgitrepo", repo.repoName());
81   }
82
83   public void test_bitbucket_server_http_personal_repo() throws URISyntaxException {
84     String url = "http://admin@localhost:7990/scm/~admin/personalrepo.git";
85     VcsHostingRepo repo = WellKnownHostingsUtil.getBitbucketServerRepo(new URIish(url));
86     assertNotNull(repo);
87     assertEquals("http://localhost:7990/users/admin/repos/personalrepo", repo.repositoryUrl());
88     assertEquals("admin", repo.owner());
89     assertEquals("personalrepo", repo.repoName());
90   }
91
92   public void test_bitbucket_server_http_project_repo() throws URISyntaxException {
93     String url = "https://admin@localhost/scm/TP/projectrepo.git";
94     VcsHostingRepo repo = WellKnownHostingsUtil.getBitbucketServerRepo(new URIish(url));
95     assertNotNull(repo);
96     assertEquals("https://localhost/projects/TP/repos/projectrepo", repo.repositoryUrl());
97     assertEquals("TP", repo.owner());
98     assertEquals("projectrepo", repo.repoName());
99   }
100
101   public void test_vsts_https() throws URISyntaxException {
102     String url = "https://spav5.visualstudio.com/_git/MyFirstProject";
103     VcsHostingRepo repo = WellKnownHostingsUtil.getVSTSRepo(new URIish(url));
104     assertNotNull(repo);
105     assertEquals("https://spav5.visualstudio.com/_git/MyFirstProject", repo.repositoryUrl());
106     assertEquals("spav5", repo.owner());
107     assertEquals("MyFirstProject", repo.repoName());
108   }
109
110   public void test_vsts_ssh() throws URISyntaxException {
111     String url = "ssh://spav5@spav5.visualstudio.com:22/_git/MyFirstProject";
112     VcsHostingRepo repo = WellKnownHostingsUtil.getVSTSRepo(new URIish(url));
113     assertNotNull(repo);
114     assertEquals("https://spav5.visualstudio.com/_git/MyFirstProject", repo.repositoryUrl());
115     assertEquals("spav5", repo.owner());
116     assertEquals("MyFirstProject", repo.repoName());
117   }
118 }