diff --git a/device-detection.hash.engine.on-premise/src/main/cxx/device-detection-cxx b/device-detection.hash.engine.on-premise/src/main/cxx/device-detection-cxx index 9027aa894..c7b2822ad 160000 --- a/device-detection.hash.engine.on-premise/src/main/cxx/device-detection-cxx +++ b/device-detection.hash.engine.on-premise/src/main/cxx/device-detection-cxx @@ -1 +1 @@ -Subproject commit 9027aa8949e7888759dd4de224d9e47c7c4724fb +Subproject commit c7b2822ada54dc8e43c5aeb638141a85ed079c67 diff --git a/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/data/DataValidatorHash.java b/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/data/DataValidatorHash.java index f5d8fce11..336a52141 100644 --- a/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/data/DataValidatorHash.java +++ b/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/data/DataValidatorHash.java @@ -29,6 +29,7 @@ import fiftyone.pipeline.core.data.FlowData; import fiftyone.pipeline.engines.data.AspectPropertyValue; import fiftyone.pipeline.engines.exceptions.NoValueException; +import fiftyone.pipeline.engines.fiftyone.data.ComponentMetaData; import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData; import java.util.Arrays; @@ -81,13 +82,28 @@ public void validateData(FlowData data, boolean validEvidence) throws NoValueExc if (validEvidence == false) { assertEquals("0-0-0-0", elementData.getDeviceId().getValue()); } - int validKeys = 0; - for (String key : data.getEvidence().asKeyMap().keySet()) { - if (engine.getEvidenceKeyFilter().include(key)) { - validKeys++; - } + // Since the detection result shape was unified in device-detection-cxx + // (issue #362), the number of results - and therefore the number of + // matched User-Agents - is determined by the components the engine can + // populate, not by how many evidence keys were supplied. Supplying + // redundant evidence no longer changes it. The exact number depends on + // which components the data file makes available, so assert the bound + // rather than a fixed value, and that valid evidence produces at least + // one result. + int componentCount = 0; + for (ComponentMetaData component : engine.getComponents()) { + componentCount++; + } + int matchedUserAgents = elementData.getUserAgents().getValue().size(); + assertTrue( + "There should be no more matched User-Agents (" + matchedUserAgents + + ") than components populated by the engine (" + componentCount + ")", + matchedUserAgents <= componentCount); + if (validEvidence) { + assertTrue( + "Valid evidence should produce at least one result", + matchedUserAgents >= 1); } - assertEquals("validKeys vs userAgents size mismatch", validKeys, elementData.getUserAgents().getValue().size()); } @Override diff --git a/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/data/ValueTests.java b/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/data/ValueTests.java index f1da2a119..6ccc631bf 100644 --- a/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/data/ValueTests.java +++ b/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/data/ValueTests.java @@ -30,6 +30,7 @@ import fiftyone.pipeline.core.data.FlowData; import fiftyone.pipeline.engines.data.AspectPropertyValue; import fiftyone.pipeline.engines.exceptions.PropertyMissingException; +import fiftyone.pipeline.engines.fiftyone.data.ComponentMetaData; import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData; import java.lang.reflect.Method; @@ -59,7 +60,21 @@ public static void matchedUserAgents(Wrapper wrapper) throws Exception { .process(); ElementData elementData = data.get(wrapper.getEngine().getElementDataKey()); DeviceData device = (DeviceData) elementData; - assertEquals(1, device.getUserAgents().getValue().size()); + // Since the detection result shape was unified in + // device-detection-cxx (issue #362), a single User-Agent produces + // one result - and so one matched User-Agent - per component the + // engine populates, rather than exactly one overall. The number + // depends on the data file, so assert the bound here and validate + // every matched substring below. + int componentCount = 0; + for (ComponentMetaData component : wrapper.getComponents()) { + componentCount++; + } + int matchedCount = device.getUserAgents().getValue().size(); + assertTrue( + "Expected between 1 and " + componentCount + + " matched User-Agents, got " + matchedCount, + matchedCount >= 1 && matchedCount <= componentCount); for (String matchedUa : device.getUserAgents().getValue()) { for (String substring : matchedUa.split("_|\\{|\\}")) { if (substring.isEmpty() == false) {