Return-Path: Delivered-To: apmail-maven-archiva-commits-archive@locus.apache.org Received: (qmail 21906 invoked from network); 26 Oct 2007 01:00:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Oct 2007 01:00:18 -0000 Received: (qmail 72237 invoked by uid 500); 26 Oct 2007 01:00:06 -0000 Delivered-To: apmail-maven-archiva-commits-archive@maven.apache.org Received: (qmail 72193 invoked by uid 500); 26 Oct 2007 01:00:06 -0000 Mailing-List: contact archiva-commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: archiva-dev@maven.apache.org Delivered-To: mailing list archiva-commits@maven.apache.org Received: (qmail 72182 invoked by uid 99); 26 Oct 2007 01:00:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Oct 2007 18:00:06 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Oct 2007 01:00:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A74D81A9832; Thu, 25 Oct 2007 17:59:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r588460 - in /maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository: RepositoryServletProxiedPluginSnapshotPolicyTest.java RepositoryServletProxiedTimestampedSnapshotPolicyTest.java Date: Fri, 26 Oct 2007 00:59:49 -0000 To: archiva-commits@maven.apache.org From: joakime@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071026005949.A74D81A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: joakime Date: Thu Oct 25 17:59:48 2007 New Revision: 588460 URL: http://svn.apache.org/viewvc?rev=588460&view=rev Log: [MRM-567] Unable to download plugin SNAPSHOT's from proxy. Adding unit tests for Timestamped Snapshot GET from RepositoryServlet (with proxies). Adding unit tests for Timestamped Plugin Snapshot GET from RepositoryServlet (with proxies). Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedPluginSnapshotPolicyTest.java (with props) maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedTimestampedSnapshotPolicyTest.java (with props) Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedPluginSnapshotPolicyTest.java URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedPluginSnapshotPolicyTest.java?rev=588460&view=auto ============================================================================== --- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedPluginSnapshotPolicyTest.java (added) +++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedPluginSnapshotPolicyTest.java Thu Oct 25 17:59:48 2007 @@ -0,0 +1,195 @@ +package org.apache.maven.archiva.web.repository; + +/* + * 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 com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.HttpUnitOptions; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +import org.apache.maven.archiva.policies.SnapshotsPolicy; + +import java.io.File; + +/** + * RepositoryServlet Tests, Proxied, Get of Timestamped Snapshot Artifacts, with varying policy settings. + * + * @author Joakim Erdfelt + * @version $Id$ + */ +public class RepositoryServletProxiedPluginSnapshotPolicyTest + extends AbstractRepositoryServletProxiedTestCase +{ + public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.IGNORED, + HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.IGNORED, HAS_MANAGED_COPY, + ( OLDER * OVER_ONE_DAY ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.IGNORED, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDailyFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY, + ( NEWER * ONE_MINUTE ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDailyPass() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY, + ( OLDER * OVER_ONE_DAY ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDisabledFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DISABLED, + HAS_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDisabledNoManagedContentFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.DISABLED, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDisabledPass() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DISABLED, + HAS_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyHourlyFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY, + ( NEWER * ONE_MINUTE ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyHourlyPass() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY, + ( OLDER * OVER_ONE_HOUR ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyOnceFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyOncePass() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY ); + } + + private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy, + boolean hasManagedCopy ) + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 ); + } + + private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy, + boolean hasManagedCopy, long deltaManagedToRemoteTimestamp ) + throws Exception + { + // --- Setup + setupSnapshotsRemoteRepo(); + setupCleanInternalRepo(); + + String resourcePath = "org/apache/archiva/archivatest-maven-plugin/4.0-alpha-1-SNAPSHOT/archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42.jar"; + String expectedRemoteContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-remote-contents"; + String expectedManagedContents = null; + File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents ); + + if ( hasManagedCopy ) + { + expectedManagedContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-managed-contents"; + File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents ); + managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp ); + } + + setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy ); + saveConfiguration(); + + // --- Execution + // process the response code later, not via an exception. + HttpUnitOptions.setExceptionsThrownOnErrorStatus( false ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath ); + WebResponse response = sc.getResponse( request ); + + // --- Verification + + switch ( expectation ) + { + case EXPECT_MANAGED_CONTENTS: + assertResponseOK( response ); + assertTrue( "Invalid Test Case: Can't expect managed contents with " + + "test that doesn't have a managed copy in the first place.", hasManagedCopy ); + assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() ); + break; + case EXPECT_REMOTE_CONTENTS: + assertResponseOK( response ); + assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() ); + break; + case EXPECT_NOT_FOUND: + assertResponseNotFound( response ); + assertManagedFileNotExists( repoRootInternal, resourcePath ); + break; + } + } +} Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedPluginSnapshotPolicyTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedPluginSnapshotPolicyTest.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedPluginSnapshotPolicyTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedTimestampedSnapshotPolicyTest.java URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedTimestampedSnapshotPolicyTest.java?rev=588460&view=auto ============================================================================== --- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedTimestampedSnapshotPolicyTest.java (added) +++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedTimestampedSnapshotPolicyTest.java Thu Oct 25 17:59:48 2007 @@ -0,0 +1,195 @@ +package org.apache.maven.archiva.web.repository; + +/* + * 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 com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.HttpUnitOptions; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +import org.apache.maven.archiva.policies.SnapshotsPolicy; + +import java.io.File; + +/** + * RepositoryServlet Tests, Proxied, Get of Timestamped Snapshot Artifacts, with varying policy settings. + * + * @author Joakim Erdfelt + * @version $Id$ + */ +public class RepositoryServletProxiedTimestampedSnapshotPolicyTest + extends AbstractRepositoryServletProxiedTestCase +{ + public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.IGNORED, + HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.IGNORED, HAS_MANAGED_COPY, + ( OLDER * OVER_ONE_DAY ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.IGNORED, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDailyFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY, + ( NEWER * ONE_MINUTE ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDailyPass() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY, + ( OLDER * OVER_ONE_DAY ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDisabledFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DISABLED, + HAS_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDisabledNoManagedContentFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.DISABLED, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyDisabledPass() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DISABLED, + HAS_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyHourlyFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY, + ( NEWER * ONE_MINUTE ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyHourlyPass() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY, + ( OLDER * OVER_ONE_HOUR ) ); + } + + public void testGetProxiedSnapshotsArtifactPolicyOnceFail() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY ); + } + + public void testGetProxiedSnapshotsArtifactPolicyOncePass() + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY ); + } + + private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy, + boolean hasManagedCopy ) + throws Exception + { + assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 ); + } + + private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy, + boolean hasManagedCopy, long deltaManagedToRemoteTimestamp ) + throws Exception + { + // --- Setup + setupSnapshotsRemoteRepo(); + setupCleanInternalRepo(); + + String resourcePath = "org/apache/archiva/test/3.0-SNAPSHOT/test-3.0-20070822.033400-42.jar"; + String expectedRemoteContents = "archiva-test-3.0-20070822.033400-42|jar-remote-contents"; + String expectedManagedContents = null; + File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents ); + + if ( hasManagedCopy ) + { + expectedManagedContents = "archiva-test-3.0-20070822.033400-42|jar-managed-contents"; + File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents ); + managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp ); + } + + setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy ); + saveConfiguration(); + + // --- Execution + // process the response code later, not via an exception. + HttpUnitOptions.setExceptionsThrownOnErrorStatus( false ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath ); + WebResponse response = sc.getResponse( request ); + + // --- Verification + + switch ( expectation ) + { + case EXPECT_MANAGED_CONTENTS: + assertResponseOK( response ); + assertTrue( "Invalid Test Case: Can't expect managed contents with " + + "test that doesn't have a managed copy in the first place.", hasManagedCopy ); + assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() ); + break; + case EXPECT_REMOTE_CONTENTS: + assertResponseOK( response ); + assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() ); + break; + case EXPECT_NOT_FOUND: + assertResponseNotFound( response ); + assertManagedFileNotExists( repoRootInternal, resourcePath ); + break; + } + } +} Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedTimestampedSnapshotPolicyTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedTimestampedSnapshotPolicyTest.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedTimestampedSnapshotPolicyTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain