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;
27 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
28 import org.apache.archiva.policies.SnapshotsPolicy;
29 import org.junit.Test;
32 import java.util.ArrayList;
35 * RepositoryServlet Tests, Proxied, Get of Timestamped Snapshot Artifacts, with varying policy settings.
39 public class RepositoryServletProxiedPluginSnapshotPolicyTest
40 extends AbstractRepositoryServletProxiedTestCase
44 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
47 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ALWAYS,
48 HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ) );
52 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
55 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
56 ( OLDER * OVER_ONE_DAY ) );
60 public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
63 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, NO_MANAGED_COPY );
67 public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
70 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
71 ( NEWER * ONE_MINUTE ) );
75 public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
78 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
82 public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
85 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
86 ( OLDER * OVER_ONE_DAY ) );
90 public void testGetProxiedSnapshotsArtifactPolicyRejectFail()
93 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER,
98 public void testGetProxiedSnapshotsArtifactPolicyRejectNoManagedContentFail()
101 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.NEVER, NO_MANAGED_COPY );
105 public void testGetProxiedSnapshotsArtifactPolicyRejectPass()
108 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER,
113 public void testGetProxiedSnapshotsArtifactPolicyHourlyFail()
116 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
117 ( NEWER * ONE_MINUTE ) );
121 public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent()
124 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY );
128 public void testGetProxiedSnapshotsArtifactPolicyHourlyPass()
131 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
132 ( OLDER * OVER_ONE_HOUR ) );
136 public void testGetProxiedSnapshotsArtifactPolicyOnceFail()
139 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY );
143 public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent()
146 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
150 public void testGetProxiedSnapshotsArtifactPolicyOncePass()
153 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
156 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
157 boolean hasManagedCopy )
160 assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 );
163 private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
164 boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
168 setupSnapshotsRemoteRepo();
169 setupCleanInternalRepo();
171 String resourcePath = "org/apache/archiva/archivatest-maven-plugin/4.0-alpha-1-SNAPSHOT/archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42.jar";
172 String expectedRemoteContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-remote-contents";
173 String expectedManagedContents = null;
174 File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
176 if ( hasManagedCopy )
178 expectedManagedContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-managed-contents";
179 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
180 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
183 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( 0 ) );
185 setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
189 // process the response code later, not via an exception.
190 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
192 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
193 WebResponse response = getServletUnitClient().getResponse( request );
197 switch ( expectation )
199 case EXPECT_MANAGED_CONTENTS:
200 assertResponseOK( response );
201 assertTrue( "Invalid Test Case: Can't expect managed contents with "
202 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
203 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
205 case EXPECT_REMOTE_CONTENTS:
206 assertResponseOK( response );
207 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
209 case EXPECT_NOT_FOUND:
210 assertResponseNotFound( response );
211 assertManagedFileNotExists( repoRootInternal, resourcePath );