Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Oberlies2014-04-02 11:19:33 -0400
committerTobias Oberlies2014-04-04 05:58:09 -0400
commitd3b5c0ba29623cff08e03b65e43e2e2baacd185c (patch)
tree36450c3386d5ebc33982ff6379395a0f00b412e7
parent897cc929497333d1bc75b1e59a5225f27c2a2c57 (diff)
downloadorg.eclipse.tycho.nexus-d3b5c0ba29623cff08e03b65e43e2e2baacd185c.tar.gz
org.eclipse.tycho.nexus-d3b5c0ba29623cff08e03b65e43e2e2baacd185c.tar.xz
org.eclipse.tycho.nexus-d3b5c0ba29623cff08e03b65e43e2e2baacd185c.zip
[refactoring] Inlined assertions in test
-rw-r--r--unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java53
1 files changed, 32 insertions, 21 deletions
diff --git a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
index 3c64da5..fcfbb66 100644
--- a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
+++ b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
@@ -17,11 +17,13 @@ import static org.sonatype.nexus.client.core.subsystem.content.Location.reposito
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;
import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.apache.commons.io.IOUtils;
@@ -38,6 +40,8 @@ import org.sonatype.nexus.testsuite.support.NexusStartAndStopStrategy.Strategy;
@NexusStartAndStopStrategy(Strategy.EACH_TEST)
public class UnzipRepositoryPluginITCase extends AbstractUnzipRepositoryPluginITCase {
+ private static final String POM_PROPERTIES_PATH_IN_ZIP = "META-INF/maven/org.example/artifact/pom.properties";
+
@Parameters
public static Collection<Object[]> data() {
// nexus versions to be tested against
@@ -106,34 +110,49 @@ public class UnzipRepositoryPluginITCase extends AbstractUnzipRepositoryPluginIT
@Test
public void testUnzipRepoWithHostedRepoAsMaster() throws Exception {
- assertDownloadExampleZipEntryFromUnzipRepository("releases.unzip", EXAMPLE_RELEASED_JAR, "artifacts/releases/");
+ assertEquals(getTestData(EXAMPLE_RELEASED_JAR, "artifacts/releases/"),
+ getFileFromZipInRepo("releases.unzip", EXAMPLE_RELEASED_JAR));
}
@Test
public void testUnzipRepoWithGroupRepoAsMaster() throws Exception {
- assertDownloadExampleZipEntryFromUnzipRepository("releases.group.unzip", EXAMPLE_RELEASED_JAR,
- "artifacts/releases/");
+ assertEquals(getTestData(EXAMPLE_RELEASED_JAR, "artifacts/releases/"),
+ getFileFromZipInRepo("releases.group.unzip", EXAMPLE_RELEASED_JAR));
}
@Test
public void testUnzipRepoWithVirtualSnapshotVersion() throws Exception {
// use virtual version "SNAPSHOT" which should translate to latest available snapshot
- assertDownloadExampleZipEntryFromUnzipRepository("snapshots.unzip", EXAMPLE_SNAPSHOT_JAR, EXAMPLE_PATH_PREFIX
- + "SNAPSHOT/" + EXAMPLE_ARTIFACTID + "-SNAPSHOT.jar", "artifacts/snapshots/");
+ assertEquals(
+ getTestData(EXAMPLE_SNAPSHOT_JAR, "artifacts/snapshots/"),
+ getFileFromZipInRepo("snapshots.unzip", EXAMPLE_PATH_PREFIX + "SNAPSHOT/" + EXAMPLE_ARTIFACTID
+ + "-SNAPSHOT.jar"));
}
- private void assertDownloadExampleZipEntryFromUnzipRepository(final String unzipRepositoryId, String artifactPath,
- String testDataPrefix) throws IOException {
- assertDownloadExampleZipEntryFromUnzipRepository(unzipRepositoryId, artifactPath, artifactPath, testDataPrefix);
+ private String getTestData(String localArtifactPath, String testDataPrefix) throws ZipException, IOException {
+ ZipFile zipFile = new ZipFile(testData().resolveFile(testDataPrefix + localArtifactPath));
+ String expectedContent;
+ try {
+ ZipEntry entry = zipFile.getEntry(POM_PROPERTIES_PATH_IN_ZIP);
+ expectedContent = IOUtils.toString(zipFile.getInputStream(entry));
+ } finally {
+ zipFile.close();
+ }
+ return expectedContent;
}
- private void assertDownloadExampleZipEntryFromUnzipRepository(final String unzipRepositoryId,
- String localArtifactPath, String remoteArtifactPath, String testDataPrefix) throws IOException {
- final String pathInZip = "META-INF/maven/org.example/artifact/pom.properties";
+ private String getFileFromZipInRepo(final String unzipRepositoryId, String zipArchivePath) throws IOException,
+ FileNotFoundException {
+ String pathToFileInRepo = zipArchivePath + "-unzip/" + POM_PROPERTIES_PATH_IN_ZIP;
+ return getContentFromRepo(unzipRepositoryId, pathToFileInRepo);
+ }
+
+ private String getContentFromRepo(final String unzipRepositoryId, String path) throws IOException,
+ FileNotFoundException {
String downloadedContent;
final File tempFile = File.createTempFile("test", "unzip");
try {
- final Location loc = repositoryLocation(unzipRepositoryId, remoteArtifactPath + "-unzip/" + pathInZip);
+ final Location loc = repositoryLocation(unzipRepositoryId, path);
getNexusContentService().download(loc, tempFile);
FileInputStream stream = new FileInputStream(tempFile);
try {
@@ -144,15 +163,7 @@ public class UnzipRepositoryPluginITCase extends AbstractUnzipRepositoryPluginIT
} finally {
tempFile.delete();
}
- ZipFile zipFile = new ZipFile(testData().resolveFile(testDataPrefix + localArtifactPath));
- String expectedContent;
- try {
- ZipEntry entry = zipFile.getEntry(pathInZip);
- expectedContent = IOUtils.toString(zipFile.getInputStream(entry));
- } finally {
- zipFile.close();
- }
- assertEquals(expectedContent, downloadedContent);
+ return downloadedContent;
}
private boolean canResolveExampleArtifact(String repositoryId, String version) {

Back to the top