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.gargoylesoftware.htmlunit.WebRequest;
23 import com.gargoylesoftware.htmlunit.WebResponse;
24 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
25 import org.apache.archiva.policies.SnapshotsPolicy;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
31 import java.util.ArrayList;
34 * RepositoryServlet Tests, Proxied, Get of Timestamped Snapshot Artifacts, with varying policy settings.
38 public class RepositoryServletProxiedTimestampedSnapshotPolicyTest
39 extends AbstractRepositoryServletProxiedTestCase
46 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
51 public void tearDown()
54 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
60 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
63 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
64 ( NEWER * OVER_ONE_DAY ) );
68 public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
71 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
72 ( OLDER * OVER_ONE_DAY ) );
76 public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
79 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, NO_MANAGED_COPY );
83 public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
86 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
87 ( NEWER * ONE_MINUTE ) );
91 public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
94 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
98 public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
101 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
102 ( OLDER * OVER_ONE_DAY ) );
106 public void testGetProxiedSnapshotsArtifactPolicyRejectFail()
109 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER, HAS_MANAGED_COPY );
113 public void testGetProxiedSnapshotsArtifactPolicyRejectNoManagedContentFail()
116 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.NEVER, NO_MANAGED_COPY );
120 public void testGetProxiedSnapshotsArtifactPolicyRejectPass()
123 assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER, HAS_MANAGED_COPY );
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,
179 long deltaManagedToRemoteTimestamp )
183 setupSnapshotsRemoteRepo();
184 setupCleanInternalRepo();
186 String resourcePath = "org/apache/archiva/test/3.0-SNAPSHOT/test-3.0-20070822.033400-42.jar";
187 String expectedRemoteContents = "archiva-test-3.0-20070822.033400-42|jar-remote-contents";
188 String expectedManagedContents = null;
189 File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
191 if ( hasManagedCopy )
193 expectedManagedContents = "archiva-test-3.0-20070822.033400-42|jar-managed-contents";
194 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
195 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
198 setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
202 // process the response code later, not via an exception.
203 //HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
205 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
206 WebResponse response = getServletUnitClient().getResponse( request );
210 switch ( expectation )
212 case EXPECT_MANAGED_CONTENTS:
213 assertResponseOK( response );
214 assertTrue( "Invalid Test Case: Can't expect managed contents with "
215 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
216 assertEquals( "Expected managed file contents", expectedManagedContents, response.getContentAsString() );
218 case EXPECT_REMOTE_CONTENTS:
219 assertResponseOK( response );
220 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getContentAsString() );
222 case EXPECT_NOT_FOUND:
223 assertResponseNotFound( response );
224 assertManagedFileNotExists( repoRootInternal, resourcePath );