Merged WOLF-6 (WOLF.0.0) to 5.1.1 (5.1.1)

121758 nsmintanca: Merged 5.0.N (5.0.4) to WOLF-6 (WOLF.0.0)
      121690 mrogers: UTF-370 - Replace TgZFormatIntegrationTest with ZipFormatIntegrationTest


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/services/full-installer/branches/5.1.1@123969 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2016-03-15 11:24:28 +00:00
parent d02014dca3
commit 31137f6ebe

View File

@@ -1,128 +1,124 @@
/* /*
* Copyright 2005-2015 Alfresco Software, Ltd. All rights reserved. * Copyright 2005-2015 Alfresco Software, Ltd. All rights reserved.
* *
* License rights for this program may be obtained from Alfresco Software, Ltd. * License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an * pursuant to a written agreement and any use of this program without such an
* agreement is prohibited. * agreement is prohibited.
*/ */
package org.alfresco.update.pkg.test; package org.alfresco.update.pkg.test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveStreamFactory; import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorException;
import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorInputStream;
import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.apache.commons.compress.compressors.CompressorStreamFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
/** /**
* Tests for the tgz format packaging. * Tests for the tgz format packaging.
* *
* To run these tests in Eclipse, add the following to the "VM arguments" for the junit Run Configuration: * To run these tests in Eclipse, add the following to the "VM arguments" for the junit Run Configuration:
* <pre> * <pre>
* -Dalfresco.update.package.tgz=target/alfresco-enterprise-update-package-2015-1-EA-SNAPSHOT.zip * -Dalfresco.update.package.zip=target/alfresco-enterprise-update-package-2015-1-EA-SNAPSHOT.zip
* </pre> * </pre>
* *
* @author Matt Ward * @author Matt Ward
*/ */
public class TgzFormatIntegrationTest extends AbstractIntegrationTest public class ZipFormatIntegrationTest extends AbstractIntegrationTest
{ {
private boolean found; private boolean found;
File updatePackage; @Before
public void setUp() throws Exception
@Before {
public void setUp() throws Exception super.setUp();
{ }
super.setUp();
String pkgName = System.getProperty("alfresco.update.package.tgz"); public final String ARTIFACT_NAME="alfresco-enterprise-update-package-";
assertNotNull("Could not determine package name.", pkgName);
updatePackage = new File(pkgName); @Test
} public void applyUpdatesScriptHasExecutableBitsSet() throws FileNotFoundException, ArchiveException, IOException, CompressorException
{
public final String ARTIFACT_NAME="alfresco-enterprise-update-package-";
if (runningOnWindows())
@Test {
public void applyUpdatesScriptHasExecutableBitsSet() throws FileNotFoundException, ArchiveException, IOException, CompressorException // This is a Unix only test.
{ return;
}
if (runningOnWindows())
{ File archive = new File(targetDir, ARTIFACT_NAME+version+".zip");
// This is a Unix only test. assertTrue("File does not exist: "+archive, archive.exists());
return; FileInputStream fis = null;
} try
{
assertTrue("File does not exist: "+ updatePackage, updatePackage.exists()); fis = new FileInputStream(archive);
FileInputStream fis = null;
try handleArchiveEntries(fis, new ArchiveEntryHandler()
{ {
fis = new FileInputStream(updatePackage); @Override
public boolean handle(ZipArchiveEntry entry)
handleArchiveEntries(fis, new ArchiveEntryHandler() {
{ System.out.println("Handling tar entry: "+entry.getName());
@Override if (entry.getName().equals(ARTIFACT_NAME+version+"/apply_updates.sh"))
public boolean handle(TarArchiveEntry entry) {
{ System.out.println("Found the unix shell wrapper script.");
System.out.println("Handling tar entry: "+entry.getName());
if (entry.getName().contains("/apply_updates.sh")) final int expectedPerms = 0755;
{ // Other bits may be set, but check 755 octal are set.
System.out.println("Found the unix shell wrapper script."); System.out.println("File has permissions: "+Integer.toString(entry.getUnixMode(), 8));
assertEquals(expectedPerms, entry.getUnixMode() & expectedPerms);
final int expectedPerms = 0755; found = true;
// Other bits may be set, but check 755 octal are set. }
System.out.println("File has permissions: "+Integer.toString(entry.getMode(), 8)); return !found;
assertEquals(expectedPerms, entry.getMode() & expectedPerms); }
found = true; });
}
return !found; assertTrue("apply_updates.sh is a required file.", found);
} }
}); finally
{
assertTrue("apply_updates.sh is a required file.", found); if (fis != null)
} {
finally fis.close();
{ }
if (fis != null) }
{ }
fis.close();
} private static interface ArchiveEntryHandler
} {
} boolean handle(ZipArchiveEntry entry);
}
private static interface ArchiveEntryHandler
{ private void handleArchiveEntries(InputStream raw, ArchiveEntryHandler handler) throws ArchiveException, IOException, CompressorException
boolean handle(TarArchiveEntry entry); {
} try
(
private void handleArchiveEntries(InputStream raw, ArchiveEntryHandler handler) throws ArchiveException, IOException, CompressorException BufferedInputStream bis = new BufferedInputStream(raw);
{ //CompressorInputStream gzIs = new CompressorStreamFactory().createCompressorInputStream(bis);
try BufferedInputStream bgzIs = new BufferedInputStream(bis);
( ZipArchiveInputStream aris = (ZipArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(bgzIs);
BufferedInputStream bis = new BufferedInputStream(raw); )
CompressorInputStream gzIs = new CompressorStreamFactory().createCompressorInputStream(bis); {
BufferedInputStream bgzIs = new BufferedInputStream(gzIs); ZipArchiveEntry entry = null;
TarArchiveInputStream aris = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(bgzIs); boolean carryOn = true;
) while (carryOn && (entry = aris.getNextZipEntry()) != null)
{ {
TarArchiveEntry entry = null; carryOn = handler.handle(entry);
boolean carryOn = true; }
while (carryOn && (entry = aris.getNextTarEntry()) != null) }
{ }
carryOn = handler.handle(entry); }
}
}
}
}