Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJochen Ehret2014-03-27 09:16:16 -0400
committerJochen Ehret2014-03-27 11:34:03 -0400
commitdeb24a020841e939459d0584746e057c0b138b27 (patch)
tree51fdf7bd5185afa237c49240fb30bc7e74b68749
parent8e8ae596e14a3fde5db6c0300768725618a19d4f (diff)
downloadorg.eclipse.tycho.nexus-deb24a020841e939459d0584746e057c0b138b27.tar.gz
org.eclipse.tycho.nexus-deb24a020841e939459d0584746e057c0b138b27.tar.xz
org.eclipse.tycho.nexus-deb24a020841e939459d0584746e057c0b138b27.zip
423014 Port unzip plugin to Nexus 2.7
* Use Nexus 2.7.0-01 and adapt to changed Nexus APIs * Use NexusTestSupport to obtain instances of Nexus repository classes Bug: 423014 Change-Id: I670aa39e351f3dea0d6ee7640d7d4109596dda47 Signed-off-by: Jochen Ehret <jochen.ehret@sap.com> Also-by: Jan Sievers <jan.sievers@sap.com>
-rw-r--r--pom.xml10
-rw-r--r--unzip-repository-plugin/pom.xml33
-rw-r--r--unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java12
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstHostedRepositoryTest.java6
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstProxyRepositoryTest.java4
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java28
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java16
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItemTest.java26
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java38
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java31
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/FSLocalRepositoryStorageMock.java12
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java24
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java25
-rw-r--r--unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipRepositoryMock.java17
14 files changed, 181 insertions, 101 deletions
diff --git a/pom.xml b/pom.xml
index bbe3c45..40900a4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,11 +71,11 @@
<properties>
<!-- nexus version we compile against -->
- <nexus.version>2.6.0-01</nexus.version>
+ <nexus.version>2.7.0-01</nexus.version>
<!-- minimum nexus version to run ITs against -->
<nexus.test.min.version>${nexus.version}</nexus.test.min.version>
<!-- maximum nexus version to run ITs against -->
- <nexus.test.max.version>2.6.2-01</nexus.test.max.version>
+ <nexus.test.max.version>2.7.1-01</nexus.test.max.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
@@ -129,6 +129,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus-test-common</artifactId>
+ <version>${nexus.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
diff --git a/unzip-repository-plugin/pom.xml b/unzip-repository-plugin/pom.xml
index 9c3c5f8..611da26 100644
--- a/unzip-repository-plugin/pom.xml
+++ b/unzip-repository-plugin/pom.xml
@@ -41,6 +41,10 @@
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.sonatype.nexus</groupId>
+ <artifactId>nexus-test-common</artifactId>
+ </dependency>
</dependencies>
<build>
@@ -94,6 +98,35 @@
</executions>
</plugin>
</plugins>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.sonatype.plugins</groupId>
+ <artifactId>app-lifecycle-maven-plugin</artifactId>
+ <goals>
+ <goal>check-dependencies</goal>
+ <goal>generate-metadata</goal>
+ </goals>
+ <versionRange>[1.0,)</versionRange>
+ </pluginExecutionFilter>
+ <action>
+ <ignore />
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
</build>
</project>
diff --git a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java
index f808ac8..951ec69 100644
--- a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java
+++ b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageFileItem.java
@@ -24,9 +24,11 @@ public final class ZippedStorageFileItem extends DefaultStorageFileItem {
private static class ZippedStorageFileContentLocator implements ContentLocator {
private final ZippedItem zippedItem;
+ private final long length;
- private ZippedStorageFileContentLocator(final ZippedItem zippedItem) {
+ private ZippedStorageFileContentLocator(final ZippedItem zippedItem, long length) {
this.zippedItem = zippedItem;
+ this.length = length;
}
@Override
@@ -44,6 +46,11 @@ public final class ZippedStorageFileItem extends DefaultStorageFileItem {
return false;
}
+ @Override
+ public long getLength() {
+ return length;
+ }
+
}
/**
@@ -58,11 +65,10 @@ public final class ZippedStorageFileItem extends DefaultStorageFileItem {
*/
public ZippedStorageFileItem(final ZippedItem zippedItem, final long length) {
super(zippedItem.getRepository(), new ResourceStoreRequest(zippedItem.getPath()), true, false,
- new ZippedStorageFileContentLocator(zippedItem));
+ new ZippedStorageFileContentLocator(zippedItem, length));
// At creation time the underlying zip entry is known.
// Keeping this information avoids to open the zip and loop over the
// entries when answering related questions
- setLength(length);
setModified(zippedItem.getLastModified());
}
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstHostedRepositoryTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstHostedRepositoryTest.java
index 2110ac2..631a6e3 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstHostedRepositoryTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstHostedRepositoryTest.java
@@ -24,8 +24,10 @@ import org.sonatype.nexus.proxy.IllegalOperationException;
import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.NoSuchResourceStoreException;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
+import org.sonatype.nexus.proxy.item.RepositoryItemUidFactory;
import org.sonatype.nexus.proxy.item.StorageCollectionItem;
import org.sonatype.nexus.proxy.item.StorageItem;
+import org.sonatype.nexus.proxy.item.uid.RepositoryItemUidAttributeManager;
import org.sonatype.nexus.util.ItemPathUtils;
/**
@@ -34,8 +36,8 @@ import org.sonatype.nexus.util.ItemPathUtils;
public class DefaultUnzipRepositoryAgainstHostedRepositoryTest extends DefaultUnzipRepositoryTest {
@Override
- protected RepositoryMock createRepositoryMock() {
- return RepositoryMock.createMasterRepo();
+ protected RepositoryMock createRepositoryMock() throws Exception {
+ return createMasterRepo();
}
@Test
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstProxyRepositoryTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstProxyRepositoryTest.java
index 1c1ad57..d38ed96 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstProxyRepositoryTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryAgainstProxyRepositoryTest.java
@@ -30,8 +30,8 @@ import org.eclipse.tycho.nexus.internal.plugin.test.RepositoryMock;
public class DefaultUnzipRepositoryAgainstProxyRepositoryTest extends DefaultUnzipRepositoryTest {
@Override
- protected RepositoryMock createRepositoryMock() {
- final RepositoryMock masterRepo = RepositoryMock.createMasterRepo();
+ protected RepositoryMock createRepositoryMock() throws Exception {
+ final RepositoryMock masterRepo = createMasterRepo();
masterRepo.setBehaveAsProxy(true);
return masterRepo;
}
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java
index c31e48e..21b93c0 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepositoryTest.java
@@ -10,10 +10,6 @@
*******************************************************************************/
package org.eclipse.tycho.nexus.internal.plugin;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.util.Collection;
@@ -21,8 +17,9 @@ import org.eclipse.tycho.nexus.internal.plugin.storage.Util;
import org.eclipse.tycho.nexus.internal.plugin.storage.ZippedStorageCollectionItem;
import org.eclipse.tycho.nexus.internal.plugin.test.RepositoryMock;
import org.eclipse.tycho.nexus.internal.plugin.test.TestUtil;
-import org.eclipse.tycho.nexus.internal.plugin.test.UnzipRepositoryMock;
+import org.eclipse.tycho.nexus.internal.plugin.test.UnzipPluginTestSupport;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.sonatype.nexus.proxy.AccessDeniedException;
import org.sonatype.nexus.proxy.IllegalOperationException;
@@ -39,24 +36,25 @@ import org.sonatype.nexus.proxy.repository.ShadowRepository;
import org.sonatype.nexus.proxy.storage.UnsupportedStorageOperationException;
import org.sonatype.nexus.util.ItemPathUtils;
-public abstract class DefaultUnzipRepositoryTest {
- protected final RepositoryMock repositoryMock;
- protected final DefaultUnzipRepository unzipRepo;
+public abstract class DefaultUnzipRepositoryTest extends UnzipPluginTestSupport {
+ protected RepositoryMock repositoryMock;
+ protected DefaultUnzipRepository unzipRepo;
+
+ protected abstract RepositoryMock createRepositoryMock() throws Exception;
- public DefaultUnzipRepositoryTest() {
+ @Before
+ public void setup() throws Exception {
repositoryMock = createRepositoryMock();
- unzipRepo = UnzipRepositoryMock.createUnzipRepository(repositoryMock);
+ unzipRepo = createUnzipRepo(repositoryMock);
}
- protected abstract RepositoryMock createRepositoryMock();
-
@Test
public void testGetRepositoryKind() {
final DefaultUnzipRepository repo = new DefaultUnzipRepository();
final RepositoryKind kind = repo.getRepositoryKind();
- assertEquals(UnzipRepository.class, kind.getMainFacet());
- assertTrue(kind.isFacetAvailable(ShadowRepository.class));
- assertFalse(kind.isFacetAvailable(HostedRepository.class));
+ Assert.assertEquals(UnzipRepository.class, kind.getMainFacet());
+ Assert.assertTrue(kind.isFacetAvailable(ShadowRepository.class));
+ Assert.assertFalse(kind.isFacetAvailable(HostedRepository.class));
}
@Test
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java
index 41bf1c5..42950ba 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/cache/UnzipCacheTest.java
@@ -10,10 +10,6 @@
*******************************************************************************/
package org.eclipse.tycho.nexus.internal.plugin.cache;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
@@ -25,11 +21,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
-import org.eclipse.tycho.nexus.internal.plugin.cache.ConversionResult;
-import org.eclipse.tycho.nexus.internal.plugin.cache.UnzipCache;
-import org.eclipse.tycho.nexus.internal.plugin.test.RepositoryMock;
import org.eclipse.tycho.nexus.internal.plugin.test.TestUtil;
-import org.eclipse.tycho.nexus.internal.plugin.test.UnzipRepositoryMock;
+import org.eclipse.tycho.nexus.internal.plugin.test.UnzipPluginTestSupport;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
@@ -37,7 +30,7 @@ import org.sonatype.nexus.proxy.ItemNotFoundException;
import org.sonatype.nexus.proxy.StorageException;
@SuppressWarnings("deprecation")
-public class UnzipCacheTest {
+public class UnzipCacheTest extends UnzipPluginTestSupport {
private static final String PATH_UP_TO_VERSION = "/ga/1.0.0-SNAPSHOT/archive-1.0.0-";
private static final String LATEST_VERSION = "20101013";
@@ -54,9 +47,8 @@ public class UnzipCacheTest {
private static File latestOtherZip;
@Before
- public void setupTestRepos() throws StorageException, ItemNotFoundException {
- snapshotRepoUnzipCache = UnzipRepositoryMock.createUnzipRepository(RepositoryMock.createSnapshotRepo())
- .getCache();
+ public void setupTestRepos() throws Exception {
+ snapshotRepoUnzipCache = createUnzipRepo(createSnapshotRepo()).getCache();
oldZip = snapshotRepoUnzipCache.getArchive(PATH_TO_OLD_ZIP);
oldOtherzip = snapshotRepoUnzipCache.getArchive(PATH_TO_OLD_OTHER_ZIP);
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItemTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItemTest.java
index fdf5720..2782809 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItemTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZipAwareStorageCollectionItemTest.java
@@ -17,9 +17,10 @@ import java.util.ArrayList;
import org.eclipse.tycho.nexus.internal.plugin.DefaultUnzipRepository;
import org.eclipse.tycho.nexus.internal.plugin.test.RepositoryMock;
import org.eclipse.tycho.nexus.internal.plugin.test.TestUtil;
-import org.eclipse.tycho.nexus.internal.plugin.test.UnzipRepositoryMock;
+import org.eclipse.tycho.nexus.internal.plugin.test.UnzipPluginTestSupport;
import org.junit.AfterClass;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,15 +32,22 @@ import org.sonatype.nexus.proxy.item.StorageCollectionItem;
import org.sonatype.nexus.proxy.item.StorageItem;
@SuppressWarnings("nls")
-public class ZipAwareStorageCollectionItemTest {
+public class ZipAwareStorageCollectionItemTest extends UnzipPluginTestSupport {
protected Logger testLogger = LoggerFactory.getLogger(getClass());
+ private RepositoryMock masterRepository;
+ private DefaultUnzipRepository unzipRepositoryMock;
+
+ @Before
+ public void setup() throws Exception {
+ masterRepository = createMasterRepo();
+ unzipRepositoryMock = createUnzipRepo(masterRepository);
+ }
+
@Test
public void testListWithArchiveMember() throws ItemNotFoundException, IOException, AccessDeniedException,
NoSuchResourceStoreException, IllegalOperationException {
- final RepositoryMock masterRepository = RepositoryMock.createMasterRepo();
- final DefaultUnzipRepository unzipRepositoryMock = UnzipRepositoryMock.createUnzipRepository(masterRepository);
final StorageCollectionItem collectionStorageItem = (StorageCollectionItem) masterRepository
.createStorageItem("/dir/subdir");
final ZipAwareStorageCollectionItem zipAwareStorageCollectionItem = new ZipAwareStorageCollectionItem(
@@ -53,9 +61,8 @@ public class ZipAwareStorageCollectionItemTest {
@Test
public void testListWithSnapshotArchives() throws Exception {
- final RepositoryMock masterRepository = RepositoryMock.createSnapshotRepo();
- final DefaultUnzipRepository unzipRepositoryMock = UnzipRepositoryMock.createUnzipRepository(masterRepository);
- final StorageCollectionItem collectionStorageItem = (StorageCollectionItem) masterRepository
+ unzipRepositoryMock = createUnzipRepo(createSnapshotRepo());
+ final StorageCollectionItem collectionStorageItem = (StorageCollectionItem) createSnapshotRepo()
.createStorageItem("/ga/1.0.0-SNAPSHOT");
final ZipAwareStorageCollectionItem zipAwareStorageCollectionItem = new ZipAwareStorageCollectionItem(
unzipRepositoryMock, collectionStorageItem, testLogger);
@@ -63,14 +70,11 @@ public class ZipAwareStorageCollectionItemTest {
"/ga/1.0.0-SNAPSHOT/archive-1.0.0-SNAPSHOT-juhu.zip" + Util.UNZIP_TYPE_EXTENSION,
"/ga/1.0.0-SNAPSHOT/archive-1.0.0-SNAPSHOT.zip" + Util.UNZIP_TYPE_EXTENSION }, new String[0],
zipAwareStorageCollectionItem.list());
-
}
@Test
public void testModificationTimes() throws ItemNotFoundException, IOException, AccessDeniedException,
NoSuchResourceStoreException, IllegalOperationException {
- final RepositoryMock masterRepository = RepositoryMock.createMasterRepo();
- final DefaultUnzipRepository unzipRepositoryMock = UnzipRepositoryMock.createUnzipRepository(masterRepository);
final StorageCollectionItem collectionStorageItem = (StorageCollectionItem) masterRepository
.createStorageItem("/dir/subdir");
final ZipAwareStorageCollectionItem zipAwareStorageCollectionItem = new ZipAwareStorageCollectionItem(
@@ -88,8 +92,6 @@ public class ZipAwareStorageCollectionItemTest {
@Test
public void testListWithoutArchiveMember() throws ItemNotFoundException, IOException, AccessDeniedException,
NoSuchResourceStoreException, IllegalOperationException {
- final RepositoryMock masterRepository = RepositoryMock.createMasterRepo();
- final DefaultUnzipRepository unzipRepositoryMock = UnzipRepositoryMock.createUnzipRepository(masterRepository);
final StorageCollectionItem collectionStorageItem = (StorageCollectionItem) masterRepository
.createStorageItem("/dir");
final ZipAwareStorageCollectionItem zipAwareStorageCollectionItem = new ZipAwareStorageCollectionItem(
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java
index fd3a83a..96d9841 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedItemTest.java
@@ -13,11 +13,11 @@ package org.eclipse.tycho.nexus.internal.plugin.storage;
import java.io.IOException;
import org.eclipse.tycho.nexus.internal.plugin.DefaultUnzipRepository;
-import org.eclipse.tycho.nexus.internal.plugin.test.RepositoryMock;
import org.eclipse.tycho.nexus.internal.plugin.test.TestUtil;
-import org.eclipse.tycho.nexus.internal.plugin.test.UnzipRepositoryMock;
+import org.eclipse.tycho.nexus.internal.plugin.test.UnzipPluginTestSupport;
import org.junit.AfterClass;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import org.sonatype.nexus.proxy.ItemNotFoundException;
@@ -27,11 +27,17 @@ import org.sonatype.nexus.proxy.item.DefaultStorageFileItem;
import org.sonatype.nexus.util.ItemPathUtils;
@SuppressWarnings("nls")
-public class ZippedItemTest {
+public class ZippedItemTest extends UnzipPluginTestSupport {
+
private final String pathToArchive = "/dir/subdir/archive.zip";
private final String pathToUnzippedArchive = "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION;
- private final DefaultUnzipRepository unzipReposMock =
- UnzipRepositoryMock.createUnzipRepository(RepositoryMock.createMasterRepo());
+
+ private DefaultUnzipRepository unzipReposMock;
+
+ @Before
+ public void setup() throws Exception {
+ unzipReposMock = createUnzipRepo(createMasterRepo());
+ }
@Test
public void testZippedItemInRoot() throws ItemNotFoundException, IOException {
@@ -87,8 +93,8 @@ public class ZippedItemTest {
Assert.assertEquals(pathToUnzippedArchive, zippedItem.getPath());
Assert.assertNull(zippedItem.getMimeType());
- final DefaultStorageCollectionItem zippedStorageItem =
- (DefaultStorageCollectionItem) zippedItem.getZippedStorageItem();
+ final DefaultStorageCollectionItem zippedStorageItem = (DefaultStorageCollectionItem) zippedItem
+ .getZippedStorageItem();
Assert.assertEquals(pathToUnzippedArchive, zippedStorageItem.getPath());
}
@@ -101,8 +107,8 @@ public class ZippedItemTest {
Assert.assertEquals(pathToUnzippedArchive, zippedItem.getPath());
Assert.assertNull(zippedItem.getMimeType());
- final DefaultStorageCollectionItem zippedStorageItem =
- (DefaultStorageCollectionItem) zippedItem.getZippedStorageItem();
+ final DefaultStorageCollectionItem zippedStorageItem = (DefaultStorageCollectionItem) zippedItem
+ .getZippedStorageItem();
Assert.assertEquals(pathToUnzippedArchive, zippedStorageItem.getPath());
}
@@ -115,8 +121,8 @@ public class ZippedItemTest {
Assert.assertEquals(pathToUnzippedArchive + "/" + pathInZip, zippedItem.getPath());
Assert.assertNull(zippedItem.getMimeType());
- final DefaultStorageCollectionItem zippedStorageItem =
- (DefaultStorageCollectionItem) zippedItem.getZippedStorageItem();
+ final DefaultStorageCollectionItem zippedStorageItem = (DefaultStorageCollectionItem) zippedItem
+ .getZippedStorageItem();
Assert.assertEquals(pathToUnzippedArchive + "/" + pathInZip, zippedStorageItem.getPath());
}
@@ -127,13 +133,13 @@ public class ZippedItemTest {
Assert.assertEquals(ItemPathUtils.cleanUpTrailingSlash(pathInZip), zippedItem.getPathInZip());
Assert.assertEquals(ItemPathUtils.cleanUpTrailingSlash(pathToUnzippedArchive + "/" + pathInZip),
- zippedItem.getPath());
+ zippedItem.getPath());
Assert.assertNull(zippedItem.getMimeType());
- final DefaultStorageCollectionItem zippedStorageItem =
- (DefaultStorageCollectionItem) zippedItem.getZippedStorageItem();
+ final DefaultStorageCollectionItem zippedStorageItem = (DefaultStorageCollectionItem) zippedItem
+ .getZippedStorageItem();
Assert.assertEquals(ItemPathUtils.cleanUpTrailingSlash(pathToUnzippedArchive + "/" + pathInZip),
- zippedStorageItem.getPath());
+ zippedStorageItem.getPath());
}
@Test(expected = LocalStorageException.class)
@@ -157,7 +163,7 @@ public class ZippedItemTest {
final ZippedItem zippedItem = createZippedItem(pathInZip);
TestUtil.assertMembers(new String[] { pathToUnzippedArchive + "/" + pathInZip + "subdir" },
- new String[] { pathToUnzippedArchive + "/" + pathInZip + "test.txt" }, zippedItem.listMembers());
+ new String[] { pathToUnzippedArchive + "/" + pathInZip + "test.txt" }, zippedItem.listMembers());
}
@Test(expected = LocalStorageException.class)
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java
index d08b9c2..dd22dbc 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/storage/ZippedStorageCollectionItemTest.java
@@ -10,17 +10,15 @@
*******************************************************************************/
package org.eclipse.tycho.nexus.internal.plugin.storage;
-import static org.junit.Assert.assertEquals;
-
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import org.eclipse.tycho.nexus.internal.plugin.DefaultUnzipRepository;
-import org.eclipse.tycho.nexus.internal.plugin.test.RepositoryMock;
import org.eclipse.tycho.nexus.internal.plugin.test.TestUtil;
-import org.eclipse.tycho.nexus.internal.plugin.test.UnzipRepositoryMock;
+import org.eclipse.tycho.nexus.internal.plugin.test.UnzipPluginTestSupport;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
@@ -32,36 +30,35 @@ import org.sonatype.nexus.proxy.NoSuchResourceStoreException;
import org.sonatype.nexus.proxy.item.StorageItem;
@SuppressWarnings("nls")
-public class ZippedStorageCollectionItemTest {
+public class ZippedStorageCollectionItemTest extends UnzipPluginTestSupport {
private DefaultUnzipRepository unzipRepositoryMock;
protected Logger testLogger = LoggerFactory.getLogger(getClass());
@Before
- public void setupRepo() {
- unzipRepositoryMock = UnzipRepositoryMock.createUnzipRepository(RepositoryMock.createMasterRepo());
+ public void setupRepo() throws Exception {
+ unzipRepositoryMock = createUnzipRepo(createMasterRepo());
}
@Test
public void testList() throws ItemNotFoundException, IOException, AccessDeniedException,
NoSuchResourceStoreException, IllegalOperationException {
- final ZippedItem zippedItem =
- new ZippedItem(unzipRepositoryMock, "/dir/subdir/archive.zip", "dir", 0L, testLogger);
+ final ZippedItem zippedItem = new ZippedItem(unzipRepositoryMock, "/dir/subdir/archive.zip", "dir", 0L,
+ testLogger);
final ZippedStorageCollectionItem zippedStorageCollectionItem = new ZippedStorageCollectionItem(zippedItem);
TestUtil.assertMembers(new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/dir/subdir" },
- new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/dir/test.txt" },
- zippedStorageCollectionItem.list());
+ new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/dir/test.txt" },
+ zippedStorageCollectionItem.list());
}
@Test
public void testListInRoot() throws ItemNotFoundException, IOException, AccessDeniedException,
NoSuchResourceStoreException, IllegalOperationException {
- final ZippedItem zippedItem =
- new ZippedItem(unzipRepositoryMock, "/dir/subdir/archive.zip", "", 0L, testLogger);
+ final ZippedItem zippedItem = new ZippedItem(unzipRepositoryMock, "/dir/subdir/archive.zip", "", 0L, testLogger);
final ZippedStorageCollectionItem zippedStorageCollectionItem = new ZippedStorageCollectionItem(zippedItem);
TestUtil.assertMembers(new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/dir" },
- new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/test.txt" },
- zippedStorageCollectionItem.list());
+ new String[] { "/dir/subdir/archive.zip" + Util.UNZIP_TYPE_EXTENSION + "/test.txt" },
+ zippedStorageCollectionItem.list());
}
@Test
@@ -72,13 +69,13 @@ public class ZippedStorageCollectionItemTest {
final ZippedItem zipItem = new ZippedItem(unzipRepositoryMock, "/dir/subdir/archive.zip", "", time, testLogger);
final ZippedStorageCollectionItem zipStorageCollectionItem = new ZippedStorageCollectionItem(zipItem);
- assertEquals(time, zipStorageCollectionItem.getModified());
+ Assert.assertEquals(time, zipStorageCollectionItem.getModified());
//timestamps of zip entries are not time zone aware, therefore all entries shall inherit
//the timestamp of the zip file itself
final Collection<StorageItem> list = zipStorageCollectionItem.list();
for (final StorageItem storageItem : list) {
- assertEquals(time, storageItem.getModified());
+ Assert.assertEquals(time, storageItem.getModified());
}
}
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/FSLocalRepositoryStorageMock.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/FSLocalRepositoryStorageMock.java
index e6ce511..515a20f 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/FSLocalRepositoryStorageMock.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/FSLocalRepositoryStorageMock.java
@@ -14,21 +14,23 @@ import java.io.File;
import java.io.IOException;
import org.codehaus.plexus.util.FileUtils;
+import org.easymock.EasyMock;
import org.sonatype.nexus.mime.DefaultMimeSupport;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
-import org.sonatype.nexus.proxy.item.DefaultLinkPersister;
+import org.sonatype.nexus.proxy.item.LinkPersister;
import org.sonatype.nexus.proxy.repository.Repository;
import org.sonatype.nexus.proxy.storage.local.fs.DefaultFSLocalRepositoryStorage;
import org.sonatype.nexus.proxy.storage.local.fs.DefaultFSPeer;
-import org.sonatype.nexus.proxy.wastebasket.DefaultWastebasket;
+import org.sonatype.nexus.proxy.wastebasket.Wastebasket;
public class FSLocalRepositoryStorageMock extends DefaultFSLocalRepositoryStorage {
private final File baseDir = FileUtils.createTempFile("nexus-unzip" + File.separator, "test-storage", null);
- public FSLocalRepositoryStorageMock() {
- super(new DefaultWastebasket(), new DefaultLinkPersister(), new DefaultMimeSupport(), new DefaultFSPeer());
-
+ public FSLocalRepositoryStorageMock(LinkPersister linkPersister) {
+ // Wastebasket implementation cannot be retrieved with lookup()
+ // -> use nice mock for now (deletion of items is not tested)
+ super(EasyMock.createNiceMock(Wastebasket.class), linkPersister, new DefaultMimeSupport(), new DefaultFSPeer());
if (baseDir.exists()) {
try {
FileUtils.forceDelete(baseDir);
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java
index 1c03859..d89c071 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/RepositoryMock.java
@@ -30,12 +30,10 @@ import org.sonatype.nexus.proxy.NoSuchResourceStoreException;
import org.sonatype.nexus.proxy.ResourceStoreRequest;
import org.sonatype.nexus.proxy.StorageException;
import org.sonatype.nexus.proxy.item.ContentLocator;
-import org.sonatype.nexus.proxy.item.DefaultRepositoryItemUidFactory;
import org.sonatype.nexus.proxy.item.DefaultStorageFileItem;
import org.sonatype.nexus.proxy.item.RepositoryItemUidFactory;
import org.sonatype.nexus.proxy.item.StorageCollectionItem;
import org.sonatype.nexus.proxy.item.StorageItem;
-import org.sonatype.nexus.proxy.item.uid.DefaultRepositoryItemUidAttributeManager;
import org.sonatype.nexus.proxy.item.uid.RepositoryItemUidAttributeManager;
import org.sonatype.nexus.proxy.registry.ContentClass;
import org.sonatype.nexus.proxy.repository.AbstractRepository;
@@ -48,13 +46,17 @@ public class RepositoryMock extends AbstractRepository {
private final String repositoryId;
private boolean behaveAsProxy = false;
+ private RepositoryItemUidFactory repositoryItemUidFactory;
+ private RepositoryItemUidAttributeManager repositoryItemUidAttributeManager;
+
/**
* Creates a Repository with dummy snapshot content from src/test/resources/snapshotRepo
*
* @return
*/
- public static RepositoryMock createSnapshotRepo() {
- return new RepositoryMock("snapshotRepo");
+ public static RepositoryMock createSnapshotRepo(RepositoryItemUidFactory repositoryItemUidFactory,
+ RepositoryItemUidAttributeManager repositoryItemUidAttributeManager) {
+ return new RepositoryMock("snapshotRepo", repositoryItemUidFactory, repositoryItemUidAttributeManager);
}
/**
@@ -62,12 +64,16 @@ public class RepositoryMock extends AbstractRepository {
*
* @return
*/
- public static RepositoryMock createMasterRepo() {
- return new RepositoryMock("masterRepo");
+ public static RepositoryMock createMasterRepo(RepositoryItemUidFactory repositoryItemUidFactory,
+ RepositoryItemUidAttributeManager repositoryItemUidAttributeManager) {
+ return new RepositoryMock("masterRepo", repositoryItemUidFactory, repositoryItemUidAttributeManager);
}
- private RepositoryMock(final String repositoryId) {
+ private RepositoryMock(final String repositoryId, RepositoryItemUidFactory repositoryItemUidFactory,
+ RepositoryItemUidAttributeManager repositoryItemUidAttributeManager) {
this.repositoryId = repositoryId;
+ this.repositoryItemUidFactory = repositoryItemUidFactory;
+ this.repositoryItemUidAttributeManager = repositoryItemUidAttributeManager;
}
@Override
@@ -102,12 +108,12 @@ public class RepositoryMock extends AbstractRepository {
@Override
protected RepositoryItemUidFactory getRepositoryItemUidFactory() {
- return new DefaultRepositoryItemUidFactory();
+ return repositoryItemUidFactory;
}
@Override
public RepositoryItemUidAttributeManager getRepositoryItemUidAttributeManager() {
- return new DefaultRepositoryItemUidAttributeManager();
+ return repositoryItemUidAttributeManager;
}
public StorageItem createStorageItem(final String path) throws StorageException, ItemNotFoundException,
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java
new file mode 100644
index 0000000..f352976
--- /dev/null
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipPluginTestSupport.java
@@ -0,0 +1,25 @@
+package org.eclipse.tycho.nexus.internal.plugin.test;
+
+import org.eclipse.tycho.nexus.internal.plugin.DefaultUnzipRepository;
+import org.sonatype.nexus.proxy.item.LinkPersister;
+import org.sonatype.nexus.proxy.item.RepositoryItemUidFactory;
+import org.sonatype.nexus.proxy.item.uid.RepositoryItemUidAttributeManager;
+import org.sonatype.nexus.test.NexusTestSupport;
+
+public class UnzipPluginTestSupport extends NexusTestSupport {
+
+ protected RepositoryMock createMasterRepo() throws Exception {
+ return RepositoryMock.createMasterRepo(lookup(RepositoryItemUidFactory.class),
+ lookup(RepositoryItemUidAttributeManager.class));
+ }
+
+ protected RepositoryMock createSnapshotRepo() throws Exception {
+ return RepositoryMock.createSnapshotRepo(lookup(RepositoryItemUidFactory.class),
+ lookup(RepositoryItemUidAttributeManager.class));
+ }
+
+ protected DefaultUnzipRepository createUnzipRepo(RepositoryMock masterRepository) throws Exception {
+ return UnzipRepositoryMock.createUnzipRepository(masterRepository, lookup(LinkPersister.class),
+ lookup(RepositoryItemUidFactory.class));
+ }
+}
diff --git a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipRepositoryMock.java b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipRepositoryMock.java
index dd435e0..f6a95f2 100644
--- a/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipRepositoryMock.java
+++ b/unzip-repository-plugin/src/test/java/org/eclipse/tycho/nexus/internal/plugin/test/UnzipRepositoryMock.java
@@ -13,7 +13,7 @@ package org.eclipse.tycho.nexus.internal.plugin.test;
import org.easymock.EasyMock;
import org.eclipse.tycho.nexus.internal.plugin.DefaultUnzipRepository;
import org.sonatype.nexus.proxy.attributes.AttributesHandler;
-import org.sonatype.nexus.proxy.item.DefaultRepositoryItemUidFactory;
+import org.sonatype.nexus.proxy.item.LinkPersister;
import org.sonatype.nexus.proxy.item.RepositoryItemUidFactory;
import org.sonatype.nexus.proxy.repository.LocalStatus;
import org.sonatype.nexus.proxy.repository.Repository;
@@ -22,15 +22,20 @@ import org.sonatype.nexus.proxy.storage.local.LocalRepositoryStorage;
public class UnzipRepositoryMock extends DefaultUnzipRepository {
private final Repository masterRepository;
- private final LocalRepositoryStorage localStorage = new FSLocalRepositoryStorageMock();
+ private final LocalRepositoryStorage localStorage;
+ private final RepositoryItemUidFactory repositoryItemUidFactory;
- public static DefaultUnzipRepository createUnzipRepository(final Repository masterRepo) {
- return new UnzipRepositoryMock(masterRepo);
+ public static DefaultUnzipRepository createUnzipRepository(final Repository masterRepo,
+ LinkPersister linkPersister, RepositoryItemUidFactory repositoryItemUidFactory) {
+ return new UnzipRepositoryMock(masterRepo, linkPersister, repositoryItemUidFactory);
}
- private UnzipRepositoryMock(final Repository masterRepository) {
+ private UnzipRepositoryMock(final Repository masterRepository, LinkPersister linkPersister,
+ RepositoryItemUidFactory repositoryItemUidFactory) {
super();
this.masterRepository = masterRepository;
+ this.localStorage = new FSLocalRepositoryStorageMock(linkPersister);
+ this.repositoryItemUidFactory = repositoryItemUidFactory;
}
@Override
@@ -50,7 +55,7 @@ public class UnzipRepositoryMock extends DefaultUnzipRepository {
@Override
protected RepositoryItemUidFactory getRepositoryItemUidFactory() {
- return new DefaultRepositoryItemUidFactory();
+ return repositoryItemUidFactory;
}
@Override

Back to the top