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
24 import com.meterware.httpunit.GetMethodWebRequest;
25 import com.meterware.httpunit.HttpUnitOptions;
26 import com.meterware.httpunit.WebRequest;
27 import com.meterware.httpunit.WebResponse;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
33 * RepositoryServlet Tests, Proxied, Get of resources that are not artifacts or metadata, with varying policy settings.
35 * @version $Id: RepositoryServletProxiedReleasePolicyTest.java 661174 2008-05-29 01:49:41Z jdumay $
37 public class RepositoryServletProxiedPassthroughTest
38 extends AbstractRepositoryServletProxiedTestCase
40 private static final String CONTENT_SHA1 = "2aab0a51c04c9023636852f3e63a68034ba10142";
42 private static final String PATH_SHA1 = "org/apache/archiva/test/1.0/test-1.0.jar.sha1";
44 private static final String CONTENT_ASC =
45 "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1.4.8 (Darwin)\n" + "\n"
46 + "iEYEABECAAYFAkiAIVgACgkQxbsDNW2stZZjyACeK3LW+ZDeawCyJj4XgvUaJkNh\n"
47 + "qIEAoIUiijY4Iw82RWOT75Rt3yZuY6ZI\n" + "=WLkm\n" + "-----END PGP SIGNATURE-----\n";
49 private static final String PATH_ASC = "org/apache/archiva/test/1.0/test-1.0.jar.asc";
59 public void tearDown()
66 public void testGetProxiedManagedNewerSha1()
69 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_SHA1,
74 public void testGetProxiedManagedOlderSha1()
77 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_SHA1,
82 public void testGetProxiedNoManagedContentSha1()
85 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
89 public void testGetProxiedEqualSha1()
92 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
96 public void testGetProxiedManagedNewerAsc()
99 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_ASC,
104 public void testGetProxiedManagedOlderAsc()
107 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_ASC,
112 public void testGetProxiedNoManagedContentAsc()
115 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
119 public void testGetProxiedEqualAsc()
122 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
125 private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, String path, String content )
128 assertGetProxiedResource( expectation, hasManagedCopy, 0, path, content );
131 private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp,
132 String path, String contents )
136 setupCentralRemoteRepo();
137 setupCleanInternalRepo();
139 String expectedRemoteContents = contents;
140 String expectedManagedContents = null;
141 File remoteFile = populateRepo( remoteCentral, path, expectedRemoteContents );
143 if ( hasManagedCopy )
145 expectedManagedContents = contents;
146 File managedFile = populateRepo( repoRootInternal, path, expectedManagedContents );
147 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
150 setupConnector( REPOID_INTERNAL, remoteCentral );
154 // process the response code later, not via an exception.
155 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
157 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + path );
158 WebResponse response = getServletUnitClient().getResponse( request );
162 switch ( expectation )
164 case EXPECT_MANAGED_CONTENTS:
165 assertResponseOK( response );
166 assertTrue( "Invalid Test Case: Can't expect managed contents with "
167 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
168 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
170 case EXPECT_REMOTE_CONTENTS:
171 assertResponseOK( response, path );
172 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
174 case EXPECT_NOT_FOUND:
175 assertResponseNotFound( response );
176 assertManagedFileNotExists( repoRootInternal, path );