From 69fad2da3e1802ee741a5f85e39558c11df44e9e Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 9 Dec 2013 11:21:30 +0000 Subject: [MRM-1761] add unit test git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1549544 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/archiva/DownloadSnapshotTest.java | 151 +++++++++++++++++++++ .../archiva-model-1.4-M4-20130425.081822-1.jar | Bin 0 -> 26682 bytes .../archiva-model-1.4-M4-20130425.081822-1.jar.md5 | 1 + ...archiva-model-1.4-M4-20130425.081822-1.jar.sha1 | 1 + .../archiva-model-1.4-M4-20130425.081822-1.pom | 97 +++++++++++++ .../archiva-model-1.4-M4-20130425.081822-1.pom.md5 | 1 + ...archiva-model-1.4-M4-20130425.081822-1.pom.sha1 | 1 + .../1.4-M4-SNAPSHOT/maven-metadata.xml | 14 ++ .../1.4-M4-SNAPSHOT/maven-metadata.xml.md5 | 1 + .../1.4-M4-SNAPSHOT/maven-metadata.xml.sha1 | 1 + .../archiva/archiva-model/maven-metadata.xml | 13 ++ .../archiva/archiva-model/maven-metadata.xml.md5 | 1 + .../archiva/archiva-model/maven-metadata.xml.sha1 | 1 + 13 files changed, 283 insertions(+) create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadSnapshotTest.java create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar.md5 create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar.sha1 create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom.md5 create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom.sha1 create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml.md5 create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml.sha1 create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml.md5 create mode 100644 archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml.sha1 (limited to 'archiva-modules/archiva-web') diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadSnapshotTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadSnapshotTest.java new file mode 100644 index 000000000..2cc9ed84c --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/DownloadSnapshotTest.java @@ -0,0 +1,151 @@ +package org.apache.archiva; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.redback.rest.api.services.RoleManagementService; +import org.apache.archiva.remotedownload.AbstractDownloadTest; +import org.apache.archiva.rest.api.services.ManagedRepositoriesService; +import org.apache.archiva.security.common.ArchivaRoleConstants; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.apache.commons.io.FileUtils; +import org.apache.maven.wagon.providers.http.HttpWagon; +import org.apache.maven.wagon.repository.Repository; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +/** + * @author Olivier Lamy + */ +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public class DownloadSnapshotTest + extends AbstractDownloadTest +{ + protected Logger log = LoggerFactory.getLogger( getClass() ); + + public Server redirectServer = null; + + public int redirectPort; + + public Server repoServer = null; + + public int repoServerPort; + + @BeforeClass + public static void setAppServerBase() + { + previousAppServerBase = System.getProperty( "appserver.base" ); + System.setProperty( "appserver.base", "target/" + DownloadSnapshotTest.class.getName() ); + } + + + @AfterClass + public static void resetAppServerBase() + { + System.setProperty( "appserver.base", previousAppServerBase ); + } + + protected String getSpringConfigLocation() + { + return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml"; + } + + + @Test + public void downloadSNAPSHOT() + throws Exception + { + + File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" ); + if ( tmpIndexDir.exists() ) + { + FileUtils.deleteDirectory( tmpIndexDir ); + } + String id = Long.toString( System.currentTimeMillis() ); + ManagedRepository managedRepository = new ManagedRepository(); + managedRepository.setId( id ); + managedRepository.setName( "name of " + id ); + managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/snapshot-repo" ); + managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id ); + + ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(); + + if ( managedRepositoriesService.getManagedRepository( id ) != null ) + { + managedRepositoriesService.deleteManagedRepository( id, false ); + } + + getManagedRepositoriesService().addManagedRepository( managedRepository ); + + RoleManagementService roleManagementService = getRoleManagementService( authorizationHeader ); + + if ( !roleManagementService.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, + id ) ) + { + roleManagementService.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id ); + } + + getUserService( authorizationHeader ).createGuestUser(); + roleManagementService.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, "guest" ); + + roleManagementService.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id, + "guest" ); + + getUserService( authorizationHeader ).removeFromCache( "guest" ); + + File file = new File( "target/archiva-model-1.4-M4-SNAPSHOT.jar" ); + if ( file.exists() ) + { + file.delete(); + } + + HttpWagon httpWagon = new HttpWagon(); + httpWagon.connect( new Repository( "foo", "http://localhost:" + port ) ); + + httpWagon.get( "/repository/"+ id +"/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-SNAPSHOT.jar", file ); + + ZipFile zipFile = new ZipFile( file ); + List entries = getZipEntriesNames( zipFile ); + ZipEntry zipEntry = zipFile.getEntry( "org/apache/archiva/model/ArchivaArtifact.class" ); + assertNotNull( "cannot find zipEntry org/apache/archiva/model/ArchivaArtifact.class, entries: " + entries + ", content is: " + + FileUtils.readFileToString( file ), zipEntry ); + zipFile.close(); + file.deleteOnExit(); + + + + } + +} diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar new file mode 100644 index 000000000..717933377 Binary files /dev/null and b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar differ diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar.md5 b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar.md5 new file mode 100644 index 000000000..adc54397e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar.md5 @@ -0,0 +1 @@ +7bbbf7bd56cc977171a377bcf8fc575d archiva-model-1.4-M4-20130425.081822-1.jar \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar.sha1 b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar.sha1 new file mode 100644 index 000000000..3e1103280 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar.sha1 @@ -0,0 +1 @@ +dd78b70834d1c65d09445f1b8b8b7ceacd70176d archiva-model-1.4-M4-20130425.081822-1.jar \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom new file mode 100644 index 000000000..a13aec642 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom @@ -0,0 +1,97 @@ + + + + + + org.apache.archiva + archiva-base + 1.4-M4-SNAPSHOT + + 4.0.0 + archiva-model + bundle + Archiva Base :: Model + + + commons-lang + commons-lang + + + commons-collections + commons-collections + + + org.apache.archiva + archiva-common + + + org.apache.archiva + archiva-test-utils + ${project.version} + test + + + org.apache.logging.log4j + log4j-jcl + runtime + + + + + + org.codehaus.modello + modello-maven-plugin + + 1.3.0 + false + + src/main/mdo/archiva-base.xml + + + + + archiva-base + + java + xsd + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.archiva.model + ${project.version} + + org.apache.archiva.model;version=${project.version} + + + org.apache.archiva.common.utils;version=${project.version}, + org.apache.commons.lang;version="[2.4,3)" + + + + + + + diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom.md5 b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom.md5 new file mode 100644 index 000000000..588e27f7e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom.md5 @@ -0,0 +1 @@ +4224fdcd90735e016789c05f82661775 archiva-model-1.4-M4-20130425.081822-1.pom \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom.sha1 b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom.sha1 new file mode 100644 index 000000000..dd67c960e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.pom.sha1 @@ -0,0 +1 @@ +751ebd75a9929191173bbbd98aed65e90a76546a archiva-model-1.4-M4-20130425.081822-1.pom \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..a5cef0911 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,14 @@ + + + + org.apache.archiva + archiva-model + 1.4-M4-SNAPSHOT + + + 1 + 20130425.081822 + + 20130425081822 + + diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml.md5 b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml.md5 new file mode 100644 index 000000000..49b43e7c5 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml.md5 @@ -0,0 +1 @@ +38b2d54f0788d21907565904a7508d37 maven-metadata.xml \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml.sha1 b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml.sha1 new file mode 100644 index 000000000..1946b173f --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +8cdfb3f0decf06645f38bd0007b4a4a40f75ad25 maven-metadata.xml \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml new file mode 100644 index 000000000..9632603b5 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml @@ -0,0 +1,13 @@ + + + + org.apache.archiva + archiva-model + + 1.4-M4-SNAPSHOT + + 1.4-M4-SNAPSHOT + + 20130425081823 + + diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml.md5 b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml.md5 new file mode 100644 index 000000000..ef6576a6e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml.md5 @@ -0,0 +1 @@ +ffe12bb5232c77cf8681f8d069026f88 maven-metadata.xml \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml.sha1 b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml.sha1 new file mode 100644 index 000000000..10690a438 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +cf7767cf64fa5eba6b66f9cba3401bca19baef54 maven-metadata.xml \ No newline at end of file -- cgit v1.2.3