|
| 1 | +package com.amazonaws.services.lambda.runtime.events; |
| 2 | + |
| 3 | +import com.amazonaws.services.lambda.runtime.events.models.HttpHeaders; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +import java.util.*; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.*; |
| 9 | +import static org.assertj.core.api.Assertions.assertThat; |
| 10 | + |
| 11 | +public class HttpHeadersTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + public void testHttpHeadersCanBeInit() { |
| 15 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testValueCanBeAddedToHttpHeaders() { |
| 20 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 21 | + obj.put("key", "value"); |
| 22 | + assertThat(obj).hasSize(1); |
| 23 | + assertThat(obj).containsEntry("key", "value"); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void testValuesCanBeAddedToHttpHeaders() { |
| 28 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 29 | + obj.put("key", "value"); |
| 30 | + obj.put("key2", "value2"); |
| 31 | + obj.put("key3", "value3"); |
| 32 | + |
| 33 | + assertThat(obj).hasSize(3); |
| 34 | + assertThat(obj).containsEntry("key", "value"); |
| 35 | + assertThat(obj).containsEntry("key2", "value2"); |
| 36 | + assertThat(obj).containsEntry("key3", "value3"); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testOverridingHttpHeadersKeysIsCaseInsensitive() { |
| 41 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 42 | + obj.put("key", "value"); |
| 43 | + obj.put("KEY", "value2"); |
| 44 | + obj.put("kEy", "value3"); |
| 45 | + |
| 46 | + assertThat(obj).hasSize(1); |
| 47 | + assertThat(obj).containsEntry("key", "value3"); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void testValuesCanBeRemovedFromHttpHeaders() { |
| 52 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 53 | + obj.put("key", "value"); |
| 54 | + |
| 55 | + assertThat(obj).hasSize(1); |
| 56 | + obj.remove("key"); |
| 57 | + assertThat(obj).isEmpty(); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testContainedKeysAreContainedInHttpHeaders() { |
| 62 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 63 | + obj.put("key", "value"); |
| 64 | + |
| 65 | + assertTrue(obj.containsKey("key")); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testContainedValuesAreContainedInHttpHeaders() { |
| 70 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 71 | + obj.put("key", "value"); |
| 72 | + |
| 73 | + assertTrue(obj.containsValue("value")); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void testPutAllWorksInHttpHeaders() { |
| 78 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 79 | + obj.put("key", "value"); |
| 80 | + obj.put("key2", "value2"); |
| 81 | + |
| 82 | + Map<String, String> otherMap = new HashMap<>(); |
| 83 | + otherMap.put("otherKey1", "otherVal1"); |
| 84 | + otherMap.put("otherKey2", "otherVal2"); |
| 85 | + otherMap.put("otherKey3", "otherVal3"); |
| 86 | + |
| 87 | + obj.putAll(otherMap); |
| 88 | + |
| 89 | + assertThat(obj).hasSize(5); |
| 90 | + assertThat(obj).containsEntry("key", "value"); |
| 91 | + assertThat(obj).containsEntry("key2", "value2"); |
| 92 | + assertThat(obj).containsEntry("otherKey1", "otherVal1"); |
| 93 | + assertThat(obj).containsEntry("otherKey2", "otherVal2"); |
| 94 | + assertThat(obj).containsEntry("otherKey3", "otherVal3"); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testClearWorksInHttpHeaders() { |
| 99 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 100 | + obj.put("key", "value"); |
| 101 | + obj.put("key2", "value2"); |
| 102 | + |
| 103 | + assertThat(obj).hasSize(2); |
| 104 | + |
| 105 | + obj.clear(); |
| 106 | + |
| 107 | + assertThat(obj).hasSize(0); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void testKeySetWorksInHttpHeaders() { |
| 112 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 113 | + obj.put("key", "value"); |
| 114 | + obj.put("key2", "value2"); |
| 115 | + |
| 116 | + Set<String> keySet = obj.keySet(); |
| 117 | + |
| 118 | + assertNotNull(keySet); |
| 119 | + assertThat(keySet).hasSize(2); |
| 120 | + assertThat(keySet).contains("key", "key2"); |
| 121 | + } |
| 122 | + |
| 123 | + @Test |
| 124 | + public void testValuesWorksInHttpHeaders() { |
| 125 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 126 | + obj.put("key", "value"); |
| 127 | + obj.put("key2", "value2"); |
| 128 | + |
| 129 | + Collection<String> values = obj.values(); |
| 130 | + |
| 131 | + assertNotNull(values); |
| 132 | + assertThat(values).hasSize(2); |
| 133 | + assertThat(values).contains("value", "value2"); |
| 134 | + } |
| 135 | + |
| 136 | + @Test |
| 137 | + public void testEntrySetWorksInHttpHeaders() { |
| 138 | + HttpHeaders<String> obj = new HttpHeaders<>(); |
| 139 | + obj.put("key", "value"); |
| 140 | + obj.put("key2", "value2"); |
| 141 | + |
| 142 | + Set<Map.Entry<String, String>> entrySet = obj.entrySet(); |
| 143 | + |
| 144 | + assertNotNull(entrySet); |
| 145 | + assertThat(entrySet).hasSize(2); |
| 146 | + assertThat(entrySet).contains(new AbstractMap.SimpleEntry<>("key", "value")); |
| 147 | + assertThat(entrySet).contains(new AbstractMap.SimpleEntry<>("key2", "value2")); |
| 148 | + } |
| 149 | +} |
0 commit comments