Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.uberfire.io.attribute;
  
  import java.io.File;
  import java.net.URI;
  import java.util.Date;
  import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.junit.Test;
 import  org.uberfire.java.nio.base.version.VersionAttributeView;
 import  org.uberfire.java.nio.file.Files;
 import  org.uberfire.java.nio.file.OpenOption;
 import  org.uberfire.java.nio.file.Path;
 import  org.uberfire.java.nio.file.attribute.FileAttribute;
 
 import static org.junit.Assert.*;

 
 public class DotFileAttrViewTest {
 
     protected static final List<FiletempFiles = new ArrayList<File>();
 
     private static boolean created = false;
 
     @Test
     public void testDotFileAttrAccess() throws IOException {
         final URI newRepo = URI.create"git://" + new Date().getTime() + "-repo-test" );
         ioService().newFileSystemnewReponew HashMap<StringObject>() );
 
         final Path dir = ioService().getnewRepo );
         final Path file = dir.resolve( "myFile.txt" );
 
         ioService().writefile"mycontent", Collections.<OpenOption>emptySet() );
 
         {
             final DublinCoreView view = ioService().getFileAttributeViewfileDublinCoreView.class );
 
             assertNotNullview );
 
             assertNotNullview.readAttributes() );
 
             assertNotNullview.readAttributes().languages() );
 
             assertEquals( 0, view.readAttributes().languages().size() );
         }
 
         ioService().writefile"mycontent", Collections.<OpenOption>emptySet(), new FileAttribute<Object>() {
                                @Override
                                public String name() {
                                    return "dcore.creator";
                                }
 
                                @Override
                                public Object value() {
                                    return "some user name here";
                                }
                            }, new FileAttribute<Object>() {
                                @Override
                                public String name() {
                                    return "dcore.language[0]";
                                }
 
                                @Override
                                public Object value() {
                                    return "en";
                                }
                            }, new FileAttribute<Object>() {
                                @Override
                                public String name() {
                                    return "dcore.language[1]";
                                }
 
                                @Override
                                public Object value() {
                                    return "pt-BR";
                                }
                            }
                          );
 
         {
             final DublinCoreView view = ioService().getFileAttributeViewfileDublinCoreView.class );
 
             assertNotNullview );
 
             assertNotNullview.readAttributes() );
 
             assertNotNullview.readAttributes().languages() );
            assertEquals( 2, view.readAttributes().languages().size() );
            assertTrueview.readAttributes().languages().contains"pt-BR" ) );
            assertTrueview.readAttributes().languages().contains"en" ) );
            assertEquals( 1, view.readAttributes().creators().size() );
            assertTrueview.readAttributes().creators().contains"some user name here" ) );
        }
        final Path dotFile = file.getParent().resolve( ".myFile.txt" );
        assertTrue( Files.exists( dotFile ) );
        final VersionAttributeView attrs = Files.getFileAttributeView( dotFile, VersionAttributeView.class );
        assertEquals( 1, attrs.readAttributes().history().records().size() );
        final Map<StringObjectresult = Files.readAttributes( dotFile"*" );
        assertNotNullresult );
    }
    protected static IOService ioService = null;
    public IOService ioService() {
        if (  == null ) {
             = new IOServiceDotFileImpl();
        }
        return ;
    }
    @Before
    public void setup() throws IOException {
        if ( ! ) {
            final String path = createTempDirectory().getAbsolutePath();
            System.setProperty"org.uberfire.nio.git.dir"path );
            ..println".niogit: " + path );
            final URI newRepo = URI.create"git://repo-test" );
            try {
                ioService().newFileSystemnewReponew HashMap<StringObject>() );
            } catch ( final Exception ex ) {
            } finally {
                 = true;
            }
        }
    }
    @AfterClass
    public static void cleanup() {
        for ( final File tempFile :  ) {
            FileUtils.deleteQuietlytempFile );
        }
    }
    public static File createTempDirectory()
            throws IOException {
        final File temp = File.createTempFile"temp", Long.toString( System.nanoTime() ) );
        if ( !( temp.delete() ) ) {
            throw new IOException"Could not delete temp file: " + temp.getAbsolutePath() );
        }
        if ( !( temp.mkdir() ) ) {
            throw new IOException"Could not create temp directory: " + temp.getAbsolutePath() );
        }
        .addtemp );
        return temp;
    }
New to GrepCode? Check out our FAQ X