1 package org.apache.maven.archiva.web.repository;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.meterware.httpunit.GetMethodWebRequest;
23 import com.meterware.httpunit.HttpUnitOptions;
24 import com.meterware.httpunit.WebRequest;
25 import com.meterware.httpunit.WebResponse;
27 import org.apache.maven.archiva.policies.SnapshotsPolicy;
32 * RepositoryServlet Tests, Proxied, Get of Timestamped Snapshot Artifacts, with varying policy settings.
34 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
37 public class RepositoryServletProxiedPluginSnapshotPolicyTest
38 extends AbstractRepositoryServletProxiedTestCase
40 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
43 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.IGNORED,
44 HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ) );
47 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
50 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.IGNORED, HAS_MANAGED_COPY,
51 ( OLDER * OVER_ONE_DAY ) );
54 public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
57 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.IGNORED, NO_MANAGED_COPY );
60 public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
63 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
64 ( NEWER * ONE_MINUTE ) );
67 public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
70 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
73 public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
76 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
77 ( OLDER * OVER_ONE_DAY ) );
80 public void testGetProxiedSnapshotsArtifactPolicyDisabledFail()
83 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DISABLED,
87 public void testGetProxiedSnapshotsArtifactPolicyDisabledNoManagedContentFail()
90 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.DISABLED, NO_MANAGED_COPY );
93 public void testGetProxiedSnapshotsArtifactPolicyDisabledPass()
96 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DISABLED,
100 public void testGetProxiedSnapshotsArtifactPolicyHourlyFail()
103 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
104 ( NEWER * ONE_MINUTE ) );
107 public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent()
110 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY );
113 public void testGetProxiedSnapshotsArtifactPolicyHourlyPass()
116 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
117 ( OLDER * OVER_ONE_HOUR ) );
120 public void testGetProxiedSnapshotsArtifactPolicyOnceFail()
123 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY );
126 public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent()
129 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
132 public void testGetProxiedSnapshotsArtifactPolicyOncePass()
135 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
138 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
139 boolean hasManagedCopy )
142 assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 );
145 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
146 boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
150 setupSnapshotsRemoteRepo();
151 setupCleanInternalRepo();
153 String resourcePath = "org/apache/archiva/archivatest-maven-plugin/4.0-alpha-1-SNAPSHOT/archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42.jar";
154 String expectedRemoteContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-remote-contents";
155 String expectedManagedContents = null;
156 File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
158 if ( hasManagedCopy )
160 expectedManagedContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-managed-contents";
161 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
162 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
165 setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
169 // process the response code later, not via an exception.
170 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
172 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
173 WebResponse response = sc.getResponse( request );
177 switch ( expectation )
179 case EXPECT_MANAGED_CONTENTS:
180 assertResponseOK( response );
181 assertTrue( "Invalid Test Case: Can't expect managed contents with "
182 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
183 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
185 case EXPECT_REMOTE_CONTENTS:
186 assertResponseOK( response );
187 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
189 case EXPECT_NOT_FOUND:
190 assertResponseNotFound( response );
191 assertManagedFileNotExists( repoRootInternal, resourcePath );