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.Test;
33 * RepositoryServlet Tests, Proxied, Get of Snapshot Artifacts, with varying policy settings.
37 public class RepositoryServletProxiedSnapshotPolicyTest
38 extends AbstractRepositoryServletProxiedTestCase
42 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
45 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ALWAYS,
46 HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ) );
50 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
53 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
54 ( OLDER * OVER_ONE_DAY ) );
58 public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
61 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, NO_MANAGED_COPY );
65 public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
68 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
69 ( NEWER * ONE_MINUTE ) );
73 public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
76 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
80 public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
83 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
84 ( OLDER * OVER_ONE_DAY ) );
88 public void testGetProxiedSnapshotsArtifactPolicyRejectFail()
91 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER,
96 public void testGetProxiedSnapshotsArtifactPolicyRejectNoManagedContentFail()
99 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.NEVER, NO_MANAGED_COPY );
103 public void testGetProxiedSnapshotsArtifactPolicyRejectPass()
106 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER,
111 public void testGetProxiedSnapshotsArtifactPolicyHourlyFail()
114 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
115 ( NEWER * ONE_MINUTE ) );
119 public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent()
122 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY );
126 public void testGetProxiedSnapshotsArtifactPolicyHourlyPass()
129 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
130 ( OLDER * OVER_ONE_HOUR ) );
134 public void testGetProxiedSnapshotsArtifactPolicyOnceFail()
137 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY );
141 public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent()
144 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
148 public void testGetProxiedSnapshotsArtifactPolicyOncePass()
151 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
154 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
155 boolean hasManagedCopy )
158 assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 );
161 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
162 boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
166 setupSnapshotsRemoteRepo();
167 setupCleanInternalRepo();
169 String resourcePath = "org/apache/archiva/test/2.0-SNAPSHOT/test-2.0-SNAPSHOT.jar";
170 String expectedRemoteContents = "archiva-test-2.0-SNAPSHOT|jar-remote-contents";
171 String expectedManagedContents = null;
172 File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
174 if ( hasManagedCopy )
176 expectedManagedContents = "archiva-test-2.0-SNAPSHOT|jar-managed-contents";
177 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
178 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
181 setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
185 // process the response code later, not via an exception.
186 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
188 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
189 WebResponse response = sc.getResponse( request );
193 switch ( expectation )
195 case EXPECT_MANAGED_CONTENTS:
196 assertResponseOK( response );
197 assertTrue( "Invalid Test Case: Can't expect managed contents with "
198 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
199 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
201 case EXPECT_REMOTE_CONTENTS:
202 assertResponseOK( response );
203 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
205 case EXPECT_NOT_FOUND:
206 assertResponseNotFound( response );
207 assertManagedFileNotExists( repoRootInternal, resourcePath );