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

@@ -20,8 +20,8 @@ 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;
@@ -33,24 +33,19 @@ import org.junit.Test;
* *
* 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 @Before
public void setUp() throws Exception public void setUp() throws Exception
{ {
super.setUp(); super.setUp();
String pkgName = System.getProperty("alfresco.update.package.tgz");
assertNotNull("Could not determine package name.", pkgName);
updatePackage = new File(pkgName);
} }
public final String ARTIFACT_NAME="alfresco-enterprise-update-package-"; public final String ARTIFACT_NAME="alfresco-enterprise-update-package-";
@@ -59,32 +54,33 @@ public class TgzFormatIntegrationTest extends AbstractIntegrationTest
public void applyUpdatesScriptHasExecutableBitsSet() throws FileNotFoundException, ArchiveException, IOException, CompressorException public void applyUpdatesScriptHasExecutableBitsSet() throws FileNotFoundException, ArchiveException, IOException, CompressorException
{ {
if (runningOnWindows()) if (runningOnWindows())
{ {
// This is a Unix only test. // This is a Unix only test.
return; return;
} }
assertTrue("File does not exist: "+ updatePackage, updatePackage.exists()); File archive = new File(targetDir, ARTIFACT_NAME+version+".zip");
assertTrue("File does not exist: "+archive, archive.exists());
FileInputStream fis = null; FileInputStream fis = null;
try try
{ {
fis = new FileInputStream(updatePackage); fis = new FileInputStream(archive);
handleArchiveEntries(fis, new ArchiveEntryHandler() handleArchiveEntries(fis, new ArchiveEntryHandler()
{ {
@Override @Override
public boolean handle(TarArchiveEntry entry) public boolean handle(ZipArchiveEntry entry)
{ {
System.out.println("Handling tar entry: "+entry.getName()); System.out.println("Handling tar entry: "+entry.getName());
if (entry.getName().contains("/apply_updates.sh")) if (entry.getName().equals(ARTIFACT_NAME+version+"/apply_updates.sh"))
{ {
System.out.println("Found the unix shell wrapper script."); System.out.println("Found the unix shell wrapper script.");
final int expectedPerms = 0755; final int expectedPerms = 0755;
// Other bits may be set, but check 755 octal are set. // Other bits may be set, but check 755 octal are set.
System.out.println("File has permissions: "+Integer.toString(entry.getMode(), 8)); System.out.println("File has permissions: "+Integer.toString(entry.getUnixMode(), 8));
assertEquals(expectedPerms, entry.getMode() & expectedPerms); assertEquals(expectedPerms, entry.getUnixMode() & expectedPerms);
found = true; found = true;
} }
return !found; return !found;
@@ -104,7 +100,7 @@ public class TgzFormatIntegrationTest extends AbstractIntegrationTest
private static interface ArchiveEntryHandler private static interface ArchiveEntryHandler
{ {
boolean handle(TarArchiveEntry entry); boolean handle(ZipArchiveEntry entry);
} }
private void handleArchiveEntries(InputStream raw, ArchiveEntryHandler handler) throws ArchiveException, IOException, CompressorException private void handleArchiveEntries(InputStream raw, ArchiveEntryHandler handler) throws ArchiveException, IOException, CompressorException
@@ -112,14 +108,14 @@ public class TgzFormatIntegrationTest extends AbstractIntegrationTest
try try
( (
BufferedInputStream bis = new BufferedInputStream(raw); BufferedInputStream bis = new BufferedInputStream(raw);
CompressorInputStream gzIs = new CompressorStreamFactory().createCompressorInputStream(bis); //CompressorInputStream gzIs = new CompressorStreamFactory().createCompressorInputStream(bis);
BufferedInputStream bgzIs = new BufferedInputStream(gzIs); BufferedInputStream bgzIs = new BufferedInputStream(bis);
TarArchiveInputStream aris = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(bgzIs); ZipArchiveInputStream aris = (ZipArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(bgzIs);
) )
{ {
TarArchiveEntry entry = null; ZipArchiveEntry entry = null;
boolean carryOn = true; boolean carryOn = true;
while (carryOn && (entry = aris.getNextTarEntry()) != null) while (carryOn && (entry = aris.getNextZipEntry()) != null)
{ {
carryOn = handler.handle(entry); carryOn = handler.handle(entry);
} }