You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Antonio Terreno (JIRA)" <ji...@apache.org> on 2009/01/15 12:18:00 UTC

[jira] Created: (VFS-234) Can't listen to file modifications, event raised is fileCreated rather than fileChanged

Can't listen to file modifications, event raised is fileCreated rather than fileChanged
---------------------------------------------------------------------------------------

                 Key: VFS-234
                 URL: https://issues.apache.org/jira/browse/VFS-234
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 1.0
         Environment: Windows, Java 6
            Reporter: Antonio Terreno


It seems like that a FileCreated event is raised even when the file changes. 
I checked out the tests on the repository and the test is on file creation not modification. 

The below test uses mockito to mock the Listener, I had the same result using a real listener. 

    @Test 
    public void testShouldListenToFileChanges() throws Exception {
        FileObject child = folder.resolveFile( "fileToChange.txt" );
        FileSystem fs = folder.getFileSystem();
        
        FileMonitor defaultFileMonitor = new DefaultFileMonitor(fileListener);
        defaultFileMonitor.addFile( child );        
        fs.addListener( child, fileListener );        

        OutputStream out = child.getContent().getOutputStream();
        out.write( "bla".getBytes() );
        out.close();        
        child.getContent().close();
        
        verify( fileListener).fileCreated( argThat( isAFileChangeEventOn( child ) ) );
        verify( fileListener).fileChanged( argThat( isAFileChangeEventOn( child ) ) );
    }

class FileChangeEventMatcher extends BaseMatcher<FileChangeEvent> {
       
    private final FileObject fileObject;

    public FileChangeEventMatcher( FileObject fileObject ) {
        this.fileObject = fileObject;
    }
    
    public static FileChangeEventMatcher isAFileChangeEventOn( FileObject child ) {
        return new FileChangeEventMatcher( child );
    }

    @Override
    public boolean matches( Object obj ) {
        FileChangeEvent event = (FileChangeEvent) ( obj );

        if ( event.getFile().equals( fileObject ) )
            return true;

        return false;
    }

    @Override
    public void describeTo( Description description ) {
    }
}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (VFS-234) Can't listen to file modifications, event raised is fileCreated rather than fileChanged

Posted by "Ralph Goers (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12778225#action_12778225 ] 

Ralph Goers commented on VFS-234:
---------------------------------

Have you tested this on trunk? I am pretty sure that there are unit tests that verify the correct behavior.

> Can't listen to file modifications, event raised is fileCreated rather than fileChanged
> ---------------------------------------------------------------------------------------
>
>                 Key: VFS-234
>                 URL: https://issues.apache.org/jira/browse/VFS-234
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Windows, Java 6
>            Reporter: Antonio Terreno
>
> It seems like that a FileCreated event is raised even when the file changes. 
> I checked out the tests on the repository and the test is on file creation not modification. 
> The below test uses mockito to mock the Listener, I had the same result using a real listener. 
>     @Test 
>     public void testShouldListenToFileChanges() throws Exception {
>         FileObject child = folder.resolveFile( "fileToChange.txt" );
>         FileSystem fs = folder.getFileSystem();
>         
>         FileMonitor defaultFileMonitor = new DefaultFileMonitor(fileListener);
>         defaultFileMonitor.addFile( child );        
>         fs.addListener( child, fileListener );        
>         OutputStream out = child.getContent().getOutputStream();
>         out.write( "bla".getBytes() );
>         out.close();        
>         child.getContent().close();
>         
>         verify( fileListener).fileCreated( argThat( isAFileChangeEventOn( child ) ) );
>         verify( fileListener).fileChanged( argThat( isAFileChangeEventOn( child ) ) );
>     }
> class FileChangeEventMatcher extends BaseMatcher<FileChangeEvent> {
>        
>     private final FileObject fileObject;
>     public FileChangeEventMatcher( FileObject fileObject ) {
>         this.fileObject = fileObject;
>     }
>     
>     public static FileChangeEventMatcher isAFileChangeEventOn( FileObject child ) {
>         return new FileChangeEventMatcher( child );
>     }
>     @Override
>     public boolean matches( Object obj ) {
>         FileChangeEvent event = (FileChangeEvent) ( obj );
>         if ( event.getFile().equals( fileObject ) )
>             return true;
>         return false;
>     }
>     @Override
>     public void describeTo( Description description ) {
>     }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.