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.classic.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.ClassicHttpRequest;
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 TestClassicHttpRequests {
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", HttpDelete.class },
52 { "get", HttpGet.class },
53 { "head", HttpHead.class },
54 { "options", HttpOptions.class },
55 { "patch", HttpPatch.class },
56 { "post", HttpPost.class },
57 { "put", HttpPut.class },
58 { "trace", HttpTrace.class }
59
60 });
61 }
62
63 private final String methodName;
64
65 private final Class<ClassicHttpRequest> expectedClass;
66
67 public TestClassicHttpRequests(final String methodName,
68 final Class<ClassicHttpRequest> expectedClass) {
69 this.methodName = methodName;
70 this.expectedClass = expectedClass;
71 }
72
73 @Test
74 public void testCreateMethodUri() {
75 Assert.assertEquals(expectedClass, ClassicHttpRequests.create(methodName, URI_FIXTURE).getClass());
76 }
77
78 @Test
79 public void testCreateMethodUriString() {
80 Assert.assertEquals(expectedClass, ClassicHttpRequests.create(methodName, URI_STRING_FIXTURE).getClass());
81 }
82
83 @Test
84 public void testCreateFromString() throws Exception {
85 final Method httpMethod = ClassicHttpRequests.class.getMethod(methodName, String.class);
86 Assert.assertEquals(expectedClass,
87 httpMethod.invoke(null, URI_STRING_FIXTURE).getClass());
88 }
89
90 @Test
91 public void testCreateFromURI() throws Exception {
92 final Method httpMethod = ClassicHttpRequests.class.getMethod(methodName, URI.class);
93 Assert.assertEquals(expectedClass,
94 httpMethod.invoke(null, URI_FIXTURE).getClass());
95 }
96 }