35
35
36
36
import junit .framework .Assert ;
37
37
38
- import org .apache .commons .logging .Log ;
39
38
import org .codehaus .plexus .util .FileUtils ;
40
39
import org .codehaus .plexus .util .IOUtil ;
41
40
import org .junit .Test ;
@@ -63,9 +62,10 @@ public class BaseTest extends AbstractTestCase {
63
62
*/
64
63
@ Test
65
64
public void testChannelXml () throws Exception {
65
+ unzipPearNet ();
66
66
final IPearUtility util = getPearUtility (false );
67
67
68
- final File pearFolder = new File ("pear.php.net" ).getAbsoluteFile ();
68
+ final File pearFolder = new File ("target/ pear.php.net" ).getAbsoluteFile ();
69
69
final IPearChannel channel = util .channelDiscoverLocal (pearFolder );
70
70
Assert .assertNotNull (channel );
71
71
Assert .assertNotNull (channel .getPrimaryServer ());
@@ -251,12 +251,13 @@ public void testVersionData() throws Exception {
251
251
*/
252
252
@ Test
253
253
public void testPackageInstallation () throws Exception {
254
- final IPearChannel channel = getChannel (true );
255
- final IPackage pkg = channel .getPackage ("Auth" );
256
- final IPackageVersion version = pkg .getVersion ("1.6.4" );
254
+ final IPearUtility util = getPearUtility (true , true );
255
+ final IPearChannel channel = util .lookupChannel ("pear" );
256
+ final IPackage pkg = channel .getPackage ("Validate_AT" );
257
+ final IPackageVersion version = pkg .getVersion ("0.5.2" );
257
258
Assert .assertNull (pkg .getInstalledVersion ());
258
259
version .install ();
259
- Assert .assertEquals ("1.6.4 " , pkg .getInstalledVersion ().getVersion ().getPearVersion ());
260
+ Assert .assertEquals ("0.5.2 " , pkg .getInstalledVersion ().getVersion ().getPearVersion ());
260
261
261
262
Assert .assertTrue (
262
263
channel .getPearUtility ().getPhpDir ().getAbsolutePath ().startsWith (
@@ -312,7 +313,7 @@ public void testVersionMapping() throws Exception {
312
313
Assert .assertEquals ("1.5.0-RC1" , PackageHelper .convertPearVersionToMavenVersion ("1.5.0RC1" ));
313
314
Assert .assertEquals ("1.3.0-r3" , PackageHelper .convertPearVersionToMavenVersion ("1.3.0r3" ));
314
315
Assert .assertEquals ("2.0.0-dev1" , PackageHelper .convertPearVersionToMavenVersion ("2.0.0dev1" ));
315
- Assert .assertEquals ("1.2.2beta1 " , PackageHelper .convertPearVersionToMavenVersion ("1.2.2-beta-1 " ));
316
+ Assert .assertEquals ("1.2.2-beta-1 " , PackageHelper .convertPearVersionToMavenVersion ("1.2.2beta1 " ));
316
317
Assert .assertEquals ("0.9.7-dev" , PackageHelper .convertPearVersionToMavenVersion ("0.9.7dev" ));
317
318
Assert .assertEquals ("0.5.2-beta" , PackageHelper .convertPearVersionToMavenVersion ("0.5.2beta" ));
318
319
Assert .assertEquals ("1.4-beta-1" , PackageHelper .convertPearVersionToMavenVersion ("1.4b1" ));
@@ -408,24 +409,33 @@ public void testFileLayoutV2() throws Exception {
408
409
*/
409
410
private IPearChannel getChannel (final boolean install )
410
411
throws Exception {
412
+ unzipPearNet ();
411
413
final IPearUtility util = getPearUtility (install );
412
414
413
- final File pearFolder = new File ("pear.php.net" ).getAbsoluteFile ();
415
+ final File pearFolder = new File ("target/ pear.php.net" ).getAbsoluteFile ();
414
416
final IPearChannel channel = util .channelDiscoverLocal (pearFolder );
415
417
return channel ;
416
418
}
417
419
420
+ private void unzipPearNet () throws IOException {
421
+ final File target = new File ("target/pear.php.net" );
422
+ if (!target .exists ()) {
423
+ target .mkdirs ();
424
+ final File pearZip = new File (
425
+ "target/test-classes/org/phpmaven/pear/library/test/pear.php.net.zip" );
426
+ unzip (pearZip , target .getParentFile ());
427
+ }
428
+ }
429
+
418
430
/**
419
431
* Unpacks a zip file.
420
432
*
421
- * @param log Logging
422
433
* @param zipFile the zip file
423
434
* @param destDir the destination directory
424
435
* @throws IOException if something goes wrong
425
436
*/
426
- private void unzip (Log log , File zipFile , File destDir ) throws IOException {
437
+ private void unzip (File zipFile , File destDir ) throws IOException {
427
438
final ZipFile zip = new ZipFile (zipFile );
428
- log .debug ("unzip " + zipFile .getAbsolutePath ());
429
439
430
440
final Enumeration <? extends ZipEntry > items = zip .entries ();
431
441
while (items .hasMoreElements ()) {
@@ -476,7 +486,19 @@ private void unpackZipEntry(ZipEntry zipEntry, InputStream zipEntryInputStream,
476
486
* @return
477
487
* @throws Exception
478
488
*/
479
- private IPearUtility getPearUtility (final boolean install )
489
+ private IPearUtility getPearUtility (final boolean install )
490
+ throws Exception {
491
+ return this .getPearUtility (install , false );
492
+ }
493
+
494
+ /**
495
+ * Returns the pear utility.
496
+ * @param install
497
+ * @return
498
+ * @throws Exception
499
+ */
500
+ @ SuppressWarnings ("unchecked" )
501
+ private IPearUtility getPearUtility (final boolean install , final boolean upgrade )
480
502
throws Exception {
481
503
final File testDir = new File ("target/test" ).getAbsoluteFile ();
482
504
FileUtils .deleteDirectory (testDir );
@@ -489,7 +511,7 @@ private IPearUtility getPearUtility(final boolean install)
489
511
}
490
512
491
513
if (install ) {
492
- util .installPear (false );
514
+ util .installPear (upgrade );
493
515
}
494
516
return util ;
495
517
}
0 commit comments