Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2010-03-25 21:32:34 +0000
committerAndrew Niefer2010-03-25 21:32:34 +0000
commit36f097652c0d84fdc85a61ce104e1b435a1403cf (patch)
tree995847a41a191e6d907273e7547d6f9b9617cce3 /bundles/org.eclipse.equinox.p2.tests/src/org
parenta4d3ee31129b9eeef0c583851debcf8d2305eae9 (diff)
downloadrt.equinox.p2-36f097652c0d84fdc85a61ce104e1b435a1403cf.tar.gz
rt.equinox.p2-36f097652c0d84fdc85a61ce104e1b435a1403cf.tar.xz
rt.equinox.p2-36f097652c0d84fdc85a61ce104e1b435a1403cf.zip
capture stdout during tests
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/StringBufferStream.java55
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java14
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java29
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java91
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java38
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java28
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java29
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java19
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java15
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SiteIndexFileTest.java144
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java113
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java11
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java11
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java126
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java14
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/SiteXMLActionTest.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java30
19 files changed, 498 insertions, 295 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/StringBufferStream.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/StringBufferStream.java
new file mode 100644
index 000000000..8eb268967
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/StringBufferStream.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.p2.tests;
+
+import java.io.OutputStream;
+
+public class StringBufferStream extends OutputStream {
+ private StringBuffer buffer;
+
+ public StringBufferStream() {
+ this.buffer = new StringBuffer();
+ }
+
+ public StringBufferStream(StringBuffer buffer) {
+ this.buffer = buffer;
+ }
+
+ public StringBuffer getBuffer() {
+ return buffer;
+ }
+
+ @Override
+ public void close() {
+ //nothing
+ }
+
+ @Override
+ public void flush() {
+ //nothing
+ }
+
+ @Override
+ public void write(byte[] b) {
+ buffer.append(new String(b));
+ }
+
+ @Override
+ public void write(int b) {
+ buffer.append(new String(new byte[] {(byte) b}));
+ }
+
+ @Override
+ public void write(byte[] buf, int off, int len) {
+ buffer.append(new String(buf, off, len));
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java
index 5b8835b3a..f39ee4d56 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/ArtifactRepositoryManagerTest.java
@@ -10,8 +10,7 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.artifact.repository;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import junit.framework.Test;
@@ -74,13 +73,16 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest {
public void testLoadMissingRepository() throws IOException {
File tempFile = File.createTempFile("testLoadMissingArtifactRepository", null);
URI location = tempFile.toURI();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
manager.loadRepository(location, null);
fail("1.0");//should fail
} catch (ProvisionException e) {
assertEquals("1.1", IStatus.ERROR, e.getStatus().getSeverity());
assertEquals("1.2", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode());
} finally {
+ System.setOut(out);
tempFile.delete();
}
}
@@ -277,7 +279,13 @@ public class ArtifactRepositoryManagerTest extends AbstractProvisioningTest {
*/
public void testDuplicateElement() {
File duplicateElementXML = getTestData("testDuplicateElement", "testData/artifactRepo/duplicateElement");
- assertEquals("Ensure correct number of artifact keys exist", 2, getArtifactKeyCount(duplicateElementXML.toURI()));
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ assertEquals("Ensure correct number of artifact keys exist", 2, getArtifactKeyCount(duplicateElementXML.toURI()));
+ } finally {
+ System.setOut(out);
+ }
}
public void testEnablement() {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java
index d87106c04..dd143b22b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/CompositeArtifactRepositoryTest.java
@@ -30,8 +30,7 @@ import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.artifact.*;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
-import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
-import org.eclipse.equinox.p2.tests.TestArtifactRepository;
+import org.eclipse.equinox.p2.tests.*;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
public class CompositeArtifactRepositoryTest extends AbstractProvisioningTest {
@@ -577,10 +576,14 @@ public class CompositeArtifactRepositoryTest extends AbstractProvisioningTest {
File knownGoodRepoLocation = getTestData("0.1", "/testData/artifactRepo/composite/good.remote");
CompositeArtifactRepository compRepo = null;
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
compRepo = (CompositeArtifactRepository) getArtifactRepositoryManager().loadRepository(knownGoodRepoLocation.toURI(), null);
} catch (ProvisionException e) {
fail("0.99", e);
+ } finally {
+ System.setOut(out);
}
List children = compRepo.getChildren();
@@ -647,25 +650,33 @@ public class CompositeArtifactRepositoryTest extends AbstractProvisioningTest {
public void testSyntaxErrorWhileParsing() {
File badCompositeArtifacts = getTestData("1", "/testData/artifactRepo/composite/Bad/syntaxError");
-
+ PrintStream err = System.err;
+ StringBuffer buffer = new StringBuffer();
try {
+ System.setErr(new PrintStream(new StringBufferStream(buffer)));
getArtifactRepositoryManager().loadRepository(badCompositeArtifacts.toURI(), null);
//Error while parsing expected
fail("Expected ProvisionException has not been thrown");
} catch (ProvisionException e) {
- //expected.
- //TODO more meaningful verification?
+ assertTrue(buffer.toString().contains("The element type \"children\" must be terminated by the matching end-tag \"</children>\""));
+ } finally {
+ System.setErr(err);
}
}
public void testMissingRequireattributeWhileParsing() {
File badCompositeArtifacts = getTestData("1", "/testData/artifactRepo/composite/Bad/missingRequiredAttribute");
CompositeArtifactRepository compRepo = null;
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
compRepo = (CompositeArtifactRepository) getArtifactRepositoryManager().loadRepository(badCompositeArtifacts.toURI(), null);
} catch (ProvisionException e) {
fail("Error loading repository", e);
+ } finally {
+ System.setOut(out);
}
+
assertEquals("Repository should only have 1 child", 1, compRepo.getChildren().size());
}
@@ -845,7 +856,9 @@ public class CompositeArtifactRepositoryTest extends AbstractProvisioningTest {
* Ensure that we can create a non-local composite repository.
*/
public void testNonLocalRepo() {
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
URI location = new URI("memory:/in/memory");
URI childOne = new URI("memory:/in/memory/one");
URI childTwo = new URI("memory:/in/memory/two");
@@ -865,6 +878,8 @@ public class CompositeArtifactRepositoryTest extends AbstractProvisioningTest {
assertEquals("1.3", 2, repository.getChildren().size());
} catch (URISyntaxException e) {
fail("99.0", e);
+ } finally {
+ System.setOut(out);
}
}
@@ -904,7 +919,9 @@ public class CompositeArtifactRepositoryTest extends AbstractProvisioningTest {
}
public void testRelativeRemoveChild() {
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
URI location = new URI("memory:/in/memory");
URI one = new URI("one");
URI two = new URI("two");
@@ -921,6 +938,8 @@ public class CompositeArtifactRepositoryTest extends AbstractProvisioningTest {
assertEquals("1.2", 0, repository.getChildren().size());
} catch (URISyntaxException e) {
fail("99.0", e);
+ } finally {
+ System.setOut(out);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java
index 3123e80ff..946a59d06 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/DirectorApplicationTest.java
@@ -11,16 +11,19 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.director;
-import java.io.*;
+import java.io.File;
+import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URI;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.director.app.DirectorApplication;
+import org.eclipse.equinox.internal.simpleconfigurator.utils.URIUtil;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.IRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.StringBufferStream;
/**
* Various automated tests of the {@link IDirector} API.
@@ -30,9 +33,21 @@ public class DirectorApplicationTest extends AbstractProvisioningTest {
/**
* runs default director app.
*/
- private void runDirectorApp(String message, final String[] args) throws Exception {
- DirectorApplication application = new DirectorApplication();
- application.run(args);
+ private StringBuffer runDirectorApp(String message, final String[] args) throws Exception {
+ PrintStream out = System.out;
+ PrintStream err = System.err;
+ StringBuffer buffer = new StringBuffer();
+ try {
+ PrintStream newStream = new PrintStream(new StringBufferStream(buffer));
+ System.setOut(newStream);
+ System.setErr(newStream);
+ DirectorApplication application = new DirectorApplication();
+ application.run(args);
+ } finally {
+ System.setOut(out);
+ System.setErr(err);
+ }
+ return buffer;
}
/**
@@ -52,13 +67,7 @@ public class DirectorApplicationTest extends AbstractProvisioningTest {
* creates the director app arguments based on the arguments submitted with bug 248045
*/
private String[] getSingleRepoArgs(String message, File metadataRepo, File artifactRepo, File destinationRepo, String installIU) {
- String[] args = new String[0];
- try {
- args = new String[] {"-metadataRepository", metadataRepo.toURL().toExternalForm(), "-artifactRepository", artifactRepo.toURL().toExternalForm(), "-installIU", installIU, "-destination", destinationRepo.toURL().toExternalForm(), "-profile", "PlatformSDKProfile", "-profileProperties", "org.eclipse.update.install.features=true", "-bundlepool", destinationRepo.getAbsolutePath(), "-roaming"};
- } catch (MalformedURLException e) {
- fail(message, e);
- }
- return args;
+ return new String[] {"-metadataRepository", URIUtil.toUnencodedString(metadataRepo.toURI()), "-artifactRepository", URIUtil.toUnencodedString(artifactRepo.toURI()), "-installIU", installIU, "-destination", URIUtil.toUnencodedString(destinationRepo.toURI()), "-profile", "PlatformSDKProfile", "-profileProperties", "org.eclipse.update.install.features=true", "-bundlepool", destinationRepo.getAbsolutePath(), "-roaming"};
}
/**
@@ -92,13 +101,18 @@ public class DirectorApplicationTest extends AbstractProvisioningTest {
//Setup: use default arguments
String[] args = getSingleRepoArgs("1.0", metadataRepo, artifactRepo, destinationRepo, installIU);
+ StringBuffer outputBuffer = null;
try {
- runDirectorApp("1.1", args);
+ outputBuffer = runDirectorApp("1.1", args);
} catch (ProvisionException e) {
//expected, fall through
} catch (Exception e) {
fail("1.2", e);
}
+ String outputString = outputBuffer.toString();
+ assertTrue(outputString.contains("No repository found at " + metadataRepo.toURI().toString()));
+ assertTrue(outputString.contains("No repository found at " + artifactRepo.toURI().toString()));
+
//remove the agent data produced by the director
delete(new File(destinationRepo, "p2"));
//this will only succeed if the destination is empty, which is what we expect because the install failed
@@ -133,13 +147,17 @@ public class DirectorApplicationTest extends AbstractProvisioningTest {
//Setup: use default arguments
String[] args = getSingleRepoArgs("2.1", metadataRepo, artifactRepo, destinationRepo, installIU);
+ StringBuffer outputBuffer = null;
try {
- runDirectorApp("2.2", args);
+ outputBuffer = runDirectorApp("2.2", args);
} catch (ProvisionException e) {
//expected, fall through
} catch (Exception e) {
fail("2.3", e);
}
+
+ assertTrue(outputBuffer.toString().contains("No repository found at " + metadataRepo.toURI().toString()));
+
//remove the agent data produced by the director
delete(new File(destinationRepo, "p2"));
//this will only succeed if the destination is empty, which is what we expect because the install failed
@@ -172,14 +190,17 @@ public class DirectorApplicationTest extends AbstractProvisioningTest {
//Setup: use default arguments
String[] args = getSingleRepoArgs("3.1", metadataRepo, artifactRepo, destinationRepo, installIU);
-
+ StringBuffer outputBuffer = null;
try {
- runDirectorApp("3.2", args);
+ outputBuffer = runDirectorApp("3.2", args);
} catch (ProvisionException e) {
//expected, fall through
} catch (Exception e) {
fail("3.3", e);
}
+
+ assertTrue(outputBuffer.toString().contains("No repository found at " + artifactRepo.toURI().toString()));
+
//remove the agent data produced by the director
delete(new File(destinationRepo, "p2"));
//this will only succeed if the destination is empty, which is what we expect because the install failed
@@ -583,18 +604,9 @@ public class DirectorApplicationTest extends AbstractProvisioningTest {
String[] args = getSingleRepoArgs("12.4", metadataRepo2, artifactRepo2, destinationRepo, "yetanotherplugin");
destinationRepo.mkdirs();
- PrintStream oldErr = System.err;
- PrintStream newErr = new PrintStream(new FileOutputStream(destinationRepo + "/err.out"));
- System.setErr(newErr);
- try {
- runDirectorApp("12.5", args);
- } finally {
- System.setErr(oldErr);
- newErr.close();
- }
-
- assertLogContainsLine(new File(destinationRepo, "err.out"), "The installable unit yetanotherplugin has not been found.");
+ StringBuffer buffer = runDirectorApp("12.5", args);
+ assertTrue(buffer.toString().contains("The installable unit yetanotherplugin has not been found."));
final URI[] afterArtifactRepos = artifactManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
final URI[] afterMetadataRepos = metadataManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
@@ -630,18 +642,8 @@ public class DirectorApplicationTest extends AbstractProvisioningTest {
String[] args = getSingleRepoArgs("13.4", metadataRepo2, artifactRepo2, destinationRepo, "helloworld");
destinationRepo.mkdirs();
- PrintStream oldOut = System.out;
- PrintStream newOut = new PrintStream(new FileOutputStream(destinationRepo + "/out.out"));
- System.setOut(newOut);
-
- try {
- runDirectorApp("13.5", args);
- } finally {
- System.setOut(oldOut);
- newOut.close();
- }
-
- assertLogContainsLine(new File(destinationRepo, "out.out"), "Installing helloworld 1.0.0.");
+ StringBuffer buffer = runDirectorApp("13.5", args);
+ assertTrue(buffer.toString().contains("Installing helloworld 1.0.0."));
artifactManager.removeRepository(artifactRepo1.toURI());
metadataManager.removeRepository(metadataRepo1.toURI());
@@ -665,18 +667,9 @@ public class DirectorApplicationTest extends AbstractProvisioningTest {
String[] args = getSingleRepoUninstallArgs("14.1", srcRepo, destinationRepo, "helloworld");
destinationRepo.mkdirs();
- PrintStream oldErr = System.err;
- PrintStream newErr = new PrintStream(new FileOutputStream(destinationRepo + "/err.out"));
- System.setErr(newErr);
-
- try {
- runDirectorApp("14.2", args);
- } finally {
- System.setOut(oldErr);
- newErr.close();
- }
- assertLogContainsLine(new File(destinationRepo, "err.out"), "The installable unit helloworld has not been found.");
+ StringBuffer buffer = runDirectorApp("14.2", args);
+ assertTrue(buffer.toString().contains("The installable unit helloworld has not been found."));
artifactManager.removeRepository(srcRepo.toURI());
metadataManager.removeRepository(srcRepo.toURI());
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java
index 84b93b833..fbdb48ce0 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.p2.tests.engine;
import java.io.File;
+import java.io.PrintStream;
import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.engine.*;
@@ -23,6 +24,7 @@ import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescriptio
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitFragmentDescription;
import org.eclipse.equinox.p2.query.*;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.StringBufferStream;
/**
* Simple test of the engine API.
@@ -134,6 +136,23 @@ public class EngineTest extends AbstractProvisioningTest {
this("");
}
+ private IStatus perform(IProvisioningPlan plan, IPhaseSet phaseSet, StringBuffer buffer) {
+ PrintStream out = System.out;
+ IStatus result = null;
+ if (buffer == null)
+ buffer = new StringBuffer();
+ try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
+ if (phaseSet != null)
+ result = engine.perform(plan, phaseSet, new NullProgressMonitor());
+ else
+ result = engine.perform(plan, new NullProgressMonitor());
+ } finally {
+ System.setOut(out);
+ }
+ return result;
+ }
+
private static boolean deleteDirectory(File directory) {
if (directory.exists() && directory.isDirectory()) {
File[] files = directory.listFiles();
@@ -475,7 +494,10 @@ public class EngineTest extends AbstractProvisioningTest {
IProvisioningPlan plan = engine.createPlan(profile, null);
plan.addInstallableUnit(createOSGiIU());
- IStatus result = engine.perform(plan, phaseSet, new NullProgressMonitor());
+
+ StringBuffer buffer = new StringBuffer();
+ IStatus result = perform(plan, phaseSet, buffer);
+ assertTrue(buffer.toString().contains("java.lang.NullPointerException"));
assertFalse(result.isOK());
ius = getInstallableUnits(profile);
assertFalse(ius.hasNext());
@@ -514,7 +536,10 @@ public class EngineTest extends AbstractProvisioningTest {
IProvisioningPlan plan = engine.createPlan(profile, null);
plan.addInstallableUnit(createOSGiIU());
- IStatus result = engine.perform(plan, phaseSet, new NullProgressMonitor());
+
+ StringBuffer buffer = new StringBuffer();
+ IStatus result = perform(plan, phaseSet, buffer);
+ assertTrue(buffer.toString().contains("An error occurred during the org.eclipse.equinox.p2.tests.engine.EngineTest$ActionNPEPhase phase"));
assertTrue(result.isOK());
ius = getInstallableUnits(profile);
assertTrue(ius.hasNext());
@@ -551,7 +576,10 @@ public class EngineTest extends AbstractProvisioningTest {
phaseSet = new TestPhaseSet(true);
plan = engine.createPlan(profile, null);
plan.removeInstallableUnit(badUninstallIU);
- result = engine.perform(plan, phaseSet, new NullProgressMonitor());
+
+ StringBuffer buffer = new StringBuffer();
+ result = perform(plan, phaseSet, buffer);
+ assertTrue(buffer.toString().contains("An error occurred while uninstalling"));
assertTrue(result.isOK());
ius = getInstallableUnits(profile);
assertFalse(ius.hasNext());
@@ -587,7 +615,7 @@ public class EngineTest extends AbstractProvisioningTest {
IPhaseSet phaseSet = new TestPhaseSet(true);
plan = engine.createPlan(profile, null);
plan.removeInstallableUnit(badUninstallIU);
- result = engine.perform(plan, phaseSet, new NullProgressMonitor());
+ result = perform(plan, phaseSet, null);
assertTrue(result.isOK());
ius = getInstallableUnits(profile);
assertFalse(ius.hasNext());
@@ -605,7 +633,7 @@ public class EngineTest extends AbstractProvisioningTest {
plan = engine.createPlan(profile, null);
plan.addInstallableUnit(iu);
plan.setInstallableUnitProfileProperty(iu, "adifferentkey", "value");
- result = engine.perform(plan, new NullProgressMonitor());
+ result = perform(plan, null, null);
assertTrue(result.isOK());
assertTrue(profile.getInstallableUnitProperties(iu).containsKey("adifferentkey"));
assertFalse(profile.getInstallableUnitProperties(iu).containsKey("key"));
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java
index ec81c4059..6e1b38012 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.p2.tests.generator;
import java.io.File;
+import java.io.PrintStream;
import java.util.Map;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.equinox.app.IApplicationContext;
@@ -23,8 +24,7 @@ import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAndBundlesPublisherAppli
import org.eclipse.equinox.p2.publisher.eclipse.InstallPublisherApplication;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
-import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
-import org.eclipse.equinox.p2.tests.TestActivator;
+import org.eclipse.equinox.p2.tests.*;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleContext;
@@ -51,7 +51,22 @@ public class GeneratorTests extends AbstractProvisioningTest {
}
public Object go(String[] arguments) throws Exception {
- Object result = run(arguments);
+ return go(arguments, new StringBuffer());
+ }
+
+ public Object go(String[] arguments, StringBuffer buffer) throws Exception {
+ Object result = null;
+ PrintStream out = System.out;
+ PrintStream err = System.err;
+ try {
+ PrintStream stream = new PrintStream(new StringBufferStream(buffer));
+ System.setOut(stream);
+ System.setErr(stream);
+ result = run(arguments);
+ } finally {
+ System.setOut(out);
+ System.setErr(err);
+ }
if (result instanceof Exception)
throw (Exception) result;
return result;
@@ -87,13 +102,16 @@ public class GeneratorTests extends AbstractProvisioningTest {
//Taunt you one more time
application = new TestGeneratorApplication();
+ StringBuffer buffer = new StringBuffer();
try {
- application.go(arguments);
+ application.go(arguments, buffer);
fail("3.0 - Expected Illegal Argument Exception not thrown.");
} catch (IllegalArgumentException e) {
assertTrue("3.0 - Expected Illegal Argument", e.getMessage().equals(NLS.bind(Messages.exception_artifactRepoNoAppendDestroysInput, rootFolder.toURI())));
}
-
+ String outputString = buffer.toString();
+ assertTrue(outputString.contains("Not appending to artifact repository"));
+ assertTrue(outputString.contains("may destroy input files."));
assertTrue("3.1 - artifact repo existance", new File(rootFolder, "artifacts.xml").exists());
//with -updateSite
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java
index 6cfcb74a5..304c43891 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/CompositeMetadataRepositoryTest.java
@@ -13,6 +13,7 @@
package org.eclipse.equinox.p2.tests.metadata.repository;
import java.io.File;
+import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
@@ -28,8 +29,7 @@ import org.eclipse.equinox.p2.query.*;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
-import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
-import org.eclipse.equinox.p2.tests.TestData;
+import org.eclipse.equinox.p2.tests.*;
import org.eclipse.equinox.p2.tests.core.CompoundQueryableTest.CompoundQueryTestProgressMonitor;
/**
@@ -306,10 +306,15 @@ public class CompositeMetadataRepositoryTest extends AbstractProvisioningTest {
File knownGoodRepoLocation = getTestData("0.1", "/testData/metadataRepo/composite/good.remote");
CompositeMetadataRepository compRepo = null;
+
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
compRepo = (CompositeMetadataRepository) getMetadataRepositoryManager().loadRepository(knownGoodRepoLocation.toURI(), null);
} catch (ProvisionException e) {
fail("0.99", e);
+ } finally {
+ System.setOut(out);
}
List children = compRepo.getChildren();
@@ -380,13 +385,17 @@ public class CompositeMetadataRepositoryTest extends AbstractProvisioningTest {
public void testSyntaxErrorWhileParsing() {
File badCompositeContent = getTestData("1", "/testData/metadataRepo/composite/Bad/syntaxError");
+ StringBuffer buffer = new StringBuffer();
+ PrintStream err = System.err;
try {
+ System.setErr(new PrintStream(new StringBufferStream(buffer)));
getMetadataRepositoryManager().loadRepository(badCompositeContent.toURI(), null);
//Error while parsing expected
fail("Expected ProvisionException has not been thrown");
} catch (ProvisionException e) {
- //expected.
- //TODO more meaningful verification?
+ assertTrue(buffer.toString().contains("The element type \"children\" must be terminated by the matching end-tag \"</children>\"."));
+ } finally {
+ System.setErr(err);
}
}
@@ -395,10 +404,14 @@ public class CompositeMetadataRepositoryTest extends AbstractProvisioningTest {
copy("0.2", badCompositeContent, repoLocation);
CompositeMetadataRepository compRepo = null;
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
compRepo = (CompositeMetadataRepository) getMetadataRepositoryManager().loadRepository(repoLocation.toURI(), null);
} catch (ProvisionException e) {
fail("1.99", e);
+ } finally {
+ System.setOut(out);
}
assertEquals("2.0", 1, compRepo.getChildren().size());
}
@@ -574,7 +587,9 @@ public class CompositeMetadataRepositoryTest extends AbstractProvisioningTest {
* behaviour of the composite repos to aggressively load the children.
*/
public void testNonLocalRepo() {
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
URI location = new URI("http://foo.org/in/memory");
URI childOne = new URI("http://foo.org/in/memory/one");
URI childTwo = new URI("http://foo.org/in/memory/two");
@@ -594,6 +609,8 @@ public class CompositeMetadataRepositoryTest extends AbstractProvisioningTest {
assertEquals("1.3", 2, repository.getChildren().size());
} catch (URISyntaxException e) {
fail("99.0", e);
+ } finally {
+ System.setOut(out);
}
}
@@ -640,7 +657,9 @@ public class CompositeMetadataRepositoryTest extends AbstractProvisioningTest {
}
public void testRelativeRemoveChild() {
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
URI location = new URI("http://foo.org/in/memory");
URI one = new URI("one");
URI two = new URI("two");
@@ -657,6 +676,8 @@ public class CompositeMetadataRepositoryTest extends AbstractProvisioningTest {
assertEquals("1.2", 0, repository.getChildren().size());
} catch (URISyntaxException e) {
fail("99.0", e);
+ } finally {
+ System.setOut(out);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java
index b3becf8f2..5a3196a5b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java
@@ -10,8 +10,7 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.metadata.repository;
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
@@ -261,12 +260,16 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest {
File tempFile = File.createTempFile("testLoadMissingArtifactRepository", null);
tempFile.delete();
URI location = tempFile.toURI();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
manager.loadRepository(location, null);
fail("1.0");//should fail
} catch (ProvisionException e) {
assertEquals("1.1", IStatus.ERROR, e.getStatus().getSeverity());
assertEquals("1.2", ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode());
+ } finally {
+ System.setOut(out);
}
}
@@ -300,12 +303,16 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest {
public void testLoadBrokenRepository() {
File site = getTestData("Repository", "/testData/metadataRepo/bad/");
URI location = site.toURI();
+ PrintStream err = System.err;
try {
+ System.setErr(new PrintStream(new StringBufferStream()));
manager.loadRepository(location, null);
fail("1.0");//should fail
} catch (ProvisionException e) {
assertEquals("1.1", IStatus.ERROR, e.getStatus().getSeverity());
assertEquals("1.2", ProvisionException.REPOSITORY_FAILED_READ, e.getStatus().getCode());
+ } finally {
+ System.setErr(err);
}
}
@@ -317,12 +324,16 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest {
public void testLoadBrokenSimpleRepositoryWithGoodUpdateSite() {
File site = getTestData("Repository", "/testData/metadataRepo/badSimpleGoodUpdateSite/");
URI location = site.toURI();
+ PrintStream err = System.err;
try {
+ System.setErr(new PrintStream(new StringBufferStream()));
manager.loadRepository(location, null);
fail("1.0");//should fail
} catch (ProvisionException e) {
assertEquals("1.1", IStatus.ERROR, e.getStatus().getSeverity());
assertEquals("1.2", ProvisionException.REPOSITORY_FAILED_READ, e.getStatus().getCode());
+ } finally {
+ System.setErr(err);
}
}
@@ -544,10 +555,14 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest {
public void testUnreadableFailingFilter() throws ProvisionException {
File site = getTestData("unreadable", "/testData/metadataRepo/badFilter/unreadable");
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
manager.loadRepository(site.toURI(), null);
} catch (ProvisionException e) {
return;
+ } finally {
+ System.setOut(out);
}
fail("Unexpected code path, the unreadable repo should not have loaded");
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
index 8081352a0..2b2db7161 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SPIMetadataRepositoryTest.java
@@ -10,10 +10,7 @@
******************************************************************************/
package org.eclipse.equinox.p2.tests.metadata.repository;
-import org.eclipse.equinox.p2.query.MatchQuery;
-
-import java.io.File;
-import java.io.UnsupportedEncodingException;
+import java.io.*;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
@@ -30,10 +27,12 @@ import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitPatchDescr
import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.MatchQuery;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.StringBufferStream;
/**
* Test API of the metadata interfaces with an SPI implementation.
@@ -779,7 +778,13 @@ public class SPIMetadataRepositoryTest extends AbstractProvisioningTest {
repo.addInstallableUnits(Arrays.asList(MetadataFactory.createInstallableUnit(iuDescription), MetadataFactory.createInstallableUnitPatch(iuPatchDescription)));
- repo = manager.refreshRepository(repoLocation.toURI(), null);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ repo = manager.refreshRepository(repoLocation.toURI(), null);
+ } finally {
+ System.setOut(out);
+ }
IQueryResult queryResult = repo.query(new AllAcceptingQuery(), new NullProgressMonitor());
assertEquals(2, queryResultSize(queryResult));
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SiteIndexFileTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SiteIndexFileTest.java
index e8165f806..82ee58880 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SiteIndexFileTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/SiteIndexFileTest.java
@@ -183,7 +183,15 @@ public class SiteIndexFileTest extends AbstractProvisioningTest {
public void testBadIndex1() throws Exception {
File indexFile = TestData.getFile("metadataRepo/indexfiles", "badIndex.p2");
InputStream inputStream = new FileInputStream(indexFile);
- LocationProperties locationProperties = LocationProperties.create(inputStream);
+
+ PrintStream out = System.out;
+ LocationProperties locationProperties = null;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ locationProperties = LocationProperties.create(inputStream);
+ } finally {
+ System.setOut(out);
+ }
assertNotNull(locationProperties);
assertFalse(locationProperties.exists());
}
@@ -243,62 +251,104 @@ public class SiteIndexFileTest extends AbstractProvisioningTest {
*/
public void testSingleRepository1() throws Exception {
URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test1").toURI();
- IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
* Tests that metadata repository manager can read a simple index.p2 file
*/
public void testSingleRepository2() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test2").toURI();
- IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(repository instanceof LocalMetadataRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test2").toURI();
+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(repository instanceof LocalMetadataRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
* Tests that when a bad index.p2 file is specified, the metadata repository manager can work just fine
*/
public void testBadIndexFileInRepository() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "badtest1").toURI();
- IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(repository instanceof LocalMetadataRepository || repository instanceof UpdateSiteMetadataRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "badtest1").toURI();
+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(repository instanceof LocalMetadataRepository || repository instanceof UpdateSiteMetadataRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
* Tests that when a simple index.p2 file is specified, the metadata repository manager can read and handle it just fine
*/
public void testMultiRepository1() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test3").toURI();
- IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test3").toURI();
+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
* Tests that when a simple index.p2 file is specified, the metadata repository manager can read and handle it just fine
*/
public void testMultiRepository2() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test4").toURI();
- IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test4").toURI();
+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
* Tests that when a simple index.p2 file is specified, the metadata repository manager can read and handle it just fine
*/
public void testDuplicateEntries() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test5").toURI();
- IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "test5").toURI();
+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
* Tests that the STOP token is handled properly by the metadata repository manager
*/
public void testStop1() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "stop1").toURI();
- IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "stop1").toURI();
+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(repository instanceof UpdateSiteMetadataRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
@@ -319,24 +369,36 @@ public class SiteIndexFileTest extends AbstractProvisioningTest {
* Tests a composite repository to ensure it loads fine as well as all its children
*/
public void testCompositeRepo() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "compositeRepo").toURI();
- IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue("1.0", repository instanceof CompositeMetadataRepository);
- CompositeMetadataRepository compositeMetadataRepository = (CompositeMetadataRepository) repository;
- assertEquals("1.1", 2, compositeMetadataRepository.getChildren().size());
- IMetadataRepository child1 = getMetadataRepositoryManager().loadRepository(compositeMetadataRepository.getChildren().get(0), new NullProgressMonitor());
- IMetadataRepository child2 = getMetadataRepositoryManager().loadRepository(compositeMetadataRepository.getChildren().get(1), new NullProgressMonitor());
- assertTrue("1.2", child1 instanceof UpdateSiteMetadataRepository);
- assertTrue("1.2", child2 instanceof LocalMetadataRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "compositeRepo").toURI();
+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue("1.0", repository instanceof CompositeMetadataRepository);
+ CompositeMetadataRepository compositeMetadataRepository = (CompositeMetadataRepository) repository;
+ assertEquals("1.1", 2, compositeMetadataRepository.getChildren().size());
+ IMetadataRepository child1 = getMetadataRepositoryManager().loadRepository(compositeMetadataRepository.getChildren().get(0), new NullProgressMonitor());
+ IMetadataRepository child2 = getMetadataRepositoryManager().loadRepository(compositeMetadataRepository.getChildren().get(1), new NullProgressMonitor());
+ assertTrue("1.2", child1 instanceof UpdateSiteMetadataRepository);
+ assertTrue("1.2", child2 instanceof LocalMetadataRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
* Tests that an artifact repository manager can handle an index.p2 file
*/
public void testSimpleArtifact() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "artifactTest1").toURI();
- IArtifactRepository repository = getArtifactRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(repository instanceof SimpleArtifactRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "artifactTest1").toURI();
+ IArtifactRepository repository = getArtifactRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(repository instanceof SimpleArtifactRepository);
+ } finally {
+ System.setOut(out);
+ }
}
/*
@@ -358,10 +420,16 @@ public class SiteIndexFileTest extends AbstractProvisioningTest {
* can fully loaded
*/
public void testFullRepository() throws Exception {
- URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "fullRepository").toURI();
- IMetadataRepository metadataRepository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- IArtifactRepository artifactRepository = getArtifactRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
- assertTrue(metadataRepository instanceof UpdateSiteMetadataRepository);
- assertTrue(artifactRepository instanceof SimpleArtifactRepository);
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ URI repositoryLocation = TestData.getFile("metadataRepo/multipleRepos", "fullRepository").toURI();
+ IMetadataRepository metadataRepository = getMetadataRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ IArtifactRepository artifactRepository = getArtifactRepositoryManager().loadRepository(repositoryLocation, new NullProgressMonitor());
+ assertTrue(metadataRepository instanceof UpdateSiteMetadataRepository);
+ assertTrue(artifactRepository instanceof SimpleArtifactRepository);
+ } finally {
+ System.setOut(out);
+ }
}
}
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 15f96e180..eb44203ee 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
@@ -29,8 +29,7 @@ import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.artifact.*;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
-import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
-import org.eclipse.equinox.p2.tests.TestActivator;
+import org.eclipse.equinox.p2.tests.*;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.util.NLS;
@@ -80,13 +79,25 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
/**
* runs the mirror application with arguments args
*/
- private void runMirrorApplication(String message, final String[] args) throws Exception {
- MirrorApplication application = new MirrorApplication();
- Map map = new HashMap();
- map.put("metadataOrArtifacts", "artifacts");
- application.setInitializationData(null, null, map);
- application.initializeFromArguments(args);
- application.run(null);
+ private StringBuffer runMirrorApplication(String message, final String[] args) throws Exception {
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
+ PrintStream err = System.err;
+ try {
+ PrintStream stream = new PrintStream(new StringBufferStream(buffer));
+ System.setOut(stream);
+ System.setErr(stream);
+ MirrorApplication application = new MirrorApplication();
+ Map map = new HashMap();
+ map.put("metadataOrArtifacts", "artifacts");
+ application.setInitializationData(null, null, map);
+ application.initializeFromArguments(args);
+ application.run(null);
+ } finally {
+ System.setOut(out);
+ System.setErr(err);
+ }
+ return buffer;
}
/**
@@ -1079,23 +1090,10 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
//for Bug 250527
public void testIgnoreErrorsArguement() {
- //Error prints to stderr, redirect that to a file
- PrintStream oldErr = System.err;
- PrintStream newErr = null;
- try {
- destRepoLocation.mkdir();
- newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err")));
- } catch (FileNotFoundException e) {
- fail("Error redirecting outputs", e);
- }
- System.setErr(newErr);
-
+ destRepoLocation.mkdir();
//run test without verbose
mirrorWithError(false);
- System.setErr(oldErr);
- newErr.close();
-
assertEquals("Verifying correct number of Keys", 1, getArtifactKeyCount(destRepoLocation.toURI()));
//Because only 1 of the artifacts exists on disk, the number of artifacts in the destination should only be 1.
//Order in which mirror application mirrors artifacts is random.
@@ -1126,19 +1124,6 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
fail("Error creating repositories", e);
}
- //Comparator prints to stderr, redirect that to a file
- PrintStream oldErr = System.err;
- PrintStream newErr = null;
- PrintStream oldOut = System.out;
- PrintStream newOut = null;
- try {
- newErr = new PrintStream(new FileOutputStream(new File(repo2Location, "sys.err")));
- newOut = new PrintStream(new FileOutputStream(new File(repo2Location, "sys.out")));
- } catch (FileNotFoundException e) {
- fail("Error redirecting outputs", e);
- }
- System.setErr(newErr);
- System.setOut(newOut);
try {
//Set compare flag.
String[] args = new String[] {"-source", repo1Location.toURL().toExternalForm(), "-destination", repo2Location.toURL().toExternalForm(), "-verbose", "-compare", "-comparator", MD5ArtifactComparator.MD5_COMPARATOR_ID};
@@ -1147,10 +1132,6 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
} catch (Exception e) {
fail("Running mirror application with duplicate descriptors with different md5 values failed", e);
}
- System.setErr(oldErr);
- newErr.close();
- System.setOut(oldOut);
- newOut.close();
IArtifactDescriptor[] destDescriptors = repo2.getArtifactDescriptors(descriptor2.getArtifactKey());
assertEquals("Ensuring destination has correct number of descriptors", 1, destDescriptors.length);
@@ -1195,20 +1176,6 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
fail("Error creating repositories", e);
}
- //Comparator prints to stderr, redirect that to a file
- PrintStream oldErr = System.err;
- PrintStream newErr = null;
- PrintStream oldOut = System.out;
- PrintStream newOut = null;
- try {
- destRepoLocation.mkdir();
- newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err")));
- newOut = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.out")));
- } catch (FileNotFoundException e) {
- fail("Error redirecting outputs", e);
- }
- System.setErr(newErr);
- System.setOut(newOut);
try {
//Set compareAgaist
String[] args = new String[] {"-source", repoLocation.toURL().toExternalForm(), "-destination", destRepoLocation.toURL().toExternalForm(), "-compareAgainst", baselineLocation.toURL().toExternalForm(), "-verbose", "-compare", "-comparator", MD5ArtifactComparator.MD5_COMPARATOR_ID};
@@ -1217,10 +1184,6 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
} catch (Exception e) {
fail("Running mirror application with baseline compare", e);
}
- System.setErr(oldErr);
- newErr.close();
- System.setOut(oldOut);
- newOut.close();
IArtifactRepository destination = null;
try {
@@ -1317,23 +1280,9 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
assertNotNull("Assert log file is not null", log);
assertTrue("Clearing log file", log.getFile().delete());
- //Comparator prints to stderr, redirect that to a file
- PrintStream oldErr = System.err;
- PrintStream newErr = null;
- try {
- destRepoLocation.mkdir();
- newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err")));
- } catch (FileNotFoundException e) {
- fail("Error redirecting outputs", e);
- }
- System.setErr(newErr);
-
//run test without verbose resulting in error
mirrorWithError(false);
- System.setErr(oldErr);
- newErr.close();
-
//verify log
try {
String[] parts = new String[] {"java.io.FileNotFoundException: ", "helloworld_1.0.0.jar"};
@@ -1371,21 +1320,6 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
assertNotNull("Assert log file is not null", log);
assertTrue("Clearing log file", log.getFile().delete());
- //Comparator prints to stdout, redirect that to a file
- PrintStream oldOut = System.out;
- PrintStream newOut = null;
- PrintStream oldErr = System.err;
- PrintStream newErr = null;
- try {
- destRepoLocation.mkdir();
- newOut = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.out")));
- newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err")));
- } catch (FileNotFoundException e) {
- fail("Error redirecting output", e);
- }
- System.setOut(newOut);
- System.setErr(newErr);
-
//run test with verbose, results in error
mirrorWithError(true);
@@ -1412,11 +1346,6 @@ public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
fail("Error running mirror application to generate INFO items", e);
}
- System.setOut(oldOut);
- newOut.close();
- System.setErr(oldErr);
- newErr.close();
-
IArtifactRepository sourceRepository = null;
try {
sourceRepository = getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java
index 3158ca310..455b0b7be 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/ArtifactRepositoryCleanupTest.java
@@ -11,10 +11,12 @@
package org.eclipse.equinox.p2.tests.mirror;
import java.io.File;
+import java.io.PrintStream;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.StringBufferStream;
/**
* Test to ensure MirrorApplication handles loading an removing repositories correctly
@@ -54,7 +56,14 @@ public class ArtifactRepositoryCleanupTest extends AbstractProvisioningTest {
MirrorApplication application = new MirrorApplication();
String[] args = new String[] {"-source", source.toURL().toExternalForm(), "-destination", destination.toURL().toExternalForm(), append ? "-append" : ""};
application.initializeFromArguments(args);
- application.run(null);
+
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ application.run(null);
+ } finally {
+ System.setOut(out);
+ }
}
/**
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java
index 5ecfe2dc5..77a84115a 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataRepositoryCleanupTest.java
@@ -11,10 +11,12 @@
package org.eclipse.equinox.p2.tests.mirror;
import java.io.File;
+import java.io.PrintStream;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.StringBufferStream;
/**
* Test to ensure MirrorApplication handles loading an removing repositories correctly
@@ -54,7 +56,14 @@ public class MetadataRepositoryCleanupTest extends AbstractProvisioningTest {
MirrorApplication application = new MirrorApplication();
String[] args = new String[] {"-source", source.toURL().toExternalForm(), "-destination", destination.toURL().toExternalForm(), append ? "-append" : ""};
application.initializeFromArguments(args);
- application.run(null);
+
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ application.run(null);
+ } finally {
+ System.setOut(out);
+ }
}
/**
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 2a675de36..f96a6c341 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
@@ -30,8 +30,7 @@ import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.artifact.*;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;
-import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
-import org.eclipse.equinox.p2.tests.TestActivator;
+import org.eclipse.equinox.p2.tests.*;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.util.NLS;
@@ -78,7 +77,7 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
super.tearDown();
}
- private void basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination, String destName) throws Exception {
+ private StringBuffer basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination, String destName) throws Exception {
MirrorApplication app = new MirrorApplication();
if (destination != null) {
@@ -94,15 +93,24 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
RepositoryDescriptor src = createRepositoryDescriptor(source, null, null, null);
app.addSource(src);
}
- app.run(null);
+
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
+ app.run(null);
+ } finally {
+ System.setOut(out);
+ }
+ return buffer;
}
- private void basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination) throws Exception {
- basicRunMirrorApplication(message, source, destination, append, formatDestination, null);
+ private StringBuffer basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination) throws Exception {
+ return basicRunMirrorApplication(message, source, destination, append, formatDestination, null);
}
- private void basicRunMirrorApplication(String message, URI source, URI destination) throws Exception {
- basicRunMirrorApplication(message, source, destination, null, null, null);
+ private StringBuffer basicRunMirrorApplication(String message, URI source, URI destination) throws Exception {
+ return basicRunMirrorApplication(message, source, destination, null, null, null);
}
private RepositoryDescriptor createRepositoryDescriptor(URI location, Boolean append, URI format, String name) {
@@ -293,7 +301,9 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
File errorSourceLocation = getTestData("loading error data", "testData/artifactRepo/missingSingleArtifact");
File validSourceLocation = getTestData("loading error data", "testData/artifactRepo/simple");
//repo contains an artifact entry for a file that does not exist on disk. this should throw a file not found exception
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream()));
MirrorApplication app = new MirrorApplication();
app.addSource(createRepositoryDescriptor(errorSourceLocation.toURI(), null, null, null));
app.addSource(createRepositoryDescriptor(validSourceLocation.toURI(), null, null, null));
@@ -305,6 +315,8 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
app.run(null);
} catch (Exception e) {
fail("Running mirror application with errored source failed", e);
+ } finally {
+ System.setOut(out);
}
}
@@ -852,7 +864,10 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
}
assertEquals("Assert name is set correctly before mirror", oldName, destinationRepo.getName());
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
MirrorApplication app = new MirrorApplication();
app.addSource(createRepositoryDescriptor(sourceRepoLocation.toURI(), null, null, null));
app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, newName));
@@ -861,6 +876,8 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
} catch (Exception e) {
fail("Error running mirror application", e);
+ } finally {
+ System.setOut(out);
}
try {
@@ -1144,20 +1161,9 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
fail("Error creating repositories", e);
}
- //Comparator prints to stderr, redirect that to a file
- PrintStream oldErr = System.err;
- PrintStream newErr = null;
- PrintStream oldOut = System.out;
- PrintStream newOut = null;
+ PrintStream out = System.out;
try {
- try {
- newErr = new PrintStream(new FileOutputStream(new File(repo2Location, "sys.err")));
- newOut = new PrintStream(new FileOutputStream(new File(repo2Location, "sys.out")));
- } catch (FileNotFoundException e) {
- fail("Error redirecting outputs", e);
- }
- System.setErr(newErr);
- System.setOut(newOut);
+ System.setOut(new PrintStream(new StringBufferStream()));
MirrorApplication app = null;
try {
app = new MirrorApplication();
@@ -1172,12 +1178,7 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
fail("Running mirror application with duplicate descriptors with different md5 values failed", e);
}
} finally {
- System.setErr(oldErr);
- if (newErr != null)
- newErr.close();
- System.setOut(oldOut);
- if (newOut != null)
- newOut.close();
+ System.setOut(out);
}
IArtifactDescriptor[] destDescriptors = repo2.getArtifactDescriptors(descriptor2.getArtifactKey());
@@ -1223,43 +1224,25 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
fail("Error creating repositories", e);
}
- //Comparator prints to stderr, redirect that to a file
- PrintStream oldErr = System.err;
- PrintStream newErr = null;
- PrintStream oldOut = System.out;
- PrintStream newOut = null;
+ MirrorApplication app = null;
+ PrintStream out = System.out;
try {
- try {
- destRepoLocation.mkdir();
- newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err")));
- newOut = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.out")));
- } catch (FileNotFoundException e) {
- fail("Error redirecting outputs", e);
- }
- System.setErr(newErr);
- System.setOut(newOut);
- MirrorApplication app = null;
- try {
- app = new MirrorApplication();
- app.addSource(createRepositoryDescriptor(repoLocation.toURI(), null, null, null));
- app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, null));
- //Set baseline
- app.setBaseline(baselineLocation.toURI());
- app.setVerbose(true);
- //Set compare flag.
- app.setCompare(true);
- //run the mirror application
- app.run(null);
- } catch (Exception e) {
- fail("Running mirror application with baseline compare", e);
- }
+ System.setOut(new PrintStream(new StringBufferStream()));
+ app = new MirrorApplication();
+ app.addSource(createRepositoryDescriptor(repoLocation.toURI(), null, null, null));
+ app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, null));
+ //Set baseline
+ app.setBaseline(baselineLocation.toURI());
+ app.setVerbose(true);
+ //Set compare flag.
+ app.setCompare(true);
+ //run the mirror application
+ app.run(null);
+ } catch (Exception e) {
+ fail("Running mirror application with baseline compare", e);
+
} finally {
- System.setErr(oldErr);
- if (newErr != null)
- newErr.close();
- System.setOut(oldOut);
- if (newOut != null)
- newOut.close();
+ System.setOut(out);
}
IArtifactRepository destination = null;
@@ -1299,7 +1282,7 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
manager.removeRepository(srcLocation);
}
- public Iterator<IArtifactKey> everything() {
+ public synchronized Iterator<IArtifactKey> everything() {
return ((SimpleArtifactRepository) source).everything();
}
@@ -1355,24 +1338,13 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest {
assertNotNull("Assert log file is not null", log);
assertTrue("Clearing log file", log.getFile().delete());
- //Comparator prints to stderr, redirect that to a file
- PrintStream oldErr = System.err;
- PrintStream newErr = null;
+ PrintStream out = System.out;
try {
- try {
- destRepoLocation.mkdir();
- newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err")));
- } catch (FileNotFoundException e) {
- fail("Error redirecting outputs", e);
- }
- System.setErr(newErr);
-
+ System.setOut(new PrintStream(new StringBufferStream()));
//run test without verbose resulting in error
mirrorWithError(false);
} finally {
- System.setErr(oldErr);
- if (newErr != null)
- newErr.close();
+ System.setOut(out);
}
//verify log
try {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java
index abe3fb259..9a581ebac 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/GeneralPublisherTests.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.publisher;
+import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.NoSuchElementException;
import junit.framework.TestCase;
@@ -17,6 +18,7 @@ import org.eclipse.equinox.internal.p2.publisher.Messages;
import org.eclipse.equinox.internal.p2.publisher.QuotedTokenizer;
import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile;
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAndBundlesPublisherApplication;
+import org.eclipse.equinox.p2.tests.StringBufferStream;
public class GeneralPublisherTests extends TestCase {
@@ -32,11 +34,17 @@ public class GeneralPublisherTests extends TestCase {
public void testInvalidConfiguration1() {
FeaturesAndBundlesPublisherApplication application = new FeaturesAndBundlesPublisherApplication();
Integer retValue = 0;
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
retValue = (Integer) application.run(new String[0]);
} catch (Exception e) {
fail("0.99");
+ } finally {
+ System.setOut(out);
}
+ assertTrue(buffer.toString().contains("A metadata repository must be specified."));
assertEquals("1.0", 1, retValue.intValue());
assertEquals("1.1", Messages.exception_noMetadataRepo, application.getStatus().getMessage());
}
@@ -44,11 +52,17 @@ public class GeneralPublisherTests extends TestCase {
public void testInvalidConfiguration2() {
FeaturesAndBundlesPublisherApplication application = new FeaturesAndBundlesPublisherApplication();
Integer retValue = 0;
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
retValue = (Integer) application.run(new String[] {"-metadataRepository foo", "-publishArtifacts"});
} catch (Exception e) {
fail("0.99");
+ } finally {
+ System.setOut(out);
}
+ assertTrue(buffer.toString().contains("An artifact repository must be specified in order to publish artifacts."));
assertEquals("1.0", 1, retValue.intValue());
assertEquals("1.1", Messages.exception_noArtifactRepo, application.getStatus().getMessage());
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java
index fc232a3e9..c4cf0f7a6 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/CategoryPublisherTest.java
@@ -10,11 +10,11 @@
package org.eclipse.equinox.p2.tests.publisher.actions;
import java.io.File;
+import java.io.PrintStream;
import java.net.URI;
import org.eclipse.equinox.internal.p2.updatesite.CategoryPublisherApplication;
import org.eclipse.equinox.p2.publisher.AbstractPublisherApplication;
-import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
-import org.eclipse.equinox.p2.tests.TestData;
+import org.eclipse.equinox.p2.tests.*;
/**
*
@@ -24,8 +24,16 @@ public class CategoryPublisherTest extends AbstractProvisioningTest {
/**
* runs default director app.
*/
- protected void runPublisherApp(AbstractPublisherApplication application, final String[] args) throws Exception {
- application.run(args);
+ protected StringBuffer runPublisherApp(AbstractPublisherApplication application, final String[] args) throws Exception {
+ PrintStream out = System.out;
+ StringBuffer buffer = new StringBuffer();
+ try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
+ application.run(args);
+ } finally {
+ System.setOut(out);
+ }
+ return buffer;
}
public void testCompressCategoryRepo() throws Exception {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java
index 8cfd9d5ed..75ff6faa5 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/publisher/actions/FeaturesActionTest.java
@@ -150,7 +150,6 @@ public class FeaturesActionTest extends ActionTest {
ITouchpointInstruction instruction = tpData.iterator().next().getInstruction("install");
assertNotNull(instruction);
assertEquals("ln(targetDir:@artifact,linkTarget:foo/lib.1.so,linkName:lib.so);chmod(targetDir:@artifact,targetFile:lib/lib.so,permissions:755);", instruction.getBody());
- System.out.println(fooGroup.getFilter());
assertNull(fooGroup.getFilter());
/*verify bar*/
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/SiteXMLActionTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/SiteXMLActionTest.java
index a401bf1ca..765a76865 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/SiteXMLActionTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/SiteXMLActionTest.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.p2.tests.updatesite;
import java.io.File;
+import java.io.PrintStream;
import java.net.URI;
import java.util.Collection;
import java.util.Iterator;
@@ -47,7 +48,13 @@ public class SiteXMLActionTest extends AbstractProvisioningTest {
featuresAction.perform(info, actionResult, new NullProgressMonitor());
SiteXMLAction action = new SiteXMLAction(siteLocation, null);
- action.perform(info, actionResult, getMonitor());
+ PrintStream out = System.out;
+ try {
+ System.setOut(new PrintStream(new StringBufferStream()));
+ action.perform(info, actionResult, getMonitor());
+ } finally {
+ System.setOut(out);
+ }
}
public void testQualifier() {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java
index fd2a87a99..2f0fdc78d 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java
@@ -39,6 +39,7 @@ import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.repository.spi.AbstractRepository;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.StringBufferStream;
import org.w3c.dom.*;
/**
@@ -285,11 +286,17 @@ public class UpdateSiteTest extends AbstractProvisioningTest {
} catch (ProvisionException e) {
fail("0.2", e);
}
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
updatesite.loadFeatures(new NullProgressMonitor());
} catch (ProvisionException e) {
fail("0.4", e);
+ } finally {
+ System.setOut(out);
}
+ assertTrue(buffer.toString().contains("Content is not allowed in prolog."));
}
public void testBadDigestBadSite() {
@@ -344,12 +351,19 @@ public class UpdateSiteTest extends AbstractProvisioningTest {
} catch (ProvisionException e) {
fail("0.2", e);
}
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length;
assertEquals(0, featureCount);
} catch (ProvisionException e) {
fail("0.5");
+
+ } finally {
+ System.setOut(out);
}
+ assertTrue(buffer.toString().contains("Error reading feature"));
}
public void testGoodFeatureURL() {
@@ -427,12 +441,18 @@ public class UpdateSiteTest extends AbstractProvisioningTest {
} catch (ProvisionException e) {
fail("0.2", e);
}
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
int featureCount = updatesite.loadFeatures(new NullProgressMonitor()).length;
assertEquals(1, featureCount);
} catch (ProvisionException e) {
fail("0.5");
+ } finally {
+ System.setOut(out);
}
+ assertTrue(buffer.toString().contains("Error reading feature"));
}
public void testNoFeatureIdAndVersion() {
@@ -571,15 +591,21 @@ public class UpdateSiteTest extends AbstractProvisioningTest {
}
public void testRepoWithFeatureWithNullUpdateURL() {
- IMetadataRepositoryManager repoMan = (IMetadataRepositoryManager) (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
+ IMetadataRepositoryManager repoMan = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
assertNotNull(repoMan);
File site = getTestData("Update site", "/testData/updatesite/missingUpdateURLFeature/");
IMetadataRepository metadataRepo = null;
+ StringBuffer buffer = new StringBuffer();
+ PrintStream out = System.out;
try {
+ System.setOut(new PrintStream(new StringBufferStream(buffer)));
metadataRepo = repoMan.loadRepository(site.toURI(), null);
} catch (ProvisionException e) {
fail("Can't load repository missingUpdateURLFeature");
+ } finally {
+ System.setOut(out);
}
+ assertTrue(buffer.toString().contains("Invalid site reference null in feature test.featurewithmissingupdateurl."));
IQuery<IInstallableUnit> query = QueryUtil.createIUQuery("test.featurewithmissingupdateurl.feature.group", Version.create("1.0.0"));
IQueryResult result = metadataRepo.query(query, null);
assertEquals("1.0", 1, queryResultSize(result));
@@ -686,7 +712,7 @@ public class UpdateSiteTest extends AbstractProvisioningTest {
File site = getTestData("0.1", "/testData/updatesite/site");
URI siteURI = site.toURI();
- IMetadataRepositoryManager metadataRepoMan = (IMetadataRepositoryManager) (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
+ IMetadataRepositoryManager metadataRepoMan = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
assertNotNull(metadataRepoMan);
URI[] knownRepos = metadataRepoMan.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);

Back to the top