From 6728d79b144ba63508c190bf232fbd1e644c7164 Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Wed, 1 Jul 2026 01:37:03 +0600 Subject: [PATCH] [AI-FSSDK] [FSSDK-12750] Use attribute id instead of key for CMAB prediction requests --- .../ab/cmab/service/DefaultCmabService.java | 4 +-- .../ab/cmab/DefaultCmabServiceTest.java | 31 +++++++------------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/core-api/src/main/java/com/optimizely/ab/cmab/service/DefaultCmabService.java b/core-api/src/main/java/com/optimizely/ab/cmab/service/DefaultCmabService.java index 75835a9f8..dfd10998c 100644 --- a/core-api/src/main/java/com/optimizely/ab/cmab/service/DefaultCmabService.java +++ b/core-api/src/main/java/com/optimizely/ab/cmab/service/DefaultCmabService.java @@ -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. @@ -154,7 +154,7 @@ private Map 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); } diff --git a/core-api/src/test/java/com/optimizely/ab/cmab/DefaultCmabServiceTest.java b/core-api/src/test/java/com/optimizely/ab/cmab/DefaultCmabServiceTest.java index 671b8c1b8..d3210c7b0 100644 --- a/core-api/src/test/java/com/optimizely/ab/cmab/DefaultCmabServiceTest.java +++ b/core-api/src/test/java/com/optimizely/ab/cmab/DefaultCmabServiceTest.java @@ -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. @@ -142,8 +142,8 @@ public void testIgnoresCacheWhenOptionGiven() { assertNotNull(decision.getCmabUuid()); Map 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()); } @@ -199,8 +199,8 @@ public void testNewDecisionWhenHashChanges() { assertEquals("varE", decision.getVariationId()); Map 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()); } @@ -221,12 +221,11 @@ public void testOnlyCmabAttributesPassedToClient() { List 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 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()); } @@ -275,10 +274,9 @@ public void testAttributeFilteringBehavior() { List options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE); cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options); - // Verify only the configured attributes (age, location) are passed Map 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()); } @@ -306,9 +304,8 @@ public void testMissingAttributeMappingBehavior() { List 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 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 @@ -328,13 +325,9 @@ public void testMissingUserAttributeBehavior() { List options = Arrays.asList(OptimizelyDecideOption.IGNORE_CMAB_CACHE); cmabService.getDecision(mockProjectConfig, mockUserContext, "exp1", options); - // Should only include the attribute the user has Map 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