summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Bull2012-09-20 15:33:51 (EDT)
committerIan Bull2012-10-01 17:44:26 (EDT)
commitec7d2f597acf5f0048fb6d6b204a951786e42630 (patch)
tree42c496e7fe7052262dec0caf6c70480e5e5bbbd9
parent2f4b8b75353f177c3857fe09b9be6546f78ff3bb (diff)
downloadrt.equinox.p2-ec7d2f597acf5f0048fb6d6b204a951786e42630.zip
rt.equinox.p2-ec7d2f597acf5f0048fb6d6b204a951786e42630.tar.gz
rt.equinox.p2-ec7d2f597acf5f0048fb6d6b204a951786e42630.tar.bz2
Revert "Revert "Bug 387557 - stable tests""v20121001-214426
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java74
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java29
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java37
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java39
5 files changed, 103 insertions, 79 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
index 74f9529..e511f02 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
@@ -12,9 +12,12 @@ import java.lang.reflect.Field;
import java.net.URI;
import java.net.URL;
import java.util.*;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.core.helpers.URLUtil;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
@@ -1630,4 +1633,75 @@ public abstract class AbstractProvisioningTest extends TestCase {
}
fail("String:" + lines[idx] + " not found");
}
+
+ protected void assertEqualArtifacts(String message, SimpleArtifactRepository expected, SimpleArtifactRepository actual) {
+ IQueryResult expectedKeys = expected.query(ArtifactKeyQuery.ALL_KEYS, null);
+ for (Iterator iterator = expectedKeys.iterator(); iterator.hasNext();) {
+ IArtifactKey key = (IArtifactKey) iterator.next();
+ IArtifactDescriptor[] expectedDescriptors = expected.getArtifactDescriptors(key);
+ IArtifactDescriptor[] actualDescriptors = actual.getArtifactDescriptors(key);
+
+ if (expectedDescriptors == null || actualDescriptors == null)
+ if (!(expectedDescriptors == null && actualDescriptors == null))
+ fail(message + " missing key " + key);
+
+ top: for (int j = 0; j < expectedDescriptors.length; j++) {
+ for (int k = 0; k < actualDescriptors.length; k++) {
+ if (Arrays.equals(expectedDescriptors[j].getProcessingSteps(), actualDescriptors[k].getProcessingSteps())) {
+ File expectedFile = expected.getArtifactFile(expectedDescriptors[j]);
+ File actualFile = actual.getArtifactFile(actualDescriptors[k]);
+ if (expectedFile == null || actualFile == null)
+ fail(message + " descriptor mismatch");
+ if (!(expectedFile.exists() && actualFile.exists()))
+ fail(message + " file does not exist");
+ if ("jar".equals(new Path(expectedFile.getName()).getFileExtension())) {
+ //compare jar contents
+ assertEqualJars(expectedFile, actualFile);
+ } else {
+ //otherwise just compare file size
+ assertEquals("Different file: " + expectedFile.getName(), expectedFile.length(), actualFile.length());
+ }
+ continue top;
+ }
+ }
+ fail(message + "Missing expected descriptor" + expectedDescriptors[j]);
+ }
+ }
+ }
+
+ protected void assertEqualJars(File expectedFile, File actualFile) {
+ JarFile expectedJar = null, actualJar = null;
+ try {
+ expectedJar = new JarFile(expectedFile);
+ actualJar = new JarFile(actualFile);
+ int expectedEntryCount = 0, actualEntryCount = 0;
+ for (Enumeration<JarEntry> en = expectedJar.entries(); en.hasMoreElements();) {
+ expectedEntryCount++;
+ JarEntry expectedEntry = en.nextElement();
+ JarEntry actualEntry = actualJar.getJarEntry(expectedEntry.getName());
+ assertNotNull(actualEntry);
+ assertEquals("Unmatched entry size: " + expectedEntry.getName(), expectedEntry.getSize(), actualEntry.getSize());
+ }
+ for (Enumeration<JarEntry> en = expectedJar.entries(); en.hasMoreElements();) {
+ actualEntryCount++;
+ en.nextElement();
+ }
+ assertEquals("Unexpected difference in entries for " + expectedFile.getName(), expectedEntryCount, actualEntryCount);
+ } catch (IOException e) {
+ fail("Unexpected error comparing jars", e);
+ } finally {
+ ensureClosed(expectedJar);
+ ensureClosed(actualJar);
+ }
+ }
+
+ private void ensureClosed(JarFile file) {
+ if (file == null)
+ return;
+ try {
+ file.close();
+ } catch (IOException e) {
+ //ignore
+ }
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java
index b2b8f93..5bbcc59 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java
@@ -12,16 +12,16 @@ package org.eclipse.equinox.p2.tests.artifact.processors;
import java.io.*;
import java.util.Arrays;
-import junit.framework.TestCase;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.artifact.processors.pack200.Pack200ProcessorStep;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
import org.eclipse.equinox.internal.p2.jarprocessor.PackStep;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.eclipse.equinox.p2.tests.TestActivator;
import org.osgi.framework.Bundle;
-public class Pack200ProcessorTest extends TestCase {
+public class Pack200ProcessorTest extends AbstractProvisioningTest {
public Pack200ProcessorTest(String name) {
super(name);
@@ -68,6 +68,20 @@ public class Pack200ProcessorTest extends TestCase {
assertFalse(step.getStatus().isOK());
}
+ private File tempFolder;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ tempFolder = getTempFolder();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ delete(tempFolder);
+ }
+
/**
* Tests the case where we are unpacking a file that was not packed by
* our own pack step. In this case the eclipse.inf may not be present
@@ -80,21 +94,22 @@ public class Pack200ProcessorTest extends TestCase {
return;
// Setup the processor
ProcessingStep step = new Pack200ProcessorStep();
- ByteArrayOutputStream destination = new ByteArrayOutputStream();
+
+ File destinationFile = new File(tempFolder, "testUnpackFileNotPackedByJarProcessor.jar");
+ OutputStream destination = new BufferedOutputStream(new FileOutputStream(destinationFile));
step.link(destination, new NullProgressMonitor());
// drive the source data through the step
Bundle bundle = TestActivator.getContext().getBundle();
InputStream inputStream = bundle.getEntry("testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar.pack.gz").openStream();
FileUtils.copyStream(inputStream, true, step, true);
+ destination.close();
// Get the expected result
- inputStream = bundle.getEntry("testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar").openStream();
- ByteArrayOutputStream expected = new ByteArrayOutputStream();
- FileUtils.copyStream(inputStream, true, expected, true);
+ File expected = getTestData("Missing test data", "testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar");
// Compare
- assertTrue(Arrays.equals(expected.toByteArray(), destination.toByteArray()));
+ assertEqualJars(expected, destinationFile);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java
index 2918bb8..4812afd 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java
@@ -136,7 +136,8 @@ public class ProcessingStepHandlerTest extends AbstractProvisioningTest {
assertTrue("Step is not ready.", status.isOK());
InputStream inputStream = TestActivator.getContext().getBundle().getEntry("testData/jarprocessor.jar.pack.gz").openStream();
FileUtils.copyStream(inputStream, true, testStream, true);
- assertEquals(35062, result.size());
+ //the value 34759 obtained by manually unpacking the test artifact using unpack200.exe from sun 7u2 JRE
+ assertEquals(34759, result.size());
}
public void testCreateByteShifterPS() {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java
index 0cc2ef6..23806ad 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java
@@ -295,39 +295,6 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
}
/**
- * ensures that all files with entries in the repo have corresponding files on disk.
- * Not Biconditional.
- */
- private void assertFileSizes(String message, SimpleArtifactRepository expected, SimpleArtifactRepository actual) {
- IQueryResult expectedKeys = expected.query(ArtifactKeyQuery.ALL_KEYS, null);
- for (Iterator iterator = expectedKeys.iterator(); iterator.hasNext();) {
- IArtifactKey key = (IArtifactKey) iterator.next();
- IArtifactDescriptor[] expectedDescriptors = expected.getArtifactDescriptors(key);
- IArtifactDescriptor[] actualDescriptors = actual.getArtifactDescriptors(key);
-
- if (expectedDescriptors == null || actualDescriptors == null)
- if (!(expectedDescriptors == null && actualDescriptors == null))
- fail(message + " missing key " + key);
-
- top: for (int j = 0; j < expectedDescriptors.length; j++) {
- for (int k = 0; k < actualDescriptors.length; k++) {
- if (Arrays.equals(expectedDescriptors[j].getProcessingSteps(), actualDescriptors[k].getProcessingSteps())) {
- File expectedFile = expected.getArtifactFile(expectedDescriptors[j]);
- File actualFile = actual.getArtifactFile(actualDescriptors[k]);
- if (expectedFile == null || actualFile == null)
- fail(message + " descriptor mismatch");
- if (!(expectedFile.exists() && actualFile.exists()))
- fail(message + " file does not exist");
- assertTrue(expectedFile.length() == actualFile.length());
- continue top;
- }
- }
- fail(message + "Missing expected descriptor" + expectedDescriptors[j]);
- }
- }
- }
-
- /**
* Tests mirroring all artifacts in a repository to an empty repository
* Source contains A, B
* Target contains
@@ -884,7 +851,7 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
//Verify Contents
assertContentEquals("26.4", getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null));
//Verify files on disk
- assertFileSizes("26.5", (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null));
+ assertEqualArtifacts("26.5", (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null));
} catch (ProvisionException e) {
fail("26.6", e);
}
@@ -951,7 +918,7 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
fail("27.3 no canonical found for " + key.toString());
//ensure the canonical matches that in the expected
- assertFileSizes("27.3", (SimpleArtifactRepository) destinationRepo, (SimpleArtifactRepository) packedRepo);
+ assertEqualArtifacts("27.3", (SimpleArtifactRepository) destinationRepo, (SimpleArtifactRepository) packedRepo);
}
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java
index 7b240a5..624373c 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -321,39 +321,6 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
}
/**
- * ensures that all files with entries in the repo have corresponding files on disk.
- * Not Biconditional.
- */
- private void assertFileSizes(String message, SimpleArtifactRepository expected, SimpleArtifactRepository actual) {
- IQueryResult expectedKeys = expected.query(ArtifactKeyQuery.ALL_KEYS, null);
- for (Iterator iterator = expectedKeys.iterator(); iterator.hasNext();) {
- IArtifactKey key = (IArtifactKey) iterator.next();
- IArtifactDescriptor[] expectedDescriptors = expected.getArtifactDescriptors(key);
- IArtifactDescriptor[] actualDescriptors = actual.getArtifactDescriptors(key);
-
- if (expectedDescriptors == null || actualDescriptors == null)
- if (!(expectedDescriptors == null && actualDescriptors == null))
- fail(message + " missing key " + key);
-
- top: for (int j = 0; j < expectedDescriptors.length; j++) {
- for (int k = 0; k < actualDescriptors.length; k++) {
- if (Arrays.equals(expectedDescriptors[j].getProcessingSteps(), actualDescriptors[k].getProcessingSteps())) {
- File expectedFile = expected.getArtifactFile(expectedDescriptors[j]);
- File actualFile = actual.getArtifactFile(actualDescriptors[k]);
- if (expectedFile == null || actualFile == null)
- fail(message + " descriptor mismatch");
- if (!(expectedFile.exists() && actualFile.exists()))
- fail(message + " file does not exist");
- assertEquals("Unexpected difference in " + actualFile.getName(), expectedFile.length(), actualFile.length());
- continue top;
- }
- }
- fail(message + "Missing expected descriptor" + expectedDescriptors[j]);
- }
- }
- }
-
- /**
* Tests mirroring all artifacts in a repository to an empty repository
* Source contains A, B
* Target contains
@@ -904,7 +871,7 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
//Verify Contents
assertContentEquals("26.4", getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null));
//Verify files on disk
- assertFileSizes("26.5", (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null));
+ assertEqualArtifacts("26.5", (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null));
} catch (ProvisionException e) {
fail("26.6", e);
}
@@ -971,7 +938,7 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
fail("27.3 no canonical found for " + key.toString());
//ensure the canonical matches that in the expected
- assertFileSizes("27.3", (SimpleArtifactRepository) destinationRepo, (SimpleArtifactRepository) packedRepo);
+ assertEqualArtifacts("27.3", (SimpleArtifactRepository) destinationRepo, (SimpleArtifactRepository) packedRepo);
}
}
}