View Javadoc
1   /*
2    * The MIT License
3    *
4    * Copyright (c) 2004, The Codehaus
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  package org.codehaus.plexus.archiver.manager;
25  
26  import java.io.File;
27  import org.codehaus.plexus.PlexusTestCase;
28  import org.codehaus.plexus.archiver.Archiver;
29  import org.codehaus.plexus.archiver.UnArchiver;
30  
31  /**
32   * @author Dan T. Tran
33   */
34  public class ArchiverManagerTest
35      extends PlexusTestCase
36  {
37  
38      public void testLookupArchiver()
39          throws Exception
40      {
41          ArchiverManager manager = (ArchiverManager) lookup( ArchiverManager.ROLE );
42  
43          Archiver archiver = manager.getArchiver( "jar" );
44          assertNotNull( archiver );
45      }
46  
47      public void testReuseArchiver()
48          throws Exception
49      {
50          ArchiverManager manager = (ArchiverManager) lookup( ArchiverManager.ROLE );
51  
52          Archiver archiver = manager.getArchiver( "jar" );
53          assertNotNull( archiver );
54  
55          archiver.addDirectory( new File( getBasedir() ) );
56  
57          Archiver newArchiver = manager.getArchiver( "jar" );
58          assertNotNull( newArchiver );
59          assertFalse( newArchiver.equals( archiver ) );
60  
61          assertTrue( !newArchiver.getResources().hasNext() );
62      }
63  
64      public void testLookupUnArchiver()
65          throws Exception
66      {
67          ArchiverManager manager = (ArchiverManager) lookup( ArchiverManager.ROLE );
68  
69          UnArchiver unarchiver = manager.getUnArchiver( "zip" );
70          assertNotNull( unarchiver );
71      }
72  
73      public void testLookupUnknownArchiver()
74          throws Exception
75      {
76          ArchiverManager manager = (ArchiverManager) lookup( ArchiverManager.ROLE );
77          try
78          {
79              manager.getArchiver( "Unknown" );
80              fail();
81          }
82          catch ( NoSuchArchiverException ignore )
83          {
84          }
85      }
86  
87      public void testLookupUnknownUnArchiver()
88          throws Exception
89      {
90          ArchiverManager manager = (ArchiverManager) lookup( ArchiverManager.ROLE );
91          try
92          {
93              manager.getUnArchiver( "Unknown" );
94              fail();
95          }
96          catch ( NoSuchArchiverException ignore )
97          {
98          }
99      }
100 
101     public void testLookupUnArchiverUsingFile()
102         throws Exception
103     {
104         ArchiverManager manager = (ArchiverManager) lookup( ArchiverManager.ROLE );
105 
106         UnArchiver unarchiver = manager.getUnArchiver( new File( "test.tar.gz" ) );
107         assertNotNull( unarchiver );
108 
109         unarchiver = manager.getUnArchiver( new File( "test.tar.bz2" ) );
110         assertNotNull( unarchiver );
111 
112         unarchiver = manager.getUnArchiver( new File( "test.tgz" ) );
113         assertNotNull( unarchiver );
114 
115         unarchiver = manager.getUnArchiver( new File( "test.tbz2" ) );
116         assertNotNull( unarchiver );
117 
118         unarchiver = manager.getUnArchiver( new File( "test.bzip2" ) );
119         assertNotNull( unarchiver );
120 
121         unarchiver = manager.getUnArchiver( new File( "test.tar" ) );
122         assertNotNull( unarchiver );
123 
124     }
125 
126     public void testLookupArchiverUsingFile()
127         throws Exception
128     {
129         ArchiverManager manager = (ArchiverManager) lookup( ArchiverManager.ROLE );
130 
131         Archiver archiver = manager.getArchiver( new File( "test.gzip" ) );
132         assertNotNull( archiver );
133 
134         archiver = manager.getArchiver( new File( "test.bzip2" ) );
135         assertNotNull( archiver );
136 
137         archiver = manager.getArchiver( new File( "test.tar" ) );
138         assertNotNull( archiver );
139 
140     }
141 
142     public void testUnspportedLookupArchiverUsingFile()
143         throws Exception
144     {
145         ArchiverManager manager = (ArchiverManager) lookup( ArchiverManager.ROLE );
146 
147         try
148         {
149             manager.getArchiver( new File( "test.tbz2" ) );
150             //until we support this type, this must fail
151             fail( "Please remove this test." );
152         }
153         catch ( NoSuchArchiverException ignore )
154         {
155 
156         }
157 
158         try
159         {
160             manager.getArchiver( new File( "test.tgz" ) );
161             //until we support this type, this must fail
162             fail( "Please remove this test." );
163         }
164         catch ( NoSuchArchiverException ignore )
165         {
166 
167         }
168 
169         try
170         {
171             manager.getArchiver( new File( "test.tar.gz" ) );
172             //until we support this type, this must fail
173             fail( "Please remove this test." );
174         }
175         catch ( NoSuchArchiverException ignore )
176         {
177 
178         }
179 
180         try
181         {
182             manager.getArchiver( new File( "test.tar.bz2" ) );
183             //until we support this type, this must fail
184             fail( "Please remove this test." );
185         }
186         catch ( NoSuchArchiverException ignore )
187         {
188 
189         }
190     }
191 
192 }