Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.uberfire.io.attribute;
  
  import java.io.File;
  import java.util.List;
  
 import org.junit.Test;
 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 DublinCoreTest {
 
     protected static final List<FiletempFiles = new ArrayList<File>();
 
     @Test
     public void testDCore() throws IOException {
         final Path dir = ioService().getcreateTempDirectory().toURI() );
         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" ) );
         }
 
         ioService().setAttributesfilenew FileAttribute<Object>() {
            @Override
            public String name() {
                return "dcore.identifier";
            }
            @Override
            public Object value() {
                return file.toUri().toString();
            }
        } );
        {
            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" ) );
            assertEquals( 1, view.readAttributes().identifiers().size() );
            assertTrueview.readAttributes().identifiers().containsfile.toUri().toString() ) );
        }
    }
    protected static IOService ioService = null;
    public IOService ioService() {
        if (  == null ) {
             = new IOServiceDotFileImpl();
        }
        return ;
    }
    @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