1 package org.apache.archiva.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.gargoylesoftware.htmlunit.WebRequest;
23 import com.gargoylesoftware.htmlunit.WebResponse;
24 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
25 import org.apache.archiva.policies.ReleasesPolicy;
26 import org.junit.Test;
27
28 import java.io.File;
29 import java.util.ArrayList;
30
31
32
33
34
35
36 public class RepositoryServletProxiedReleasePolicyTest
37 extends AbstractRepositoryServletProxiedTestCase
38 {
39 @Test
40 public void testGetProxiedReleaseArtifactPolicyAlwaysManagedNewer()
41 throws Exception
42 {
43 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.ALWAYS, HAS_MANAGED_COPY,
44 ( NEWER * OVER_ONE_DAY ) );
45 }
46
47 @Test
48 public void testGetProxiedReleaseArtifactPolicyAlwaysManagedOlder()
49 throws Exception
50 {
51 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ALWAYS, HAS_MANAGED_COPY,
52 ( OLDER * OVER_ONE_DAY ) );
53 }
54
55 @Test
56 public void testGetProxiedReleaseArtifactPolicyAlwaysNoManagedContent()
57 throws Exception
58 {
59 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ALWAYS, NO_MANAGED_COPY );
60 }
61
62 @Test
63 public void testGetProxiedReleaseArtifactPolicyDailyFail()
64 throws Exception
65 {
66 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.DAILY, HAS_MANAGED_COPY,
67 ( NEWER * ONE_MINUTE ) );
68 }
69
70 @Test
71 public void testGetProxiedReleaseArtifactPolicyDailyNoManagedContent()
72 throws Exception
73 {
74 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.DAILY, NO_MANAGED_COPY );
75 }
76
77 @Test
78 public void testGetProxiedReleaseArtifactPolicyDailyPass()
79 throws Exception
80 {
81 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.DAILY, HAS_MANAGED_COPY,
82 ( OLDER * OVER_ONE_DAY ) );
83 }
84
85 @Test
86 public void testGetProxiedReleaseArtifactPolicyRejectFail()
87 throws Exception
88 {
89 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.NEVER, HAS_MANAGED_COPY );
90 }
91
92 @Test
93 public void testGetProxiedReleaseArtifactPolicyRejectNoManagedContentFail()
94 throws Exception
95 {
96 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_NOT_FOUND, ReleasesPolicy.NEVER, NO_MANAGED_COPY );
97 }
98
99 @Test
100 public void testGetProxiedReleaseArtifactPolicyRejectPass()
101 throws Exception
102 {
103 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.NEVER, HAS_MANAGED_COPY );
104 }
105
106 @Test
107 public void testGetProxiedReleaseArtifactPolicyHourlyFail()
108 throws Exception
109 {
110 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.HOURLY, HAS_MANAGED_COPY,
111 ( NEWER * ONE_MINUTE ) );
112 }
113
114 @Test
115 public void testGetProxiedReleaseArtifactPolicyHourlyNoManagedContent()
116 throws Exception
117 {
118 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.HOURLY, NO_MANAGED_COPY );
119 }
120
121 @Test
122 public void testGetProxiedReleaseArtifactPolicyHourlyPass()
123 throws Exception
124 {
125 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.HOURLY, HAS_MANAGED_COPY,
126 ( OLDER * OVER_ONE_HOUR ) );
127 }
128
129 @Test
130 public void testGetProxiedReleaseArtifactPolicyOnceFail()
131 throws Exception
132 {
133 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_MANAGED_CONTENTS, ReleasesPolicy.ONCE, HAS_MANAGED_COPY );
134 }
135
136 @Test
137 public void testGetProxiedReleaseArtifactPolicyOnceNoManagedContent()
138 throws Exception
139 {
140 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ONCE, NO_MANAGED_COPY );
141 }
142
143 @Test
144 public void testGetProxiedReleaseArtifactPolicyOncePass()
145 throws Exception
146 {
147 assertGetProxiedReleaseArtifactWithPolicy( EXPECT_REMOTE_CONTENTS, ReleasesPolicy.ONCE, NO_MANAGED_COPY );
148 }
149
150 private void assertGetProxiedReleaseArtifactWithPolicy( int expectation, String releasePolicy,
151 boolean hasManagedCopy )
152 throws Exception
153 {
154 assertGetProxiedReleaseArtifactWithPolicy( expectation, releasePolicy, hasManagedCopy, 0 );
155 }
156
157 private void assertGetProxiedReleaseArtifactWithPolicy( int expectation, String releasePolicy,
158 boolean hasManagedCopy, long deltaManagedToRemoteTimestamp )
159 throws Exception
160 {
161
162 setupCentralRemoteRepo();
163 setupCleanInternalRepo();
164
165 String resourcePath = "org/apache/archiva/test/1.0/test-1.0.jar";
166 String expectedRemoteContents = "archiva-test-1.0|jar-remote-contents";
167 String expectedManagedContents = null;
168 File remoteFile = populateRepo( remoteCentral, resourcePath, expectedRemoteContents );
169
170 if ( hasManagedCopy )
171 {
172 expectedManagedContents = "archiva-test-1.0|jar-managed-contents";
173 File managedFile = populateRepo( repoRootInternal, resourcePath, expectedManagedContents );
174 managedFile.setLastModified( remoteFile.lastModified() + deltaManagedToRemoteTimestamp );
175 }
176
177 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
178
179 setupReleaseConnector( REPOID_INTERNAL, remoteCentral, releasePolicy );
180 saveConfiguration();
181
182
183
184
185
186 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + resourcePath );
187 WebResponse response = getServletUnitClient().getResponse( request );
188
189
190
191 switch ( expectation )
192 {
193 case EXPECT_MANAGED_CONTENTS:
194 assertResponseOK( response );
195 assertTrue( "Invalid Test Case: Can't expect managed contents with "
196 + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
197 assertEquals( "Expected managed file contents", expectedManagedContents, response.getContentAsString() );
198 break;
199 case EXPECT_REMOTE_CONTENTS:
200 assertResponseOK( response );
201 assertEquals( "Expected remote file contents", expectedRemoteContents, response.getContentAsString() );
202 break;
203 case EXPECT_NOT_FOUND:
204 assertResponseNotFound( response );
205 assertManagedFileNotExists( repoRootInternal, resourcePath );
206 break;
207 }
208 }
209 }