KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > networkplaces > NetworkPlaceInstallTest


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.networkplaces;
21
22 import static org.junit.Assert.assertEquals;
23
24 import java.util.GregorianCalendar JavaDoc;
25
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28
29 /**
30  */

31 public class NetworkPlaceInstallTest {
32     
33     static NetworkPlaceInstall install;
34
35     @BeforeClass
36     public static void setUp() throws Exception JavaDoc {
37         install = new NetworkPlaceInstall();
38     }
39     
40     @Test
41     public void uncPath() throws Exception JavaDoc {
42         // Simple UNC path
43
NetworkPlace np = create("\\\\windowsserver");
44         NetworkPlaceUtil.convertNetworkPlace(np);
45         test(np, "smb", "windowsserver", 0, "", "", "");
46         
47         // Simple UNC path with share
48
np = create("\\\\windowsserver\\MyShare");
49         NetworkPlaceUtil.convertNetworkPlace(np);
50         test(np, "smb", "windowsserver", 0, "/MyShare", "", "");
51         
52         // Simple UNC path with share with spaces
53
np = create("\\\\windowsserver\\My Share");
54         NetworkPlaceUtil.convertNetworkPlace(np);
55         test(np, "smb", "windowsserver", 0, "/My Share", "", "");
56     }
57
58     
59     @Test
60     public void localPath() throws Exception JavaDoc {
61         // Local path
62
String JavaDoc dir = System.getProperty("user.dir");
63         NetworkPlace np = create(dir);
64         NetworkPlaceUtil.convertNetworkPlace(np);
65         test(np, "file", "", 0, dir, "", "");
66         
67         // Windows path
68
dir = "C:\\Program Files\\SSL-Explorer";
69         np = create(dir);
70         NetworkPlaceUtil.convertNetworkPlace(np);
71         test(np, "file", "", 0, dir, "", "");
72         
73         // UNIX path
74
dir = "/home/joeb/My Documents";
75         np = create(dir);
76         NetworkPlaceUtil.convertNetworkPlace(np);
77         test(np, "file", "", 0, dir, "", "");
78     }
79     
80     @Test
81     public void uriPath() throws Exception JavaDoc {
82         // FTP URI
83
NetworkPlace np = create("ftp://joeb:secret@ftpserver.test.com/home/joeb");
84         NetworkPlaceUtil.convertNetworkPlace(np);
85         test(np, "ftp", "ftpserver.test.com", 0, "/home/joeb", "joeb", "secret");
86
87         // FTP URI with replacements
88
np = create("ftp://${session:username}:${session:password}@ftpserver.test.com/home/brett");
89         NetworkPlaceUtil.convertNetworkPlace(np);
90         test(np, "ftp", "ftpserver.test.com", 0, "/home/brett", "${session:username}", "${session:password}");
91
92         // FTP URI with encoded bits
93
np = create("ftp://joeb%3A:sec%2Bret@ftpserver.test.com/home/joeb/Dir%20With+Spaces");
94         NetworkPlaceUtil.convertNetworkPlace(np);
95         test(np, "ftp", "ftpserver.test.com", 0, "/home/joeb/Dir With Spaces", "joeb:", "sec+ret");
96         
97         // SMB URI
98
np = create("smb://smbserver.test.com/MyShare");
99         NetworkPlaceUtil.convertNetworkPlace(np);
100         test(np, "smb", "smbserver.test.com", 0, "/MyShare", "", "");
101
102         // Absolute file URI
103
np = create("file://opt/sslexplorer/logs");
104         NetworkPlaceUtil.convertNetworkPlace(np);
105         test(np, "file", "", 0, "/opt/sslexplorer/logs", "", "");
106         
107         // Windows Absolute file URI
108
np = create("file:///C:/Documents and Settings/joeb");
109         NetworkPlaceUtil.convertNetworkPlace(np);
110         test(np, "file", "", 0, "C:/Documents and Settings/joeb", "", "");
111         
112     }
113     
114     public static void test(NetworkPlace np, String JavaDoc scheme, String JavaDoc host, int port, String JavaDoc path, String JavaDoc username, String JavaDoc password) {
115         assertEquals("Scheme", scheme, np.getScheme());
116         assertEquals("Host", host, np.getHost());
117         assertEquals("Port", port, np.getPort());
118         assertEquals("Path", path, np.getPath());
119         assertEquals("Username", username, np.getUsername());
120         assertEquals("Password", password, np.getPassword());
121     }
122
123     public static NetworkPlace create(String JavaDoc path) throws Exception JavaDoc {
124         return new DefaultNetworkPlace(0,
125                         0,
126                         "",
127                         "NP",
128                         "NP",
129                         null,
130                         path,
131                         0,
132                         "",
133                         "",
134                         NetworkPlace.TYPE_NORMAL,
135                         false,
136                         false,
137                         false,
138                         false,
139                         new GregorianCalendar JavaDoc(),
140                         new GregorianCalendar JavaDoc());
141
142     }
143 }
144
Popular Tags