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.
36 public class RepositoryServletProxiedPassthroughTest
37 extends AbstractRepositoryServletProxiedTestCase
39 private static final String CONTENT_SHA1 = "2aab0a51c04c9023636852f3e63a68034ba10142";
41 private static final String PATH_SHA1 = "org/apache/archiva/test/1.0/test-1.0.jar.sha1";
43 private static final String CONTENT_ASC =
44 "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1.4.8 (Darwin)\n" + "\n"
45 + "iEYEABECAAYFAkiAIVgACgkQxbsDNW2stZZjyACeK3LW+ZDeawCyJj4XgvUaJkNh\n"
46 + "qIEAoIUiijY4Iw82RWOT75Rt3yZuY6ZI\n" + "=WLkm\n" + "-----END PGP SIGNATURE-----\n";
48 private static final String PATH_ASC = "org/apache/archiva/test/1.0/test-1.0.jar.asc";
58 public void tearDown()
65 public void testGetProxiedManagedNewerSha1()
68 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_SHA1,
73 public void testGetProxiedManagedOlderSha1()
76 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_SHA1,
81 public void testGetProxiedNoManagedContentSha1()
84 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
88 public void testGetProxiedEqualSha1()
91 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
95 public void testGetProxiedManagedNewerAsc()
98 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_ASC,
103 public void testGetProxiedManagedOlderAsc()
106 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_ASC,
111 public void testGetProxiedNoManagedContentAsc()
114 assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
118 public void testGetProxiedEqualAsc()
121 assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
124 private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, String path, String content )
127 assertGetProxiedResource( expectation, hasManagedCopy, 0, path, content );
130 private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp,
131 String path, String contents )
135 setupCentralRemoteRepo();
136 setupCleanInternalRepo();
138 String expectedRemoteContents = contents;
139 String expectedManagedContents = null;
140 File remoteFile = populateRepo( remoteCentral, path, expectedRemoteContents );
142 if ( hasManagedCopy )
144 expectedManagedContents = contents;
145 File managedFile = populateRepo( repoRootInternal, path, expectedManagedContents );
146 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
149 setupConnector( REPOID_INTERNAL, remoteCentral );
153 // process the response code later, not via an exception.
154 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
156 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + path );
157 WebResponse response = getServletUnitClient().getResponse( request );
161 switch ( expectation )
163 case EXPECT_MANAGED_CONTENTS:
164 assertResponseOK( response );
165 assertTrue( "Invalid Test Case: Can't expect managed contents with "
166 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
167 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
169 case EXPECT_REMOTE_CONTENTS:
170 assertResponseOK( response, path );
171 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
173 case EXPECT_NOT_FOUND:
174 assertResponseNotFound( response );
175 assertManagedFileNotExists( repoRootInternal, path );