KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.excalibur.source.SourceNotFoundException;
22 import org.apache.excalibur.source.SourceValidity;
23 import org.apache.excalibur.source.impl.ResourceSource;
24
25 /**
26  * Test case for ResourceSource.
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  * @version $Id: ResourceSourceTestCase.java 492443 2007-01-04 08:26:28Z cziegeler $
30  */

31 public class ResourceSourceTestCase extends TestCase
32 {
33
34     public ResourceSourceTestCase()
35     {
36         this("ResourceSource");
37     }
38
39     public ResourceSourceTestCase(String JavaDoc name)
40     {
41         super(name);
42     }
43
44     protected void setUp() throws Exception JavaDoc
45     {
46         super.setUp();
47     }
48
49     public void testExistingSource() throws Exception JavaDoc
50     {
51         ResourceSource src = new ResourceSource("resource://org/apache/excalibur/source/test/ResourceSourceTestCase.class");
52         assertTrue("Resource doesn't exist", src.exists());
53         assertTrue("Lentgh should be positive", src.getContentLength() > 0);
54         assertNotNull("InputStream shouldn't be null", src.getInputStream());
55     }
56
57     public void testNonExistingSource() throws Exception JavaDoc
58     {
59         ResourceSource src = new ResourceSource("resource://org/apache/excalibur/source/test/DoesNotExist");
60         assertFalse("Resource shouldn't exist", src.exists());
61         assertEquals("Should have no length", -1, src.getContentLength());
62         assertEquals("Should have no lastModified", 0, src.getLastModified());
63         
64         try
65         {
66             src.getInputStream();
67             fail("getInputStream should fail");
68         } catch(SourceNotFoundException e) {
69             // This is what we're waiting for
70
}
71     }
72
73     public void testValidity() throws Exception JavaDoc
74     {
75         ResourceSource src1 = new ResourceSource("resource://org/apache/excalibur/source/test/ResourceSourceTestCase.class");
76         ResourceSource src2 = new ResourceSource("resource://org/apache/excalibur/source/test/ResourceSourceTestCase.class");
77
78         SourceValidity val1 = src1.getValidity();
79         SourceValidity val2 = src2.getValidity();
80         
81         assertEquals("Validities should match", SourceValidity.VALID, val1.isValid(val2));
82     }
83
84     protected void tearDown() throws Exception JavaDoc
85     {
86         super.tearDown();
87     }
88
89 }
90
Popular Tags