Project

General

Profile

Download (2.05 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.common;
2

    
3
import static org.junit.Assert.*;
4

    
5
import java.net.MalformedURLException;
6
import java.net.URI;
7
import java.net.URISyntaxException;
8
import java.net.URL;
9
import java.util.ArrayList;
10
import java.util.List;
11

    
12
import junit.framework.Assert;
13

    
14
import org.apache.http.NameValuePair;
15
import org.apache.http.message.BasicNameValuePair;
16
import org.apache.log4j.Logger;
17
import org.junit.Before;
18
import org.junit.BeforeClass;
19
import org.junit.Test;
20

    
21
public class UriUtilsTest {
22
	private static final Logger logger = Logger.getLogger(UriUtilsTest.class);
23
	
24
	@BeforeClass
25
	public static void setUpBeforeClass() throws Exception {
26
	}
27

    
28
	@Before
29
	public void setUp() throws Exception {
30
	}
31

    
32
//********************* TESTS **********************************************/
33
	
34
	@Test
35
	public void testCreateUri() {
36
		try {
37
			URL baseUrl = new URL("http://www.abc.de");
38
			String subPath = "fgh";
39
			String fragment = "frag";
40
			URI uri = UriUtils.createUri(baseUrl, subPath, null, fragment);
41
			Assert.assertEquals("http://www.abc.de/fgh#frag", uri.toString());
42
			List<NameValuePair> qparams = new ArrayList<NameValuePair>(0);
43
			NameValuePair pair1 = new BasicNameValuePair("param1","value1");
44
			qparams.add(pair1);
45
			uri = UriUtils.createUri(baseUrl, subPath, qparams, fragment);
46
			Assert.assertEquals("http://www.abc.de/fgh?param1=value1#frag", uri.toString());
47
			
48
		} catch (MalformedURLException e) {
49
			e.printStackTrace();
50
			Assert.fail(e.getMessage());
51
		} catch (URISyntaxException e) {
52
			e.printStackTrace();
53
			Assert.fail(e.getMessage());
54
		}
55
	}
56

    
57
	@Test
58
	public void testIsInternetAvailable() {
59
		URI firstUri = URI.create("http://www.gmx.de/");
60
		boolean isAvailable = UriUtils.isInternetAvailable(firstUri);
61
		if (isAvailable == false){
62
			logger.warn("Internet is not available!");
63
		}
64
	}
65
	
66
	@Test
67
	public void testIsRootServerAvailable() {
68
		boolean isAvailable = UriUtils.isRootServerAvailable("www.gmx.de");
69
		if (isAvailable == false){
70
			logger.warn("RootServer is not available!");
71
		}
72
	}
73

    
74
}
(3-3/5)