1 package org.apache.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;
26 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
27 import org.apache.archiva.policies.SnapshotsPolicy;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
33 import java.util.ArrayList;
36 * RepositoryServlet Tests, Proxied, Get of Timestamped Snapshot Artifacts, with varying policy settings.
40 public class RepositoryServletProxiedTimestampedSnapshotPolicyTest
41 extends AbstractRepositoryServletProxiedTestCase
48 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
53 public void tearDown()
56 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
62 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
65 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
66 ( NEWER * OVER_ONE_DAY ) );
70 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
73 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
74 ( OLDER * OVER_ONE_DAY ) );
78 public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
81 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, NO_MANAGED_COPY );
85 public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
88 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
89 ( NEWER * ONE_MINUTE ) );
93 public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
96 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
100 public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
103 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
104 ( OLDER * OVER_ONE_DAY ) );
108 public void testGetProxiedSnapshotsArtifactPolicyRejectFail()
111 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER, HAS_MANAGED_COPY );
115 public void testGetProxiedSnapshotsArtifactPolicyRejectNoManagedContentFail()
118 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.NEVER, NO_MANAGED_COPY );
122 public void testGetProxiedSnapshotsArtifactPolicyRejectPass()
125 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER, HAS_MANAGED_COPY );
129 public void testGetProxiedSnapshotsArtifactPolicyHourlyFail()
132 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
133 ( NEWER * ONE_MINUTE ) );
137 public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent()
140 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY );
144 public void testGetProxiedSnapshotsArtifactPolicyHourlyPass()
147 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
148 ( OLDER * OVER_ONE_HOUR ) );
152 public void testGetProxiedSnapshotsArtifactPolicyOnceFail()
155 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY );
159 public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent()
162 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
166 public void testGetProxiedSnapshotsArtifactPolicyOncePass()
169 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
172 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
173 boolean hasManagedCopy )
176 assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 );
179 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
180 boolean hasManagedCopy,
181 long deltaManagedToRemoteTimestamp )
185 setupSnapshotsRemoteRepo();
186 setupCleanInternalRepo();
188 String resourcePath = "org/apache/archiva/test/3.0-SNAPSHOT/test-3.0-20070822.033400-42.jar";
189 String expectedRemoteContents = "archiva-test-3.0-20070822.033400-42|jar-remote-contents";
190 String expectedManagedContents = null;
191 File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
193 if ( hasManagedCopy )
195 expectedManagedContents = "archiva-test-3.0-20070822.033400-42|jar-managed-contents";
196 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
197 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
200 setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
204 // process the response code later, not via an exception.
205 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
207 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
208 WebResponse response = getServletUnitClient().getResponse( request );
212 switch ( expectation )
214 case EXPECT_MANAGED_CONTENTS:
215 assertResponseOK( response );
216 assertTrue( "Invalid Test Case: Can't expect managed contents with "
217 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
218 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
220 case EXPECT_REMOTE_CONTENTS:
221 assertResponseOK( response );
222 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
224 case EXPECT_NOT_FOUND:
225 assertResponseNotFound( response );
226 assertManagedFileNotExists( repoRootInternal, resourcePath );