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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.server;
import com.yahoo.collections.Tuple2;
import com.yahoo.container.jdisc.HttpResponse;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
* @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
* @since 5.7.0
*/
public class VersionsTestCase {
private static final List<String> EMPTY = Collections.emptyList();
private static final List<String> ONE_TWO = Arrays.asList("1", "2");
private static final List<String> TWO_THREE = Arrays.asList("3", "2");
private static final List<String> ONE_NULL_TWO = Arrays.asList("1", null, "2");
private static final List<String> ONE_COMMA_TWO = Collections.singletonList("1, 2");
private static final List<String> ONE_EMPTY_TWO = Arrays.asList("1", "", "2");
private static final List<String> TOO_LARGE_NUMBER = Collections.singletonList("1000000000");
private static final List<String> TWO_TOO_LARGE_NUMBER = Arrays.asList("2", "1000000000");
private static final List<String> TWO_COMMA_TOO_LARGE_NUMBER = Arrays.asList("2,1000000000");
private static final List<String> GARBAGE = Collections.singletonList("garbage");
@Test
public void testEmpty() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(EMPTY);
assertThat(v.first, instanceOf(ErrorHttpResponse.class));
assertThat(v.second, is(-1));
}
@Test
public void testOneTwo() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_TWO);
assertThat(v.first, nullValue());
assertThat(v.second, is(2));
}
@Test
public void testTwoThree() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(TWO_THREE);
assertThat(v.first, nullValue());
assertThat(v.second, is(3));
}
@Test
public void testOneNullTwo() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_NULL_TWO);
assertThat(v.first, nullValue());
assertThat(v.second, is(2));
}
@Test
public void testOneCommaTwo() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_COMMA_TWO);
assertThat(v.first, nullValue());
assertThat(v.second, is(2));
}
@Test
public void testOneEmptyTwo() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_EMPTY_TWO);
assertThat(v.first, nullValue());
assertThat(v.second, is(2));
}
@Test
public void testTooLarge() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(TOO_LARGE_NUMBER);
assertThat(v.first, instanceOf(ErrorHttpResponse.class));
assertThat(v.second, is(-1));
}
@Test
public void testTwoTooLarge() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(TWO_TOO_LARGE_NUMBER);
assertThat(v.first, nullValue());
assertThat(v.second, is(2));
}
@Test
public void testTwoCommaTooLarge() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(TWO_COMMA_TOO_LARGE_NUMBER);
assertThat(v.first, nullValue());
assertThat(v.second, is(2));
}
@Test
public void testGarbage() throws Exception {
Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(GARBAGE);
assertThat(v.first, instanceOf(ErrorHttpResponse.class));
assertThat(v.second, is(-1));
}
}
|