1 package fr.jayasoft.ivy.repository.vfs; 2 3 import java.net.URI ; 4 import java.util.ArrayList ; 5 import java.util.Arrays ; 6 import java.util.Collections ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 10 import junit.framework.TestCase; 11 12 13 public class VfsResourceTest extends TestCase { 14 private VfsTestHelper helper = null; 15 16 public VfsResourceTest() { 17 super(); 18 } 19 20 public VfsResourceTest(String arg0) { 21 super(arg0); 22 } 23 24 public void setUp() throws Exception { 25 helper = new VfsTestHelper(); 26 } 27 28 public void tearDown() { 29 helper = null; 30 } 31 32 35 public void testCreateResourceThatExists() throws Exception { 36 Iterator vfsURIs = helper.createVFSUriSet(VfsTestHelper.TEST_IVY_XML).iterator(); 37 while (vfsURIs.hasNext()) { 38 VfsURI vfsURI = (VfsURI) vfsURIs.next(); 39 String resId = vfsURI.toString(); 40 VfsResource res = new VfsResource(resId, helper.fsManager); 41 if (res == null) { 42 fail("Unexpected null value on VFS URI: " + resId); 43 } 44 45 if (! res.exists()) { 46 fail("Resource does not exist and it should: " + resId); 47 } 48 49 if (! new URI (resId).equals(new URI (res.getName()).normalize())) { 53 fail("Failed on getName. Expected: " + resId + ". Actual: " + res.getName()); 54 } 55 56 if (res.getLastModified() == 0 ) { 57 fail("Expected non-null file modification date for URI: " + resId); 58 } 59 60 if (res.getContentLength() == 0 ) { 61 fail("Expected non-zero file length for URI: " + resId); 62 } 63 64 if (! res.physicallyExists()) { 65 fail("Physical existence check returned false for existing resource: " + resId); 66 } 67 } 68 } 69 70 75 public void testCreateResourceThatDoesntExist() throws Exception { 76 Iterator vfsURIs = helper.createVFSUriSet("zzyyxx.zzyyxx").iterator(); 77 while (vfsURIs.hasNext()) { 78 VfsURI vfsURI = (VfsURI) vfsURIs.next(); 79 String resId = vfsURI.toString(); 80 VfsResource res = new VfsResource(resId, helper.fsManager); 81 if (res == null) { 82 fail("Unexpected null value on VFS URI: " + resId); 83 } 84 85 if (res.exists()) { 86 fail("Resource does not exist and it shouldn't: " + resId); 87 } 88 89 if (! new URI (resId).equals(new URI (res.getName()).normalize())) { 93 fail("Failed on getName. Expected: " + resId + ". Actual: " + res.getName()); 94 } 95 96 if (res.getLastModified() != 0 ) { 97 fail("Expected null file modification date for URI: " + resId + ": " + res.getLastModified()); 98 } 99 100 if (res.getContentLength() != 0 ) { 101 fail("Expected non-zero file length for URI: " + resId); 102 } 103 104 if (res.physicallyExists()) { 105 fail("Physical existence check returned true for non-existent resource: " + resId); 106 } 107 } 108 } 109 110 114 public void testBadURI() throws Exception { 115 String vfsURI = "smb1:/goobeldygook"; 116 VfsResource res = new VfsResource(vfsURI, helper.fsManager); 117 118 119 if (res == null) { 120 fail("Unexpected null value on VFS URI: " + vfsURI); 121 } 122 123 if (res.exists()) { 124 fail("Resource is marked as existing and it should not: " + vfsURI); 125 } 126 127 if (! res.getName().equals("smb1:/goobeldygook")) { 128 fail("Failed on getName. Expected: " + vfsURI + ". Actual: " + res.getName()); 129 } 130 131 if (res.getLastModified() != 0 ) { 132 fail("Expected null file modification date for URI: " + vfsURI + ": " + res.getLastModified()); 133 } 134 135 if (res.getContentLength() != 0 ) { 136 fail("Expected zero file length for URI: " + vfsURI); 137 } 138 139 if (res.physicallyExists()) { 140 fail("Physical existence check returned false for existing resource: " + vfsURI); 141 } 142 } 143 144 145 146 150 public void testListFolderChildren() throws Exception { 151 final String testFolder = "2/mod10.1"; 152 final List expectedFiles = Arrays.asList(new String [] {"ivy-1.0.xml", 153 "ivy-1.1.xml", 154 "ivy-1.2.xml", 155 "ivy-1.3.xml"}); 156 157 Iterator baseVfsURIs = helper.createVFSUriSet(testFolder).iterator(); 158 while(baseVfsURIs.hasNext()) { 159 VfsURI baseVfsURI = (VfsURI) baseVfsURIs.next(); 160 161 List expected = new ArrayList (); 162 for (int i = 0; i < expectedFiles.size(); i++) { 163 String resId = baseVfsURI.toString() + "/" + expectedFiles.get(i); 164 expected.add(resId); 165 } 166 167 List actual = new ArrayList (); 168 VfsResource res = new VfsResource(baseVfsURI.toString(), helper.fsManager); 169 Iterator children = res.getChildren().iterator(); 170 while (children.hasNext()) { 171 String resId = (String ) children.next(); 172 if (! resId.endsWith(".svn")) { 174 actual.add(resId); 175 } 176 } 177 178 Collections.sort(actual); 179 Collections.sort(expected); 180 if (! actual.equals(expected)) { 181 fail("\nExpected: " + expected.toString() + "\n.Actual: " + actual.toString()); 182 } 183 } 184 } 185 186 191 public void testListFileChildren() throws Exception { 192 Iterator testSet = helper.createVFSUriSet(VfsTestHelper.TEST_IVY_XML).iterator(); 193 while (testSet.hasNext()) { 194 VfsURI vfsURI = (VfsURI) testSet.next(); 195 VfsResource res = new VfsResource(vfsURI.toString(), helper.fsManager); 196 List results = res.getChildren(); 197 if (results.size() > 0) { 198 fail("getChildren query on file provided results when it shouldn't have"); 199 } 200 } 201 } 202 203 208 public void testListImaginary() throws Exception { 209 Iterator testSet = helper.createVFSUriSet("idontexistzzxx").iterator(); 210 while (testSet.hasNext()) { 211 VfsURI vfsURI = (VfsURI) testSet.next(); 212 VfsResource res = new VfsResource(vfsURI.toString(), helper.fsManager); 213 List results = res.getChildren(); 214 if (results.size() > 0) { 215 fail("getChildren query on file provided results when it shouldn't have"); 216 } 217 } 218 } 219 } 220 221 | Popular Tags |