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 package org.apache.hc.client5.http.impl.cache;
28
29
30 import org.apache.hc.core5.http.HttpVersion;
31 import org.hamcrest.MatcherAssert;
32 import org.hamcrest.Matchers;
33 import org.junit.jupiter.api.Assertions;
34 import org.junit.jupiter.api.BeforeEach;
35 import org.junit.jupiter.api.Test;
36
37 class TestViaCacheGenerator {
38
39 private ViaCacheGenerator impl;
40
41 @BeforeEach
42 void setUp() {
43 impl = new ViaCacheGenerator();
44 }
45
46 @Test
47 void testViaValueGeneration() {
48 Assertions.assertEquals("1.1 localhost (Apache-HttpClient/UNAVAILABLE (cache))",
49 impl.generateViaHeader(null, HttpVersion.DEFAULT));
50 Assertions.assertEquals("2.0 localhost (Apache-HttpClient/UNAVAILABLE (cache))",
51 impl.generateViaHeader(null, HttpVersion.HTTP_2));
52 }
53
54 @Test
55 void testViaValueLookup() {
56 MatcherAssert.assertThat(impl.lookup(HttpVersion.DEFAULT),
57 Matchers.startsWith("1.1 localhost (Apache-HttpClient/"));
58 MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_1_0),
59 Matchers.startsWith("1.0 localhost (Apache-HttpClient/"));
60 MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_1_1),
61 Matchers.startsWith("1.1 localhost (Apache-HttpClient/"));
62 MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_2),
63 Matchers.startsWith("2.0 localhost (Apache-HttpClient/"));
64 MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_2_0),
65 Matchers.startsWith("2.0 localhost (Apache-HttpClient/"));
66 MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_1_0),
67 Matchers.startsWith("1.0 localhost (Apache-HttpClient/"));
68 MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_1_1),
69 Matchers.startsWith("1.1 localhost (Apache-HttpClient/"));
70 MatcherAssert.assertThat(impl.lookup(HttpVersion.HTTP_2_0),
71 Matchers.startsWith("2.0 localhost (Apache-HttpClient/"));
72 Assertions.assertEquals(3, impl.internalCache.size());
73 }
74
75 }