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.ReleasesPolicy;
28 import org.junit.Test;
31 import java.util.ArrayList;
34 * RepositoryServlet Tests, Proxied, Get of Release Artifacts, with varying policy settings.
38 public class RepositoryServletProxiedReleasePolicyTest
39 extends AbstractRepositoryServletProxiedTestCase
42 public void testGetProxiedReleaseArtifactPolicyAlwaysManagedNewer()
45 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.ALWAYS, HAS_MANAGED_COPY,
46 ( NEWER * OVER_ONE_DAY ) );
50 public void testGetProxiedReleaseArtifactPolicyAlwaysManagedOlder()
53 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ALWAYS, HAS_MANAGED_COPY,
54 ( OLDER * OVER_ONE_DAY ) );
58 public void testGetProxiedReleaseArtifactPolicyAlwaysNoManagedContent()
61 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ALWAYS, NO_MANAGED_COPY );
65 public void testGetProxiedReleaseArtifactPolicyDailyFail()
68 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.DAILY, HAS_MANAGED_COPY,
69 ( NEWER * ONE_MINUTE ) );
73 public void testGetProxiedReleaseArtifactPolicyDailyNoManagedContent()
76 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.DAILY, NO_MANAGED_COPY );
80 public void testGetProxiedReleaseArtifactPolicyDailyPass()
83 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.DAILY, HAS_MANAGED_COPY,
84 ( OLDER * OVER_ONE_DAY ) );
88 public void testGetProxiedReleaseArtifactPolicyRejectFail()
91 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.NEVER, HAS_MANAGED_COPY );
95 public void testGetProxiedReleaseArtifactPolicyRejectNoManagedContentFail()
98 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_NOT_FOUND, ReleasesPolicy.NEVER, NO_MANAGED_COPY );
102 public void testGetProxiedReleaseArtifactPolicyRejectPass()
105 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.NEVER, HAS_MANAGED_COPY );
109 public void testGetProxiedReleaseArtifactPolicyHourlyFail()
112 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.HOURLY, HAS_MANAGED_COPY,
113 ( NEWER * ONE_MINUTE ) );
117 public void testGetProxiedReleaseArtifactPolicyHourlyNoManagedContent()
120 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.HOURLY, NO_MANAGED_COPY );
124 public void testGetProxiedReleaseArtifactPolicyHourlyPass()
127 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.HOURLY, HAS_MANAGED_COPY,
128 ( OLDER * OVER_ONE_HOUR ) );
132 public void testGetProxiedReleaseArtifactPolicyOnceFail()
135 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.ONCE, HAS_MANAGED_COPY );
139 public void testGetProxiedReleaseArtifactPolicyOnceNoManagedContent()
142 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ONCE, NO_MANAGED_COPY );
146 public void testGetProxiedReleaseArtifactPolicyOncePass()
149 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ONCE, NO_MANAGED_COPY );
152 private void assertGetProxiedReleaseArtifactWithPolicy( int expectation, String releasePolicy,
153 boolean hasManagedCopy )
156 assertGetProxiedReleaseArtifactWithPolicy( expectation, releasePolicy, hasManagedCopy, 0 );
159 private void assertGetProxiedReleaseArtifactWithPolicy( int expectation, String releasePolicy,
160 boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
164 setupCentralRemoteRepo();
165 setupCleanInternalRepo();
167 String resourcePath = "org/apache/archiva/test/1.0/test-1.0.jar";
168 String expectedRemoteContents = "archiva-test-1.0|jar-remote-contents";
169 String expectedManagedContents = null;
170 File remoteFile = populateRepo( remoteCentral, resourcePath, expectedRemoteContents );
172 if ( hasManagedCopy )
174 expectedManagedContents = "archiva-test-1.0|jar-managed-contents";
175 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
176 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
179 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
181 setupReleaseConnector( REPOID_INTERNAL, remoteCentral, releasePolicy );
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 = getServletUnitClient().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 );