2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.logging.servlet.jaxrs;
19 import static org.testng.Assert.assertEquals;
20 import static org.testng.Assert.assertNull;
22 import java.util.function.Function;
23 import org.openecomp.sdc.logging.servlet.HttpHeader;
24 import org.testng.annotations.Test;
27 * Unit tests mutliple-option headers.
32 public class HttpHeaderTest {
35 public void valueReturnedWhenSinglePossibleHeader() {
37 final String key = "Head";
38 final String value = "1234";
40 Function<String, String> reader = createReader(key, value);
41 HttpHeader header = new HttpHeader(key);
42 assertEquals(header.getAny(reader), value);
46 public void nullReturnedWhenSingleNoMatchingHeader() {
48 final String key = "Head";
50 Function<String, String> reader = createReader(key, null);
51 HttpHeader header = new HttpHeader(key);
52 assertNull(header.getAny(reader));
56 public void nullReturnedWhenNoneHeaderMatches() {
57 Function<String, String> reader = createReader("None", "Value");
58 HttpHeader header = new HttpHeader("A", "B", "C");
59 assertNull(header.getAny(reader));
63 public void valueReturnedWhenLastHeaderMatches() {
65 final String lastKey = "Last";
66 final String value = "1234";
68 Function<String, String> reader = createReader(lastKey, value);
69 HttpHeader header = new HttpHeader("First", "Second", lastKey);
70 assertEquals(header.getAny(reader), value);
74 public void valueReturnedWhenFirstHeaderMatches() {
76 final String firstKey = "First";
77 final String value = "1234";
79 Function<String, String> reader = createReader(firstKey, value);
80 HttpHeader header = new HttpHeader(firstKey, "Second", "Third");
81 assertEquals(header.getAny(reader), value);
85 public void valueReturnedWhenMiddleHeaderMatches() {
87 final String middleKey = "Second";
88 final String value = "1234";
90 Function<String, String> reader = createReader(middleKey, value);
91 HttpHeader header = new HttpHeader("First", middleKey, "Third");
92 assertEquals(header.getAny(reader), value);
95 private Function<String, String> createReader(String key, String value) {
96 return h -> h.equals(key) ? value : null;