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.ArchivaConfiguration;
27 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
28 import org.apache.archiva.policies.SnapshotsPolicy;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
34 import java.util.ArrayList;
37 * RepositoryServlet Tests, Proxied, Get of Snapshot Artifacts, with varying policy settings.
41 public class RepositoryServletProxiedSnapshotPolicyTest
42 extends AbstractRepositoryServletProxiedTestCase
49 applicationContext.getBean( ArchivaConfiguration.class ).getConfiguration().setProxyConnectors(
50 new ArrayList<ProxyConnectorConfiguration>() );
55 public void tearDown()
58 applicationContext.getBean( ArchivaConfiguration.class ).getConfiguration().setProxyConnectors(
59 new ArrayList<ProxyConnectorConfiguration>() );
65 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
68 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
69 ( NEWER * OVER_ONE_DAY ) );
73 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
76 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
77 ( OLDER * OVER_ONE_DAY ) );
81 public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
84 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, NO_MANAGED_COPY );
88 public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
91 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
92 ( NEWER * ONE_MINUTE ) );
96 public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
99 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
103 public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
106 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
107 ( OLDER * OVER_ONE_DAY ) );
111 public void testGetProxiedSnapshotsArtifactPolicyRejectFail()
114 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER, HAS_MANAGED_COPY );
118 public void testGetProxiedSnapshotsArtifactPolicyRejectNoManagedContentFail()
121 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.NEVER, NO_MANAGED_COPY );
125 public void testGetProxiedSnapshotsArtifactPolicyRejectPass()
128 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER, HAS_MANAGED_COPY );
132 public void testGetProxiedSnapshotsArtifactPolicyHourlyFail()
135 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
136 ( NEWER * ONE_MINUTE ) );
140 public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent()
143 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY );
147 public void testGetProxiedSnapshotsArtifactPolicyHourlyPass()
150 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
151 ( OLDER * OVER_ONE_HOUR ) );
155 public void testGetProxiedSnapshotsArtifactPolicyOnceFail()
158 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY );
162 public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent()
165 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
169 public void testGetProxiedSnapshotsArtifactPolicyOncePass()
172 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
175 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
176 boolean hasManagedCopy )
179 assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 );
182 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
183 boolean hasManagedCopy,
184 long deltaManagedToRemoteTimestamp )
188 setupSnapshotsRemoteRepo();
189 setupCleanInternalRepo();
191 String resourcePath = "org/apache/archiva/test/2.0-SNAPSHOT/test-2.0-SNAPSHOT.jar";
192 String expectedRemoteContents = "archiva-test-2.0-SNAPSHOT|jar-remote-contents";
193 String expectedManagedContents = null;
194 File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
196 if ( hasManagedCopy )
198 expectedManagedContents = "archiva-test-2.0-SNAPSHOT|jar-managed-contents";
199 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
200 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
203 setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
207 // process the response code later, not via an exception.
208 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
210 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
211 WebResponse response = getServletUnitClient().getResponse( request );
215 switch ( expectation )
217 case EXPECT_MANAGED_CONTENTS:
218 assertResponseOK( response );
219 assertTrue( "Invalid Test Case: Can't expect managed contents with "
220 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
221 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
223 case EXPECT_REMOTE_CONTENTS:
224 assertResponseOK( response );
225 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
227 case EXPECT_NOT_FOUND:
228 assertResponseNotFound( response );
229 assertManagedFileNotExists( repoRootInternal, resourcePath );