12 Replies Latest reply on Nov 6, 2007 2:21 PM by alesj

    Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS

    alesj

      I get a failing VFS test - FileVFSUnitTestCase.testVFSFileURIFactory.

      java.io.IOException: No context factory for vfsfile:/C:/projects/jboss-vfs/target/test-classes/
       at org.jboss.virtual.VFS.getVFS(VFS.java:85)
       at org.jboss.test.virtual.test.FileVFSUnitTestCase.testVFSFileURIFactory(FileVFSUnitTestCase.java:104)
       at org.jboss.test.virtual.test.FileVFSUnitTestCase.testVFSFileURIFactory(FileVFSUnitTestCase.java:104)


      There was this in VirtualFile:
       public URL toURL() throws MalformedURLException, URISyntaxException
       {
       return getHandler().toVfsUrl();
       }
      


      I guess it needs to be changed to:
       public URL toURL() throws MalformedURLException, URISyntaxException
       {
       return getHandler().toURL();
       }
      


        • 1. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
          alesj

          But this then breaks AbstractVFSContextTest.testGetVFS:

           public void testGetVFS() throws Exception
           {
           VFSContext context = getVFSContext("simple");
           URI rootURI = context.getRootURI();
           VFS vfs = context.getVFS();
           VirtualFile rootFile = vfs.getRoot();
          
           URI uri = new URI("vfs" + rootURI);
           URI rfUri = rootFile.toURI();
           assertEquals(uri, rfUri);
           }
          


          What's the deal here?
          Are both tests OK?

          Fixing transformation between uri/url?
          Or adding simple vfs* context factories?

          • 2. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
            starksm64
            • 3. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
              alesj

               

              "scott.stark@jboss.org" wrote:
              This is http://jira.jboss.com/jira/browse/JBMICROCONT-155.

              Uf, I need to start looking at the JIRA issues first. Specially if they are assigned to me. :-)

              I'm almost done with '..', getting the first simple tests to pass.

              • 4. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                alesj

                What can be the reason my File.delete() doesn't return true == doesn't really delete the file?
                Security issues?

                Getting all those tests that should delete to fail ...

                • 5. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                  starksm64

                  Permissions on the file system, a directory that is not empty are the main reasons.

                  • 6. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                    alesj

                     

                    "scott.stark@jboss.org" wrote:
                    Permissions on the file system, a directory that is not empty are the main reasons.

                    Even for a temp file?
                     public void testFileURLs()
                     throws Exception
                     {
                     File tmp = File.createTempFile("testFileURLs", null);
                     URL tmpURL = tmp.toURL();
                     URLConnection conn = tmpURL.openConnection();
                     long lastModified = conn.getLastModified();
                     System.out.println("lastModified, "+lastModified);
                     assertNotSame("lastModified", 0, lastModified);
                     assertTrue(tmp.getAbsolutePath()+" deleted", tmp.delete());
                     conn = tmpURL.openConnection();
                     lastModified = conn.getLastModified();
                     System.out.println("lastModified after delete, "+lastModified);
                     assertEquals("lastModified", 0, lastModified);
                     }
                    


                    • 7. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                      starksm64

                      I imagine its because of the URLConnection having the file open. This is one of the problems with the url handler apis, no way to close/disconnect. Try getting the InputStream and closing that before deleting the file.

                      • 8. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                        alesj

                        This - JBMICROCONT-155 - is fixed in the trunk.

                        Will see what I can do with these open/undeletable files.

                        • 9. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                          alesj

                          What needs to be closed here

                           public void testFileExists()
                           throws Exception
                           {
                           File tmpRoot = File.createTempFile("vfs", ".root");
                           tmpRoot.delete();
                           tmpRoot.mkdir();
                           File tmp = File.createTempFile("testFileExists", null, tmpRoot);
                           log.info("+++ testFileExists, tmp="+tmp.getCanonicalPath());
                          
                           URL rootURL = tmpRoot.toURL();
                           VFS vfs = VFS.getVFS(rootURL);
                           VirtualFile tmpVF = vfs.findChild(tmp.getName());
                           assertTrue(tmpVF.getPathName()+".exists()", tmpVF.exists());
                           assertTrue("tmp.delete()", tmp.delete());
                           assertFalse(tmpVF.getPathName()+".exists()", tmpVF.exists());
                           assertTrue(tmpRoot+".delete()", tmpRoot.delete());
                           }
                          

                          in order to be able to delete tmp file on Winz?

                          This worked for the URLConnection test case:
                           InputStream in = conn.getInputStream();
                           long lastModified;
                           try
                           {
                           lastModified = conn.getLastModified();
                           System.out.println("lastModified, "+lastModified);
                           assertNotSame("lastModified", 0, lastModified);
                           }
                           finally
                           {
                           in.close();
                           }
                           assertTrue(tmp.getAbsolutePath()+" deleted", tmp.delete());
                          


                          • 10. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                            starksm64

                            What delete fails? I can't see how the testFileExists delete should fail.

                            • 11. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                              alesj

                               

                              "scott.stark@jboss.org" wrote:
                              What delete fails? I can't see how the testFileExists delete should fail.

                              If you run this test case on Winz, the file is not deleted, so File.delete (tmp.delete()) doesn't return true.


                              • 12. Re: Failing FileVFSUnitTestCase.testVFSFileURIFactory in VFS
                                alesj

                                 

                                "alesj" wrote:
                                "scott.stark@jboss.org" wrote:
                                What delete fails? I can't see how the testFileExists delete should fail.

                                If you run this test case on Winz, the file is not deleted, so File.delete (tmp.delete()) doesn't return true.

                                Since, similar to URLExistsUnitTestCase, looks like something is again holding the resources.
                                3500 DEBUG [FileVFSUnitTestCase] ==== Starting testFileExists ====
                                3500 INFO [FileVFSUnitTestCase] +++ testFileExists, tmp=C:\tmp\vfs\vfs33660.root\testFileExists33661.tmp
                                3500 DEBUG [FileVFSUnitTestCase] testFileExists took 0ms
                                3500 DEBUG [FileVFSUnitTestCase] ==== Stopping testFileExists ====
                                
                                junit.framework.AssertionFailedError: tmp.delete()
                                 at org.jboss.test.virtual.test.FileVFSUnitTestCase.testFileExists(FileVFSUnitTestCase.java:1287)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)