1 package org
.spearce
.jgit
.transport
;
3 import junit
.framework
.TestCase
;
5 public class URIishTest
extends TestCase
{
7 public void testUnixFile() throws Exception
{
8 final String str
= "/home/m y";
9 URIish u
= new URIish(str
);
10 assertNull(u
.getScheme());
11 assertFalse(u
.isRemote());
12 assertEquals(str
, u
.getPath());
13 assertEquals(str
, u
.toString());
14 assertEquals(u
, new URIish(str
));
17 public void testWindowsFile() throws Exception
{
18 final String str
= "D:/m y";
19 URIish u
= new URIish(str
);
20 assertNull(u
.getScheme());
21 assertFalse(u
.isRemote());
22 assertEquals(str
, u
.getPath());
23 assertEquals(str
, u
.toString());
24 assertEquals(u
, new URIish(str
));
27 public void testFileProtoUnix() throws Exception
{
28 final String str
= "file:///home/m y";
29 URIish u
= new URIish(str
);
30 assertEquals("file", u
.getScheme());
31 assertFalse(u
.isRemote());
32 assertEquals("/home/m y", u
.getPath());
33 assertEquals(str
, u
.toString());
34 assertEquals(u
, new URIish(str
));
37 public void testFileProtoWindows() throws Exception
{
38 final String str
= "file:///D:/m y";
39 URIish u
= new URIish(str
);
40 assertEquals("file", u
.getScheme());
41 assertFalse(u
.isRemote());
42 assertEquals("D:/m y", u
.getPath());
43 assertEquals(str
, u
.toString());
44 assertEquals(u
, new URIish(str
));
47 public void testGitProtoUnix() throws Exception
{
48 final String str
= "git://example.com/home/m y";
49 URIish u
= new URIish(str
);
50 assertEquals("git", u
.getScheme());
51 assertTrue(u
.isRemote());
52 assertEquals("example.com", u
.getHost());
53 assertEquals("/home/m y", u
.getPath());
54 assertEquals(str
, u
.toString());
55 assertEquals(u
, new URIish(str
));
58 public void testGitProtoUnixPort() throws Exception
{
59 final String str
= "git://example.com:333/home/m y";
60 URIish u
= new URIish(str
);
61 assertEquals("git", u
.getScheme());
62 assertTrue(u
.isRemote());
63 assertEquals("example.com", u
.getHost());
64 assertEquals("/home/m y", u
.getPath());
65 assertEquals(333, u
.getPort());
66 assertEquals(str
, u
.toString());
67 assertEquals(u
, new URIish(str
));
70 public void testGitProtoWindowsPort() throws Exception
{
71 final String str
= "git://example.com:338/D:/m y";
72 URIish u
= new URIish(str
);
73 assertEquals("git", u
.getScheme());
74 assertTrue(u
.isRemote());
75 assertEquals("D:/m y", u
.getPath());
76 assertEquals(338, u
.getPort());
77 assertEquals("example.com", u
.getHost());
78 assertEquals(str
, u
.toString());
79 assertEquals(u
, new URIish(str
));
82 public void testGitProtoWindows() throws Exception
{
83 final String str
= "git://example.com/D:/m y";
84 URIish u
= new URIish(str
);
85 assertEquals("git", u
.getScheme());
86 assertTrue(u
.isRemote());
87 assertEquals("D:/m y", u
.getPath());
88 assertEquals("example.com", u
.getHost());
89 assertEquals(-1, u
.getPort());
90 assertEquals(str
, u
.toString());
91 assertEquals(u
, new URIish(str
));
94 public void testScpStyleWithoutUser() throws Exception
{
95 final String str
= "example.com:some/p ath";
96 URIish u
= new URIish(str
);
97 assertNull(u
.getScheme());
98 assertTrue(u
.isRemote());
99 assertEquals("some/p ath", u
.getPath());
100 assertEquals("example.com", u
.getHost());
101 assertEquals(-1, u
.getPort());
102 assertEquals(str
, u
.toString());
103 assertEquals(u
, new URIish(str
));
106 public void testScpStyleWithUser() throws Exception
{
107 final String str
= "user@example.com:some/p ath";
108 URIish u
= new URIish(str
);
109 assertNull(u
.getScheme());
110 assertTrue(u
.isRemote());
111 assertEquals("some/p ath", u
.getPath());
112 assertEquals("user", u
.getUser());
113 assertEquals("example.com", u
.getHost());
114 assertEquals(-1, u
.getPort());
115 assertEquals(str
, u
.toString());
116 assertEquals(u
, new URIish(str
));
119 public void testGitSshProto() throws Exception
{
120 final String str
= "git+ssh://example.com/some/p ath";
121 URIish u
= new URIish(str
);
122 assertEquals("git+ssh", u
.getScheme());
123 assertTrue(u
.isRemote());
124 assertEquals("/some/p ath", u
.getPath());
125 assertEquals("example.com", u
.getHost());
126 assertEquals(-1, u
.getPort());
127 assertEquals(str
, u
.toString());
128 assertEquals(u
, new URIish(str
));
131 public void testSshGitProto() throws Exception
{
132 final String str
= "ssh+git://example.com/some/p ath";
133 URIish u
= new URIish(str
);
134 assertEquals("ssh+git", u
.getScheme());
135 assertTrue(u
.isRemote());
136 assertEquals("/some/p ath", u
.getPath());
137 assertEquals("example.com", u
.getHost());
138 assertEquals(-1, u
.getPort());
139 assertEquals(str
, u
.toString());
140 assertEquals(u
, new URIish(str
));
143 public void testSshProto() throws Exception
{
144 final String str
= "ssh://example.com/some/p ath";
145 URIish u
= new URIish(str
);
146 assertEquals("ssh", u
.getScheme());
147 assertTrue(u
.isRemote());
148 assertEquals("/some/p ath", u
.getPath());
149 assertEquals("example.com", u
.getHost());
150 assertEquals(-1, u
.getPort());
151 assertEquals(str
, u
.toString());
152 assertEquals(u
, new URIish(str
));
155 public void testSshProtoWithUserAndPort() throws Exception
{
156 final String str
= "ssh://user@example.com:33/some/p ath";
157 URIish u
= new URIish(str
);
158 assertEquals("ssh", u
.getScheme());
159 assertTrue(u
.isRemote());
160 assertEquals("/some/p ath", u
.getPath());
161 assertEquals("example.com", u
.getHost());
162 assertEquals("user", u
.getUser());
163 assertNull(u
.getPass());
164 assertEquals(33, u
.getPort());
165 assertEquals(str
, u
.toString());
166 assertEquals(u
, new URIish(str
));
169 public void testSshProtoWithUserPassAndPort() throws Exception
{
170 final String str
= "ssh://user:pass@example.com:33/some/p ath";
171 URIish u
= new URIish(str
);
172 assertEquals("ssh", u
.getScheme());
173 assertTrue(u
.isRemote());
174 assertEquals("/some/p ath", u
.getPath());
175 assertEquals("example.com", u
.getHost());
176 assertEquals("user", u
.getUser());
177 assertEquals("pass", u
.getPass());
178 assertEquals(33, u
.getPort());
179 assertEquals(str
, u
.toString());
180 assertEquals(u
, new URIish(str
));