]> source.dussan.org Git - archiva.git/blob
655061f8c5ed89b06fe5c01d703b636802d30fc8
[archiva.git] /
1 package org.apache.archiva.webdav;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import java.io.File;
23
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;
31
32 /**
33  * RepositoryServlet Tests, Proxied, Get of resources that are not artifacts or metadata, with varying policy settings.
34  * 
35  * @version $Id: RepositoryServletProxiedReleasePolicyTest.java 661174 2008-05-29 01:49:41Z jdumay $
36  */
37 public class RepositoryServletProxiedPassthroughTest
38     extends AbstractRepositoryServletProxiedTestCase
39 {
40     private static final String CONTENT_SHA1 = "2aab0a51c04c9023636852f3e63a68034ba10142";
41
42     private static final String PATH_SHA1 = "org/apache/archiva/test/1.0/test-1.0.jar.sha1";
43
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";
48
49     private static final String PATH_ASC = "org/apache/archiva/test/1.0/test-1.0.jar.asc";
50
51     @Before
52     public void setup()
53         throws Exception
54     {
55         super.setUp();
56     }
57
58     @After
59     public void tearDown()
60         throws Exception
61     {
62         super.tearDown();
63     }
64
65     @Test
66     public void testGetProxiedManagedNewerSha1()
67         throws Exception
68     {
69         assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_SHA1,
70                                   CONTENT_SHA1 );
71     }
72
73     @Test
74     public void testGetProxiedManagedOlderSha1()
75         throws Exception
76     {
77         assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_SHA1,
78                                   CONTENT_SHA1 );
79     }
80
81     @Test
82     public void testGetProxiedNoManagedContentSha1()
83         throws Exception
84     {
85         assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
86     }
87
88     @Test
89     public void testGetProxiedEqualSha1()
90         throws Exception
91     {
92         assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
93     }
94
95     @Test
96     public void testGetProxiedManagedNewerAsc()
97         throws Exception
98     {
99         assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_ASC,
100                                   CONTENT_ASC );
101     }
102
103     @Test
104     public void testGetProxiedManagedOlderAsc()
105         throws Exception
106     {
107         assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_ASC,
108                                   CONTENT_ASC );
109     }
110
111     @Test
112     public void testGetProxiedNoManagedContentAsc()
113         throws Exception
114     {
115         assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
116     }
117
118     @Test
119     public void testGetProxiedEqualAsc()
120         throws Exception
121     {
122         assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
123     }
124
125     private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, String path, String content )
126         throws Exception
127     {
128         assertGetProxiedResource( expectation, hasManagedCopy, 0, path, content );
129     }
130
131     private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp,
132                                            String path, String contents )
133         throws Exception
134     {
135         // --- Setup
136         setupCentralRemoteRepo();
137         setupCleanInternalRepo();
138
139         String expectedRemoteContents = contents;
140         String expectedManagedContents = null;
141         File remoteFile = populateRepo( remoteCentral, path, expectedRemoteContents );
142
143         if ( hasManagedCopy )
144         {
145             expectedManagedContents = contents;
146             File managedFile = populateRepo( repoRootInternal, path, expectedManagedContents );
147             managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
148         }
149
150         setupConnector( REPOID_INTERNAL, remoteCentral );
151         saveConfiguration();
152
153         // --- Execution
154         // process the response code later, not via an exception.
155         HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
156
157         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + path );
158         WebResponse response = getServletUnitClient().getResponse( request );
159
160         // --- Verification
161
162         switch ( expectation )
163         {
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() );
169                 break;
170             case EXPECT_REMOTE_CONTENTS:
171                 assertResponseOK( response, path );
172                 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
173                 break;
174             case EXPECT_NOT_FOUND:
175                 assertResponseNotFound( response );
176                 assertManagedFileNotExists( repoRootInternal, path );
177                 break;
178         }
179     }
180 }