1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.client5.http.async.methods;
29
30 import java.lang.reflect.Method;
31 import java.net.URI;
32 import java.util.Arrays;
33
34 import org.apache.hc.core5.http.HttpRequest;
35 import org.junit.Assert;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.junit.runners.Parameterized;
39 import org.junit.runners.Parameterized.Parameters;
40
41 @RunWith(Parameterized.class)
42 public class SimpleBasicHttpRequests {
43
44 private static final String URI_STRING_FIXTURE = "http://localhost";
45 private static final URI URI_FIXTURE = URI.create(URI_STRING_FIXTURE);
46
47 @Parameters(name = "{index}: {0} => {1}")
48 public static Iterable<Object[]> data() {
49 return Arrays.asList(new Object[][] {
50
51 { "delete", "DELETE" },
52 { "get", "GET" },
53 { "head", "HEAD" },
54 { "options", "OPTIONS" },
55 { "patch", "PATCH" },
56 { "post", "POST" },
57 { "put", "PUT" },
58 { "trace", "TRACE" }
59
60 });
61 }
62
63 private final String methodName;
64
65 private final String expectedMethod;
66
67 public SimpleBasicHttpRequests(final String methodName, final String expectedMethod) {
68 this.methodName = methodName;
69 this.expectedMethod = expectedMethod;
70 }
71
72 @Test
73 public void testCreateMethodUri() {
74 Assert.assertEquals(SimpleHttpRequest.class, SimpleHttpRequests.create(methodName, URI_FIXTURE).getClass());
75 Assert.assertEquals(SimpleHttpRequest.class, SimpleHttpRequests.create(expectedMethod, URI_FIXTURE).getClass());
76 }
77
78 @Test
79 public void testCreateMethodUriString() {
80 Assert.assertEquals(SimpleHttpRequest.class, SimpleHttpRequests.create(methodName, URI_STRING_FIXTURE).getClass());
81 Assert.assertEquals(SimpleHttpRequest.class, SimpleHttpRequests.create(expectedMethod, URI_STRING_FIXTURE).getClass());
82 }
83
84 @Test
85 public void testCreateClassicHttpRequest() throws Exception {
86 final Method httpMethod = SimpleHttpRequests.class.getMethod(methodName, URI.class);
87 final HttpRequest basicHttpRequest = (HttpRequest) httpMethod.invoke(null, URI_FIXTURE);
88 Assert.assertEquals(SimpleHttpRequest.class, basicHttpRequest.getClass());
89 Assert.assertEquals(expectedMethod, basicHttpRequest.getMethod());
90 }
91 }