1 package org.apache.maven.archiva.webdav;
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;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
35 * RepositoryServlet Tests, Proxied, Get of Timestamped Snapshot Artifacts, with varying policy settings.
39 public class RepositoryServletProxiedTimestampedSnapshotPolicyTest
40 extends AbstractRepositoryServletProxiedTestCase
51 public void tearDown()
58 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
61 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ALWAYS,
62 HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ) );
66 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
69 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
70 ( OLDER * OVER_ONE_DAY ) );
74 public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
77 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, NO_MANAGED_COPY );
81 public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
84 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
85 ( NEWER * ONE_MINUTE ) );
89 public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
92 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
96 public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
99 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
100 ( OLDER * OVER_ONE_DAY ) );
104 public void testGetProxiedSnapshotsArtifactPolicyRejectFail()
107 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER,
112 public void testGetProxiedSnapshotsArtifactPolicyRejectNoManagedContentFail()
115 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.NEVER, NO_MANAGED_COPY );
119 public void testGetProxiedSnapshotsArtifactPolicyRejectPass()
122 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER,
127 public void testGetProxiedSnapshotsArtifactPolicyHourlyFail()
130 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
131 ( NEWER * ONE_MINUTE ) );
135 public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent()
138 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY );
142 public void testGetProxiedSnapshotsArtifactPolicyHourlyPass()
145 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
146 ( OLDER * OVER_ONE_HOUR ) );
150 public void testGetProxiedSnapshotsArtifactPolicyOnceFail()
153 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY );
157 public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent()
160 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
164 public void testGetProxiedSnapshotsArtifactPolicyOncePass()
167 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
170 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
171 boolean hasManagedCopy )
174 assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 );
177 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
178 boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
182 setupSnapshotsRemoteRepo();
183 setupCleanInternalRepo();
185 String resourcePath = "org/apache/archiva/test/3.0-SNAPSHOT/test-3.0-20070822.033400-42.jar";
186 String expectedRemoteContents = "archiva-test-3.0-20070822.033400-42|jar-remote-contents";
187 String expectedManagedContents = null;
188 File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
190 if ( hasManagedCopy )
192 expectedManagedContents = "archiva-test-3.0-20070822.033400-42|jar-managed-contents";
193 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
194 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
197 setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
201 // process the response code later, not via an exception.
202 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
204 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
205 WebResponse response = sc.getResponse( request );
209 switch ( expectation )
211 case EXPECT_MANAGED_CONTENTS:
212 assertResponseOK( response );
213 assertTrue( "Invalid Test Case: Can't expect managed contents with "
214 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
215 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
217 case EXPECT_REMOTE_CONTENTS:
218 assertResponseOK( response );
219 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
221 case EXPECT_NOT_FOUND:
222 assertResponseNotFound( response );
223 assertManagedFileNotExists( repoRootInternal, resourcePath );