1   //
2   // Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
3   // All rights reserved.
4   //
5   // Redistribution and use in source and binary forms, with or without modification, 
6   // are permitted provided that the following conditions are met:
7   //
8   // * Redistributions of source code must retain the above copyright notice, 
9   //	 this list of conditions and the following disclaimer.
10  // * Redistributions in binary form must reproduce the above copyright notice, 
11  //	 this list of conditions and the following disclaimer in the documentation 
12  //	 and/or other materials provided with the distribution.
13  // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. 
14  //	 nor the names of its contributors may be used to endorse or promote products 
15  //	 derived from this software without specific prior written permission.
16  //
17  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
18  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
19  // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
21  // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
22  // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23  // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
24  // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
25  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
26  // POSSIBILITY OF SUCH DAMAGE.
27  //
28  
29  package org.objectledge.filesystem;
30  
31  import java.io.IOException;
32  
33  import junit.framework.TestCase;
34  
35  /***
36   *
37   *
38   * @author <a href="Rafal.Krzewski">rafal@caltha.pl</a>
39   * @version $Id: ClasspathFileSystemProviderTest.java,v 1.3 2004/04/01 08:54:25 fil Exp $
40   */
41  public class ClasspathFileSystemProviderTest extends TestCase
42  {
43      protected ClasspathFileSystemProvider provider;
44  
45      /***
46       * Constructor for LocalFileProviderTest.
47       * @param arg0
48       */
49      public ClasspathFileSystemProviderTest(String arg0)
50      {
51          super(arg0);
52      }
53  
54      /*
55       * @see TestCase#setUp()
56       */
57      protected void setUp() throws Exception
58      {
59          super.setUp();
60          provider = new ClasspathFileSystemProvider("classpath", 
61              ClasspathFileSystemProvider.class.getClassLoader());
62      }
63  
64      public void testGetName()
65      {
66          assertEquals(provider.getName(), "classpath");
67      }
68  
69      public void testIsReadOnly()
70      {
71          assertTrue("Provider is read only", provider.isReadOnly());
72      }
73  
74      public void testExists()
75      {
76          assertTrue("File does not exist - check test resources!",
77                     provider.exists("org/objectledge/filesystem/ClasspathFileSystemProvider.class"));
78          assertFalse("File exists - check test resources!", provider.exists("nofile"));
79      }
80  
81      public void testIsFile()
82      {
83          assertTrue("The resource is not a file - check test resources!", 
84              provider.isFile("org/objectledge/filesystem/ClasspathFileSystemProvider.class"));
85          //assertFalse("The resource is a file - check test resources!", 
86          //  			provider.isFile("org/objectledge/filesystem/"));
87      }
88  
89      public void testIsDirectory()
90      {
91          //assertTrue("The resource is not a directory - check test resources!", 
92          //			provider.isDirectory("org/objectledge/filesystem/"));
93          assertFalse("The resource is a directory - check test resources!", 
94          	provider.isDirectory("org/objectledge/filesystem/ClasspathFileSystemProvider.class"));
95      }
96  
97      public void testCanRead()
98      {
99  		assertTrue("The resource is not readable - check test resources!", 
100 			provider.canRead("org/objectledge/filesystem/ClasspathFileSystemProvider.class"));
101 		assertFalse("The resource is readable - check test resources!", 
102 			provider.canRead("nofile"));
103     }
104 
105     public void testCanWrite()
106     {
107 		assertFalse("The resource is writable - check test resources!", 
108 					provider.canWrite("nofile"));
109     }
110 
111     public void testList()  
112         throws Exception
113     {
114 		//String[] list = provider.list("/org/");
115         //assertEquals(1, list.length);
116     }
117 
118     public void testCreateNewFile()
119     	throws Exception 
120     {
121 		try
122 		{
123 			provider.createNewFile("foo");
124 			fail("should throw the exception");
125 		}
126 		catch(IOException e)
127 		{
128 			// expected
129 		}
130 	}
131 		
132     public void testMkdirs()
133     throws IOException
134     {
135         try
136         {
137             provider.mkdirs("foo");
138             fail("should throw the exception");
139         }
140         catch(IOException e)
141         {
142             // expected
143         }
144     }
145 
146     public void testDelete()
147     {
148         try
149         {
150             provider.delete("foo");
151             fail("should throw the exception");
152         }
153         catch(IOException e)
154         {
155             // expected
156         }
157     }
158 
159     public void testRename()
160     {
161         try
162         {
163             provider.rename("foo","foo");
164             fail("should throw the exception");
165         }
166         catch(IOException e)
167         {
168             // expected
169         }
170     }
171 
172     public void testGetInputStream()
173     {
174         //TODO Implement getInputStream().
175     }
176 
177     public void testGetOutputStream()
178     {
179         assertNull(provider.getOutputStream("",true));
180     }
181 
182     public void testGetRandomAccess()
183     {
184         assertNull(provider.getRandomAccess("",""));
185     }
186 
187     public void testLastModified()
188     {
189         assertEquals(-1L, provider.lastModified(""));
190         //assertEquals(true, 1079100713000L == provider.
191         //    lastModified("org/objectledge/filesystem/ClasspathFileSystemProvider.class"));
192     }
193 
194     public void testLength()
195     {
196         assertEquals(-1L, provider.length(""));
197         //assertEquals(true, 12345L == provider.
198         //    length("org/objectledge/filesystem/ClasspathFileSystemProvider.class"));
199     }
200 }