1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Kevin Rogers
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.commons.vfs;
22  
23  import java.net.URI;
24  import java.util.List;
25  
26  import junit.framework.TestCase;
27  
28  /**
29   * @
30   */
31  public abstract class AbstractVFolderTest extends TestCase {
32  
33      private VVolume testVolume = null;
34  
35      private URI testURI = null;
36  
37      private final VFS vfs = new VFS();
38  
39      /**
40       * Constructor for AbstractVFolderTest.
41       * @param arg0
42       */
43      public AbstractVFolderTest(String arg0) {
44          super(arg0);
45      }
46  
47      public abstract URI getTestURI();
48  
49      public final VVolume getTestVolume() {
50          return this.testVolume;
51      }
52  
53      public final void setTestVolume( final VVolume volume ) {
54          this.testVolume = volume;
55      }
56  
57      public final void setTestURI( final URI uri ) {
58          this.testURI = uri;
59      }
60  
61      /**
62       * @see junit.framework.TestCase#setUp()
63       */
64      @Override
65      protected void setUp() throws Exception {
66          this.testURI = this.getTestURI();
67          this.setTestVolume( vfs.resolveAsVolume( this.testURI ) );
68      }
69  
70      public void testAppendAbsolutePath() {
71          // TODO
72      }
73  
74      public void testAppendAbsolutePathOnVolume() {
75          // TODO
76      }
77  
78      public void testAppendRelativePath() {
79          // TODO
80      }
81  
82      public void testAppendRelativePathOnVolume() {
83          // TODO
84      }
85  
86      public void testAppendURI() {
87          // TODO
88      }
89  
90      public void testCheckVEntry() {
91          final VFolder dir_pkg = this.testVolume.getRootVFolder().checkVFolder( "dir.pkg" );
92          // Check a ventry to see if it exists
93          assertNotNull( dir_pkg.checkVEntry( "dir.ms" ) );
94          // Check that it's correctly identifying a file
95          assertTrue( dir_pkg.checkVEntry( "dir.ms" ) instanceof VFile );
96          // Check that it's correctly identifying a folder
97          assertTrue( dir_pkg.checkVEntry( "inventory" ) instanceof VFolder );
98      }
99  
100     public void testCheckVFile() {
101         final VFolder dir_pkg = this.testVolume.getRootVFolder().checkVFolder( "dir.pkg" );
102         // Check a vfile to see if it exists and is a file
103         assertNotNull( dir_pkg.checkVFile( "dir.ms" ) );
104     }
105 
106     public void testCheckVFolder() {
107         final VFolder dir_pkg = this.testVolume.getRootVFolder().checkVFolder( "dir.pkg" );
108         // Check a vfolder to see if it exists and is a folder
109         assertNotNull( dir_pkg.checkVFolder( "inventory" ) );
110     }
111 
112     public void testExists() {
113         final VFolder dir_pkg = this.testVolume.getRootVFolder().getVFolder( "dir.pkg" );
114         assertTrue( dir_pkg.exists() );
115         final VFolder non_existant_dir = this.testVolume.getRootVFolder().getVFolder( "fibble" );
116         assertFalse( non_existant_dir.exists() );
117     }
118 
119     public void testGetAbsolutePath() {
120         // TODO
121     }
122 
123     public void testGetAbsolutePathOnVolume() {
124         // TODO
125     }
126 
127     public void testGetMIMEType() {
128         // TODO
129     }
130 
131     public void testGetMIMETypeHandler() {
132         // TODO
133     }
134 
135     public void testGetName() {
136         // TODO
137     }
138 
139     public void testGetParent() {
140         // TODO
141     }
142 
143     public void testGetRelativePath() {
144         // TODO
145     }
146 
147     public void testGetRelativePathOnVolume() {
148         // TODO
149     }
150 
151     public void testGetURI() {
152         // TODO
153     }
154 
155     public void testGetVFile() {
156         final VFolder dir_pkg = this.testVolume.getRootVFolder().checkVFolder( "dir.pkg" );
157         // Get a vfile
158         final VFile vfile = dir_pkg.getVFile( "dir.ms" );
159         // Check it exists and is a file
160         assertTrue( vfile.exists() );
161     }
162 
163     public void testGetVFolder() {
164         final VFolder dir_pkg = this.testVolume.getRootVFolder().checkVFolder( "dir.pkg" );
165         // Get a vfolder
166         final VFolder vfol = dir_pkg.getVFolder( "inventory" );
167         // Check it exists and is a folder
168         assertTrue( vfol.exists() );
169     }
170 
171     public void testGetVolume() {
172         // TODO
173     }
174 
175     public void testListEntries() {
176         final VFolder dir_pkg = this.testVolume.getRootVFolder().checkVFolder( "dir.pkg" );
177         // Get a list of all entries in a folder
178         final List sampleList = dir_pkg.listEntries();
179         // Check the right number of entries are found
180         assertEquals( 3, sampleList.size() );
181     }
182 
183     public void testListFiles() {
184         final VFolder dir_pkg = this.testVolume.getRootVFolder().checkVFolder( "dir.pkg" );
185         // Get a list of all files in a folder and check the right number are found
186         assertEquals( 1, dir_pkg.listFiles().size() );
187         // Get a list of all files in a folder and check the right number are found
188         final VFolder inventory = dir_pkg.checkVFolder( "inventory" );
189         assertEquals( 3, inventory.listFiles().size() );
190     }
191 
192     public void testListFolders() {
193         final VFolder dir_pkg = this.testVolume.getRootVFolder().checkVFolder( "dir.pkg" );
194         // Get a list of all folders in a folder and check the right number are found
195         assertEquals( 2, dir_pkg.listFolders().size() );
196         final VFolder inventory = dir_pkg.checkVFolder( "inventory" );
197         // Get a list of all folders in a folder and check the right number are found
198         assertEquals( 1, inventory.listFolders().size() );
199     }
200 
201     public void testResolveAsFile() {
202         // TODO
203     }
204 
205     public void testResolveAsFolder() {
206         final VFolder dir_pkg = this.vfs.resolveAsFolder( this.testURI.resolve( "dir.pkg/" ) );
207         assertNotNull( dir_pkg );
208     }
209 
210     public void testResolveAsVolume() {
211         // TODO
212     }
213 
214     /*
215      * Test for String toString()
216      */
217     public void testToString() {
218         // TODO
219     }
220 
221     public void testToVolume() {
222         // TODO
223     }
224 
225 }