Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2025, Optimizely
* Copyright 2025-2026, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -154,7 +154,7 @@ private Map<String, Object> filterAttributes(ProjectConfig projectConfig, Optimi
Attribute attribute = attributeIdMapping.get(attributeId);
if (attribute != null) {
if (userAttributes.containsKey(attribute.getKey())) {
filteredAttributes.put(attribute.getKey(), userAttributes.get(attribute.getKey()));
filteredAttributes.put(attribute.getId(), userAttributes.get(attribute.getKey()));
} else {
logger.debug("User attribute '{}' not found for attribute ID '{}'", attribute.getKey(), attributeId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2025, Optimizely
* Copyright 2025-2026, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -142,8 +142,8 @@ public void testIgnoresCacheWhenOptionGiven() {
assertNotNull(decision.getCmabUuid());

Map<String, Object> expectedAttributes = new HashMap<>();
expectedAttributes.put("age", 25);
expectedAttributes.put("location", "USA");
expectedAttributes.put("66", 25);
expectedAttributes.put("77", "USA");
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
}

Expand Down Expand Up @@ -199,8 +199,8 @@ public void testNewDecisionWhenHashChanges() {
assertEquals("varE", decision.getVariationId());

Map<String, Object> expectedAttributes = new HashMap<>();
expectedAttributes.put("age", 25);
expectedAttributes.put("location", "USA");
expectedAttributes.put("66", 25);
expectedAttributes.put("77", "USA");
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
}

Expand All @@ -221,12 +221,11 @@ public void testOnlyCmabAttributesPassedToClient() {
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE);
CmabDecision decision = cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options);

// Verify only age and location are passed (attributes configured in setUp)
Map<String, Object> expectedAttributes = new HashMap<>();
expectedAttributes.put("age", 25);
expectedAttributes.put("location", "USA");
expectedAttributes.put("66", 25);
expectedAttributes.put("77", "USA");
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());

assertEquals("varF", decision.getVariationId());
assertNotNull(decision.getCmabUuid());
}
Expand Down Expand Up @@ -275,10 +274,9 @@ public void testAttributeFilteringBehavior() {
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE);
cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options);

// Verify only the configured attributes (age, location) are passed
Map<String, Object> expectedAttributes = new HashMap<>();
expectedAttributes.put("age", 25);
expectedAttributes.put("location", "USA");
expectedAttributes.put("66", 25);
expectedAttributes.put("77", "USA");
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());
}

Expand Down Expand Up @@ -306,9 +304,8 @@ public void testMissingAttributeMappingBehavior() {
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE);
cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options);

// Should only include the attribute that exists (age with ID 66)
Map<String, Object> expectedAttributes = new HashMap<>();
expectedAttributes.put("age", 25);
expectedAttributes.put("66", 25);
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());

// Verify debug log was called for missing attribute
Expand All @@ -328,13 +325,9 @@ public void testMissingUserAttributeBehavior() {
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE);
cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options);

// Should only include the attribute the user has
Map<String, Object> expectedAttributes = new HashMap<>();
expectedAttributes.put("age", 25);
expectedAttributes.put("66", 25);
verify(mockCmabClient).fetchDecision(eq("exp1"), eq("user123"), eq(expectedAttributes), anyString());

// Remove the logger verification if it's causing issues
// verify(mockLogger).debug(anyString(), eq("location"), eq("exp1"));
}

@Test
Expand Down
Loading