1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.transport.http.apache;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertTrue;
14
15 import java.net.MalformedURLException;
16 import java.util.List;
17 import java.util.Locale;
18
19 import org.apache.http.HttpEntity;
20 import org.apache.http.HttpResponse;
21 import org.apache.http.ProtocolVersion;
22 import org.apache.http.StatusLine;
23 import org.apache.http.message.AbstractHttpMessage;
24 import org.junit.Test;
25
26 public class HttpClientConnectionTest {
27 @Test
28 public void testGetHeaderFieldsAllowMultipleValues()
29 throws MalformedURLException {
30 HttpResponse responseMock = new HttpResponseMock();
31 String headerField = "WWW-Authenticate";
32 responseMock.addHeader(headerField, "Basic");
33 responseMock.addHeader(headerField, "Digest");
34 responseMock.addHeader(headerField, "NTLM");
35 HttpClientConnection connection = new HttpClientConnection(
36 "http://0.0.0.0/");
37 connection.resp = responseMock;
38 List<String> headerValues = connection.getHeaderFields()
39 .get(headerField);
40 assertEquals(3, headerValues.size());
41 assertTrue(headerValues.contains("Basic"));
42 assertTrue(headerValues.contains("Digest"));
43 assertTrue(headerValues.contains("NTLM"));
44 }
45
46 private static class HttpResponseMock extends AbstractHttpMessage
47 implements HttpResponse {
48 @Override
49 public StatusLine getStatusLine() {
50 throw new UnsupportedOperationException();
51 }
52
53 @Override
54 public void setStatusLine(StatusLine statusLine) {
55 throw new UnsupportedOperationException();
56 }
57
58 @Override
59 public void setStatusLine(ProtocolVersion protocolVersion, int i) {
60 throw new UnsupportedOperationException();
61 }
62
63 @Override
64 public void setStatusLine(ProtocolVersion protocolVersion, int i,
65 String s) {
66 throw new UnsupportedOperationException();
67 }
68
69 @Override
70 public void setStatusCode(int i) throws IllegalStateException {
71 throw new UnsupportedOperationException();
72 }
73
74 @Override
75 public void setReasonPhrase(String s) throws IllegalStateException {
76 throw new UnsupportedOperationException();
77 }
78
79 @Override
80 public HttpEntity getEntity() {
81 throw new UnsupportedOperationException();
82 }
83
84 @Override
85 public void setEntity(HttpEntity httpEntity) {
86 throw new UnsupportedOperationException();
87 }
88
89 @Override
90 public Locale getLocale() {
91 throw new UnsupportedOperationException();
92 }
93
94 @Override
95 public void setLocale(Locale locale) {
96 throw new UnsupportedOperationException();
97 }
98
99 @Override
100 public ProtocolVersion getProtocolVersion() {
101 throw new UnsupportedOperationException();
102 }
103 }
104 }