|
2 | 2 |
|
3 | 3 | import org.apache.http.HttpRequest; |
4 | 4 | import org.apache.http.HttpResponse; |
| 5 | +import org.apache.http.client.methods.HttpDelete; |
| 6 | +import org.apache.http.client.methods.HttpGet; |
| 7 | +import org.apache.http.client.methods.HttpHead; |
| 8 | +import org.apache.http.client.methods.HttpOptions; |
| 9 | +import org.apache.http.client.methods.HttpPatch; |
| 10 | +import org.apache.http.client.methods.HttpPost; |
| 11 | +import org.apache.http.client.methods.HttpPut; |
| 12 | +import org.apache.http.client.methods.HttpRequestWrapper; |
5 | 13 | import org.apache.http.protocol.HttpContext; |
6 | 14 | import org.apache.http.protocol.HttpProcessor; |
7 | 15 | import org.jfrog.artifactory.client.httpClient.http.ProxyConfig; |
8 | 16 | import org.jfrog.artifactory.client.impl.ArtifactoryRequestImpl; |
| 17 | +import org.testng.annotations.DataProvider; |
9 | 18 | import org.testng.annotations.Test; |
10 | 19 |
|
11 | 20 | import java.io.IOException; |
|
19 | 28 | */ |
20 | 29 | public class ArtifactoryTests { |
21 | 30 |
|
| 31 | + @DataProvider(name = "httpMethods") |
| 32 | + public Object[][] getHttpMethodData() { |
| 33 | + return new Object[][]{ |
| 34 | + {ArtifactoryRequest.Method.GET, HttpGet.class}, |
| 35 | + {ArtifactoryRequest.Method.POST, HttpPost.class}, |
| 36 | + {ArtifactoryRequest.Method.PUT, HttpPut.class}, |
| 37 | + {ArtifactoryRequest.Method.DELETE, HttpDelete.class}, |
| 38 | + {ArtifactoryRequest.Method.PATCH, HttpPatch.class}, |
| 39 | + {ArtifactoryRequest.Method.OPTIONS, HttpOptions.class}, |
| 40 | + {ArtifactoryRequest.Method.HEAD, HttpHead.class}, |
| 41 | + }; |
| 42 | + } |
| 43 | + |
22 | 44 | @Test |
23 | 45 | public void urlsTest() throws IOException { |
24 | 46 | Artifactory artifactory; |
@@ -208,4 +230,22 @@ public void process(HttpResponse response, HttpContext context) { |
208 | 230 | assertEquals(requestInterceptions.intValue(), 0); |
209 | 231 | assertEquals(responseInterceptions.intValue(), 0); |
210 | 232 | } |
| 233 | + |
| 234 | + @Test(dataProvider = "httpMethods") |
| 235 | + public void httpMethodsTest(ArtifactoryRequest.Method method, Class<?> expectedClass) { |
| 236 | + ArtifactoryRequest artifactoryRequest = new ArtifactoryRequestImpl() |
| 237 | + .method(method); |
| 238 | + |
| 239 | + ArtifactoryClientBuilder builder = ArtifactoryClientBuilder.create(); |
| 240 | + builder.setUrl("http://local/"); |
| 241 | + builder.addInterceptorLast((httpRequest, httpContext) -> |
| 242 | + assertEquals(((HttpRequestWrapper) httpRequest).getOriginal().getClass(), expectedClass) |
| 243 | + ); |
| 244 | + |
| 245 | + try { |
| 246 | + builder.build().restCall(artifactoryRequest); |
| 247 | + } catch (IOException e) { |
| 248 | + // We expect an IOException since http://local/ is not a valid URL, but the interceptor should have been called. |
| 249 | + } |
| 250 | + } |
211 | 251 | } |
0 commit comments