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