1 package org.apache.maven.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
24 import com.meterware.httpunit.GetMethodWebRequest;
25 import com.meterware.httpunit.HttpUnitOptions;
26 import com.meterware.httpunit.WebRequest;
27 import com.meterware.httpunit.WebResponse;
30 * RepositoryServlet Tests, Proxied, Get of resources that are not artifacts or metadata, with varying policy settings.
32 * @version $Id: RepositoryServletProxiedReleasePolicyTest.java 661174 2008-05-29 01:49:41Z jdumay $
34 public class RepositoryServletProxiedPassthroughTest
35 extends AbstractRepositoryServletProxiedTestCase
37 private static final String CONTENT_SHA1 = "2aab0a51c04c9023636852f3e63a68034ba10142";
39 private static final String PATH_SHA1 = "org/apache/archiva/test/1.0/test-1.0.jar.sha1";
41 private static final String CONTENT_ASC =
42 "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1.4.8 (Darwin)\n" + "\n"
43 + "iEYEABECAAYFAkiAIVgACgkQxbsDNW2stZZjyACeK3LW+ZDeawCyJj4XgvUaJkNh\n"
44 + "qIEAoIUiijY4Iw82RWOT75Rt3yZuY6ZI\n" + "=WLkm\n" + "-----END PGP SIGNATURE-----\n";
46 private static final String PATH_ASC = "org/apache/archiva/test/1.0/test-1.0.jar.asc";
48 public void testGetProxiedManagedNewerSha1()
51 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_SHA1,
55 public void testGetProxiedManagedOlderSha1()
58 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_SHA1,
62 public void testGetProxiedNoManagedContentSha1()
65 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
68 public void testGetProxiedEqualSha1()
71 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
74 public void testGetProxiedManagedNewerAsc()
77 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_ASC,
81 public void testGetProxiedManagedOlderAsc()
84 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_ASC,
88 public void testGetProxiedNoManagedContentAsc()
91 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
94 public void testGetProxiedEqualAsc()
97 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
100 private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, String path, String content )
103 assertGetProxiedResource( expectation, hasManagedCopy, 0, path, content );
106 private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp,
107 String path, String contents )
111 setupCentralRemoteRepo();
112 setupCleanInternalRepo();
114 String expectedRemoteContents = contents;
115 String expectedManagedContents = null;
116 File remoteFile = populateRepo( remoteCentral, path, expectedRemoteContents );
118 if ( hasManagedCopy )
120 expectedManagedContents = contents;
121 File managedFile = populateRepo( repoRootInternal, path, expectedManagedContents );
122 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
125 setupConnector( REPOID_INTERNAL, remoteCentral );
129 // process the response code later, not via an exception.
130 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
132 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + path );
133 WebResponse response = sc.getResponse( request );
137 switch ( expectation )
139 case EXPECT_MANAGED_CONTENTS:
140 assertResponseOK( response );
141 assertTrue( "Invalid Test Case: Can't expect managed contents with "
142 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
143 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
145 case EXPECT_REMOTE_CONTENTS:
146 assertResponseOK( response );
147 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
149 case EXPECT_NOT_FOUND:
150 assertResponseNotFound( response );
151 assertManagedFileNotExists( repoRootInternal, path );