|
17 | 17 | package com.optimizely.ab.config.audience; |
18 | 18 |
|
19 | 19 | import ch.qos.logback.classic.Level; |
| 20 | +import com.fasterxml.jackson.databind.deser.std.MapEntryDeserializer; |
20 | 21 | import com.optimizely.ab.internal.LogbackVerifier; |
21 | 22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
22 | 23 | import org.junit.Before; |
@@ -191,24 +192,35 @@ public void unexpectedAttributeTypeNull() throws Exception { |
191 | 192 | "Audience condition \"{name='browser_type', type='custom_attribute', match='gt', value=20}\" evaluated to UNKNOWN because a null value was passed for user attribute \"browser_type\""); |
192 | 193 | } |
193 | 194 |
|
194 | | - |
195 | 195 | /** |
196 | | - * Verify that UserAttribute.evaluate returns null on missing attribute value. |
| 196 | + * Verify that UserAttribute.evaluate returns null (and log debug message) on missing attribute value. |
197 | 197 | */ |
198 | 198 | @Test |
199 | | - public void missingAttribute() throws Exception { |
200 | | - UserAttribute testInstance = new UserAttribute("browser_type", "custom_attribute", "gt", 20); |
201 | | - assertNull(testInstance.evaluate(null, Collections.EMPTY_MAP)); |
202 | | - logbackVerifier.expectMessage(Level.DEBUG, |
203 | | - "Audience condition \"{name='browser_type', type='custom_attribute', match='gt', value=20}\" evaluated to UNKNOWN because no value was passed for user attribute \"browser_type\""); |
204 | | - } |
205 | | - |
206 | | - @Test |
207 | | - public void missingAttribute_semVersion() throws Exception { |
208 | | - UserAttribute testInstance = new UserAttribute("app_version", "custom_attribute", "semver_eq", "1.0.2"); |
209 | | - assertNull(testInstance.evaluate(null, Collections.EMPTY_MAP)); |
210 | | - logbackVerifier.expectMessage(Level.DEBUG, |
211 | | - "Audience condition \"{name='app_version', type='custom_attribute', match='semver_eq', value='1.0.2'}\" evaluated to UNKNOWN because no value was passed for user attribute \"app_version\""); |
| 199 | + public void missingAttribute_returnsNullAndLogDebugMessage() throws Exception { |
| 200 | + // check with all valid value types for each match |
| 201 | + |
| 202 | + Map<String, Object[]> items = new HashMap<>(); |
| 203 | + items.put("exact", new Object[]{"string", 123, true}); |
| 204 | + items.put("substring", new Object[]{"string"}); |
| 205 | + items.put("gt", new Object[]{123, 5.3}); |
| 206 | + items.put("ge", new Object[]{123, 5.3}); |
| 207 | + items.put("lt", new Object[]{123, 5.3}); |
| 208 | + items.put("le", new Object[]{123, 5.3}); |
| 209 | + items.put("semver_eq", new Object[]{"1.2.3"}); |
| 210 | + items.put("semver_ge", new Object[]{"1.2.3"}); |
| 211 | + items.put("semver_gt", new Object[]{"1.2.3"}); |
| 212 | + items.put("semver_le", new Object[]{"1.2.3"}); |
| 213 | + items.put("semver_lt", new Object[]{"1.2.3"}); |
| 214 | + |
| 215 | + for (Map.Entry<String, Object[]> entry : items.entrySet()) { |
| 216 | + for (Object value : entry.getValue()) { |
| 217 | + UserAttribute testInstance = new UserAttribute("n", "custom_attribute", entry.getKey(), value); |
| 218 | + assertNull(testInstance.evaluate(null, Collections.EMPTY_MAP)); |
| 219 | + String valueStr = (value instanceof String) ? ("'" + value + "'") : value.toString(); |
| 220 | + logbackVerifier.expectMessage(Level.DEBUG, |
| 221 | + "Audience condition \"{name='n', type='custom_attribute', match='" + entry.getKey() + "', value=" + valueStr + "}\" evaluated to UNKNOWN because no value was passed for user attribute \"n\""); |
| 222 | + } |
| 223 | + } |
212 | 224 | } |
213 | 225 |
|
214 | 226 | /** |
|
0 commit comments