From 2b84a8063a8690e2f9667fa3eafe22ce1f406745 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:16:02 +0000 Subject: [PATCH 01/28] Test: only one thread at a time reads the native results of finished device data device-detection-specification/pipeline-elements/device-detection-on-premise.md line 327 at 706de1f0: Aspect Data that reads its values from a ResultsHash instance MUST let only one thread at a time read from its results. Covers a match metric (DeviceId), a typed property read (IsMobile) and the public getValues. DD-18. --- .../ResultsOneThreadAtATimeTests.java | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ResultsOneThreadAtATimeTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ResultsOneThreadAtATimeTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ResultsOneThreadAtATimeTests.java new file mode 100644 index 000000000..162fb7580 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ResultsOneThreadAtATimeTests.java @@ -0,0 +1,174 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.ResultsHashSwig; +import fiftyone.pipeline.core.data.FlowData; +import fiftyone.pipeline.engines.services.MissingPropertyService; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.slf4j.Logger; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.RETURNS_DEFAULTS; +import static org.mockito.Mockito.mock; + +/** + * Finished Element Data MUST be safe to read from several threads at once, + * so Aspect Data that reads its values from a ResultsHash instance MUST let + * only one thread at a time read from its results + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 327 at 706de1f0). Each test reads the same data from two threads, and + * the mock results record the most threads that were ever inside them at + * once. A thread that gets in waits for the other to join it, up to a + * limit. With a lock the other cannot join, so the wait runs out and one + * thread was inside at a time. Without one, both are inside together. The + * limit only makes a test with a lock take longer, never fail. + */ +public class ResultsOneThreadAtATimeTests { + + private static final long JOIN_WAIT_MILLIS = 500; + + /** + * Answer for every native results call that counts the threads inside the + * results, and gives a value of the type the call returns. + */ + private static class CountingAnswer implements Answer { + private final AtomicInteger inside = new AtomicInteger(); + private final AtomicInteger most = new AtomicInteger(); + private final CountDownLatch bothInside = new CountDownLatch(2); + + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + String name = invocation.getMethod().getName(); + if (name.equals("close") || name.equals("delete") || + name.equals("finalize")) { + return null; + } + int now = inside.incrementAndGet(); + most.accumulateAndGet(now, Math::max); + bothInside.countDown(); + try { + bothInside.await(JOIN_WAIT_MILLIS, TimeUnit.MILLISECONDS); + Class returns = invocation.getMethod().getReturnType(); + if (name.equals("getDeviceId")) { + return "0-0-0-0"; + } + if (name.equals("containsProperty")) { + return true; + } + if (returns.getName().contains(".interop.swig.")) { + // A value with no value, as the native code gives for a + // property with none. + return mock(returns); + } + return RETURNS_DEFAULTS.answer(invocation); + } + finally { + inside.decrementAndGet(); + } + } + } + + private static int mostThreadsInsideResults( + Consumer read) throws Exception { + CountingAnswer answer = new CountingAnswer(); + ResultsHashSwig results = mock(ResultsHashSwig.class, answer); + FlowData flowData = mock(FlowData.class); + DeviceDataHashDefault data = new DeviceDataHashDefault( + mock(Logger.class), + flowData, + mock(DeviceDetectionHashEngine.class), + mock(MissingPropertyService.class)); + data.setResults(results); + + CountDownLatch start = new CountDownLatch(1); + List errors = new ArrayList<>(); + List threads = new ArrayList<>(); + for (int i = 0; i < 2; i++) { + Thread thread = new Thread(() -> { + try { + start.await(); + read.accept(data); + } catch (Throwable t) { + synchronized (errors) { + errors.add(t); + } + } + }); + thread.start(); + threads.add(thread); + } + start.countDown(); + for (Thread thread : threads) { + thread.join(); + } + if (errors.isEmpty() == false) { + throw new AssertionError("A read failed", errors.get(0)); + } + return answer.most.get(); + } + + /** + * A match metric, such as DeviceId, reads the results too, and walks every + * graph not yet walked. + */ + @Test + public void Results_MatchMetric_OneThreadAtATime() throws Exception { + assertEquals( + "Two threads read the native results at once for DeviceId", + 1, + mostThreadsInsideResults(d -> d.getDeviceId())); + } + + /** + * A typed property read, which first asks the results whether they have + * the property. + */ + @Test + public void Results_PropertyRead_OneThreadAtATime() throws Exception { + assertEquals( + "Two threads read the native results at once for IsMobile", + 1, + mostThreadsInsideResults(d -> d.getIsMobile())); + } + + /** + * The public list read. + */ + @Test + public void Results_GetValues_OneThreadAtATime() throws Exception { + assertEquals( + "Two threads read the native results at once for getValues", + 1, + mostThreadsInsideResults(d -> d.getValues("HardwareName"))); + } +} From 8e1a1fcdd24456ed4bdb1e335666a93828f82665 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:20:56 +0000 Subject: [PATCH 02/28] Fix: hold one lock for every read of the native results in device data device-detection-specification/pipeline-elements/device-detection-on-premise.md line 327 at 706de1f0: Aspect Data that reads its values from a ResultsHash instance MUST let only one thread at a time read from its results. The lock in DeviceDataBaseOnPremise.tryGetValue covered only the typed getters. The check that the results have a property, the public getValues, the match metrics (which can walk every graph not yet walked) and close read the results with no lock. DeviceDataHashDefault now holds one lock of its own for each of them. DD-18. --- .../flowelements/DeviceDataHashDefault.java | 234 ++++++++++-------- 1 file changed, 131 insertions(+), 103 deletions(-) diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java index 691761125..6d7845fca 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java @@ -74,6 +74,14 @@ public class DeviceDataHashDefault */ private final DeviceDetectionHashEngine hashEngine; + /** + * Held for every read of the native results. A native results instance + * is used by one thread at a time, because reading a value writes into + * it, so this lets finished data be read from several threads at once. + * @see Specification + */ + private final Object resultsLock = new Object(); + /** * Constructs a new instance. * @param logger used for logging @@ -259,9 +267,11 @@ private AspectPropertyValue> getUserAgentsInternal() { @Override protected boolean propertyIsAvailable(String propertyName) { checkState(); - for (ResultsHashSwig results : resultsList) { - if (results.containsProperty(Swig.asBytes(propertyName))) { - return true; + synchronized (resultsLock) { + for (ResultsHashSwig results : resultsList) { + if (results.containsProperty(Swig.asBytes(propertyName))) { + return true; + } } } return false; @@ -272,20 +282,22 @@ public AspectPropertyValue> getValues(String propertyName) { checkState(); AspectPropertyValue> result = new AspectPropertyValueDefault<>(); - ResultsHashSwig results = getSingleResults(propertyName); - if (results != null) { - Integer index = indexOf(propertyName); - try (VectorStringValuesSwig value = index == null ? - results.getValues(Swig.asBytes(propertyName)) : - results.getValues(index)) { - if (value.hasValue()) { - try (VectorStringSwig vector = value.getValue()) { - result.setValue(Collections.unmodifiableList( - Swig.asList(vector))); + synchronized (resultsLock) { + ResultsHashSwig results = getSingleResults(propertyName); + if (results != null) { + Integer index = indexOf(propertyName); + try (VectorStringValuesSwig value = index == null ? + results.getValues(Swig.asBytes(propertyName)) : + results.getValues(index)) { + if (value.hasValue()) { + try (VectorStringSwig vector = value.getValue()) { + result.setValue(Collections.unmodifiableList( + Swig.asList(vector))); + } + } + else { + result.setNoValueMessage(value.getNoValueMessage()); } - } - else { - result.setNoValueMessage(value.getNoValueMessage()); } } } @@ -295,17 +307,19 @@ public AspectPropertyValue> getValues(String propertyName) { @Override protected AspectPropertyValue getValueAsString(String propertyName) { AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsHashSwig results = getSingleResults(propertyName); - if (results != null) { - Integer index = indexOf(propertyName); - try (StringValueSwig value = index == null ? - results.getValueAsString(Swig.asBytes(propertyName)) : - results.getValueAsString(index)) { - if (value.hasValue()) { - result.setValue(value.getValue()); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); + synchronized (resultsLock) { + ResultsHashSwig results = getSingleResults(propertyName); + if (results != null) { + Integer index = indexOf(propertyName); + try (StringValueSwig value = index == null ? + results.getValueAsString(Swig.asBytes(propertyName)) : + results.getValueAsString(index)) { + if (value.hasValue()) { + result.setValue(value.getValue()); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } } } } @@ -317,17 +331,19 @@ protected AspectPropertyValue getValueAsJavaScript( String propertyName) { AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsHashSwig results = getSingleResults(propertyName); - if (results != null) { - Integer index = indexOf(propertyName); - try (StringValueSwig value = index == null ? - results.getValueAsString(Swig.asBytes(propertyName)) : - results.getValueAsString(index)) { - if (value.hasValue()) { - result.setValue(new JavaScript(value.getValue())); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); + synchronized (resultsLock) { + ResultsHashSwig results = getSingleResults(propertyName); + if (results != null) { + Integer index = indexOf(propertyName); + try (StringValueSwig value = index == null ? + results.getValueAsString(Swig.asBytes(propertyName)) : + results.getValueAsString(index)) { + if (value.hasValue()) { + result.setValue(new JavaScript(value.getValue())); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } } } } @@ -338,17 +354,19 @@ protected AspectPropertyValue getValueAsJavaScript( protected AspectPropertyValue getValueAsInteger( String propertyName) { AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsHashSwig results = getSingleResults(propertyName); - if (results != null) { - Integer index = indexOf(propertyName); - try (IntegerValueSwig value = index == null ? - results.getValueAsInteger(Swig.asBytes(propertyName)) : - results.getValueAsInteger(index)) { - if (value.hasValue()) { - result.setValue(value.getValue()); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); + synchronized (resultsLock) { + ResultsHashSwig results = getSingleResults(propertyName); + if (results != null) { + Integer index = indexOf(propertyName); + try (IntegerValueSwig value = index == null ? + results.getValueAsInteger(Swig.asBytes(propertyName)) : + results.getValueAsInteger(index)) { + if (value.hasValue()) { + result.setValue(value.getValue()); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } } } } @@ -358,17 +376,19 @@ protected AspectPropertyValue getValueAsInteger( @Override protected AspectPropertyValue getValueAsBool(String propertyName) { AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsHashSwig results = getSingleResults(propertyName); - if (results != null) { - Integer index = indexOf(propertyName); - try (BoolValueSwig value = index == null ? - results.getValueAsBool(Swig.asBytes(propertyName)) : - results.getValueAsBool(index)) { - if (value.hasValue()) { - result.setValue(value.getValue()); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); + synchronized (resultsLock) { + ResultsHashSwig results = getSingleResults(propertyName); + if (results != null) { + Integer index = indexOf(propertyName); + try (BoolValueSwig value = index == null ? + results.getValueAsBool(Swig.asBytes(propertyName)) : + results.getValueAsBool(index)) { + if (value.hasValue()) { + result.setValue(value.getValue()); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } } } } @@ -378,17 +398,19 @@ protected AspectPropertyValue getValueAsBool(String propertyName) { @Override protected AspectPropertyValue getValueAsDouble(String propertyName) { AspectPropertyValue result = new AspectPropertyValueDefault<>(); - ResultsHashSwig results = getSingleResults(propertyName); - if (results != null) { - Integer index = indexOf(propertyName); - try (DoubleValueSwig value = index == null ? - results.getValueAsDouble(Swig.asBytes(propertyName)) : - results.getValueAsDouble(index)) { - if (value.hasValue()) { - result.setValue(value.getValue()); - } - else { - result.setNoValueMessage(value.getNoValueMessage()); + synchronized (resultsLock) { + ResultsHashSwig results = getSingleResults(propertyName); + if (results != null) { + Integer index = indexOf(propertyName); + try (DoubleValueSwig value = index == null ? + results.getValueAsDouble(Swig.asBytes(propertyName)) : + results.getValueAsDouble(index)) { + if (value.hasValue()) { + result.setValue(value.getValue()); + } + else { + result.setNoValueMessage(value.getNoValueMessage()); + } } } } @@ -407,29 +429,33 @@ protected TryGetResult tryGetValue( if (result.hasValue() == false) { boolean objSet = false; Object obj = null; - if (key.equalsIgnoreCase("DeviceId")) { - obj = getDeviceIdInternal(); - objSet = true; - } else if (key.equalsIgnoreCase("Difference")) { - obj = getDifferenceInternal(); - objSet = true; - } else if (key.equalsIgnoreCase("UserAgents")) { - obj = getUserAgentsInternal(); - objSet = true; - } else if (key.equalsIgnoreCase("Drift")) { - obj = getDriftInternal(); - objSet = true; - } else if (key.equalsIgnoreCase("Iterations")) { - obj = getIterationsInternal(); - objSet = true; - } - else if (key.equalsIgnoreCase("MatchedNodes")) { - obj = getMatchedNodesInternal(); - objSet = true; - } - else if (key.equalsIgnoreCase("Method")){ - obj = getMethodInternal(); - objSet = true; + // A match metric describes every component, so reading one can + // walk every graph not yet walked, which writes into the results. + synchronized (resultsLock) { + if (key.equalsIgnoreCase("DeviceId")) { + obj = getDeviceIdInternal(); + objSet = true; + } else if (key.equalsIgnoreCase("Difference")) { + obj = getDifferenceInternal(); + objSet = true; + } else if (key.equalsIgnoreCase("UserAgents")) { + obj = getUserAgentsInternal(); + objSet = true; + } else if (key.equalsIgnoreCase("Drift")) { + obj = getDriftInternal(); + objSet = true; + } else if (key.equalsIgnoreCase("Iterations")) { + obj = getIterationsInternal(); + objSet = true; + } + else if (key.equalsIgnoreCase("MatchedNodes")) { + obj = getMatchedNodesInternal(); + objSet = true; + } + else if (key.equalsIgnoreCase("Method")){ + obj = getMethodInternal(); + objSet = true; + } } if (objSet == true) { try { @@ -462,15 +488,17 @@ private void checkState() { @Override public void close() { - closed = true; - for (ResultsHashSwig result : resultsList) { - try { - result.close(); - } catch (Exception e) { - logger.error("Failed to close native results instance. " + - "A DeviceDataHash instance contains native unmanaged " + - "memory which needs to be closed. Failing to close " + - "could lead to memory leaks.", e); + synchronized (resultsLock) { + closed = true; + for (ResultsHashSwig result : resultsList) { + try { + result.close(); + } catch (Exception e) { + logger.error("Failed to close native results instance. " + + "A DeviceDataHash instance contains native unmanaged " + + "memory which needs to be closed. Failing to close " + + "could lead to memory leaks.", e); + } } } } From 3e252cad6d559b6ef7ca903f1592be6ecb531277 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:21:05 +0000 Subject: [PATCH 03/28] Test: the engine adds metadata for each match metric, as the table gives it device-detection-specification/pipeline-elements/device-detection-on-premise.md line 452 at 706de1f0: Metadata for these Properties MUST be added, as they will not be included in the metadata exposed by the native code. Checks the order, Category, Available With, Component, type and default of each metric, over a native engine that is a mock with no properties. The default of the list-valued UserAgents is left out, as how it is described is an open question. DD-20. --- .../EngineOverMockNativeCode.java | 87 ++++++++++ .../MatchMetricMetaDataTests.java | 148 ++++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MatchMetricMetaDataTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java new file mode 100644 index 000000000..58b18200c --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java @@ -0,0 +1,87 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.ComponentMetaDataCollectionSwig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.EngineHashSwig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.MetaDataSwig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.PropertyMetaDataCollectionSwig; +import org.slf4j.Logger; + +import java.lang.reflect.Field; +import java.util.ArrayList; + +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; + +/** + * Makes a {@link DeviceDetectionHashEngine} whose native engine is a mock + * with no properties and no components of its own, so the parts of the + * engine written in Java can be tested without the native library or a data + * file. The engine's own methods run as written. Its constructor does not + * run, as it loads a data file, so the fields it would set are set here. + */ +class EngineOverMockNativeCode { + + final DeviceDetectionHashEngine engine; + + final EngineHashSwig nativeEngine; + + EngineOverMockNativeCode() throws Exception { + nativeEngine = mock(EngineHashSwig.class); + MetaDataSwig metaData = mock(MetaDataSwig.class); + PropertyMetaDataCollectionSwig properties = + mock(PropertyMetaDataCollectionSwig.class); + when(properties.getSize()).thenReturn(0L); + ComponentMetaDataCollectionSwig components = + mock(ComponentMetaDataCollectionSwig.class); + when(components.getSize()).thenReturn(0L); + when(metaData.getProperties()).thenReturn(properties); + when(metaData.getComponents()).thenReturn(components); + when(nativeEngine.getMetaData()).thenReturn(metaData); + + engine = mock( + DeviceDetectionHashEngine.class, + withSettings().defaultAnswer(CALLS_REAL_METHODS)); + set("engine", nativeEngine); + set("properties", new ArrayList<>()); + set("logger", mock(Logger.class)); + } + + private void set(String name, Object value) throws Exception { + Class type = DeviceDetectionHashEngine.class; + while (type != null) { + try { + Field field = type.getDeclaredField(name); + field.setAccessible(true); + field.set(engine, value); + return; + } catch (NoSuchFieldException e) { + type = type.getSuperclass(); + } + } + throw new NoSuchFieldException(name); + } +} diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MatchMetricMetaDataTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MatchMetricMetaDataTests.java new file mode 100644 index 000000000..e0b417302 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MatchMetricMetaDataTests.java @@ -0,0 +1,148 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +/** + * Metadata for the match metric Properties MUST be added, as they will not be + * included in the metadata exposed by the native code + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 452 at 706de1f0). The table that follows gives each one's Category, + * Available With, Component, type and default value. The native engine here + * is a mock with no properties, so every property the engine lists is one it + * added itself. + */ +public class MatchMetricMetaDataTests { + + private static final List NAMES = Arrays.asList( + "MatchedNodes", "Difference", "Drift", "DeviceId", "UserAgents", + "Iterations", "Method"); + + private static List metrics() + throws Exception { + return new EngineOverMockNativeCode().engine.getProperties(); + } + + /** + * The engine lists the seven, in the order of the table. + */ + @Test + public void MatchMetrics_AllListedInTableOrder() throws Exception { + List metrics = metrics(); + assertEquals(NAMES.size(), metrics.size()); + for (int i = 0; i < NAMES.size(); i++) { + assertEquals(NAMES.get(i), metrics.get(i).getName()); + } + } + + /** + * Category = "Device Metrics" and Available With = "Lite", "Premium", + * "Enterprise", "TAC". + */ + @Test + public void MatchMetrics_CategoryAndAvailableWith() throws Exception { + for (FiftyOneAspectPropertyMetaData property : metrics()) { + assertEquals(property.getName(), + "Device Metrics", property.getCategory()); + assertEquals(property.getName(), + Arrays.asList("Lite", "Premium", "Enterprise", "TAC"), + property.getDataTiersWherePresent()); + } + } + + /** + * Component = "Metrics". + */ + @Test + public void MatchMetrics_ComponentIsMetrics() throws Exception { + for (FiftyOneAspectPropertyMetaData property : metrics()) { + assertNotNull( + property.getName() + " has no component", + property.getComponent()); + assertEquals(property.getName(), + "Metrics", property.getComponent().getName()); + } + } + + /** + * The types in the table: int, string, and list of strings for + * UserAgents only, so only UserAgents is a list. + */ + @Test + public void MatchMetrics_TypesAsTheTableGives() throws Exception { + for (FiftyOneAspectPropertyMetaData property : metrics()) { + switch (property.getName()) { + case "MatchedNodes": + case "Difference": + case "Drift": + case "Iterations": + assertEquals(property.getName(), + Integer.class, property.getType()); + assertFalse(property.getName(), property.getList()); + break; + case "DeviceId": + case "Method": + assertEquals(property.getName(), + String.class, property.getType()); + assertFalse(property.getName() + " is a string, " + + "not a list", property.getList()); + break; + case "UserAgents": + assertEquals(property.getName(), + List.class, property.getType()); + break; + default: + throw new AssertionError( + "Unexpected property " + property.getName()); + } + } + } + + /** + * The default values in the table, other than the list-valued UserAgents + * whose description in Property metadata is an open question. + */ + @Test + public void MatchMetrics_DefaultValues() throws Exception { + for (FiftyOneAspectPropertyMetaData property : metrics()) { + String expected; + switch (property.getName()) { + case "DeviceId": expected = "0-0-0-0"; break; + case "Method": expected = "NONE"; break; + case "UserAgents": continue; + default: expected = "0"; break; + } + assertEquals(property.getName(), + expected, property.getDefaultValue().getName()); + } + } +} From 56b1acff0e9a94412d18104ca5e539be9b2d4cfb Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:24:52 +0000 Subject: [PATCH 04/28] Fix: give each match metric the Metrics component, and Method a single value device-detection-specification/pipeline-elements/device-detection-on-premise.md line 452 at 706de1f0: Metadata for these Properties MUST be added, as they will not be included in the metadata exposed by the native code. The table gives Component = "Metrics" for every match metric, where each had no component, and gives Method the type string, where it was marked as a list. The engine now makes a Metrics component once, holding the seven metrics, and each metric names it. The default of UserAgents is unchanged while how a list-valued metric is described is an open question. DD-20. --- .../onpremise/flowelements/Constants.java | 5 +- .../DeviceDetectionHashEngine.java | 52 ++++++-- .../MetricsComponentMetaData.java | 115 ++++++++++++++++++ 3 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MetricsComponentMetaData.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/Constants.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/Constants.java index 8c4086162..39734c8cd 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/Constants.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/Constants.java @@ -26,7 +26,10 @@ public class Constants { public static class MatchMetrics { /* Category */ public static final String CATEGORY = "Device Metrics"; - + + /* Component */ + public static final String COMPONENT = "Metrics"; + /* Names */ public static final String MATCHED_NODES = "MatchedNodes"; public static final String DIFFERENCE = "Difference"; diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java index 0b5c93fb1..ac55e077e 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java @@ -83,6 +83,11 @@ public class DeviceDetectionHashEngine */ private volatile boolean propertyIndexesFixed; + /** + * The Metrics component, made the first time it is needed. + */ + private volatile MetricsComponentMetaData metricsComponent; + /** * Construct a new instance of the {@link DeviceDetectionHashEngine}. * @param logger logger instance to use for logging @@ -447,6 +452,32 @@ private void setEngineMetaData() { * @return meta data for metric properties */ private List getMetricProperties() { + return getMetricsComponent().getPropertyList(); + } + + /** + * Get the Metrics component, which holds the match metric properties. It + * does not depend on the data file, so it is made once. Two threads that + * both find it missing each make one the same as the other. + * @return the Metrics component + */ + private MetricsComponentMetaData getMetricsComponent() { + MetricsComponentMetaData component = metricsComponent; + if (component == null) { + component = newMetricsComponent(); + metricsComponent = component; + } + return component; + } + + /** + * Make the Metrics component and the match metric properties in it, which + * the native code does not include in its metadata, as the table of match + * metric properties gives them. + * @return new Metrics component + */ + private MetricsComponentMetaData newMetricsComponent() { + MetricsComponentMetaData component = new MetricsComponentMetaData(); List dataFileList = Arrays.asList( "Lite", "Premium", "Enterprise", "TAC"); FiftyOneAspectPropertyMetaData[] metricProperties = @@ -467,7 +498,7 @@ private List getMetricProperties() { false, false, Constants.MatchMetrics.MATCHED_NODES_DESCRIPTION, - null, + component, Arrays.asList(), new ValueMetaDataDefault("0")), new FiftyOneAspectPropertyMetaDataDefault( @@ -485,7 +516,7 @@ private List getMetricProperties() { false, false, Constants.MatchMetrics.DIFFERENCE_DESCRIPTION, - null, + component, Arrays.asList(), new ValueMetaDataDefault("0")), new FiftyOneAspectPropertyMetaDataDefault( @@ -503,7 +534,7 @@ private List getMetricProperties() { false, false, Constants.MatchMetrics.DRIFT_DESCRIPTION, - null, + component, Arrays.asList(), new ValueMetaDataDefault("0")), new FiftyOneAspectPropertyMetaDataDefault( @@ -521,7 +552,7 @@ private List getMetricProperties() { false, false, Constants.MatchMetrics.DEVICE_ID_DESCRIPTION, - null, + component, Arrays.asList(), new ValueMetaDataDefault("0-0-0-0")), new FiftyOneAspectPropertyMetaDataDefault( @@ -539,7 +570,7 @@ private List getMetricProperties() { false, false, Constants.MatchMetrics.USER_AGENTS_DESCRIPTION, - null, + component, Arrays.asList(), new ValueMetaDataDefault("n/a")), new FiftyOneAspectPropertyMetaDataDefault( @@ -557,7 +588,7 @@ private List getMetricProperties() { false, false, Constants.MatchMetrics.ITERATIONS_DESCRIPTION, - null, + component, Arrays.asList(), new ValueMetaDataDefault("0")), new FiftyOneAspectPropertyMetaDataDefault( @@ -570,12 +601,12 @@ private List getMetricProperties() { null, (byte) 0, true, - true, + false, false, false, false, Constants.MatchMetrics.METHOD_DESCRIPTION, - null, + component, Arrays.asList( new ValueMetaDataDefault("NONE"), new ValueMetaDataDefault("PERFORMANCE"), @@ -583,7 +614,10 @@ private List getMetricProperties() { new ValueMetaDataDefault( "PREDICTIVE")), new ValueMetaDataDefault("NONE")) }; - return Arrays.asList(metricProperties); + for (FiftyOneAspectPropertyMetaData property : metricProperties) { + component.addProperty(property); + } + return component; } @Override diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MetricsComponentMetaData.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MetricsComponentMetaData.java new file mode 100644 index 000000000..f4572c409 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MetricsComponentMetaData.java @@ -0,0 +1,115 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.pipeline.engines.fiftyone.data.CloseableIterable; +import fiftyone.pipeline.engines.fiftyone.data.CloseableIterableDefault; +import fiftyone.pipeline.engines.fiftyone.data.ComponentMetaData; +import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData; +import fiftyone.pipeline.engines.fiftyone.data.ProfileMetaData; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * The Metrics component, which holds the match metric properties. The data + * file has no such component, so the engine adds it to the components the + * native code gives, and each match metric property names it as its + * component. + * @see Specification + */ +class MetricsComponentMetaData implements ComponentMetaData { + + /** + * Id of the Metrics component. The data file's components are numbered + * from 1, so this is the largest id a component can have, which no data + * file component uses. + */ + static final byte COMPONENT_ID = (byte) 255; + + private final List properties = + new ArrayList<>(); + + /** + * Add a match metric property to the component. Called only while the + * engine makes its match metric properties. + * @param property to add + */ + void addProperty(FiftyOneAspectPropertyMetaData property) { + properties.add(property); + } + + /** + * The match metric properties, in the order they were added. Holds no + * native memory, so there is nothing to close. + * @return unmodifiable list of the properties + */ + List getPropertyList() { + return Collections.unmodifiableList(properties); + } + + @Override + public byte getComponentId() { + return COMPONENT_ID; + } + + @Override + public String getName() { + return Constants.MatchMetrics.COMPONENT; + } + + /** + * The match metrics have no profiles. + * @return null + */ + @Override + public ProfileMetaData getDefaultProfile() { + return null; + } + + @Override + public CloseableIterable getProperties() { + return new CloseableIterableDefault<>( + Collections.unmodifiableList(properties)); + } + + @Override + public FiftyOneAspectPropertyMetaData getProperty(String propertyName) { + for (FiftyOneAspectPropertyMetaData property : properties) { + if (property.getName().equalsIgnoreCase(propertyName)) { + return property; + } + } + return null; + } + + @Override + public void close() { + } + + @Override + public String toString() { + return getName(); + } +} From aa549c4669370eeae2cc413548313bc0ba7751ac Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:25:15 +0000 Subject: [PATCH 05/28] Test: the engine's components include Metrics device-detection-specification/pipeline-elements/device-detection-on-premise.md line 464 at 706de1f0: Component = "Metrics" - This component MUST also be added to the list of components returned by the Engine. Over a native engine that is a mock with no components. DD-21. --- .../flowelements/MetricsComponentTests.java | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MetricsComponentTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MetricsComponentTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MetricsComponentTests.java new file mode 100644 index 000000000..233768981 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/MetricsComponentTests.java @@ -0,0 +1,104 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.pipeline.engines.fiftyone.data.CloseableIterable; +import fiftyone.pipeline.engines.fiftyone.data.ComponentMetaData; +import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Component = "Metrics" - This component MUST also be added to the list of + * components returned by the Engine + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 464 at 706de1f0). The native engine here is a mock with no components, + * so every component the engine lists is one it added itself. + */ +public class MetricsComponentTests { + + private static List components( + DeviceDetectionHashEngine engine) throws Exception { + List result = new ArrayList<>(); + try (CloseableIterable components = + engine.getComponents()) { + for (ComponentMetaData component : components) { + result.add(component); + } + } + return result; + } + + /** + * The engine's components include Metrics. + */ + @Test + public void Components_IncludeMetrics() throws Exception { + List components = + components(new EngineOverMockNativeCode().engine); + assertEquals(1, components.size()); + assertEquals("Metrics", components.get(0).getName()); + } + + /** + * The engine finds Metrics by its name. + */ + @Test + public void Components_GetByName() throws Exception { + ComponentMetaData metrics = + new EngineOverMockNativeCode().engine.getComponent("Metrics"); + assertNotNull("No component named Metrics", metrics); + assertEquals("Metrics", metrics.getName()); + } + + /** + * The Metrics component holds the match metric properties, each of which + * names Metrics as its component. + */ + @Test + public void Components_MetricsHoldsTheMatchMetrics() throws Exception { + DeviceDetectionHashEngine engine = + new EngineOverMockNativeCode().engine; + ComponentMetaData metrics = components(engine).get(0); + List names = new ArrayList<>(); + try (CloseableIterable properties = + metrics.getProperties()) { + for (FiftyOneAspectPropertyMetaData property : properties) { + names.add(property.getName()); + assertEquals(property.getName(), + "Metrics", property.getComponent().getName()); + } + } + assertEquals( + Arrays.asList("MatchedNodes", "Difference", "Drift", "DeviceId", + "UserAgents", "Iterations", "Method"), + names); + assertNotNull(metrics.getProperty("DeviceId")); + } +} From 4f5ab52d6feb9eaad1b416f6c3e5695b0161e6e7 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:27:26 +0000 Subject: [PATCH 06/28] Fix: add the Metrics component to the engine's components device-detection-specification/pipeline-elements/device-detection-on-premise.md line 464 at 706de1f0: Component = "Metrics" - This component MUST also be added to the list of components returned by the Engine. getComponents gave only the data file's components. It now gives the Metrics component after them, so getComponent("Metrics") finds it too. The metadata hash test no longer leaves out the metrics' component, which they now have, and skips the default profile of Metrics, which has no profiles. DD-21. --- .../DeviceDetectionHashEngine.java | 5 ++- .../onpremise/interop/ComponentIterable.java | 35 +++++++++++++++++-- .../onpremise/data/MetaDataHasherHash.java | 11 +++--- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java index ac55e077e..f328c1b6d 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java @@ -266,9 +266,12 @@ public ProfileMetaData getProfile(int profileId) { @Override public CloseableIterable getComponents() { + // The Metrics component holds the match metrics, which the data file + // does not have, so it is given after the data file's components. return new ComponentIterable( this, - engine.getMetaData().getComponents()); + engine.getMetaData().getComponents(), + getMetricsComponent()); } @Override diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/interop/ComponentIterable.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/interop/ComponentIterable.java index bee78cd10..77d748d2a 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/interop/ComponentIterable.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/interop/ComponentIterable.java @@ -39,6 +39,10 @@ public class ComponentIterable private final DeviceDetectionHashEngine engine; + private final long nativeSize; + + private final ComponentMetaData[] added; + /** * Create a new instance. * @param engine the engine which the meta data relates to @@ -47,14 +51,41 @@ public class ComponentIterable public ComponentIterable( DeviceDetectionHashEngine engine, ComponentMetaDataCollectionSwig collection) { - super(collection.getSize()); + this(engine, collection, collection.getSize()); + } + + /** + * Create a new instance which gives the native components and then the + * components given, such as the Metrics component, which the data file + * does not have. + * @param engine the engine which the meta data relates to + * @param collection the native collection of components + * @param added components to give after the native ones + */ + public ComponentIterable( + DeviceDetectionHashEngine engine, + ComponentMetaDataCollectionSwig collection, + ComponentMetaData... added) { + this(engine, collection, collection.getSize(), added); + } + + private ComponentIterable( + DeviceDetectionHashEngine engine, + ComponentMetaDataCollectionSwig collection, + long nativeSize, + ComponentMetaData... added) { + super(nativeSize + added.length); this.engine = engine; this.collection = collection; + this.nativeSize = nativeSize; + this.added = added; } @Override protected ComponentMetaData get(long index) { - return new ComponentMetaDataHash(engine, collection.getByIndex(index)); + return index < nativeSize ? + new ComponentMetaDataHash(engine, collection.getByIndex(index)) : + added[(int) (index - nativeSize)]; } @Override diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/data/MetaDataHasherHash.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/data/MetaDataHasherHash.java index aa5a619ba..07c97024d 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/data/MetaDataHasherHash.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/data/MetaDataHasherHash.java @@ -22,7 +22,6 @@ package fiftyone.devicedetection.hash.engine.onpremise.data; -import fiftyone.devicedetection.hash.engine.onpremise.flowelements.Constants; import fiftyone.devicedetection.shared.testhelpers.Wrapper; import fiftyone.devicedetection.shared.testhelpers.data.MetaDataHasher; import fiftyone.pipeline.engines.fiftyone.data.CloseableIterable; @@ -51,10 +50,7 @@ public int hashProperties(int hash, Wrapper wrapper) throws Exception { j++; } } - // Match metric property does not have component so don't include - if (!property.getCategory().equals(Constants.MatchMetrics.CATEGORY)) { - hash ^= property.getComponent().hashCode(); - } + hash ^= property.getComponent().hashCode(); if (property.getDefaultValue() != null) { hash ^= property.getDefaultValue().hashCode(); } @@ -93,7 +89,10 @@ public int hashComponents(int hash, Wrapper wrapper) throws Exception { i++; } } - hash ^= component.getDefaultProfile().hashCode(); + // The Metrics component has no profiles, so no default. + if (component.getDefaultProfile() != null) { + hash ^= component.getDefaultProfile().hashCode(); + } } } return hash; From 17a34699a5e396d8a43f40c4c78bdb8e82a54185 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:28:37 +0000 Subject: [PATCH 07/28] Test: the engine gives the ids of the profiles that hold a value of a property device-detection-specification/pipeline-elements/device-detection-on-premise.md line 479 at 706de1f0: The Engine MUST be able to give the ids of the profiles that hold a given value of a given Property, such as a TAC or a native model name, through the native code's EngineHash::getProfileIdsForPropertyValue(). One test over a mock native engine. One over the free data file, skipped where the file is not there, checks the ids are ascending and distinct, a value in another case matches nothing, and indexing the property with the Indexed Properties option gives the same ids. DD-22. --- .../ProfilesForPropertyValueTests.java | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ProfilesForPropertyValueTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ProfilesForPropertyValueTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ProfilesForPropertyValueTests.java new file mode 100644 index 000000000..c9b32ad28 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ProfilesForPropertyValueTests.java @@ -0,0 +1,141 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.VectorUInt32Swig; +import fiftyone.pipeline.engines.Constants; +import org.junit.Test; +import org.slf4j.ILoggerFactory; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + +import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH; +import static fiftyone.pipeline.util.FileFinder.getFilePath; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * The Engine MUST be able to give the ids of the profiles that hold a given + * value of a given Property, such as a TAC or a native model name, through + * the native code's EngineHash::getProfileIdsForPropertyValue() + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 479 at 706de1f0). The bullets after it say the name and the value are + * matched exactly, the ids are ascending and each appears once, and the + * Indexed Properties option gives the same ids without reading every + * profile. + */ +public class ProfilesForPropertyValueTests { + + private static final ILoggerFactory loggerFactory = + LoggerFactory.getILoggerFactory(); + + /** + * The engine gives the ids the native function gives, in its order, and + * passes the name and the value to it as they were given. + */ + @Test + public void ProfilesForValue_FromTheNativeFunction() throws Exception { + EngineOverMockNativeCode mocks = new EngineOverMockNativeCode(); + VectorUInt32Swig ids = mock(VectorUInt32Swig.class); + when(ids.size()).thenReturn(3); + when(ids.get(0)).thenReturn(12280L); + when(ids.get(1)).thenReturn(17470L); + when(ids.get(2)).thenReturn(4294967295L); + when(mocks.nativeEngine.getProfileIdsForPropertyValue( + "NativeModel", "iPhone14,2")).thenReturn(ids); + + List result = mocks.engine.getProfileIdsForPropertyValue( + "NativeModel", "iPhone14,2"); + + assertEquals(Arrays.asList(12280L, 17470L, 4294967295L), result); + verify(mocks.nativeEngine).getProfileIdsForPropertyValue( + "NativeModel", "iPhone14,2"); + // The native vector is released once its ids are copied. + verify(ids).close(); + } + + private static File liteFile() { + try { + return getFilePath(LITE_HASH_DATA_FILE_PATH); + } + catch (IllegalArgumentException e) { + assumeTrue(e.getMessage(), false); + return null; + } + } + + private static DeviceDetectionHashEngine build( + File file, List indexed) throws Exception { + DeviceDetectionHashEngineBuilder builder = + new DeviceDetectionHashEngineBuilder(loggerFactory, null) + .setPerformanceProfile( + Constants.PerformanceProfiles.HighPerformance) + .setAutoUpdate(false) + .setDataFileSystemWatcher(false); + if (indexed != null) { + builder.setIndexedProperties(indexed); + } + return builder.build(file.toString(), false); + } + + /** + * Against the free data file: ids are ascending and distinct, a value in + * another case gives none, and indexing the Property gives the same ids. + */ + @Test + public void ProfilesForValue_LiteDataFile() throws Exception { + File file = liteFile(); + List unindexed; + List otherCase; + try (DeviceDetectionHashEngine engine = build(file, null)) { + unindexed = engine.getProfileIdsForPropertyValue( + "PlatformName", "iOS"); + otherCase = engine.getProfileIdsForPropertyValue( + "PlatformName", "IOS"); + } + assertFalse("No profiles hold PlatformName iOS", unindexed.isEmpty()); + List sorted = new ArrayList<>(unindexed); + Collections.sort(sorted); + assertEquals("Ids are not ascending", sorted, unindexed); + assertEquals("An id appears more than once", + unindexed.size(), new HashSet<>(unindexed).size()); + assertTrue("A value in another case matched", otherCase.isEmpty()); + + try (DeviceDetectionHashEngine engine = + build(file, Collections.singletonList("PlatformName"))) { + assertEquals(unindexed, engine.getProfileIdsForPropertyValue( + "PlatformName", "iOS")); + } + } +} From a657a4ffbbc1fe9de1137f1e7c6638a9a5f79a25 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:30:04 +0000 Subject: [PATCH 08/28] Fix: give the profiles for a property value, and an Indexed Properties option device-detection-specification/pipeline-elements/device-detection-on-premise.md line 479 at 706de1f0: The Engine MUST be able to give the ids of the profiles that hold a given value of a given Property, such as a TAC or a native model name, through the native code's EngineHash::getProfileIdsForPropertyValue(). The native function was in the SWIG wrapper, but the engine kept its native engine private and nothing called it. DeviceDetectionHashEngine now has getProfileIdsForPropertyValue, which copies the native ids and releases the native vector. The builder has setIndexedProperties, the Indexed Properties option of the configuration table, so a lookup of an indexed property does not read every profile. DD-22. --- .../DeviceDetectionHashEngine.java | 28 +++++++++++++ .../DeviceDetectionHashEngineBuilder.java | 42 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java index f328c1b6d..0c5bbd1a3 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngine.java @@ -264,6 +264,34 @@ public ProfileMetaData getProfile(int profileId) { null : new ProfileMetaDataHash(this, profile); } + /** + * Get the ids of the profiles that hold a value of a property, such as a + * TAC or a native model name, from the native engine. The property name + * and the value are both matched exactly, as the data file holds them, + * so a value in another case does not match. The ids are in ascending + * order and each appears once. A property named with + * {@link DeviceDetectionHashEngineBuilder#setIndexedProperties(List)} is + * found through the native index, and any other by reading every + * profile, which gives the same ids more slowly. + * @see Specification + * @param propertyName name of the property, such as TAC or NativeModel + * @param valueName the value of the property + * @return ids of the profiles holding the value, empty when none do + */ + public List getProfileIdsForPropertyValue( + String propertyName, + String valueName) { + List result = new ArrayList<>(); + try (VectorUInt32Swig ids = + engine.getProfileIdsForPropertyValue(propertyName, valueName)) { + int size = ids.size(); + for (int i = 0; i < size; i++) { + result.add(ids.get(i)); + } + } + return result; + } + @Override public CloseableIterable getComponents() { // The Metrics component holds the match metrics, which the data file diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngineBuilder.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngineBuilder.java index 1de52bba8..ae78f9d0a 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngineBuilder.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDetectionHashEngineBuilder.java @@ -285,6 +285,48 @@ public DeviceDetectionHashEngineBuilder setUsePredictiveGraph(boolean use) { return this; } + /** + * Set the properties, such as TAC and NativeModel, whose values are + * indexed to the profiles holding them when the data file loads, so that + * {@link DeviceDetectionHashEngine#getProfileIdsForPropertyValue(String, String)} + * finds the profiles for a value of one of them without reading every + * profile. Names are matched exactly. A refresh indexes the same + * properties. + *

+ * Default is none. + * @see Specification + * @param names of the properties to index + * @return this builder + */ + @DefaultValue("None") + public DeviceDetectionHashEngineBuilder setIndexedProperties( + List names) { + try (VectorStringSwig namesSwig = new VectorStringSwig()) { + namesSwig.addAll(names); + config.setIndexedProperties(namesSwig); + } + return this; + } + + /** + * Set the properties whose values are indexed to the profiles holding + * them, as {@link #setIndexedProperties(List)} does, from a comma + * separated list of names, as a configuration file gives them. + * @param names comma separated names of the properties to index + * @return this builder + */ + @DefaultValue("None") + public DeviceDetectionHashEngineBuilder setIndexedProperties( + String names) { + List list = new ArrayList<>(); + for (String name : names.split(",")) { + if (name.trim().isEmpty() == false) { + list.add(name.trim()); + } + } + return setIndexedProperties(list); + } + @Override public DeviceDetectionHashEngineBuilder setCache( CacheConfiguration cacheConfiguration) { From ccce971370ca27c0ae024696162e9381c19b9e94 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:31:02 +0000 Subject: [PATCH 09/28] Test: every Device Detection engine populates Aspect Data device-detection-specification/data-model.md line 10 at 706de1f0: All Engines MUST populate data objects that implement Aspect Data as defined in the Pipeline specification. Checks the data type each engine is declared with, and the classes made to hold each engine's data. DD-2. --- .../data/EnginesPopulateAspectDataTests.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 device-detection/device-detection/src/test/java/fiftyone/devicedetection/data/EnginesPopulateAspectDataTests.java diff --git a/device-detection/device-detection/src/test/java/fiftyone/devicedetection/data/EnginesPopulateAspectDataTests.java b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/data/EnginesPopulateAspectDataTests.java new file mode 100644 index 000000000..03705d692 --- /dev/null +++ b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/data/EnginesPopulateAspectDataTests.java @@ -0,0 +1,103 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.data; + +import fiftyone.devicedetection.cloud.data.MultiDeviceDataCloud; +import fiftyone.devicedetection.cloud.flowelements.DeviceDataCloudInternal; +import fiftyone.devicedetection.cloud.flowelements.DeviceDetectionCloudEngine; +import fiftyone.devicedetection.cloud.flowelements.HardwareProfileCloudEngine; +import fiftyone.devicedetection.hash.engine.onpremise.flowelements.DeviceDataHashDefault; +import fiftyone.devicedetection.hash.engine.onpremise.flowelements.DeviceDetectionHashEngine; +import fiftyone.pipeline.engines.data.AspectData; +import fiftyone.pipeline.engines.data.AspectDataBase; +import fiftyone.pipeline.engines.flowelements.AspectEngine; +import org.junit.Test; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertTrue; + +/** + * All Engines MUST populate data objects that implement Aspect Data as + * defined in the Pipeline specification + * (device-detection-specification/data-model.md line 10 at 706de1f0). + * Each Device Detection engine is checked through the data type it is + * declared with, and each class that is made to hold an engine's data. + */ +public class EnginesPopulateAspectDataTests { + + private static final List> ENGINES = Arrays.asList( + DeviceDetectionHashEngine.class, + DeviceDetectionCloudEngine.class, + HardwareProfileCloudEngine.class); + + /** + * Find the data type an engine is declared with, which is the first type + * argument of the base class it extends. + */ + private static Class dataTypeOf(Class engine) { + Type type = engine.getGenericSuperclass(); + assertTrue(engine.getSimpleName() + " has no data type argument", + type instanceof ParameterizedType); + Type data = ((ParameterizedType) type).getActualTypeArguments()[0]; + assertTrue(engine.getSimpleName() + "'s data type is not a class", + data instanceof Class); + return (Class) data; + } + + @Test + public void Engines_AreAspectEngines() { + for (Class engine : ENGINES) { + assertTrue(engine.getSimpleName() + " is not an Aspect Engine", + AspectEngine.class.isAssignableFrom(engine)); + } + } + + @Test + public void Engines_DeclaredDataIsAspectData() { + for (Class engine : ENGINES) { + Class data = dataTypeOf(engine); + assertTrue(engine.getSimpleName() + " populates " + + data.getSimpleName() + ", which is not Aspect Data", + AspectData.class.isAssignableFrom(data)); + } + } + + /** + * The classes the engines' factories make, which hold the values, take + * the Pipeline's Aspect Data behaviour from its base class. + */ + @Test + public void Engines_DataMadeIsAspectData() { + for (Class made : Arrays.>asList( + DeviceDataHashDefault.class, + DeviceDataCloudInternal.class, + MultiDeviceDataCloud.class)) { + assertTrue(made.getSimpleName() + " is not Aspect Data", + AspectDataBase.class.isAssignableFrom(made)); + } + } +} From fe870d7f4ca5a2f691eda6d15f6dd7150ced412a Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:32:00 +0000 Subject: [PATCH 10/28] Test: on-premise and cloud engines return interface compatible data device-detection-specification/data-model.md line 15 at 706de1f0: Each of these Engines MUST return data that is interface compatible with the others. Checks the on-premise and cloud data are both DeviceData with the same accessors and types, and the cloud hardware lookup gives DeviceData. DD-3. --- .../data/EnginesInterfaceCompatibleTests.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 device-detection/device-detection/src/test/java/fiftyone/devicedetection/data/EnginesInterfaceCompatibleTests.java diff --git a/device-detection/device-detection/src/test/java/fiftyone/devicedetection/data/EnginesInterfaceCompatibleTests.java b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/data/EnginesInterfaceCompatibleTests.java new file mode 100644 index 000000000..1564f894a --- /dev/null +++ b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/data/EnginesInterfaceCompatibleTests.java @@ -0,0 +1,93 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.data; + +import fiftyone.devicedetection.cloud.data.DeviceDataCloud; +import fiftyone.devicedetection.cloud.data.MultiDeviceDataCloud; +import fiftyone.devicedetection.hash.engine.onpremise.data.DeviceDataHash; +import fiftyone.devicedetection.shared.DeviceData; +import fiftyone.pipeline.engines.data.AspectPropertyValue; +import org.junit.Test; + +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Each of these Engines MUST return data that is interface compatible with + * the others (device-detection-specification/data-model.md line 15 at + * 706de1f0). The on-premise and cloud data share the DeviceData interface, + * so code written against it reads either, and the cloud hardware profile + * lookup gives its profiles as DeviceData too. + */ +public class EnginesInterfaceCompatibleTests { + + @Test + public void Data_OnPremiseAndCloudAreDeviceData() { + assertTrue("On-premise data is not DeviceData", + DeviceData.class.isAssignableFrom(DeviceDataHash.class)); + assertTrue("Cloud data is not DeviceData", + DeviceData.class.isAssignableFrom(DeviceDataCloud.class)); + } + + /** + * Every property accessor of DeviceData is reached the same way, with the + * same type, through the on-premise and the cloud data. + */ + @Test + public void Data_SameAccessorsAndTypes() throws Exception { + int accessors = 0; + for (Method method : DeviceData.class.getMethods()) { + if (method.getDeclaringClass().equals(DeviceData.class) && + AspectPropertyValue.class.equals(method.getReturnType())) { + for (Class data : new Class[] { + DeviceDataHash.class, DeviceDataCloud.class}) { + Method other = data.getMethod( + method.getName(), method.getParameterTypes()); + assertEquals(data.getSimpleName() + "." + method.getName(), + method.getGenericReturnType(), + other.getGenericReturnType()); + } + accessors++; + } + } + assertTrue("DeviceData has no property accessors", accessors > 0); + } + + /** + * The hardware profile lookup gives a list of DeviceData. + */ + @Test + public void Data_HardwareProfilesAreDeviceData() throws Exception { + Type type = MultiDeviceDataCloud.class.getMethod("getProfiles") + .getGenericReturnType(); + assertTrue(type instanceof ParameterizedType); + ParameterizedType list = (ParameterizedType) type; + assertEquals(List.class, list.getRawType()); + assertEquals(DeviceData.class, list.getActualTypeArguments()[0]); + } +} From 5288ee632e452792b44bc98e28d29a538f5511f5 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:33:32 +0000 Subject: [PATCH 11/28] Test: the engine reads the evidence keys again when the data is refreshed device-detection-specification/pipeline-elements/device-detection-on-premise.md line 86 at 706de1f0: This MUST be done at start-up and any time the data is refreshed. Over a native engine that is a mock whose keys change between refreshes, so a key only the new data has is accepted after the refresh. Also checks the keys are stored, not read from the native code for each use. DD-11. --- .../EngineOverMockNativeCode.java | 26 ++++++ .../EvidenceKeysOnRefreshTests.java | 80 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EvidenceKeysOnRefreshTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java index 58b18200c..032d5f2f3 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java @@ -26,12 +26,16 @@ import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.EngineHashSwig; import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.MetaDataSwig; import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.PropertyMetaDataCollectionSwig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.VectorStringSwig; import org.slf4j.Logger; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collections; import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.withSettings; @@ -68,6 +72,28 @@ class EngineOverMockNativeCode { set("engine", nativeEngine); set("properties", new ArrayList<>()); set("logger", mock(Logger.class)); + // No data file, so a refresh from memory updates no file metadata. + set("dataFiles", new ArrayList<>()); + // The property indexes are fixed, as they are after the first load. + set("propertyIndexes", Collections.emptyMap()); + set("propertyIndexesFixed", true); + setKeys(); + } + + /** + * Set the evidence keys the native engine gives from now on. + * @param keys the keys + */ + void setKeys(String... keys) { + VectorStringSwig vector = mock( + VectorStringSwig.class, + withSettings().defaultAnswer(CALLS_REAL_METHODS)); + doReturn(keys.length).when(vector).size(); + for (int i = 0; i < keys.length; i++) { + doReturn(keys[i]).when(vector).get(i); + } + doNothing().when(vector).delete(); + when(nativeEngine.getKeys()).thenReturn(vector); } private void set(String name, Object value) throws Exception { diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EvidenceKeysOnRefreshTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EvidenceKeysOnRefreshTests.java new file mode 100644 index 000000000..94559c186 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EvidenceKeysOnRefreshTests.java @@ -0,0 +1,80 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.pipeline.core.data.EvidenceKeyFilter; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.clearInvocations; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * After loading the data source, call getKeys and store the accepted + * evidence keys. This MUST be done at start-up and any time the data is + * refreshed + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 86 at 706de1f0). The native engine here is a mock whose keys change + * between refreshes, as they do when a refresh loads a data file with other + * keys. Start-up with a real data file is covered by EvidenceKeysTests. + */ +public class EvidenceKeysOnRefreshTests { + + @Test + public void EvidenceKeys_ReadAgainOnRefresh() throws Exception { + EngineOverMockNativeCode mocks = new EngineOverMockNativeCode(); + DeviceDetectionHashEngine engine = mocks.engine; + + mocks.setKeys("header.user-agent"); + engine.refreshData(null, new byte[0]); + EvidenceKeyFilter first = engine.getEvidenceKeyFilter(); + assertTrue(first.include("header.user-agent")); + // Not case sensitive. + assertTrue(first.include("header.User-Agent")); + assertFalse(first.include("header.sec-ch-ua")); + + mocks.setKeys("header.user-agent", "header.sec-ch-ua"); + engine.refreshData(null, new byte[0]); + EvidenceKeyFilter second = engine.getEvidenceKeyFilter(); + assertTrue("A key of the new data was not accepted after refresh", + second.include("header.sec-ch-ua")); + verify(mocks.nativeEngine, times(2)).refreshData(new byte[0]); + } + + /** + * The keys are stored, so using the filter does not call the native code. + */ + @Test + public void EvidenceKeys_StoredNotReadForEachUse() throws Exception { + EngineOverMockNativeCode mocks = new EngineOverMockNativeCode(); + mocks.setKeys("header.user-agent"); + mocks.engine.refreshData(null, new byte[0]); + clearInvocations(mocks.nativeEngine); + for (int i = 0; i < 10; i++) { + mocks.engine.getEvidenceKeyFilter().include("header.user-agent"); + } + verify(mocks.nativeEngine, times(0)).getKeys(); + } +} From 1ce6add0128d44a6390fc7a9a3f06d53e45d6dd7 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:35:09 +0000 Subject: [PATCH 12/28] Test: device data reads a property from the native results only when asked device-detection-specification/pipeline-elements/device-detection-on-premise.md line 152 at 706de1f0: The Element Data MUST read a Property value from ResultsHash only when that Property is requested, and MUST NOT copy Property values out of ResultsHash while the Engine processes the Flow Data. Processing, over a native engine that is a mock, makes no call to the results it stores. That test makes native evidence, so it needs the native library, though no data file. Storing the results reads nothing, and a request for IsMobile reads IsMobile and nothing else. DD-13. --- .../ReadOnlyWhenRequestedTests.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ReadOnlyWhenRequestedTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ReadOnlyWhenRequestedTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ReadOnlyWhenRequestedTests.java new file mode 100644 index 000000000..28240f638 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ReadOnlyWhenRequestedTests.java @@ -0,0 +1,123 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.devicedetection.hash.engine.onpremise.interop.Swig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.BoolValueSwig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.EvidenceDeviceDetectionSwig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.ResultsHashSwig; +import fiftyone.pipeline.core.data.Evidence; +import fiftyone.pipeline.core.data.FlowData; +import fiftyone.pipeline.engines.services.MissingPropertyService; +import org.junit.Test; +import org.slf4j.Logger; + +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.AdditionalMatchers.aryEq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +/** + * The Element Data MUST read a Property value from ResultsHash only when + * that Property is requested, and MUST NOT copy Property values out of + * ResultsHash while the Engine processes the Flow Data + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 152 at 706de1f0). The native results here are mocks that record + * every call made to them. + */ +public class ReadOnlyWhenRequestedTests { + + private static DeviceDataHashDefault newData( + DeviceDetectionHashEngine engine) { + return new DeviceDataHashDefault( + mock(Logger.class), + mock(FlowData.class), + engine, + mock(MissingPropertyService.class)); + } + + /** + * Processing reads nothing from the results it stores. This creates + * native evidence, so it needs the native library, though no data file. + */ + @Test + public void Process_ReadsNoValue() throws Exception { + EngineOverMockNativeCode mocks = new EngineOverMockNativeCode(); + Field keys = DeviceDetectionHashEngine.class + .getDeclaredField("evidenceKeys"); + keys.setAccessible(true); + keys.set(mocks.engine, + Collections.singletonList("header.user-agent")); + ResultsHashSwig results = mock(ResultsHashSwig.class); + when(mocks.nativeEngine.process(any(EvidenceDeviceDetectionSwig.class))) + .thenReturn(results); + + Map evidence = new HashMap<>(); + evidence.put("header.user-agent", "Mozilla/5.0"); + Evidence flowEvidence = mock(Evidence.class); + when(flowEvidence.asKeyMap()).thenReturn(evidence); + FlowData flowData = mock(FlowData.class); + when(flowData.getEvidence()).thenReturn(flowEvidence); + + DeviceDataHashDefault data = newData(mocks.engine); + mocks.engine.processEngine(flowData, data); + + verify(mocks.nativeEngine).process(any(EvidenceDeviceDetectionSwig.class)); + verifyNoInteractions(results); + } + + /** + * Storing the results reads nothing, and a request for one Property reads + * that Property and no other. + */ + @Test + public void Request_ReadsOnlyThatProperty() throws Exception { + EngineOverMockNativeCode mocks = new EngineOverMockNativeCode(); + ResultsHashSwig results = mock(ResultsHashSwig.class); + BoolValueSwig value = mock(BoolValueSwig.class); + when(value.hasValue()).thenReturn(true); + when(value.getValue()).thenReturn(true); + when(results.containsProperty(any(byte[].class))).thenReturn(true); + when(results.getValueAsBool(any(byte[].class))).thenReturn(value); + when(results.getValueAsBool(any(int.class))).thenReturn(value); + + DeviceDataHashDefault data = newData(mocks.engine); + data.setResults(results); + verifyNoInteractions(results); + + assertTrue(data.getIsMobile().getValue()); + byte[] name = Swig.asBytes("ismobile"); + verify(results).containsProperty(aryEq(name)); + verify(results).getValueAsBool(aryEq(name)); + verifyNoMoreInteractions(results); + } +} From d71666f12ef97c8d39d4e5e6af3611e01e92d4d4 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:37:16 +0000 Subject: [PATCH 13/28] Test: an engine configured with no property names is created with none device-detection-specification/pipeline-elements/device-detection-on-premise.md line 189 at 706de1f0: An implementation configured with no names MUST create the Engine with no names, and MUST NOT pass the data set's names itself. Reads the names held by the native configuration the engine was created with, which the property indexes cannot show, as they are the same either way. Needs the free data file, and is skipped where it is not there. DD-14. --- .../onpremise/flowelements/NoNamesTests.java | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NoNamesTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NoNamesTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NoNamesTests.java new file mode 100644 index 000000000..0d6e05982 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NoNamesTests.java @@ -0,0 +1,106 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.RequiredPropertiesConfigSwig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.VectorStringSwig; +import fiftyone.pipeline.engines.Constants; +import org.junit.Test; +import org.slf4j.ILoggerFactory; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH; +import static fiftyone.pipeline.util.FileFinder.getFilePath; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +/** + * An implementation configured with no names MUST create the Engine with no + * names, and MUST NOT pass the data set's names itself + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 189 at 706de1f0). Reads the names the native configuration the + * engine was created with holds, which is what decides whether the engine + * walks graphs during process, rather than the indexes the engine has + * afterwards, which are the same either way. + */ +public class NoNamesTests { + + private static final ILoggerFactory loggerFactory = + LoggerFactory.getILoggerFactory(); + + private static File liteFile() { + try { + return getFilePath(LITE_HASH_DATA_FILE_PATH); + } + catch (IllegalArgumentException e) { + assumeTrue(e.getMessage(), false); + return null; + } + } + + private static List namesCreatedWith( + File file, List names) throws Exception { + DeviceDetectionHashEngineBuilder builder = + new DeviceDetectionHashEngineBuilder(loggerFactory, null) + .setPerformanceProfile( + Constants.PerformanceProfiles.HighPerformance) + .setAutoUpdate(false) + .setDataFileSystemWatcher(false); + if (names != null) { + builder.setProperties(names); + } + try (DeviceDetectionHashEngine engine = + builder.build(file.toString(), false)) { + Field field = DeviceDetectionHashEngine.class + .getDeclaredField("propertiesConfigSwig"); + field.setAccessible(true); + RequiredPropertiesConfigSwig config = + (RequiredPropertiesConfigSwig) field.get(engine); + try (VectorStringSwig given = config.getProperties()) { + return new ArrayList<>(given); + } + } + } + + @Test + public void NoNames_EngineCreatedWithNoNames() throws Exception { + File file = liteFile(); + List names = namesCreatedWith(file, null); + assertTrue("The engine was created with names " + names + + " when none were configured", names.isEmpty()); + } + + @Test + public void Names_EngineCreatedWithThoseNames() throws Exception { + File file = liteFile(); + List configured = Arrays.asList("IsMobile", "BrowserName"); + assertEquals(configured, namesCreatedWith(file, configured)); + } +} From 4c15cff70e6e2fa8f401c8a5010266812e6f3b94 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:39:52 +0000 Subject: [PATCH 14/28] Test: the published Device Detection packages hold no tests or examples device-detection-specification/packaging-and-structure.md line 16 at 706de1f0: Examples and tests SHOULD NOT be included in any published packages. Lists what each published package's main jar holds and looks for test helpers, tests and examples. DD-7. --- .../PublishedPackagesHoldNoTestsTests.java | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java diff --git a/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java new file mode 100644 index 000000000..a16362f0b --- /dev/null +++ b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java @@ -0,0 +1,108 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection; + +import fiftyone.devicedetection.cloud.flowelements.DeviceDetectionCloudEngine; +import fiftyone.devicedetection.hash.engine.onpremise.flowelements.DeviceDetectionHashEngine; +import fiftyone.devicedetection.shared.DeviceDataBase; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.assertTrue; + +/** + * Examples and tests SHOULD NOT be included in any published packages + * (device-detection-specification/packaging-and-structure.md line 16 at + * 706de1f0). Lists what each published Device Detection package's main jar + * holds, being the classes folder in a reactor build or the jar otherwise, + * and looks for test helpers, tests and examples. + */ +public class PublishedPackagesHoldNoTestsTests { + + /** + * A main class of each published Device Detection package. + */ + private static final Class[] PACKAGES = { + DeviceDataBase.class, + DeviceDetectionHashEngine.class, + DeviceDetectionCloudEngine.class, + DeviceDetectionPipelineBuilder.class + }; + + private static List entriesOf(Class type) + throws IOException, URISyntaxException { + File location = new File(type.getProtectionDomain() + .getCodeSource().getLocation().toURI()); + List entries = new ArrayList<>(); + if (location.isDirectory()) { + Path root = location.toPath(); + try (Stream paths = Files.walk(root)) { + entries.addAll(paths + .map(p -> root.relativize(p).toString().replace('\\', '/')) + .collect(Collectors.toList())); + } + } else { + try (JarFile jar = new JarFile(location)) { + Enumeration e = jar.entries(); + while (e.hasMoreElements()) { + entries.add(e.nextElement().getName()); + } + } + } + return entries; + } + + private static boolean isTestOrExample(String entry) { + String lower = entry.toLowerCase(); + return lower.contains("testhelpers/") || + lower.contains("/examples/") || + lower.endsWith("test.class") || + lower.endsWith("tests.class"); + } + + @Test + public void PublishedPackages_HoldNoTestsOrExamples() throws Exception { + List found = new ArrayList<>(); + for (Class type : PACKAGES) { + for (String entry : entriesOf(type)) { + if (isTestOrExample(entry)) { + found.add(type.getSimpleName() + "'s package: " + entry); + } + } + } + assertTrue("Published packages hold tests or examples: " + found, + found.isEmpty()); + } +} From 234d9ee29090744c2f8faeb0e320d73f7d1d7532 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:45:47 +0000 Subject: [PATCH 15/28] Fix: keep the test helpers out of the published device-detection.shared jar device-detection-specification/packaging-and-structure.md line 16 at 706de1f0: Examples and tests SHOULD NOT be included in any published packages. FileUtils and KeyUtils move from the shared module's main sources to its test sources, so the tests of the other modules still reach them through the test jar. The examples used them too, so the examples' DataFileHelper now has the data file names and the search for the best data file, and their KeyHelper reads and checks keys. DD-7. --- .../shared/testhelpers/FileUtils.java | 0 .../shared/testhelpers/KeyUtils.java | 0 .../examples/console/MatchMetrics.java | 2 +- .../console/PerformanceBenchmark.java | 2 +- .../examples/console/TacCloud.java | 4 +- .../examples/console/UpdateDataFile.java | 10 ++-- .../console/GettingStartedOnPremTest.java | 8 +-- .../examples/console/MetadataOnPremTest.java | 8 +-- .../console/OfflineProcessingTest.java | 10 ++-- .../examples/console/UpdateDataFileTest.java | 6 +-- .../examples/shared/DataFileHelper.java | 52 +++++++++++++++++-- .../examples/shared/KeyHelper.java | 45 +++++++++++++--- .../web/GettingStartedWebOnPremTest.java | 9 ++-- 13 files changed, 117 insertions(+), 39 deletions(-) rename device-detection/device-detection.shared/src/{main => test}/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java (100%) rename device-detection/device-detection.shared/src/{main => test}/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java (100%) diff --git a/device-detection/device-detection.shared/src/main/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java b/device-detection/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java similarity index 100% rename from device-detection/device-detection.shared/src/main/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java rename to device-detection/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java diff --git a/device-detection/device-detection.shared/src/main/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java b/device-detection/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java similarity index 100% rename from device-detection/device-detection.shared/src/main/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java rename to device-detection/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java diff --git a/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/MatchMetrics.java b/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/MatchMetrics.java index 3bcd93807..ae753978d 100644 --- a/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/MatchMetrics.java +++ b/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/MatchMetrics.java @@ -46,7 +46,7 @@ import java.util.Objects; import static fiftyone.common.testhelpers.LogbackHelper.configureLogback; -import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH; +import static fiftyone.devicedetection.examples.shared.DataFileHelper.LITE_HASH_DATA_FILE_PATH; import static fiftyone.pipeline.util.FileFinder.getFilePath; import static java.util.stream.Collectors.groupingBy; diff --git a/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/PerformanceBenchmark.java b/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/PerformanceBenchmark.java index cda12774b..3a527d479 100644 --- a/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/PerformanceBenchmark.java +++ b/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/PerformanceBenchmark.java @@ -47,7 +47,7 @@ import static fiftyone.devicedetection.examples.shared.DataFileHelper.getDataFileLocation; import static fiftyone.devicedetection.examples.shared.DataFileHelper.getEvidenceFile; -import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH; +import static fiftyone.devicedetection.examples.shared.DataFileHelper.LITE_HASH_DATA_FILE_PATH; import static fiftyone.pipeline.engines.Constants.PerformanceProfiles.*; /** diff --git a/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/TacCloud.java b/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/TacCloud.java index b3859fcac..ffe45a1c6 100644 --- a/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/TacCloud.java +++ b/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/TacCloud.java @@ -26,7 +26,7 @@ import fiftyone.devicedetection.cloud.data.MultiDeviceDataCloud; import fiftyone.devicedetection.shared.Constants; import fiftyone.devicedetection.shared.DeviceData; -import fiftyone.devicedetection.shared.testhelpers.KeyUtils; +import fiftyone.devicedetection.examples.shared.KeyHelper; import fiftyone.pipeline.core.configuration.PipelineOptions; import fiftyone.pipeline.core.configuration.PipelineOptionsFactory; import fiftyone.pipeline.core.data.FlowData; @@ -87,7 +87,7 @@ public static void run(String resourceKey, OutputStream os) throws Exception { // use the one supplied to this method PipelineOptions pipelineOptions = PipelineOptionsFactory.getOptionsFromFile(optionsFile); String fileResourceKey = pipelineOptions.find("CloudRequestEngine", "ResourceKey"); - if (KeyUtils.isInvalidKey(fileResourceKey)) { + if (KeyHelper.isInvalidKey(fileResourceKey)) { getOrSetSuperResourceKey(resourceKey, TAC_EXAMPLE_RESOURCE_KEY_NAME); } try (PrintWriter writer = new PrintWriter(os)) { diff --git a/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/UpdateDataFile.java b/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/UpdateDataFile.java index eae7ca9fd..a56b78bbb 100644 --- a/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/UpdateDataFile.java +++ b/examples/device-detection/console/src/main/java/fiftyone/devicedetection/examples/console/UpdateDataFile.java @@ -25,7 +25,7 @@ import fiftyone.devicedetection.examples.shared.FindOutMore; import fiftyone.devicedetection.DeviceDetectionPipelineBuilder; import fiftyone.devicedetection.examples.shared.DataFileHelper; -import fiftyone.devicedetection.shared.testhelpers.KeyUtils; +import fiftyone.devicedetection.examples.shared.KeyHelper; import fiftyone.pipeline.core.flowelements.Pipeline; import fiftyone.pipeline.engines.services.DataUpdateService; import fiftyone.pipeline.engines.services.DataUpdateServiceDefault; @@ -43,8 +43,8 @@ import static fiftyone.common.testhelpers.LogbackHelper.configureLogback; import static fiftyone.devicedetection.examples.shared.DataFileHelper.getDatafileMetaData; -import static fiftyone.devicedetection.shared.testhelpers.FileUtils.ENTERPRISE_HASH_DATA_FILE_NAME; -import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH; +import static fiftyone.devicedetection.examples.shared.DataFileHelper.ENTERPRISE_HASH_DATA_FILE_NAME; +import static fiftyone.devicedetection.examples.shared.DataFileHelper.LITE_HASH_DATA_FILE_PATH; import static fiftyone.pipeline.util.FileFinder.getFilePath; /*! @@ -236,9 +236,9 @@ static void run(String dataFilename, String licenseKey, boolean interactive) thr // try to find a license key if (Objects.isNull(licenseKey)) { - licenseKey = KeyUtils.getNamedKey(UPDATE_EXAMPLE_LICENSE_KEY_NAME); + licenseKey = KeyHelper.getNamedKey(UPDATE_EXAMPLE_LICENSE_KEY_NAME); } - if (Objects.isNull(licenseKey) || KeyUtils.isInvalidKey(licenseKey)) { + if (Objects.isNull(licenseKey) || KeyHelper.isInvalidKey(licenseKey)) { explainLicenseKey(dataFilename, new PrintWriter(System.out, true)); return; } diff --git a/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/GettingStartedOnPremTest.java b/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/GettingStartedOnPremTest.java index 779a70fc2..255649836 100644 --- a/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/GettingStartedOnPremTest.java +++ b/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/GettingStartedOnPremTest.java @@ -23,16 +23,16 @@ package fiftyone.devicedetection.examples.console; import fiftyone.devicedetection.examples.shared.EvidenceHelper; -import fiftyone.devicedetection.shared.testhelpers.FileUtils; +import fiftyone.devicedetection.examples.shared.DataFileHelper; import org.junit.Test; public class GettingStartedOnPremTest { @Test public void gettingStartedOnPremTest() throws Exception { - GettingStartedOnPrem.run(FileUtils.getHashFileName() == null - ? FileUtils.LITE_HASH_DATA_FILE_PATH - : FileUtils.getHashFileName(), + GettingStartedOnPrem.run(DataFileHelper.getHashFileName() == null + ? DataFileHelper.LITE_HASH_DATA_FILE_PATH + : DataFileHelper.getHashFileName(), EvidenceHelper.setUpEvidence(), System.out); } } \ No newline at end of file diff --git a/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/MetadataOnPremTest.java b/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/MetadataOnPremTest.java index a128b1393..2592aa5fc 100644 --- a/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/MetadataOnPremTest.java +++ b/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/MetadataOnPremTest.java @@ -22,14 +22,14 @@ package fiftyone.devicedetection.examples.console; -import fiftyone.devicedetection.shared.testhelpers.FileUtils; +import fiftyone.devicedetection.examples.shared.DataFileHelper; import org.junit.Test; public class MetadataOnPremTest { @Test public void gettingMetaDataOnPremTest() throws Exception { - MetadataOnPrem.run(FileUtils.getHashFileName() == null - ? FileUtils.LITE_HASH_DATA_FILE_PATH - : FileUtils.getHashFileName(), System.out); + MetadataOnPrem.run(DataFileHelper.getHashFileName() == null + ? DataFileHelper.LITE_HASH_DATA_FILE_PATH + : DataFileHelper.getHashFileName(), System.out); } } \ No newline at end of file diff --git a/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/OfflineProcessingTest.java b/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/OfflineProcessingTest.java index 4861f14d6..b0befcc12 100644 --- a/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/OfflineProcessingTest.java +++ b/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/OfflineProcessingTest.java @@ -22,7 +22,7 @@ package fiftyone.devicedetection.examples.console; -import fiftyone.devicedetection.shared.testhelpers.FileUtils; +import fiftyone.devicedetection.examples.shared.DataFileHelper; import org.junit.Test; import java.io.FileInputStream; @@ -31,10 +31,10 @@ public class OfflineProcessingTest { @Test public void offlineProcessingTest() throws Exception { - OfflineProcessing.run(FileUtils.getHashFileName() == null - ? FileUtils.LITE_HASH_DATA_FILE_PATH - : FileUtils.getHashFileName(), - new FileInputStream(Objects.requireNonNull(FileUtils.getEvidenceFile())), + OfflineProcessing.run(DataFileHelper.getHashFileName() == null + ? DataFileHelper.LITE_HASH_DATA_FILE_PATH + : DataFileHelper.getHashFileName(), + new FileInputStream(DataFileHelper.getEvidenceFile(null)), System.out); } diff --git a/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/UpdateDataFileTest.java b/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/UpdateDataFileTest.java index 301984e5a..d05d8061d 100644 --- a/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/UpdateDataFileTest.java +++ b/examples/device-detection/console/src/test/java/fiftyone/devicedetection/examples/console/UpdateDataFileTest.java @@ -22,7 +22,7 @@ package fiftyone.devicedetection.examples.console; -import fiftyone.devicedetection.shared.testhelpers.KeyUtils; +import fiftyone.devicedetection.examples.shared.KeyHelper; import org.junit.Test; import static fiftyone.devicedetection.examples.console.UpdateDataFile.run; @@ -33,9 +33,9 @@ public class UpdateDataFileTest { @Test public void updateExampleTest () throws Exception { - String licenseKey = KeyUtils.getNamedKey(UpdateDataFile.UPDATE_EXAMPLE_LICENSE_KEY_NAME); + String licenseKey = KeyHelper.getNamedKey(UpdateDataFile.UPDATE_EXAMPLE_LICENSE_KEY_NAME); assumeFalse("Skipping test, no license key found", - KeyUtils.isInvalidKey(licenseKey)); + KeyHelper.isInvalidKey(licenseKey)); try { run(null, licenseKey, false); } catch (IllegalStateException e) { diff --git a/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/DataFileHelper.java b/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/DataFileHelper.java index 55a9c44c1..5ac787e20 100644 --- a/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/DataFileHelper.java +++ b/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/DataFileHelper.java @@ -24,7 +24,6 @@ import fiftyone.devicedetection.hash.engine.onpremise.flowelements.DeviceDetectionHashEngine; import fiftyone.devicedetection.hash.engine.onpremise.flowelements.DeviceDetectionHashEngineBuilder; -import fiftyone.devicedetection.shared.testhelpers.FileUtils; import fiftyone.pipeline.engines.data.AspectEngineDataFile; import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData; import fiftyone.pipeline.engines.fiftyone.data.FiftyOneDataFile; @@ -75,6 +74,51 @@ public class DataFileHelper { */ public static final String NEEDS_ENTERPRISE = "needs the Enterprise data file"; + /** + * Name of the paid Enterprise data file. + */ + public static final String ENTERPRISE_HASH_DATA_FILE_NAME = + "Enterprise-HashV41.hash"; + + /** + * Name of the paid TAC data file. + */ + public static final String TAC_HASH_DATA_FILE_NAME = "TAC-HashV41.hash"; + + /** + * Where the free Lite data file is in the data repository. A search for + * the path rather than the name does not stop at another file of the + * same name, such as a Git LFS pointer in an old device-detection-data + * folder. + */ + public static final String LITE_HASH_DATA_FILE_PATH = + "device-detection/51Degrees-LiteV4.1.hash"; + + /** + * Where the free evidence file is in the data repository. + */ + public static final String EVIDENCE_FILE_PATH = + "device-detection/20000 Evidence Records.yml"; + + /** + * Find the best data file there is below the project root: the TAC file, + * then the Enterprise file, then the free Lite file. + * @return the path of the file, or null when there is none + */ + public static String getHashFileName() { + for (String name : new String[] { + TAC_HASH_DATA_FILE_NAME, + ENTERPRISE_HASH_DATA_FILE_NAME, + LITE_HASH_DATA_FILE_PATH}) { + try { + return getFilePath(name).getPath(); + } catch (Exception e) { + // Not there, so try the next. + } + } + return null; + } + public static class DatafileInfo { FiftyOneDataFile fileInfo; String tier; @@ -210,7 +254,7 @@ public static void writeEnterpriseOffer(PrintWriter output, String contactUs) { @SuppressWarnings("RedundantThrows") public static File getEvidenceFile(String evidenceFilename) throws Exception { if (Objects.isNull(evidenceFilename)) { - evidenceFilename = FileUtils.EVIDENCE_FILE_PATH; + evidenceFilename = EVIDENCE_FILE_PATH; } File evidenceFile; @@ -233,10 +277,10 @@ public static File getEvidenceFile(String evidenceFilename) throws Exception { @SuppressWarnings("RedundantThrows") public static String getDataFileLocation(String dataFilename) throws Exception { if (Objects.isNull(dataFilename)) { - dataFilename = FileUtils.getHashFileName(); + dataFilename = getHashFileName(); } if (Objects.isNull(dataFilename)) { - dataFilename = FileUtils.LITE_HASH_DATA_FILE_PATH; + dataFilename = LITE_HASH_DATA_FILE_PATH; } String dataFileLocation; try { diff --git a/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/KeyHelper.java b/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/KeyHelper.java index 06ae82900..2975b175e 100644 --- a/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/KeyHelper.java +++ b/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/KeyHelper.java @@ -22,7 +22,6 @@ package fiftyone.devicedetection.examples.shared; -import fiftyone.devicedetection.shared.testhelpers.KeyUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,6 +41,40 @@ public class KeyHelper { "_51DEGREES_RESOURCE_KEY", "_51DEGREES_RESOURCE_KEY_BESPOKE")); + /** + * Read a key from an environment variable of the name given, then of the + * name in upper case, then from a system property of the name given. + * @param keyName name of the key + * @return the key, or null when none of them is set + */ + public static String getNamedKey(String keyName) { + String resourceKey = System.getenv(keyName); + if (Objects.isNull(resourceKey)) { + resourceKey = System.getenv(keyName.toUpperCase()); + if (Objects.isNull(resourceKey)) { + resourceKey = System.getProperty(keyName); + } + } + return resourceKey; + } + + /** + * Whether a key cannot be valid, being missing, too short, or not URL + * safe Base64 of enough bytes. + * @param keyValue value to check + * @return true when the key cannot be valid + */ + public static boolean isInvalidKey(String keyValue) { + Base64.Decoder decoder = Base64.getUrlDecoder(); + try { + return Objects.isNull(keyValue) || + keyValue.trim().length() < 19 || + decoder.decode(keyValue).length < 14; + } catch (IllegalArgumentException e) { + return true; + } + } + static final String CREATE_KEY_URL = "https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=shared-src-main-java-fiftyone-devicedetection-examples-shared-keyhelper.java&utm_term=no-resource-key"; @@ -84,7 +117,7 @@ static String requireResourceKey(Function read, names.addAll(exampleNames); for (String name : names) { String value = read.apply(name); - if (KeyUtils.isInvalidKey(value) == false) { + if (isInvalidKey(value) == false) { return value.trim(); } } @@ -141,7 +174,7 @@ private static String readKey(String name) { System.getenv(name), System.getenv(name.toUpperCase()), System.getProperty(name)}) { - if (KeyUtils.isInvalidKey(value) == false) { + if (isInvalidKey(value) == false) { return value; } } @@ -178,10 +211,10 @@ public static String getOrSetResourceKey(String value, String variableName, String errorMessage, boolean shouldThrow) { if (Objects.isNull(value)) { - value = KeyUtils.getNamedKey(variableName); + value = getNamedKey(variableName); } - if (KeyUtils.isInvalidKey(value)) { + if (isInvalidKey(value)) { logger.error("\nTo access Cloud Services you must supply a " + "\"ResourceKey\" in one of the following ways: \n - in the " + "configuration file of an example,\n - as a command line parameter of a " + @@ -196,7 +229,7 @@ public static String getOrSetResourceKey(String value, String variableName, // Keep a valid key for next time. System.setProperty throws on null, // and an invalid key is not worth keeping. - if (KeyUtils.isInvalidKey(value) == false) { + if (isInvalidKey(value) == false) { System.setProperty(variableName, value); } return value; diff --git a/examples/device-detection/web/getting-started.onprem/src/test/java/fiftyone/devicedetection/examples/web/GettingStartedWebOnPremTest.java b/examples/device-detection/web/getting-started.onprem/src/test/java/fiftyone/devicedetection/examples/web/GettingStartedWebOnPremTest.java index 967773a14..59cf50e87 100644 --- a/examples/device-detection/web/getting-started.onprem/src/test/java/fiftyone/devicedetection/examples/web/GettingStartedWebOnPremTest.java +++ b/examples/device-detection/web/getting-started.onprem/src/test/java/fiftyone/devicedetection/examples/web/GettingStartedWebOnPremTest.java @@ -24,12 +24,12 @@ import fiftyone.devicedetection.examples.shared.DataFileHelper; import fiftyone.devicedetection.examples.shared.FindOutMore; -import fiftyone.devicedetection.shared.testhelpers.FileUtils; import org.eclipse.jetty.server.Server; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import java.io.File; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; @@ -47,10 +47,11 @@ public class GettingStartedWebOnPremTest { public static void startJetty() throws Exception { // With no Enterprise file, the free Lite file is found, or // downloaded, as the example finds it, so a fresh clone runs this. - System.setProperty("TestDataFile", FileUtils.getHashFile() == null + String found = DataFileHelper.getHashFileName(); + System.setProperty("TestDataFile", found == null ? DataFileHelper.findDataFile( - FileUtils.LITE_HASH_DATA_FILE_PATH).getAbsolutePath() - : FileUtils.getHashFile().getAbsolutePath()); + DataFileHelper.LITE_HASH_DATA_FILE_PATH).getAbsolutePath() + : new File(found).getAbsolutePath()); SERVER = EmbedJetty.startWebApp(getFilePath(resourceBase).getAbsolutePath(), 8081); } From a15e255b0283b47eecd34e740d31c21aa3bc3492 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:46:55 +0000 Subject: [PATCH 16/28] Test: a read of a property the engine was created with goes by position only device-detection-specification/pipeline-elements/device-detection-on-premise.md line 205 at 706de1f0: Every read SHOULD use the position. Reading IsMobile, at position 1, makes one call to the native results, the read by position, and none by name. DD-15. --- .../EngineOverMockNativeCode.java | 16 ++++ .../flowelements/ReadsByPositionTests.java | 73 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ReadsByPositionTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java index 032d5f2f3..c66d8421b 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/EngineOverMockNativeCode.java @@ -32,6 +32,8 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.doNothing; @@ -80,6 +82,20 @@ class EngineOverMockNativeCode { setKeys(); } + /** + * Set the property names the engine was created with, so each name's + * position is its place in the list. + * @param names the names + */ + void setPropertyNames(String... names) throws Exception { + Map indexes = + new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + for (int i = 0; i < names.length; i++) { + indexes.putIfAbsent(names[i], i); + } + set("propertyIndexes", indexes); + } + /** * Set the evidence keys the native engine gives from now on. * @param keys the keys diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ReadsByPositionTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ReadsByPositionTests.java new file mode 100644 index 000000000..ec5f938a0 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ReadsByPositionTests.java @@ -0,0 +1,73 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.BoolValueSwig; +import fiftyone.devicedetection.hash.engine.onpremise.interop.swig.ResultsHashSwig; +import fiftyone.pipeline.core.data.FlowData; +import fiftyone.pipeline.engines.services.MissingPropertyService; +import org.junit.Test; +import org.slf4j.Logger; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +/** + * Every read SHOULD use the position + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 205 at 706de1f0). A read by name looks the name up in the table from + * the names the engine was created with to their positions, and then reads + * by position. The native results here are mocks that record every call. + */ +public class ReadsByPositionTests { + + @Test + public void Read_OfANamedProperty_IsByPositionOnly() throws Exception { + EngineOverMockNativeCode mocks = new EngineOverMockNativeCode(); + mocks.setPropertyNames("ScreenPixelsHeight", "IsMobile"); + + ResultsHashSwig results = mock(ResultsHashSwig.class); + BoolValueSwig value = mock(BoolValueSwig.class); + when(value.hasValue()).thenReturn(true); + when(value.getValue()).thenReturn(true); + when(results.containsProperty(any(byte[].class))).thenReturn(true); + when(results.getValueAsBool(any(byte[].class))).thenReturn(value); + when(results.getValueAsBool(1)).thenReturn(value); + + DeviceDataHashDefault data = new DeviceDataHashDefault( + mock(Logger.class), + mock(FlowData.class), + mocks.engine, + mock(MissingPropertyService.class)); + data.setResults(results); + + assertTrue(data.getIsMobile().getValue()); + // IsMobile is at position 1, and nothing is read by its name. + verify(results).getValueAsBool(1); + verifyNoMoreInteractions(results); + } +} From 23783e51e17468405e97e4510f79cc759f2560f4 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:48:42 +0000 Subject: [PATCH 17/28] Fix: find a property by its position, not by a native lookup of its name device-detection-specification/pipeline-elements/device-detection-on-premise.md line 205 at 706de1f0: Every read SHOULD use the position. The values were read by position, but each read first asked the native results whether they held the property, by name. A property the engine was created with has a position, so it is now taken as available without that call, and a property the data set lacks still reads as having no value. A name with no position, and results from more than one engine, still use the name. DD-15. --- .../onpremise/flowelements/DeviceDataHashDefault.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java index 6d7845fca..c566dc65f 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/main/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/DeviceDataHashDefault.java @@ -268,6 +268,14 @@ private AspectPropertyValue> getUserAgentsInternal() { protected boolean propertyIsAvailable(String propertyName) { checkState(); synchronized (resultsLock) { + // A property the engine was created with has a position, and the + // read goes by it, so there is no need to look the name up in the + // results first. A property the data set lacks keeps its position + // and reads as having no value. With results from more than one + // engine, the name finds the results that hold the property. + if (resultsList.size() == 1 && indexOf(propertyName) != null) { + return true; + } for (ResultsHashSwig results : resultsList) { if (results.containsProperty(Swig.asBytes(propertyName))) { return true; From 7f5a91789c2b520b8aae1bc204268bdf02838bcb Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:49:06 +0000 Subject: [PATCH 18/28] Test: the engine reads what changes only on refresh from native code once device-detection-specification/pipeline-elements/device-detection-on-premise.md line 339 at 706de1f0: As such, steps SHOULD be taken to minimize this as much as possible. The last of those steps stores in the engine the values that change only on a data refresh. Counts the calls to a mock native engine for the property metadata and for the evidence keys, before and after refreshes. DD-19. --- .../NativeCallsOncePerRefreshTests.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NativeCallsOncePerRefreshTests.java diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NativeCallsOncePerRefreshTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NativeCallsOncePerRefreshTests.java new file mode 100644 index 000000000..10655e774 --- /dev/null +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NativeCallsOncePerRefreshTests.java @@ -0,0 +1,80 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.hash.engine.onpremise.flowelements; + +import org.junit.Test; + +import static org.mockito.Mockito.clearInvocations; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * The main performance bottleneck is usually marshalling data to and from + * native code. As such, steps SHOULD be taken to minimize this as much as + * possible + * (device-detection-specification/pipeline-elements/device-detection-on-premise.md + * line 339 at 706de1f0), the last being that values which change only on a + * data refresh are stored in the engine until a refresh occurs. Counts the + * calls to a mock native engine. + */ +public class NativeCallsOncePerRefreshTests { + + /** + * Property metadata is read from the native code once, and again only + * after a refresh. + */ + @Test + public void PropertyMetaData_ReadOncePerRefresh() throws Exception { + EngineOverMockNativeCode mocks = new EngineOverMockNativeCode(); + mocks.engine.refreshData(null, new byte[0]); + clearInvocations(mocks.nativeEngine); + + for (int i = 0; i < 5; i++) { + mocks.engine.getProperties(); + } + verify(mocks.nativeEngine, times(1)).getMetaData(); + + mocks.engine.refreshData(null, new byte[0]); + for (int i = 0; i < 5; i++) { + mocks.engine.getProperties(); + } + verify(mocks.nativeEngine, times(2)).getMetaData(); + } + + /** + * The evidence keys and their filter are read once for each refresh. + */ + @Test + public void EvidenceKeys_ReadOncePerRefresh() throws Exception { + EngineOverMockNativeCode mocks = new EngineOverMockNativeCode(); + mocks.setKeys("header.user-agent"); + for (int refresh = 1; refresh <= 3; refresh++) { + mocks.engine.refreshData(null, new byte[0]); + for (int i = 0; i < 5; i++) { + mocks.engine.getEvidenceKeyFilter() + .include("header.user-agent"); + } + verify(mocks.nativeEngine, times(refresh)).getKeys(); + } + } +} From 74985cda5822f734da00072360b568f70ab8f9d7 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:51:13 +0000 Subject: [PATCH 19/28] Test: the cloud Device Detection engine leaves processing to the shared logic device-detection-specification/pipeline-elements/device-detection-cloud.md line 41 at 706de1f0: The majority of the processing SHOULD be handled by the shared Cloud Aspect Engine logic. The engine should give only the parsing of its part of the response. The shared logic passes over an empty response, whose error the Cloud Request Engine has reported, and refuses a Pipeline where that engine has not run. DD-9. --- .../SharedCloudProcessingTests.java | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/SharedCloudProcessingTests.java diff --git a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/SharedCloudProcessingTests.java b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/SharedCloudProcessingTests.java new file mode 100644 index 000000000..034142dea --- /dev/null +++ b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/SharedCloudProcessingTests.java @@ -0,0 +1,168 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.cloud.flowelements; + +import fiftyone.devicedetection.cloud.data.DeviceDataCloud; +import fiftyone.pipeline.cloudrequestengine.data.CloudRequestData; +import fiftyone.pipeline.cloudrequestengine.flowelements.CloudAspectEngineBase; +import fiftyone.pipeline.cloudrequestengine.flowelements.CloudRequestEngine; +import fiftyone.pipeline.core.data.FlowData; +import fiftyone.pipeline.core.exceptions.PipelineConfigurationException; +import fiftyone.pipeline.core.flowelements.Pipeline; +import fiftyone.pipeline.engines.services.MissingPropertyServiceDefault; +import org.junit.Test; +import org.slf4j.ILoggerFactory; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * The majority of the processing SHOULD be handled by the shared Cloud Aspect + * Engine logic + * (device-detection-specification/pipeline-elements/device-detection-cloud.md + * line 41 at 706de1f0). The engine only filters and parses its part of the + * JSON, and the shared logic does the rest: it finds the Cloud Request + * Engine's data, refuses a Pipeline where that engine has not run, and + * passes over an empty response, whose error the Cloud Request Engine has + * already reported. + */ +public class SharedCloudProcessingTests { + + private static final ILoggerFactory loggerFactory = + LoggerFactory.getILoggerFactory(); + + private static DeviceDetectionCloudEngine engine() throws Exception { + DeviceDetectionCloudEngine engine = + new DeviceDetectionCloudEngineBuilder(loggerFactory).build(); + CloudRequestEngine requestEngine = mock(CloudRequestEngine.class); + when(requestEngine.getPublicProperties()).thenReturn(new HashMap<>()); + Pipeline pipeline = mock(Pipeline.class); + when(pipeline.getElement(CloudRequestEngine.class)) + .thenReturn(requestEngine); + engine.addPipeline(pipeline); + return engine; + } + + private static DeviceDataCloud process( + DeviceDetectionCloudEngine engine, + String response, + boolean processStarted) { + CloudRequestData cloudData = mock(CloudRequestData.class); + when(cloudData.getJsonResponse()).thenReturn(response); + when(cloudData.getProcessStarted()).thenReturn(processStarted); + FlowData flowData = mock(FlowData.class); + when(flowData.getFromElement(any(CloudRequestEngine.class))) + .thenReturn(cloudData); + DeviceDataCloud device = new DeviceDataCloudInternal( + loggerFactory.getLogger(DeviceDataCloud.class.getSimpleName()), + flowData, + engine, + MissingPropertyServiceDefault.getInstance()); + processThroughTheEngine(engine, flowData, device); + return device; + } + + /** + * Run the engine's processing, as the Pipeline does, through the + * processEngine method it has, whichever class declares it. + */ + static void processThroughTheEngine( + DeviceDetectionCloudEngine engine, + FlowData flowData, + DeviceDataCloud device) { + Class type = engine.getClass(); + while (type != null) { + for (Method method : type.getDeclaredMethods()) { + if (method.getName().equals("processEngine") && + method.getParameterCount() == 2) { + method.setAccessible(true); + try { + method.invoke(engine, flowData, device); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof RuntimeException) { + throw (RuntimeException) e.getCause(); + } + throw new IllegalStateException(e.getCause()); + } catch (IllegalAccessException e) { + throw new IllegalStateException(e); + } + return; + } + } + type = type.getSuperclass(); + } + throw new IllegalStateException("No processEngine method"); + } + + /** + * The engine leaves processing to the shared logic, and gives only the + * parsing of its part of the response. + */ + @Test + public void Process_IsTheSharedLogic() throws Exception { + try { + DeviceDetectionCloudEngine.class.getDeclaredMethod( + "processEngine", FlowData.class, DeviceDataCloud.class); + fail("The engine replaces the shared processing"); + } catch (NoSuchMethodException e) { + // The shared processing is used. + } + assertTrue(CloudAspectEngineBase.class.isAssignableFrom( + DeviceDetectionCloudEngine.class)); + DeviceDetectionCloudEngine.class.getDeclaredMethod( + "processCloudEngine", + FlowData.class, DeviceDataCloud.class, String.class); + } + + /** + * An empty response, after an error the Cloud Request Engine has + * reported, leaves the data without values and raises no error. + */ + @Test + public void Process_EmptyResponse_NoError() throws Exception { + try (DeviceDetectionCloudEngine engine = engine()) { + DeviceDataCloud device = process(engine, "", true); + assertTrue(device.asKeyMap().isEmpty()); + } + } + + /** + * A Pipeline where the Cloud Request Engine has not run is a + * configuration error. + */ + @Test(expected = PipelineConfigurationException.class) + public void Process_RequestEngineNotRun_ConfigurationError() + throws Exception { + try (DeviceDetectionCloudEngine engine = engine()) { + process(engine, "{ 'device': {} }", false); + } + } +} From 5c440dcf2898eb9485476d03d5348f51b1c46d3b Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:54:52 +0000 Subject: [PATCH 20/28] Fix: let the shared Cloud Aspect Engine logic process for cloud Device Detection device-detection-specification/pipeline-elements/device-detection-cloud.md line 41 at 706de1f0: The majority of the processing SHOULD be handled by the shared Cloud Aspect Engine logic. DeviceDetectionCloudEngine replaced the shared processEngine with its own, so an empty response, after an error the Cloud Request Engine had reported, threw a JSON error, and a Pipeline where that engine had not run was not refused. The engine now gives only processCloudEngine, which parses its part of the response, and the shared processEngine does the rest. Two test files that called the engine's own processEngine now go through the shared one, or call processCloudEngine with the response. DD-9. --- .../DeviceDetectionCloudEngine.java | 159 +++++++++--------- .../MissingPropertyHandlingTests.java | 4 +- .../flowelements/ProductMissingTests.java | 4 +- 3 files changed, 83 insertions(+), 84 deletions(-) diff --git a/device-detection/device-detection.cloud/src/main/java/fiftyone/devicedetection/cloud/flowelements/DeviceDetectionCloudEngine.java b/device-detection/device-detection.cloud/src/main/java/fiftyone/devicedetection/cloud/flowelements/DeviceDetectionCloudEngine.java index 128e4ebc2..3ef9d1939 100644 --- a/device-detection/device-detection.cloud/src/main/java/fiftyone/devicedetection/cloud/flowelements/DeviceDetectionCloudEngine.java +++ b/device-detection/device-detection.cloud/src/main/java/fiftyone/devicedetection/cloud/flowelements/DeviceDetectionCloudEngine.java @@ -23,7 +23,6 @@ package fiftyone.devicedetection.cloud.flowelements; import fiftyone.devicedetection.cloud.data.DeviceDataCloud; -import fiftyone.pipeline.cloudrequestengine.data.CloudRequestData; import fiftyone.pipeline.cloudrequestengine.flowelements.CloudAspectEngineBase; import fiftyone.pipeline.cloudrequestengine.flowelements.CloudRequestEngine; import fiftyone.pipeline.core.data.AccessiblePropertyMetaData; @@ -32,7 +31,6 @@ import fiftyone.pipeline.core.data.FlowData; import fiftyone.pipeline.core.data.factories.ElementDataFactory; import fiftyone.pipeline.core.data.types.JavaScript; -import fiftyone.pipeline.core.exceptions.PipelineConfigurationException; import fiftyone.pipeline.core.flowelements.Pipeline; import fiftyone.pipeline.engines.data.AspectPropertyMetaData; import fiftyone.pipeline.engines.data.AspectPropertyMetaDataDefault; @@ -124,95 +122,94 @@ public EvidenceKeyFilter getEvidenceKeyFilter() { return new EvidenceKeyFilterWhitelist(new ArrayList()); } + /** + * Parse this engine's part of the cloud response into the device data. + * The shared processing of {@link CloudAspectEngineBase} finds the + * response, refuses a Pipeline where the Cloud Request Engine has not + * run, and passes over an empty response before calling this. + * @see Specification + * @param data the flow data being processed + * @param aspectData the device data to populate + * @param json the whole response from the Cloud Request Engine + */ @Override - protected void processEngine(FlowData data, DeviceDataCloud aspectData) { - if (cloudRequestEngine == null) { - throw new PipelineConfigurationException( - "The '" + getClass().getName() + "' requires a " + - "'CloudRequestEngine' before it in the Pipeline. This " + - "engine will be unable to produce results until this is " + - "corrected."); - } - else { - CloudRequestData requestData = - data.getFromElement(cloudRequestEngine); - String json = ""; - json = requestData.getJsonResponse(); - - // Extract data from json to the aspectData instance. - JSONObject jsonObj = new JSONObject(json); - JSONObject deviceObj = getElementJson(jsonObj); + protected void processCloudEngine( + FlowData data, + DeviceDataCloud aspectData, + String json) { + // Extract data from json to the aspectData instance. + JSONObject jsonObj = new JSONObject(json); + JSONObject deviceObj = getElementJson(jsonObj); - Map deviceMap = - new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + Map deviceMap = + new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - for (AspectPropertyMetaData property : getProperties()) { - // A property the response leaves out has no entry, so - // reading it throws a PropertyMissingException. - if (deviceObj.has( - property.getName().toLowerCase(Locale.ROOT)) == false) { - continue; - } - String type = property.getType().getSimpleName(); - switch(type) { - case ("List"): - deviceMap.put( - property.getName(), - getListAspectPropertyValue(deviceObj, property)); - break; - case ("JavaScript"): - deviceMap.put( - property.getName(), - getJavaScriptAspectPropertyValue(deviceObj, property)); - break; - case ("String"): - deviceMap.put( - property.getName(), - getStringAspectPropertyValue(deviceObj, property)); - break; - case ("boolean"): - deviceMap.put( - property.getName(), - getBooleanAspectPropertyValue(deviceObj, property)); - break; - case ("int"): - deviceMap.put( - property.getName(), - getIntegerAspectPropertyValue(deviceObj, property)); + for (AspectPropertyMetaData property : getProperties()) { + // A property the response leaves out has no entry, so + // reading it throws a PropertyMissingException. + if (deviceObj.has( + property.getName().toLowerCase(Locale.ROOT)) == false) { + continue; + } + String type = property.getType().getSimpleName(); + switch(type) { + case ("List"): + deviceMap.put( + property.getName(), + getListAspectPropertyValue(deviceObj, property)); + break; + case ("JavaScript"): + deviceMap.put( + property.getName(), + getJavaScriptAspectPropertyValue(deviceObj, property)); + break; + case ("String"): + deviceMap.put( + property.getName(), + getStringAspectPropertyValue(deviceObj, property)); break; - case ("double"): - deviceMap.put( - property.getName(), - getDoubleAspectPropertyValue(deviceObj, property)); + case ("boolean"): + deviceMap.put( + property.getName(), + getBooleanAspectPropertyValue(deviceObj, property)); + break; + case ("int"): + deviceMap.put( + property.getName(), + getIntegerAspectPropertyValue(deviceObj, property)); + break; + case ("double"): + deviceMap.put( + property.getName(), + getDoubleAspectPropertyValue(deviceObj, property)); + break; + default: + deviceMap.put( + property.getName(), + getStringAspectPropertyValue(deviceObj, property)); break; - default: - deviceMap.put( - property.getName(), - getStringAspectPropertyValue(deviceObj, property)); - break; - } } + } - // Add no value messages for any properties which have not yet been - // populated. - for (String key : deviceObj.keySet()) { - if (key.endsWith("nullreason")) { - String actualKey = key - .replace("nullreason", ""); - if (deviceMap.containsKey(actualKey) == false) { - AspectPropertyValue nullValue = - new AspectPropertyValueDefault(); - nullValue.setNoValueMessage( - deviceObj.optString(key, "Unknown")); - deviceMap.put( - actualKey, - nullValue); - } + // Add no value messages for any properties which have not yet been + // populated. + for (String key : deviceObj.keySet()) { + if (key.endsWith("nullreason")) { + String actualKey = key + .replace("nullreason", ""); + if (deviceMap.containsKey(actualKey) == false) { + AspectPropertyValue nullValue = + new AspectPropertyValueDefault(); + nullValue.setNoValueMessage( + deviceObj.optString(key, "Unknown")); + deviceMap.put( + actualKey, + nullValue); } } - - aspectData.populateFromMap(deviceMap); } + + aspectData.populateFromMap(deviceMap); } @Override diff --git a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/MissingPropertyHandlingTests.java b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/MissingPropertyHandlingTests.java index 8e85a1ca0..651fe23d2 100644 --- a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/MissingPropertyHandlingTests.java +++ b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/MissingPropertyHandlingTests.java @@ -73,7 +73,7 @@ public void PropertyInResource_NullValue() throws Exception { engine.cloudRequestEngine = mock(CloudRequestEngine.class); engine.aspectProperties = properties; - engine.processEngine(flowData, device); + engine.processCloudEngine(flowData, device, nullValueJson); AspectPropertyValue priceBand = device.getPriceBand(); assertTrue(priceBand != null); @@ -116,7 +116,7 @@ public void PropertyNotInResource() throws Exception { engine.cloudRequestEngine = mock(CloudRequestEngine.class); engine.aspectProperties = properties; - engine.processEngine(flowData, device); + engine.processCloudEngine(flowData, device, nullValueJson); try { AspectPropertyValue deviceType = device.getDeviceType(); diff --git a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/ProductMissingTests.java b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/ProductMissingTests.java index 163f9b00a..cea79cdd9 100644 --- a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/ProductMissingTests.java +++ b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/ProductMissingTests.java @@ -250,6 +250,7 @@ private DeviceDataCloud process( String response) { CloudRequestData cloudData = mock(CloudRequestData.class); when(cloudData.getJsonResponse()).thenReturn(response); + when(cloudData.getProcessStarted()).thenReturn(true); FlowData flowData = mock(FlowData.class); when(flowData.getFromElement(any(CloudRequestEngine.class))) @@ -260,7 +261,8 @@ private DeviceDataCloud process( flowData, engine, MissingPropertyServiceDefault.getInstance()); - engine.processEngine(flowData, device); + SharedCloudProcessingTests.processThroughTheEngine( + engine, flowData, device); return device; } From a4f3217ae041c95cb20a69be736c5313a1b1d7c2 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Sun, 15 Nov 2026 21:55:41 +0000 Subject: [PATCH 21/28] Test: the hardware profile cloud engine processes through the shared logic device-detection-specification/pipeline-elements/hardware-profile-lookup-cloud.md line 56 at 706de1f0: The majority of the processing SHOULD be handled by the shared Cloud Aspect Engine logic. The engine gives no processing of its own. Each profile in its part of a canned response becomes DeviceData with the values and no-value reasons the response gives, and an empty response gives no profiles. DD-28. --- .../HardwareProfileCloudEngineTests.java | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/HardwareProfileCloudEngineTests.java diff --git a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/HardwareProfileCloudEngineTests.java b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/HardwareProfileCloudEngineTests.java new file mode 100644 index 000000000..59f796770 --- /dev/null +++ b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/HardwareProfileCloudEngineTests.java @@ -0,0 +1,171 @@ +/* ********************************************************************* + * This Original Work is copyright of 51 Degrees Mobile Experts Limited. + * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House, + * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU. + * + * This Original Work is licensed under the European Union Public Licence + * (EUPL) v.1.2 and is subject to its terms as set out below. + * + * If a copy of the EUPL was not distributed with this file, You can obtain + * one at https://opensource.org/licenses/EUPL-1.2. + * + * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be + * amended by the European Commission) shall be deemed incompatible for + * the purposes of the Work and the provisions of the compatibility + * clause in Article 5 of the EUPL shall not apply. + * + * If using the Work as, or as part of, a network application, by + * including the attribution notice(s) required under Article 5 of the EUPL + * in the end user terms of the application under an appropriate heading, + * such notice(s) shall fulfill the requirements of that article. + * ********************************************************************* */ + +package fiftyone.devicedetection.cloud.flowelements; + +import fiftyone.devicedetection.cloud.data.MultiDeviceDataCloud; +import fiftyone.devicedetection.shared.DeviceData; +import fiftyone.pipeline.cloudrequestengine.data.CloudRequestData; +import fiftyone.pipeline.cloudrequestengine.flowelements.CloudRequestEngine; +import fiftyone.pipeline.cloudrequestengine.flowelements.PropertyKeyedCloudEngineBase; +import fiftyone.pipeline.core.data.AccessiblePropertyMetaData.ProductMetaData; +import fiftyone.pipeline.core.data.AccessiblePropertyMetaData.PropertyMetaData; +import fiftyone.pipeline.core.data.FlowData; +import fiftyone.pipeline.core.flowelements.Pipeline; +import fiftyone.pipeline.engines.services.MissingPropertyServiceDefault; +import org.junit.Test; +import org.slf4j.ILoggerFactory; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * The majority of the processing SHOULD be handled by the shared Cloud Aspect + * Engine logic + * (device-detection-specification/pipeline-elements/hardware-profile-lookup-cloud.md + * line 56 at 706de1f0). The hardware profile engine gives no processing of + * its own, and the shared logic for property keyed engines turns each + * profile in its part of the response into DeviceData. + */ +public class HardwareProfileCloudEngineTests { + + private static final ILoggerFactory loggerFactory = + LoggerFactory.getILoggerFactory(); + + private static HardwareProfileCloudEngine engine() throws Exception { + HardwareProfileCloudEngine engine = + new HardwareProfileCloudEngineBuilder(loggerFactory).build(); + ProductMetaData product = new ProductMetaData(); + product.dataTier = "test"; + product.properties = Arrays.asList( + new PropertyMetaData("profiles", "Array", "Device", Arrays.asList( + new PropertyMetaData("hardwarevendor", "String", "Device", null), + new PropertyMetaData("hardwarename", "Array", "Device", null)))); + Map products = new HashMap<>(); + products.put("hardware", product); + CloudRequestEngine requestEngine = mock(CloudRequestEngine.class); + when(requestEngine.getPublicProperties()).thenReturn(products); + Pipeline pipeline = mock(Pipeline.class); + when(pipeline.getElement(CloudRequestEngine.class)) + .thenReturn(requestEngine); + engine.addPipeline(pipeline); + return engine; + } + + private static MultiDeviceDataCloud process( + HardwareProfileCloudEngine engine, + String response) throws Exception { + CloudRequestData cloudData = mock(CloudRequestData.class); + when(cloudData.getJsonResponse()).thenReturn(response); + when(cloudData.getProcessStarted()).thenReturn(true); + FlowData flowData = mock(FlowData.class); + when(flowData.getFromElement(any(CloudRequestEngine.class))) + .thenReturn(cloudData); + MultiDeviceDataCloud data = new MultiDeviceDataCloud( + loggerFactory.getLogger(MultiDeviceDataCloud.class.getSimpleName()), + flowData, + engine, + MissingPropertyServiceDefault.getInstance()); + // The Pipeline calls the protected processEngine of the shared base. + Method processEngine = null; + for (Class type = engine.getClass(); processEngine == null && + type != null; type = type.getSuperclass()) { + for (Method method : type.getDeclaredMethods()) { + if (method.getName().equals("processEngine") && + method.getParameterCount() == 2) { + processEngine = method; + } + } + } + processEngine.setAccessible(true); + try { + processEngine.invoke(engine, flowData, data); + } catch (InvocationTargetException e) { + throw (Exception) e.getCause(); + } + return data; + } + + /** + * The engine gives no processing of its own. + */ + @Test + public void HardwareProfile_ProcessingIsShared() { + assertTrue(PropertyKeyedCloudEngineBase.class.isAssignableFrom( + HardwareProfileCloudEngine.class)); + for (Method method : + HardwareProfileCloudEngine.class.getDeclaredMethods()) { + assertTrue("The engine processes with " + method.getName(), + method.getName().equals("processEngine") == false && + method.getName().equals("processCloudEngine") == false); + } + } + + /** + * Each profile in the engine's part of the response becomes DeviceData + * with the values the response gives. + */ + @Test + public void HardwareProfile_ProfilesAreDeviceData() throws Exception { + try (HardwareProfileCloudEngine engine = engine()) { + MultiDeviceDataCloud data = process(engine, + "{ 'hardware': { 'profiles': [" + + "{ 'hardwarevendor': 'Apple', " + + "'hardwarename': ['iPhone 12', 'iPhone 12 Pro'] }, " + + "{ 'hardwarevendor': null, " + + "'hardwarevendornullreason': 'No match', " + + "'hardwarename': [] } ] } }"); + List profiles = data.getProfiles(); + assertEquals(2, profiles.size()); + assertEquals("Apple", + profiles.get(0).getHardwareVendor().getValue()); + assertEquals(Arrays.asList("iPhone 12", "iPhone 12 Pro"), + profiles.get(0).getHardwareName().getValue()); + assertEquals(false, + profiles.get(1).getHardwareVendor().hasValue()); + assertEquals("No match", + profiles.get(1).getHardwareVendor().getNoValueMessage()); + } + } + + /** + * An empty response, after an error the Cloud Request Engine has + * reported, gives no profiles and raises no error. + */ + @Test + public void HardwareProfile_EmptyResponse_NoProfiles() throws Exception { + try (HardwareProfileCloudEngine engine = engine()) { + assertTrue(process(engine, "").getProfiles().isEmpty()); + } + } +} From cdd4138b3036514764c81e32ab30cf2bb7ad45aa Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 16 Nov 2026 15:40:47 +0000 Subject: [PATCH 22/28] Take the Device Detection test files off the deprecated FileUtils --- .../hash/engine/onpremise/flowelements/NoNamesTests.java | 2 +- .../onpremise/flowelements/ProfilesForPropertyValueTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NoNamesTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NoNamesTests.java index 0d6e05982..5136272e1 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NoNamesTests.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/NoNamesTests.java @@ -35,7 +35,7 @@ import java.util.Arrays; import java.util.List; -import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH; +import static fiftyone.devicedetection.shared.testhelpers.TestFileUtils.LITE_HASH_DATA_FILE_PATH; import static fiftyone.pipeline.util.FileFinder.getFilePath; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ProfilesForPropertyValueTests.java b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ProfilesForPropertyValueTests.java index c9b32ad28..a7f9926af 100644 --- a/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ProfilesForPropertyValueTests.java +++ b/device-detection/device-detection.hash.engine.on-premise/src/test/java/fiftyone/devicedetection/hash/engine/onpremise/flowelements/ProfilesForPropertyValueTests.java @@ -35,7 +35,7 @@ import java.util.HashSet; import java.util.List; -import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH; +import static fiftyone.devicedetection.shared.testhelpers.TestFileUtils.LITE_HASH_DATA_FILE_PATH; import static fiftyone.pipeline.util.FileFinder.getFilePath; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; From 88c03aa09d4527211cc572fc7b5b63c1760e6e5b Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 16 Nov 2026 16:13:34 +0000 Subject: [PATCH 23/28] Keep rc's getNamedKey and isInvalidKey, which the merge of rc gave the examples' KeyHelper a second time --- .../examples/shared/KeyHelper.java | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/KeyHelper.java b/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/KeyHelper.java index babe30358..9f5b6729c 100644 --- a/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/KeyHelper.java +++ b/examples/device-detection/shared/src/main/java/fiftyone/devicedetection/examples/shared/KeyHelper.java @@ -82,40 +82,6 @@ public static boolean isInvalidKey(String keyValue) { "_51DEGREES_RESOURCE_KEY", "_51DEGREES_RESOURCE_KEY_BESPOKE")); - /** - * Read a key from an environment variable of the name given, then of the - * name in upper case, then from a system property of the name given. - * @param keyName name of the key - * @return the key, or null when none of them is set - */ - public static String getNamedKey(String keyName) { - String resourceKey = System.getenv(keyName); - if (Objects.isNull(resourceKey)) { - resourceKey = System.getenv(keyName.toUpperCase()); - if (Objects.isNull(resourceKey)) { - resourceKey = System.getProperty(keyName); - } - } - return resourceKey; - } - - /** - * Whether a key cannot be valid, being missing, too short, or not URL - * safe Base64 of enough bytes. - * @param keyValue value to check - * @return true when the key cannot be valid - */ - public static boolean isInvalidKey(String keyValue) { - Base64.Decoder decoder = Base64.getUrlDecoder(); - try { - return Objects.isNull(keyValue) || - keyValue.trim().length() < 19 || - decoder.decode(keyValue).length < 14; - } catch (IllegalArgumentException e) { - return true; - } - } - static final String CREATE_KEY_URL = "https://51degrees.com/configure/?utm_source=code&utm_medium=example&utm_campaign=51degrees-java&utm_content=shared-src-main-java-fiftyone-devicedetection-examples-shared-keyhelper.java&utm_term=no-resource-key"; From e8c25590a36771cefe3ed1eeb23875a4ca88efb4 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 16 Nov 2026 18:02:04 +0000 Subject: [PATCH 24/28] Keep FileUtils and KeyUtils in the published jar, deprecated, as rc has them --- .../fiftyone/devicedetection/shared/testhelpers/FileUtils.java | 0 .../fiftyone/devicedetection/shared/testhelpers/KeyUtils.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename device-detection/device-detection.shared/src/{test => main}/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java (100%) rename device-detection/device-detection.shared/src/{test => main}/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java (100%) diff --git a/device-detection/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java b/device-detection/device-detection.shared/src/main/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java similarity index 100% rename from device-detection/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java rename to device-detection/device-detection.shared/src/main/java/fiftyone/devicedetection/shared/testhelpers/FileUtils.java diff --git a/device-detection/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java b/device-detection/device-detection.shared/src/main/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java similarity index 100% rename from device-detection/device-detection.shared/src/test/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java rename to device-detection/device-detection.shared/src/main/java/fiftyone/devicedetection/shared/testhelpers/KeyUtils.java From 60d509f2f1fbe5c56437cd581b85d8e991d2206d Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 16 Nov 2026 18:02:40 +0000 Subject: [PATCH 25/28] Let the published jar keep the two deprecated test helpers, and nothing else of the kind --- .../PublishedPackagesHoldNoTestsTests.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java index a16362f0b..904c06e18 100644 --- a/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java +++ b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java @@ -33,6 +33,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Enumeration; import java.util.List; import java.util.jar.JarEntry; @@ -84,7 +85,18 @@ private static List entriesOf(Class type) return entries; } + /** + * Test helpers that stay in the published jar, deprecated, because a + * patch release removes no public name. A later release removes them. + */ + private static final List KEPT_DEPRECATED = Arrays.asList( + "fiftyone/devicedetection/shared/testhelpers/FileUtils.class", + "fiftyone/devicedetection/shared/testhelpers/KeyUtils.class"); + private static boolean isTestOrExample(String entry) { + if (KEPT_DEPRECATED.contains(entry)) { + return false; + } String lower = entry.toLowerCase(); return lower.contains("testhelpers/") || lower.contains("/examples/") || From c1e7424b2359f6e21d00f89d1d408bc5cf86f9f4 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 16 Nov 2026 21:11:01 +0000 Subject: [PATCH 26/28] Process through the engine's public process in the empty metadata tests, now the engine leaves processing to the shared logic --- .../cloud/flowelements/EmptyMetadataTests.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/EmptyMetadataTests.java b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/EmptyMetadataTests.java index c7d121c93..e7ddc95cf 100644 --- a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/EmptyMetadataTests.java +++ b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/EmptyMetadataTests.java @@ -27,9 +27,12 @@ import fiftyone.pipeline.cloudrequestengine.flowelements.CloudRequestEngine; import fiftyone.pipeline.core.data.FlowData; import fiftyone.pipeline.core.flowelements.Pipeline; +import fiftyone.pipeline.core.typed.TypedKey; +import fiftyone.pipeline.core.flowelements.FlowElement; import fiftyone.pipeline.engines.data.AspectPropertyValue; import fiftyone.pipeline.engines.services.MissingPropertyServiceDefault; import org.junit.Before; +import org.mockito.ArgumentMatchers; import org.junit.Test; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; @@ -222,13 +225,14 @@ private DeviceDetectionCloudEngine buildEngine() throws Exception { return engine; } - private DeviceDataCloud process(DeviceDetectionCloudEngine engine) { + private DeviceDataCloud process(DeviceDetectionCloudEngine engine) + throws Exception { return process(engine, RESPONSE); } private DeviceDataCloud process( DeviceDetectionCloudEngine engine, - String response) { + String response) throws Exception { CloudRequestData cloudData = mock(CloudRequestData.class); when(cloudData.getJsonResponse()).thenReturn(response); @@ -241,7 +245,11 @@ private DeviceDataCloud process( flowData, engine, MissingPropertyServiceDefault.getInstance()); - engine.processEngine(flowData, device); + when(flowData.getOrAdd( + ArgumentMatchers.>any(), + ArgumentMatchers.>any())) + .thenReturn(device); + engine.process(flowData); return device; } } From 96a04e47bbb9c04bfe89353565f414b4d523bdb2 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 16 Nov 2026 22:09:59 +0000 Subject: [PATCH 27/28] Say in the empty metadata tests that the cloud request ran, as the shared logic checks --- .../devicedetection/cloud/flowelements/EmptyMetadataTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/EmptyMetadataTests.java b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/EmptyMetadataTests.java index e7ddc95cf..a07edb7b4 100644 --- a/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/EmptyMetadataTests.java +++ b/device-detection/device-detection.cloud/src/test/java/fiftyone/devicedetection/cloud/flowelements/EmptyMetadataTests.java @@ -235,6 +235,7 @@ private DeviceDataCloud process( String response) throws Exception { CloudRequestData cloudData = mock(CloudRequestData.class); when(cloudData.getJsonResponse()).thenReturn(response); + when(cloudData.getProcessStarted()).thenReturn(true); FlowData flowData = mock(FlowData.class); when(flowData.getFromElement(any(CloudRequestEngine.class))) From 91b52aec57f63d54188f38c8628731779f6f4b28 Mon Sep 17 00:00:00 2001 From: James Rosewell Date: Mon, 16 Nov 2026 22:34:01 +0000 Subject: [PATCH 28/28] Let the published jar keep the folder entry of the two deprecated test helpers --- .../devicedetection/PublishedPackagesHoldNoTestsTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java index 904c06e18..9bea4818b 100644 --- a/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java +++ b/device-detection/device-detection/src/test/java/fiftyone/devicedetection/PublishedPackagesHoldNoTestsTests.java @@ -87,9 +87,11 @@ private static List entriesOf(Class type) /** * Test helpers that stay in the published jar, deprecated, because a - * patch release removes no public name. A later release removes them. + * patch release removes no public name, and the folder a jar lists for + * them. A later release removes them. */ private static final List KEPT_DEPRECATED = Arrays.asList( + "fiftyone/devicedetection/shared/testhelpers/", "fiftyone/devicedetection/shared/testhelpers/FileUtils.class", "fiftyone/devicedetection/shared/testhelpers/KeyUtils.class");