KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > source > test > URLSourceTestCase


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.excalibur.source.test;
18
19 import junit.framework.TestCase;
20
21 import java.io.File JavaDoc;
22 import java.io.FileOutputStream JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.Collections JavaDoc;
25 import org.apache.excalibur.source.impl.URLSource;
26
27 /**
28  * Test case for URLSource.
29  *
30  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
31  * @version $Id: URLSourceTestCase.java,v 1.0 2005/04/16 11:47:22 shash Exp $
32  */

33 public class URLSourceTestCase extends TestCase
34 {
35
36     URLSource m_urlSource;
37     File JavaDoc tempFile;
38
39     protected void setUp() throws Exception JavaDoc
40     {
41         super.setUp();
42         m_urlSource = new URLSource();
43
44         tempFile = File.createTempFile( "filesource", "test-exists" );
45     FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(tempFile);
46     out.write(1);
47     out.close();
48     }
49
50     protected void tearDown() throws Exception JavaDoc
51     {
52         super.tearDown();
53
54         tempFile.delete();
55     }
56
57     public void testFileExists() throws Exception JavaDoc
58     {
59         m_urlSource.init( tempFile.toURL(), Collections.EMPTY_MAP );
60         assertTrue( m_urlSource.exists() );
61     }
62
63     public void testFileDoesNotExist() throws Exception JavaDoc
64     {
65         File JavaDoc tempFile = new File JavaDoc("phantom-file");
66
67         m_urlSource.init( tempFile.toURL(), Collections.EMPTY_MAP );
68         assertFalse( m_urlSource.exists() );
69     }
70
71     public void testHttpHostDoesNotExist() throws Exception JavaDoc
72     {
73         m_urlSource.init( new URL JavaDoc( "http://some.invalid.host/no_such_file" ),
74                 Collections.EMPTY_MAP );
75         assertFalse( m_urlSource.exists() );
76     }
77
78     public void testHttpDoesExist() throws Exception JavaDoc
79     {
80         m_urlSource.init( new URL JavaDoc( "http://excalibur.apache.org/" ),
81                 Collections.EMPTY_MAP );
82         assertTrue( m_urlSource.exists() );
83     }
84 }
85
Popular Tags