1 package org.apache.maven.archiva.web.repository;
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.maven.archiva.policies.ReleasesPolicy;
32 * RepositoryServlet Tests, Proxied, Get of Release Artifacts, with varying policy settings.
34 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
37 public class RepositoryServletProxiedReleasePolicyTest
38 extends AbstractRepositoryServletProxiedTestCase
40 public void testGetProxiedReleaseArtifactPolicyAlwaysManagedNewer()
43 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.ALWAYS, HAS_MANAGED_COPY,
44 ( NEWER * OVER_ONE_DAY ) );
47 public void testGetProxiedReleaseArtifactPolicyAlwaysManagedOlder()
50 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ALWAYS, HAS_MANAGED_COPY,
51 ( OLDER * OVER_ONE_DAY ) );
54 public void testGetProxiedReleaseArtifactPolicyAlwaysNoManagedContent()
57 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ALWAYS, NO_MANAGED_COPY );
60 public void testGetProxiedReleaseArtifactPolicyDailyFail()
63 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.DAILY, HAS_MANAGED_COPY,
64 ( NEWER * ONE_MINUTE ) );
67 public void testGetProxiedReleaseArtifactPolicyDailyNoManagedContent()
70 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.DAILY, NO_MANAGED_COPY );
73 public void testGetProxiedReleaseArtifactPolicyDailyPass()
76 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.DAILY, HAS_MANAGED_COPY,
77 ( OLDER * OVER_ONE_DAY ) );
80 public void testGetProxiedReleaseArtifactPolicyRejectFail()
83 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.NEVER, HAS_MANAGED_COPY );
86 public void testGetProxiedReleaseArtifactPolicyRejectNoManagedContentFail()
89 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_NOT_FOUND, ReleasesPolicy.NEVER, NO_MANAGED_COPY );
92 public void testGetProxiedReleaseArtifactPolicyRejectPass()
95 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.NEVER, HAS_MANAGED_COPY );
98 public void testGetProxiedReleaseArtifactPolicyHourlyFail()
101 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.HOURLY, HAS_MANAGED_COPY,
102 ( NEWER * ONE_MINUTE ) );
105 public void testGetProxiedReleaseArtifactPolicyHourlyNoManagedContent()
108 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.HOURLY, NO_MANAGED_COPY );
111 public void testGetProxiedReleaseArtifactPolicyHourlyPass()
114 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.HOURLY, HAS_MANAGED_COPY,
115 ( OLDER * OVER_ONE_HOUR ) );
118 public void testGetProxiedReleaseArtifactPolicyOnceFail()
121 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.ONCE, HAS_MANAGED_COPY );
124 public void testGetProxiedReleaseArtifactPolicyOnceNoManagedContent()
127 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ONCE, NO_MANAGED_COPY );
130 public void testGetProxiedReleaseArtifactPolicyOncePass()
133 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ONCE, NO_MANAGED_COPY );
136 private void assertGetProxiedReleaseArtifactWithPolicy( int expectation, String releasePolicy,
137 boolean hasManagedCopy )
140 assertGetProxiedReleaseArtifactWithPolicy( expectation, releasePolicy, hasManagedCopy, 0 );
143 private void assertGetProxiedReleaseArtifactWithPolicy( int expectation, String releasePolicy,
144 boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
148 setupCentralRemoteRepo();
149 setupCleanInternalRepo();
151 String resourcePath = "org/apache/archiva/test/1.0/test-1.0.jar";
152 String expectedRemoteContents = "archiva-test-1.0|jar-remote-contents";
153 String expectedManagedContents = null;
154 File remoteFile = populateRepo( remoteCentral, resourcePath, expectedRemoteContents );
156 if ( hasManagedCopy )
158 expectedManagedContents = "archiva-test-1.0|jar-managed-contents";
159 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
160 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
163 setupReleaseConnector( REPOID_INTERNAL, remoteCentral, releasePolicy );
167 // process the response code later, not via an exception.
168 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
170 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
171 WebResponse response = sc.getResponse( request );
175 switch ( expectation )
177 case EXPECT_MANAGED_CONTENTS:
178 assertResponseOK( response );
179 assertTrue( "Invalid Test Case: Can't expect managed contents with "
180 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
181 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
183 case EXPECT_REMOTE_CONTENTS:
184 assertResponseOK( response );
185 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
187 case EXPECT_NOT_FOUND:
188 assertResponseNotFound( response );
189 assertManagedFileNotExists( repoRootInternal, resourcePath );