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.core5.http.support;
29
30 import org.apache.hc.core5.http.ContentType;
31 import org.apache.hc.core5.http.HttpVersion;
32 import org.apache.hc.core5.http.ProtocolException;
33 import org.apache.hc.core5.http.impl.BasicEntityDetails;
34 import org.junit.jupiter.api.Assertions;
35 import org.junit.jupiter.api.Test;
36
37 public class TestExpectSupport {
38
39 @Test
40 public void testExpectParsingBasics() throws Exception {
41 Assertions.assertEquals(Expectation.CONTINUE,
42 ExpectSupport.parse(
43 BasicRequestBuilder.post()
44 .addHeader("Expect", "100-continue")
45 .build(),
46 new BasicEntityDetails(100, ContentType.TEXT_PLAIN)));
47 }
48
49 @Test
50 public void testExpectParsingTolerateEmptyTokens() throws Exception {
51 Assertions.assertEquals(Expectation.CONTINUE,
52 ExpectSupport.parse(
53 BasicRequestBuilder.post()
54 .addHeader("Expect", ",,,")
55 .addHeader("Expect", ",100-continue")
56 .addHeader("Expect", ",,,")
57 .build(),
58 new BasicEntityDetails(100, ContentType.TEXT_PLAIN)));
59 }
60
61 @Test
62 public void testExpectParsingMissingEntity() throws Exception {
63 Assertions.assertThrows(ProtocolException.class,
64 () -> ExpectSupport.parse(
65 BasicRequestBuilder.post()
66 .addHeader("Expect", "100-continue")
67 .build(),
68 null));
69 }
70
71 @Test
72 public void testExpectParsingUnknownExpectation() throws Exception {
73 Assertions.assertEquals(Expectation.UNKNOWN,
74 ExpectSupport.parse(
75 BasicRequestBuilder.post()
76 .addHeader("Expect", "whatever")
77 .addHeader("Expect", "100-continue")
78 .build(),
79 new BasicEntityDetails(100, ContentType.TEXT_PLAIN)));
80 }
81
82 @Test
83 public void testExpectParsingUnknownExpectation2() throws Exception {
84 Assertions.assertEquals(Expectation.UNKNOWN,
85 ExpectSupport.parse(
86 BasicRequestBuilder.post()
87 .addHeader("Expect", "100-continue, whatever")
88 .build(),
89 new BasicEntityDetails(100, ContentType.TEXT_PLAIN)));
90 }
91
92 @Test
93 public void testExpectParsingNoExpectation() throws Exception {
94 Assertions.assertNull(ExpectSupport.parse(
95 BasicRequestBuilder.post()
96 .build(),
97 new BasicEntityDetails(100, ContentType.TEXT_PLAIN)));
98 }
99
100 @Test
101 public void testExpectParsingIgnoreHTTP10() throws Exception {
102 Assertions.assertNull(ExpectSupport.parse(
103 BasicRequestBuilder.post()
104 .setVersion(HttpVersion.HTTP_1_0)
105 .addHeader("Expect", "100-continue")
106 .build(),
107 new BasicEntityDetails(100, ContentType.TEXT_PLAIN)));
108 }
109
110 }