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