]> source.dussan.org Git - archiva.git/blob
d03b16d6854f7201884092aaccd4ecfd0b566df7
[archiva.git] /
1 package org.apache.maven.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 com.meterware.httpunit.GetMethodWebRequest;
23 import com.meterware.httpunit.HttpUnitOptions;
24 import com.meterware.httpunit.WebRequest;
25 import com.meterware.httpunit.WebResponse;
26
27 import org.apache.maven.archiva.policies.SnapshotsPolicy;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 import java.io.File;
33
34 /**
35  * RepositoryServlet Tests, Proxied, Get of Timestamped Snapshot Artifacts, with varying policy settings. 
36  *
37  * @version $Id$
38  */
39 public class RepositoryServletProxiedTimestampedSnapshotPolicyTest
40     extends AbstractRepositoryServletProxiedTestCase
41 {
42
43     @Before
44     public void setup()
45         throws Exception
46     {
47         super.setUp();
48     }
49
50     @After
51     public void tearDown()
52         throws Exception
53     {
54         super.tearDown();
55     }
56
57     @Test
58     public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedNewer()
59         throws Exception
60     {
61         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ALWAYS,
62                                                      HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ) );
63     }
64
65     @Test
66     public void testGetProxiedSnapshotsArtifactPolicyAlwaysManagedOlder()
67         throws Exception
68     {
69         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, HAS_MANAGED_COPY,
70                                                      ( OLDER * OVER_ONE_DAY ) );
71     }
72
73     @Test
74     public void testGetProxiedSnapshotsArtifactPolicyAlwaysNoManagedContent()
75         throws Exception
76     {
77         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ALWAYS, NO_MANAGED_COPY );
78     }
79
80     @Test
81     public void testGetProxiedSnapshotsArtifactPolicyDailyFail()
82         throws Exception
83     {
84         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
85                                                      ( NEWER * ONE_MINUTE ) );
86     }
87
88     @Test
89     public void testGetProxiedSnapshotsArtifactPolicyDailyNoManagedContent()
90         throws Exception
91     {
92         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, NO_MANAGED_COPY );
93     }
94
95     @Test
96     public void testGetProxiedSnapshotsArtifactPolicyDailyPass()
97         throws Exception
98     {
99         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.DAILY, HAS_MANAGED_COPY,
100                                                      ( OLDER * OVER_ONE_DAY ) );
101     }
102
103     @Test
104     public void testGetProxiedSnapshotsArtifactPolicyRejectFail()
105         throws Exception
106     {
107         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER,
108                                                      HAS_MANAGED_COPY );
109     }
110
111     @Test
112     public void testGetProxiedSnapshotsArtifactPolicyRejectNoManagedContentFail()
113         throws Exception
114     {
115         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_NOT_FOUND, SnapshotsPolicy.NEVER, NO_MANAGED_COPY );
116     }
117
118     @Test
119     public void testGetProxiedSnapshotsArtifactPolicyRejectPass()
120         throws Exception
121     {
122         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.NEVER,
123                                                      HAS_MANAGED_COPY );
124     }
125
126     @Test
127     public void testGetProxiedSnapshotsArtifactPolicyHourlyFail()
128         throws Exception
129     {
130         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
131                                                      ( NEWER * ONE_MINUTE ) );
132     }
133
134     @Test
135     public void testGetProxiedSnapshotsArtifactPolicyHourlyNoManagedContent()
136         throws Exception
137     {
138         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, NO_MANAGED_COPY );
139     }
140
141     @Test
142     public void testGetProxiedSnapshotsArtifactPolicyHourlyPass()
143         throws Exception
144     {
145         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.HOURLY, HAS_MANAGED_COPY,
146                                                      ( OLDER * OVER_ONE_HOUR ) );
147     }
148
149     @Test
150     public void testGetProxiedSnapshotsArtifactPolicyOnceFail()
151         throws Exception
152     {
153         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, SnapshotsPolicy.ONCE, HAS_MANAGED_COPY );
154     }
155
156     @Test
157     public void testGetProxiedSnapshotsArtifactPolicyOnceNoManagedContent()
158         throws Exception
159     {
160         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
161     }
162
163     @Test
164     public void testGetProxiedSnapshotsArtifactPolicyOncePass()
165         throws Exception
166     {
167         assertGetProxiedSnapshotsArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, SnapshotsPolicy.ONCE, NO_MANAGED_COPY );
168     }
169
170     private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
171                                                               boolean hasManagedCopy )
172         throws Exception
173     {
174         assertGetProxiedSnapshotsArtifactWithPolicy( expectation, snapshotsPolicy, hasManagedCopy, 0 );
175     }
176
177     private void assertGetProxiedSnapshotsArtifactWithPolicy( int expectation, String snapshotsPolicy,
178                                                               boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
179         throws Exception
180     {
181         // --- Setup
182         setupSnapshotsRemoteRepo();
183         setupCleanInternalRepo();
184
185         String resourcePath = "org/apache/archiva/test/3.0-SNAPSHOT/test-3.0-20070822.033400-42.jar";
186         String expectedRemoteContents = "archiva-test-3.0-20070822.033400-42|jar-remote-contents";
187         String expectedManagedContents = null;
188         File remoteFile = populateRepo( remoteSnapshots, resourcePath, expectedRemoteContents );
189
190         if ( hasManagedCopy )
191         {
192             expectedManagedContents = "archiva-test-3.0-20070822.033400-42|jar-managed-contents";
193             File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
194             managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
195         }
196
197         setupSnapshotConnector( REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy );
198         saveConfiguration();
199
200         // --- Execution
201         // process the response code later, not via an exception.
202         HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
203
204         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
205         WebResponse response = sc.getResponse( request );
206
207         // --- Verification
208
209         switch ( expectation )
210         {
211             case EXPECT_MANAGED_CONTENTS:
212                 assertResponseOK( response );
213                 assertTrue( "Invalid Test Case: Can't expect managed contents with "
214                     + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
215                 assertEquals( "Expected managed file contents", expectedManagedContents, response.getText() );
216                 break;
217             case EXPECT_REMOTE_CONTENTS:
218                 assertResponseOK( response );
219                 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getText() );
220                 break;
221             case EXPECT_NOT_FOUND:
222                 assertResponseNotFound( response );
223                 assertManagedFileNotExists( repoRootInternal, resourcePath );
224                 break;
225         }
226     }
227 }