2 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * - Neither the name of the Git Development Community nor the
20 * names of its contributors may be used to endorse or promote
21 * products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 package org
.spearce
.jgit
.transport
;
41 import junit
.framework
.TestCase
;
43 public class URIishTest
extends TestCase
{
45 public void testUnixFile() throws Exception
{
46 final String str
= "/home/m y";
47 URIish u
= new URIish(str
);
48 assertNull(u
.getScheme());
49 assertFalse(u
.isRemote());
50 assertEquals(str
, u
.getPath());
51 assertEquals(str
, u
.toString());
52 assertEquals(u
, new URIish(str
));
55 public void testWindowsFile() throws Exception
{
56 final String str
= "D:/m y";
57 URIish u
= new URIish(str
);
58 assertNull(u
.getScheme());
59 assertFalse(u
.isRemote());
60 assertEquals(str
, u
.getPath());
61 assertEquals(str
, u
.toString());
62 assertEquals(u
, new URIish(str
));
65 public void testWindowsFile2() throws Exception
{
66 final String str
= "D:\\m y";
67 URIish u
= new URIish(str
);
68 assertNull(u
.getScheme());
69 assertFalse(u
.isRemote());
70 assertEquals("D:/m y", u
.getPath());
71 assertEquals("D:/m y", u
.toString());
72 assertEquals(u
, new URIish(str
));
75 public void testUNC() throws Exception
{
76 final String str
= "\\\\some\\place";
77 URIish u
= new URIish(str
);
78 assertNull(u
.getScheme());
79 assertFalse(u
.isRemote());
80 assertEquals("//some/place", u
.getPath());
81 assertEquals("//some/place", u
.toString());
82 assertEquals(u
, new URIish(str
));
85 public void testFileProtoUnix() throws Exception
{
86 final String str
= "file:///home/m y";
87 URIish u
= new URIish(str
);
88 assertEquals("file", u
.getScheme());
89 assertFalse(u
.isRemote());
90 assertEquals("/home/m y", u
.getPath());
91 assertEquals(str
, u
.toString());
92 assertEquals(u
, new URIish(str
));
95 public void testFileProtoWindows() throws Exception
{
96 final String str
= "file:///D:/m y";
97 URIish u
= new URIish(str
);
98 assertEquals("file", u
.getScheme());
99 assertFalse(u
.isRemote());
100 assertEquals("D:/m y", u
.getPath());
101 assertEquals(str
, u
.toString());
102 assertEquals(u
, new URIish(str
));
105 public void testGitProtoUnix() throws Exception
{
106 final String str
= "git://example.com/home/m y";
107 URIish u
= new URIish(str
);
108 assertEquals("git", u
.getScheme());
109 assertTrue(u
.isRemote());
110 assertEquals("example.com", u
.getHost());
111 assertEquals("/home/m y", u
.getPath());
112 assertEquals(str
, u
.toString());
113 assertEquals(u
, new URIish(str
));
116 public void testGitProtoUnixPort() throws Exception
{
117 final String str
= "git://example.com:333/home/m y";
118 URIish u
= new URIish(str
);
119 assertEquals("git", u
.getScheme());
120 assertTrue(u
.isRemote());
121 assertEquals("example.com", u
.getHost());
122 assertEquals("/home/m y", u
.getPath());
123 assertEquals(333, u
.getPort());
124 assertEquals(str
, u
.toString());
125 assertEquals(u
, new URIish(str
));
128 public void testGitProtoWindowsPort() throws Exception
{
129 final String str
= "git://example.com:338/D:/m y";
130 URIish u
= new URIish(str
);
131 assertEquals("git", u
.getScheme());
132 assertTrue(u
.isRemote());
133 assertEquals("D:/m y", u
.getPath());
134 assertEquals(338, u
.getPort());
135 assertEquals("example.com", u
.getHost());
136 assertEquals(str
, u
.toString());
137 assertEquals(u
, new URIish(str
));
140 public void testGitProtoWindows() throws Exception
{
141 final String str
= "git://example.com/D:/m y";
142 URIish u
= new URIish(str
);
143 assertEquals("git", u
.getScheme());
144 assertTrue(u
.isRemote());
145 assertEquals("D:/m y", u
.getPath());
146 assertEquals("example.com", u
.getHost());
147 assertEquals(-1, u
.getPort());
148 assertEquals(str
, u
.toString());
149 assertEquals(u
, new URIish(str
));
152 public void testScpStyleWithoutUser() throws Exception
{
153 final String str
= "example.com:some/p ath";
154 URIish u
= new URIish(str
);
155 assertNull(u
.getScheme());
156 assertTrue(u
.isRemote());
157 assertEquals("some/p ath", u
.getPath());
158 assertEquals("example.com", u
.getHost());
159 assertEquals(-1, u
.getPort());
160 assertEquals(str
, u
.toString());
161 assertEquals(u
, new URIish(str
));
164 public void testScpStyleWithUser() throws Exception
{
165 final String str
= "user@example.com:some/p ath";
166 URIish u
= new URIish(str
);
167 assertNull(u
.getScheme());
168 assertTrue(u
.isRemote());
169 assertEquals("some/p ath", u
.getPath());
170 assertEquals("user", u
.getUser());
171 assertEquals("example.com", u
.getHost());
172 assertEquals(-1, u
.getPort());
173 assertEquals(str
, u
.toString());
174 assertEquals(u
, new URIish(str
));
177 public void testGitSshProto() throws Exception
{
178 final String str
= "git+ssh://example.com/some/p ath";
179 URIish u
= new URIish(str
);
180 assertEquals("git+ssh", u
.getScheme());
181 assertTrue(u
.isRemote());
182 assertEquals("/some/p ath", u
.getPath());
183 assertEquals("example.com", u
.getHost());
184 assertEquals(-1, u
.getPort());
185 assertEquals(str
, u
.toString());
186 assertEquals(u
, new URIish(str
));
189 public void testSshGitProto() throws Exception
{
190 final String str
= "ssh+git://example.com/some/p ath";
191 URIish u
= new URIish(str
);
192 assertEquals("ssh+git", u
.getScheme());
193 assertTrue(u
.isRemote());
194 assertEquals("/some/p ath", u
.getPath());
195 assertEquals("example.com", u
.getHost());
196 assertEquals(-1, u
.getPort());
197 assertEquals(str
, u
.toString());
198 assertEquals(u
, new URIish(str
));
201 public void testSshProto() throws Exception
{
202 final String str
= "ssh://example.com/some/p ath";
203 URIish u
= new URIish(str
);
204 assertEquals("ssh", u
.getScheme());
205 assertTrue(u
.isRemote());
206 assertEquals("/some/p ath", u
.getPath());
207 assertEquals("example.com", u
.getHost());
208 assertEquals(-1, u
.getPort());
209 assertEquals(str
, u
.toString());
210 assertEquals(u
, new URIish(str
));
213 public void testSshProtoWithUserAndPort() throws Exception
{
214 final String str
= "ssh://user@example.com:33/some/p ath";
215 URIish u
= new URIish(str
);
216 assertEquals("ssh", u
.getScheme());
217 assertTrue(u
.isRemote());
218 assertEquals("/some/p ath", u
.getPath());
219 assertEquals("example.com", u
.getHost());
220 assertEquals("user", u
.getUser());
221 assertNull(u
.getPass());
222 assertEquals(33, u
.getPort());
223 assertEquals(str
, u
.toString());
224 assertEquals(u
, new URIish(str
));
227 public void testSshProtoWithUserPassAndPort() throws Exception
{
228 final String str
= "ssh://user:pass@example.com:33/some/p ath";
229 URIish u
= new URIish(str
);
230 assertEquals("ssh", u
.getScheme());
231 assertTrue(u
.isRemote());
232 assertEquals("/some/p ath", u
.getPath());
233 assertEquals("example.com", u
.getHost());
234 assertEquals("user", u
.getUser());
235 assertEquals("pass", u
.getPass());
236 assertEquals(33, u
.getPort());
237 assertEquals(str
, u
.toPrivateString());
238 assertEquals(u
.setPass(null).toPrivateString(), u
.toString());
239 assertEquals(u
, new URIish(str
));