1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.http.header;
18
19 import static org.apache.juneau.TestUtils.*;
20 import static org.apache.juneau.http.HttpHeaders.*;
21
22 import java.io.*;
23 import java.util.function.*;
24
25 import org.apache.juneau.*;
26 import org.apache.juneau.annotation.*;
27 import org.apache.juneau.common.utils.*;
28 import org.apache.juneau.http.annotation.*;
29 import org.apache.juneau.rest.annotation.*;
30 import org.apache.juneau.rest.client.*;
31 import org.apache.juneau.rest.mock.*;
32 import org.junit.jupiter.api.*;
33
34 class Authorization_Test extends TestBase {
35
36 private static final String HEADER = "Authorization";
37 private static final String VALUE = "foo";
38
39 @Rest
40 public static class A {
41 @RestOp
42 public StringReader get(@Header(name=HEADER) @Schema(cf="multi") String[] h) {
43 return reader(h == null ? "null" : Utils.join(h, ','));
44 }
45 }
46
47
48
49
50
51 @Test void a01_basic() throws Exception {
52 var c = client().build();
53
54
55 c.get().header(authorization(VALUE)).run().assertContent(VALUE);
56 c.get().header(authorization(VALUE)).run().assertContent(VALUE);
57 c.get().header(authorization(()->VALUE)).run().assertContent(VALUE);
58
59
60 c.get().header(authorization((String)null)).run().assertContent().isEmpty();
61 c.get().header(authorization((Supplier<String>)null)).run().assertContent().isEmpty();
62 c.get().header(authorization(()->null)).run().assertContent().isEmpty();
63 }
64
65
66
67
68
69 private static RestClient.Builder client() {
70 return MockRestClient.create(A.class);
71 }
72 }