View Javadoc
1   package org.codehaus.plexus.archiver.zip;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.io.InputStream;
6   import java.util.HashMap;
7   import java.util.HashSet;
8   import java.util.Iterator;
9   import java.util.Map;
10  import java.util.Set;
11  import org.codehaus.plexus.PlexusTestCase;
12  import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier;
13  import org.codehaus.plexus.components.io.resources.PlexusIoResource;
14  
15  public class PlexusArchiverZipFileResourceCollectionTest
16      extends PlexusTestCase
17  {
18  
19      public void testFilesWithIllegalHtmlChars()
20          throws Exception
21      {
22          File testZip = new File( getBasedir(), "src/test/resources/archiveWithIllegalHtmlFileName.zip" );
23          Set<String> seen = new HashSet<String>();
24          seen.add( "AFileThatNeedsHtmlEsc%3F&gt" );
25          seen.add( "Afile&lt;Yo&gt;.txt" );
26          seen.add( "File With Space.txt" );
27          seen.add( "FileWith%.txt" );
28          PlexusArchiverZipFileResourceCollection prc = new PlexusArchiverZipFileResourceCollection();
29          prc.setFile( testZip );
30          final Iterator<PlexusIoResource> entries = prc.getEntries();
31          while ( entries.hasNext() )
32          {
33              final PlexusIoResource next = entries.next();
34              assertTrue( next.getName() + "was not present", seen.remove( next.getName() ) );
35              final InputStream contents = next.getContents();
36              contents.close();
37          }
38      }
39  
40      public void testFileModes()
41          throws IOException
42      {
43          File testZip = new File( getBasedir(), "src/test/resources/zeroFileMode/mixed-file-mode.zip" );
44          Map<String, Integer> originalUnixModes = new HashMap<String, Integer>();
45          originalUnixModes.put( "platform-fat", -1 );
46          originalUnixModes.put( "zero-unix-mode", 0 );
47          // ---xrw-r-- the crazy permissions are on purpose so we don't hit some default value
48          originalUnixModes.put( "non-zero-unix-mode", 0164 );
49          PlexusArchiverZipFileResourceCollection prc = new PlexusArchiverZipFileResourceCollection();
50          prc.setFile( testZip );
51          Iterator<PlexusIoResource> entries = prc.getEntries();
52          while ( entries.hasNext() )
53          {
54              PlexusIoResource entry = entries.next();
55              int entryUnixMode = ( (ResourceAttributeSupplier) entry ).getAttributes().getOctalMode();
56              int originalUnixMode = (int) originalUnixModes.get( entry.getName() );
57              assertEquals( originalUnixMode, entryUnixMode );
58          }
59      }
60  
61  }