Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
129f538
Test: give each missing property message in the specification's text
jwrosewell Nov 15, 2026
c95a573
Fix: give the missing property messages in the specification's text
jwrosewell Nov 15, 2026
79d32ef
Test: decide a missing property's reason in the specification's order
jwrosewell Nov 15, 2026
8960b86
Fix: decide a missing property's reason in the specification's order
jwrosewell Nov 15, 2026
19e227d
Test: give CloudRequestFailed from the IP Intelligence and location e…
jwrosewell Nov 15, 2026
196b21f
Fix: record a failed cloud request in the IP Intelligence and locatio…
jwrosewell Nov 15, 2026
5b7d01b
Test: read a Device Detection value by its position, with no lookup b…
jwrosewell Nov 15, 2026
b636a06
Fix: say a Device Detection property is held from its position
jwrosewell Nov 15, 2026
a22f3db
Test: read an IP Intelligence value by its position, with no lookup b…
jwrosewell Nov 15, 2026
697634c
Fix: say an IP Intelligence property is held from its position
jwrosewell Nov 15, 2026
cf459d1
Test: turn usage sharing off in every IP Intelligence console example
jwrosewell Nov 15, 2026
4c9baab
Fix: turn usage sharing off in the IP Intelligence console examples
jwrosewell Nov 15, 2026
bff84a9
Test: illustrate a programmatic data update in a Device Detection exa…
jwrosewell Nov 15, 2026
5605ead
Fix: add a console example that updates the data file from code
jwrosewell Nov 15, 2026
7855869
Test: declare on FlowData each exception its methods throw
jwrosewell Nov 15, 2026
474fae8
Fix: declare on FlowData the exceptions its methods throw
jwrosewell Nov 15, 2026
47423fa
Test: keep tests and test helpers out of the published Device Detecti…
jwrosewell Nov 15, 2026
f368fae
Fix: move the test helpers out of the published device-detection.shar…
jwrosewell Nov 15, 2026
5ec7e8d
Test: keep FileUtils and KeyUtils in the published jar, deprecated
jwrosewell Nov 15, 2026
cce971b
Fix: keep FileUtils and KeyUtils in the published jar, deprecated
jwrosewell Nov 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,19 @@ protected void processEngine(FlowData data, DeviceDataCloud aspectData) {
else {
CloudRequestData requestData =
data.getFromElement(cloudRequestEngine);
String json = "";
json = requestData.getJsonResponse();
setCloudRequestFailed(data, aspectData, cloudRequestEngine);
String json = requestData.getJsonResponse();

// A failed request can leave no response, which the Cloud
// Request Engine has reported.
if (json == null || json.isEmpty()) {
logger.warn("The " + getClass().getSimpleName() + " did " +
"not process as the JSON response from the " +
"CloudRequestEngine was null or empty. Please refer to " +
"errors generated by the CloudRequestEngine in the logs " +
"as this indicates an error occurred there.");
return;
}

// Extract data from json to the aspectData instance.
JSONObject jsonObj = new JSONObject(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import fiftyone.devicedetection.shared.testhelpers.UserAgentGenerator;
import fiftyone.pipeline.util.FileFinder;

import static fiftyone.devicedetection.shared.testhelpers.FileUtils.UA_FILE_PATH;
import static fiftyone.devicedetection.shared.testhelpers.TestFileUtils.UA_FILE_PATH;

public class TestsBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import fiftyone.devicedetection.cloud.flowelements.DeviceDetectionCloudEngine;
import fiftyone.devicedetection.cloud.flowelements.DeviceDetectionCloudEngineBuilder;
import fiftyone.devicedetection.shared.testhelpers.KeyUtils;
import fiftyone.devicedetection.shared.testhelpers.TestKeyUtils;
import fiftyone.pipeline.cloudrequestengine.flowelements.CloudRequestEngine;
import fiftyone.pipeline.cloudrequestengine.flowelements.CloudRequestEngineBuilder;
import fiftyone.pipeline.core.flowelements.Pipeline;
Expand All @@ -47,7 +47,7 @@ public class WrapperCloud implements Closeable {
public WrapperCloud() throws Exception {
cloudRequestEngine =
new CloudRequestEngineBuilder(loggerFactory)
.setResourceKey(KeyUtils.getNamedKey("TestResourceKey"))
.setResourceKey(TestKeyUtils.getNamedKey("TestResourceKey"))
.build();
deviceDetectionCloudEngine = new DeviceDetectionCloudEngineBuilder(loggerFactory)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/* *********************************************************************
* 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.CloudRequestEngine;
import fiftyone.pipeline.core.data.AccessiblePropertyMetaData.ProductMetaData;
import fiftyone.pipeline.core.data.AccessiblePropertyMetaData.PropertyMetaData;
import fiftyone.pipeline.core.data.FlowData;
import fiftyone.pipeline.core.data.FlowError;
import fiftyone.pipeline.core.flowelements.Pipeline;
import fiftyone.pipeline.engines.exceptions.PropertyMissingException;
import fiftyone.pipeline.engines.services.MissingPropertyServiceDefault;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* When the Cloud Request Engine's request for the Flow Data failed, a
* property of the Device Detection cloud engine is missing with the
* CloudRequestFailed reason, rather than a reason about the resource key.
*/
public class CloudRequestFailedTests {

private static final String CLOUD_REQUEST_FAILED =
"Property 'hardwarevendor' not found in data for element 'device'. " +
"This is because an upstream cloud request failed, so no data was " +
"available to populate the property.";

private ILoggerFactory loggerFactory;

private CloudRequestEngine requestEngine;

@Before
public void init() {
Logger logger = mock(Logger.class);
loggerFactory = mock(ILoggerFactory.class);
when(loggerFactory.getLogger(anyString())).thenReturn(logger);
}

@Test
public void RequestFailedWithNoResponse_CloudRequestFailed()
throws Exception {
assertCloudRequestFailed(null);
}

@Test
public void RequestFailedWithAnErrorResponse_CloudRequestFailed()
throws Exception {
assertCloudRequestFailed("{ \"errors\": [ \"an error\" ] }");
}

@Test
public void RequestSucceeded_ReasonIsAboutTheResourceKey()
throws Exception {
try (DeviceDetectionCloudEngine engine = buildEngine()) {
DeviceDataCloud data = process(
engine,
"{ \"device\": { \"ismobile\": true } }",
Collections.<FlowError>emptyList());
assertMissing(
"PropertyNotAccessibleWithResourceKey",
null,
data);
}
}

private void assertCloudRequestFailed(String response) throws Exception {
try (DeviceDetectionCloudEngine engine = buildEngine()) {
DeviceDataCloud data = process(
engine,
response,
Collections.<FlowError>singletonList(new FlowError.Default(
new Exception("The cloud request failed."),
requestEngine)));
assertMissing("CloudRequestFailed", CLOUD_REQUEST_FAILED, data);
}
}

private static void assertMissing(
String reason,
String message,
DeviceDataCloud data) {
try {
data.getHardwareVendor();
fail("A PropertyMissingException should have been thrown");
} catch (PropertyMissingException e) {
assertEquals(e.getMessage(), reason, e.getReason().name());
if (message != null) {
assertEquals(message, e.getMessage());
}
}
}

/**
* An engine whose Cloud Request Engine reports the device product,
* holding IsMobile alone.
*/
// thenReturn has a varargs overload, so a generic Map is an unchecked array.
@SuppressWarnings("unchecked")
private DeviceDetectionCloudEngine buildEngine() throws Exception {
DeviceDetectionCloudEngine engine =
new DeviceDetectionCloudEngineBuilder(loggerFactory).build();

ProductMetaData product = new ProductMetaData();
product.dataTier = "test";
product.properties = Arrays.asList(
new PropertyMetaData("ismobile", "Boolean", "cat", null));
Map<String, ProductMetaData> publicProperties = new HashMap<>();
publicProperties.put("device", product);

requestEngine = mock(CloudRequestEngine.class);
when(requestEngine.getPublicProperties()).thenReturn(publicProperties);

Pipeline pipeline = mock(Pipeline.class);
when(pipeline.getElement(CloudRequestEngine.class))
.thenReturn(requestEngine);

engine.addPipeline(pipeline);
return engine;
}

private DeviceDataCloud process(
DeviceDetectionCloudEngine engine,
String response,
Collection<FlowError> errors) 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);
when(flowData.getErrors()).thenReturn(errors);

DeviceDataCloud device = new DeviceDataCloudInternal(
loggerFactory.getLogger(DeviceDataCloud.class.getSimpleName()),
flowData,
engine,
MissingPropertyServiceDefault.getInstance());
try {
engine.processEngine(flowData, device);
} catch (RuntimeException e) {
// A failed request's response may not be readable. The
// property is read afterwards either way, as it is through a
// Pipeline that suppresses process exceptions.
}
return device;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ private AspectPropertyValue<List<String>> getUserAgentsInternal() {
@Override
protected boolean propertyIsAvailable(String propertyName) {
checkState();
// A property the engine has a position for is held by its results,
// so that needs no lookup of the name in native code.
if (indexOf(propertyName) != null) {
return resultsList.isEmpty() == false;
}
for (ResultsHashSwig results : resultsList) {
if (results.containsProperty(Swig.asBytes(propertyName))) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
package fiftyone.devicedetection.hash.engine.onpremise;

import fiftyone.devicedetection.shared.testhelpers.UserAgentGenerator;
import fiftyone.devicedetection.shared.testhelpers.FileUtils;
import fiftyone.devicedetection.shared.testhelpers.TestFileUtils;
import fiftyone.pipeline.engines.Constants;

import static fiftyone.devicedetection.shared.testhelpers.FileUtils.UA_FILE_PATH;
import static fiftyone.devicedetection.shared.testhelpers.TestFileUtils.UA_FILE_PATH;
import static fiftyone.pipeline.util.FileFinder.getFilePath;

public class TestsBase {
Expand All @@ -44,7 +44,7 @@ protected UserAgentGenerator getUserAgents() {

protected void testInitialize(Constants.PerformanceProfiles profile) throws Exception {
wrapper = new WrapperHash(
FileUtils.getHashFile(),
TestFileUtils.getHashFile(),
profile);
userAgents = new UserAgentGenerator(
getFilePath(UA_FILE_PATH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import org.slf4j.ILoggerFactory;
import org.slf4j.LoggerFactory;

import fiftyone.devicedetection.shared.testhelpers.FileUtils;
import fiftyone.devicedetection.shared.testhelpers.TestFileUtils;
import fiftyone.pipeline.engines.Constants;
import fiftyone.pipeline.engines.fiftyone.data.FiftyOneAspectPropertyMetaData;
import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH;
import static fiftyone.devicedetection.shared.testhelpers.FileUtils.TAC_HASH_DATA_FILE_NAME;
import static fiftyone.devicedetection.shared.testhelpers.TestFileUtils.LITE_HASH_DATA_FILE_PATH;
import static fiftyone.devicedetection.shared.testhelpers.TestFileUtils.TAC_HASH_DATA_FILE_NAME;
import static fiftyone.pipeline.util.FileFinder.getFilePath;

public class EngineTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
import java.util.Map;
import java.util.Set;

import static fiftyone.devicedetection.shared.testhelpers.FileUtils.LITE_HASH_DATA_FILE_PATH;
import static fiftyone.devicedetection.shared.testhelpers.FileUtils.TAC_HASH_DATA_FILE_NAME;
import static fiftyone.devicedetection.shared.testhelpers.TestFileUtils.LITE_HASH_DATA_FILE_PATH;
import static fiftyone.devicedetection.shared.testhelpers.TestFileUtils.TAC_HASH_DATA_FILE_NAME;
import static fiftyone.pipeline.util.FileFinder.getFilePath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down
Loading
Loading